blob: c642e642cc83aa04707da8a164101f3940460900 [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 Gregorfd35cde2011-03-02 18:50:38 +000070/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000071/// 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 Gregor14454802011-02-25 02:25:35 +0000378 /// \brief Transform the given nested-name-specifier with source-location
379 /// information.
380 ///
381 /// By default, transforms all of the types and declarations within the
382 /// nested-name-specifier. Subclasses may override this function to provide
383 /// alternate behavior.
384 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
385 NestedNameSpecifierLoc NNS,
386 QualType ObjectType = QualType(),
387 NamedDecl *FirstQualifierInScope = 0);
388
Douglas Gregorf816bd72009-09-03 22:13:48 +0000389 /// \brief Transform the given declaration name.
390 ///
391 /// By default, transforms the types of conversion function, constructor,
392 /// and destructor names and then (if needed) rebuilds the declaration name.
393 /// Identifiers and selectors are returned unmodified. Sublcasses may
394 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000395 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000396 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000397
Douglas Gregord6ff3322009-08-04 16:50:30 +0000398 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000399 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000400 /// \param SS The nested-name-specifier that qualifies the template
401 /// name. This nested-name-specifier must already have been transformed.
402 ///
403 /// \param Name The template name to transform.
404 ///
405 /// \param NameLoc The source location of the template name.
406 ///
407 /// \param ObjectType If we're translating a template name within a member
408 /// access expression, this is the type of the object whose member template
409 /// is being referenced.
410 ///
411 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
412 /// also refers to a name within the current (lexical) scope, this is the
413 /// declaration it refers to.
414 ///
415 /// By default, transforms the template name by transforming the declarations
416 /// and nested-name-specifiers that occur within the template name.
417 /// Subclasses may override this function to provide alternate behavior.
418 TemplateName TransformTemplateName(CXXScopeSpec &SS,
419 TemplateName Name,
420 SourceLocation NameLoc,
421 QualType ObjectType = QualType(),
422 NamedDecl *FirstQualifierInScope = 0);
423
Douglas Gregord6ff3322009-08-04 16:50:30 +0000424 /// \brief Transform the given template argument.
425 ///
Mike Stump11289f42009-09-09 15:08:12 +0000426 /// By default, this operation transforms the type, expression, or
427 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000428 /// new template argument from the transformed result. Subclasses may
429 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000430 ///
431 /// Returns true if there was an error.
432 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
433 TemplateArgumentLoc &Output);
434
Douglas Gregor62e06f22010-12-20 17:31:10 +0000435 /// \brief Transform the given set of template arguments.
436 ///
437 /// By default, this operation transforms all of the template arguments
438 /// in the input set using \c TransformTemplateArgument(), and appends
439 /// the transformed arguments to the output list.
440 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000441 /// Note that this overload of \c TransformTemplateArguments() is merely
442 /// a convenience function. Subclasses that wish to override this behavior
443 /// should override the iterator-based member template version.
444 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000445 /// \param Inputs The set of template arguments to be transformed.
446 ///
447 /// \param NumInputs The number of template arguments in \p Inputs.
448 ///
449 /// \param Outputs The set of transformed template arguments output by this
450 /// routine.
451 ///
452 /// Returns true if an error occurred.
453 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
454 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000455 TemplateArgumentListInfo &Outputs) {
456 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
457 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000458
459 /// \brief Transform the given set of template arguments.
460 ///
461 /// By default, this operation transforms all of the template arguments
462 /// in the input set using \c TransformTemplateArgument(), and appends
463 /// the transformed arguments to the output list.
464 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000465 /// \param First An iterator to the first template argument.
466 ///
467 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000468 ///
469 /// \param Outputs The set of transformed template arguments output by this
470 /// routine.
471 ///
472 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000473 template<typename InputIterator>
474 bool TransformTemplateArguments(InputIterator First,
475 InputIterator Last,
476 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000477
John McCall0ad16662009-10-29 08:12:44 +0000478 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
479 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
480 TemplateArgumentLoc &ArgLoc);
481
John McCallbcd03502009-12-07 02:54:59 +0000482 /// \brief Fakes up a TypeSourceInfo for a type.
483 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
484 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000485 getDerived().getBaseLocation());
486 }
Mike Stump11289f42009-09-09 15:08:12 +0000487
John McCall550e0c22009-10-21 00:40:46 +0000488#define ABSTRACT_TYPELOC(CLASS, PARENT)
489#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000490 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000491#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000492
John McCall31f82722010-11-12 08:19:04 +0000493 QualType
494 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
495 TemplateSpecializationTypeLoc TL,
496 TemplateName Template);
497
498 QualType
499 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
500 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000501 TemplateName Template,
502 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000503
504 QualType
505 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000506 DependentTemplateSpecializationTypeLoc TL,
507 NestedNameSpecifierLoc QualifierLoc);
508
John McCall58f10c32010-03-11 09:03:00 +0000509 /// \brief Transforms the parameters of a function type into the
510 /// given vectors.
511 ///
512 /// The result vectors should be kept in sync; null entries in the
513 /// variables vector are acceptable.
514 ///
515 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000516 bool TransformFunctionTypeParams(SourceLocation Loc,
517 ParmVarDecl **Params, unsigned NumParams,
518 const QualType *ParamTypes,
John McCall58f10c32010-03-11 09:03:00 +0000519 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregordd472162011-01-07 00:20:55 +0000520 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000521
522 /// \brief Transforms a single function-type parameter. Return null
523 /// on error.
Douglas Gregor715e4612011-01-14 22:40:04 +0000524 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
525 llvm::Optional<unsigned> NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +0000526
John McCall31f82722010-11-12 08:19:04 +0000527 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000528
John McCalldadc5752010-08-24 06:29:42 +0000529 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
530 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000531
Douglas Gregorebe10102009-08-20 07:17:43 +0000532#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000533 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000534#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000535 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000536#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000537#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000538
Douglas Gregord6ff3322009-08-04 16:50:30 +0000539 /// \brief Build a new pointer type given its pointee type.
540 ///
541 /// By default, performs semantic analysis when building the pointer type.
542 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000543 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000544
545 /// \brief Build a new block pointer type given its pointee type.
546 ///
Mike Stump11289f42009-09-09 15:08:12 +0000547 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000548 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000549 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000550
John McCall70dd5f62009-10-30 00:06:24 +0000551 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000552 ///
John McCall70dd5f62009-10-30 00:06:24 +0000553 /// By default, performs semantic analysis when building the
554 /// reference type. Subclasses may override this routine to provide
555 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000556 ///
John McCall70dd5f62009-10-30 00:06:24 +0000557 /// \param LValue whether the type was written with an lvalue sigil
558 /// or an rvalue sigil.
559 QualType RebuildReferenceType(QualType ReferentType,
560 bool LValue,
561 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000562
Douglas Gregord6ff3322009-08-04 16:50:30 +0000563 /// \brief Build a new member pointer type given the pointee type and the
564 /// class type it refers into.
565 ///
566 /// By default, performs semantic analysis when building the member pointer
567 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000568 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
569 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000570
Douglas Gregord6ff3322009-08-04 16:50:30 +0000571 /// \brief Build a new array type given the element type, size
572 /// modifier, size of the array (if known), size expression, and index type
573 /// 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 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000578 QualType RebuildArrayType(QualType ElementType,
579 ArrayType::ArraySizeModifier SizeMod,
580 const llvm::APInt *Size,
581 Expr *SizeExpr,
582 unsigned IndexTypeQuals,
583 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000584
Douglas Gregord6ff3322009-08-04 16:50:30 +0000585 /// \brief Build a new constant array type given the element type, size
586 /// modifier, (known) size of the array, and index type qualifiers.
587 ///
588 /// By default, performs semantic analysis when building the array type.
589 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000590 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000591 ArrayType::ArraySizeModifier SizeMod,
592 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000593 unsigned IndexTypeQuals,
594 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000595
Douglas Gregord6ff3322009-08-04 16:50:30 +0000596 /// \brief Build a new incomplete array type given the element type, size
597 /// modifier, and index type qualifiers.
598 ///
599 /// By default, performs semantic analysis when building the array type.
600 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000601 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000602 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000603 unsigned IndexTypeQuals,
604 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000605
Mike Stump11289f42009-09-09 15:08:12 +0000606 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000607 /// size modifier, size expression, and index type qualifiers.
608 ///
609 /// By default, performs semantic analysis when building the array type.
610 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000611 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000612 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000613 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000614 unsigned IndexTypeQuals,
615 SourceRange BracketsRange);
616
Mike Stump11289f42009-09-09 15:08:12 +0000617 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000618 /// size modifier, size expression, and index type qualifiers.
619 ///
620 /// By default, performs semantic analysis when building the array type.
621 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000622 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000623 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000624 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000625 unsigned IndexTypeQuals,
626 SourceRange BracketsRange);
627
628 /// \brief Build a new vector type given the element type and
629 /// number of elements.
630 ///
631 /// By default, performs semantic analysis when building the vector type.
632 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000633 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000634 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000635
Douglas Gregord6ff3322009-08-04 16:50:30 +0000636 /// \brief Build a new extended vector type given the element type and
637 /// number of elements.
638 ///
639 /// By default, performs semantic analysis when building the vector type.
640 /// Subclasses may override this routine to provide different behavior.
641 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
642 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000643
644 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000645 /// given the element type and number of elements.
646 ///
647 /// By default, performs semantic analysis when building the vector type.
648 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000649 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000650 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000651 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000652
Douglas Gregord6ff3322009-08-04 16:50:30 +0000653 /// \brief Build a new function type.
654 ///
655 /// By default, performs semantic analysis when building the function type.
656 /// Subclasses may override this routine to provide different behavior.
657 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000658 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000659 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000660 bool Variadic, unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +0000661 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +0000662 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000663
John McCall550e0c22009-10-21 00:40:46 +0000664 /// \brief Build a new unprototyped function type.
665 QualType RebuildFunctionNoProtoType(QualType ResultType);
666
John McCallb96ec562009-12-04 22:46:56 +0000667 /// \brief Rebuild an unresolved typename type, given the decl that
668 /// the UnresolvedUsingTypenameDecl was transformed to.
669 QualType RebuildUnresolvedUsingType(Decl *D);
670
Douglas Gregord6ff3322009-08-04 16:50:30 +0000671 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000672 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000673 return SemaRef.Context.getTypeDeclType(Typedef);
674 }
675
676 /// \brief Build a new class/struct/union type.
677 QualType RebuildRecordType(RecordDecl *Record) {
678 return SemaRef.Context.getTypeDeclType(Record);
679 }
680
681 /// \brief Build a new Enum type.
682 QualType RebuildEnumType(EnumDecl *Enum) {
683 return SemaRef.Context.getTypeDeclType(Enum);
684 }
John McCallfcc33b02009-09-05 00:15:47 +0000685
Mike Stump11289f42009-09-09 15:08:12 +0000686 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000687 ///
688 /// By default, performs semantic analysis when building the typeof type.
689 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000690 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000691
Mike Stump11289f42009-09-09 15:08:12 +0000692 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000693 ///
694 /// By default, builds a new TypeOfType with the given underlying type.
695 QualType RebuildTypeOfType(QualType Underlying);
696
Mike Stump11289f42009-09-09 15:08:12 +0000697 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000698 ///
699 /// By default, performs semantic analysis when building the decltype type.
700 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000701 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000702
Richard Smith30482bc2011-02-20 03:19:35 +0000703 /// \brief Build a new C++0x auto type.
704 ///
705 /// By default, builds a new AutoType with the given deduced type.
706 QualType RebuildAutoType(QualType Deduced) {
707 return SemaRef.Context.getAutoType(Deduced);
708 }
709
Douglas Gregord6ff3322009-08-04 16:50:30 +0000710 /// \brief Build a new template specialization type.
711 ///
712 /// By default, performs semantic analysis when building the template
713 /// specialization type. Subclasses may override this routine to provide
714 /// different behavior.
715 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000716 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000717 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000718
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000719 /// \brief Build a new parenthesized type.
720 ///
721 /// By default, builds a new ParenType type from the inner type.
722 /// Subclasses may override this routine to provide different behavior.
723 QualType RebuildParenType(QualType InnerType) {
724 return SemaRef.Context.getParenType(InnerType);
725 }
726
Douglas Gregord6ff3322009-08-04 16:50:30 +0000727 /// \brief Build a new qualified name type.
728 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000729 /// By default, builds a new ElaboratedType type from the keyword,
730 /// the nested-name-specifier and the named type.
731 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000732 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
733 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000734 NestedNameSpecifierLoc QualifierLoc,
735 QualType Named) {
736 return SemaRef.Context.getElaboratedType(Keyword,
737 QualifierLoc.getNestedNameSpecifier(),
738 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000739 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740
741 /// \brief Build a new typename type that refers to a template-id.
742 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000743 /// By default, builds a new DependentNameType type from the
744 /// nested-name-specifier and the given type. Subclasses may override
745 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000746 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000747 ElaboratedTypeKeyword Keyword,
748 NestedNameSpecifierLoc QualifierLoc,
749 const IdentifierInfo *Name,
750 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000751 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000752 // Rebuild the template name.
753 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000754 CXXScopeSpec SS;
755 SS.Adopt(QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000756 TemplateName InstName
Douglas Gregor9db53502011-03-02 18:07:45 +0000757 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000758
759 if (InstName.isNull())
760 return QualType();
761
762 // If it's still dependent, make a dependent specialization.
763 if (InstName.getAsDependentTemplateName())
764 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
765 QualifierLoc.getNestedNameSpecifier(),
766 Name,
767 Args);
768
769 // Otherwise, make an elaborated type wrapping a non-dependent
770 // specialization.
771 QualType T =
772 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
773 if (T.isNull()) return QualType();
774
775 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
776 return T;
777
778 return SemaRef.Context.getElaboratedType(Keyword,
779 QualifierLoc.getNestedNameSpecifier(),
780 T);
781 }
782
Douglas Gregord6ff3322009-08-04 16:50:30 +0000783 /// \brief Build a new typename type that refers to an identifier.
784 ///
785 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000786 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000787 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000788 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000789 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000790 NestedNameSpecifierLoc QualifierLoc,
791 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000792 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000793 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000794 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000795
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000796 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000797 // If the name is still dependent, just build a new dependent name type.
798 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000799 return SemaRef.Context.getDependentNameType(Keyword,
800 QualifierLoc.getNestedNameSpecifier(),
801 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000802 }
803
Abramo Bagnara6150c882010-05-11 21:36:43 +0000804 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000805 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000806 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000807
808 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
809
Abramo Bagnarad7548482010-05-19 21:37:53 +0000810 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000811 // into a non-dependent elaborated-type-specifier. Find the tag we're
812 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000813 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000814 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
815 if (!DC)
816 return QualType();
817
John McCallbf8c5192010-05-27 06:40:31 +0000818 if (SemaRef.RequireCompleteDeclContext(SS, DC))
819 return QualType();
820
Douglas Gregore677daf2010-03-31 22:19:08 +0000821 TagDecl *Tag = 0;
822 SemaRef.LookupQualifiedName(Result, DC);
823 switch (Result.getResultKind()) {
824 case LookupResult::NotFound:
825 case LookupResult::NotFoundInCurrentInstantiation:
826 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000827
Douglas Gregore677daf2010-03-31 22:19:08 +0000828 case LookupResult::Found:
829 Tag = Result.getAsSingle<TagDecl>();
830 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000831
Douglas Gregore677daf2010-03-31 22:19:08 +0000832 case LookupResult::FoundOverloaded:
833 case LookupResult::FoundUnresolvedValue:
834 llvm_unreachable("Tag lookup cannot find non-tags");
835 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000836
Douglas Gregore677daf2010-03-31 22:19:08 +0000837 case LookupResult::Ambiguous:
838 // Let the LookupResult structure handle ambiguities.
839 return QualType();
840 }
841
842 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000843 // Check where the name exists but isn't a tag type and use that to emit
844 // better diagnostics.
845 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
846 SemaRef.LookupQualifiedName(Result, DC);
847 switch (Result.getResultKind()) {
848 case LookupResult::Found:
849 case LookupResult::FoundOverloaded:
850 case LookupResult::FoundUnresolvedValue: {
851 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
852 unsigned Kind = 0;
853 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000854 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
855 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000856 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
857 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
858 break;
859 }
860 default:
861 // FIXME: Would be nice to highlight just the source range.
862 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
863 << Kind << Id << DC;
864 break;
865 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000866 return QualType();
867 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000868
Abramo Bagnarad7548482010-05-19 21:37:53 +0000869 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
870 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000871 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
872 return QualType();
873 }
874
875 // Build the elaborated-type-specifier type.
876 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000877 return SemaRef.Context.getElaboratedType(Keyword,
878 QualifierLoc.getNestedNameSpecifier(),
879 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000880 }
Mike Stump11289f42009-09-09 15:08:12 +0000881
Douglas Gregor822d0302011-01-12 17:07:58 +0000882 /// \brief Build a new pack expansion type.
883 ///
884 /// By default, builds a new PackExpansionType type from the given pattern.
885 /// Subclasses may override this routine to provide different behavior.
886 QualType RebuildPackExpansionType(QualType Pattern,
887 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000888 SourceLocation EllipsisLoc,
889 llvm::Optional<unsigned> NumExpansions) {
890 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
891 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000892 }
893
Douglas Gregor71dc5092009-08-06 06:41:21 +0000894 /// \brief Build a new template name given a nested name specifier, a flag
895 /// indicating whether the "template" keyword was provided, and the template
896 /// that the template name refers to.
897 ///
898 /// By default, builds the new template name directly. Subclasses may override
899 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000900 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +0000901 bool TemplateKW,
902 TemplateDecl *Template);
903
Douglas Gregor71dc5092009-08-06 06:41:21 +0000904 /// \brief Build a new template name given a nested name specifier and the
905 /// name that is referred to as a template.
906 ///
907 /// By default, performs semantic analysis to determine whether the name can
908 /// be resolved to a specific template, then builds the appropriate kind of
909 /// template name. Subclasses may override this routine to provide different
910 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000911 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
912 const IdentifierInfo &Name,
913 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +0000914 QualType ObjectType,
915 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000916
Douglas Gregor71395fa2009-11-04 00:56:37 +0000917 /// \brief Build a new template name given a nested name specifier and the
918 /// overloaded operator name that is referred to as a template.
919 ///
920 /// By default, performs semantic analysis to determine whether the name can
921 /// be resolved to a specific template, then builds the appropriate kind of
922 /// template name. Subclasses may override this routine to provide different
923 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000924 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000925 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +0000926 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000927 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000928
929 /// \brief Build a new template name given a template template parameter pack
930 /// and the
931 ///
932 /// By default, performs semantic analysis to determine whether the name can
933 /// be resolved to a specific template, then builds the appropriate kind of
934 /// template name. Subclasses may override this routine to provide different
935 /// behavior.
936 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
937 const TemplateArgument &ArgPack) {
938 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
939 }
940
Douglas Gregorebe10102009-08-20 07:17:43 +0000941 /// \brief Build a new compound statement.
942 ///
943 /// By default, performs semantic analysis to build the new statement.
944 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000945 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000946 MultiStmtArg Statements,
947 SourceLocation RBraceLoc,
948 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000949 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000950 IsStmtExpr);
951 }
952
953 /// \brief Build a new case statement.
954 ///
955 /// By default, performs semantic analysis to build the new statement.
956 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000957 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000958 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000959 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000960 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000961 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000962 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000963 ColonLoc);
964 }
Mike Stump11289f42009-09-09 15:08:12 +0000965
Douglas Gregorebe10102009-08-20 07:17:43 +0000966 /// \brief Attach the body to a new case statement.
967 ///
968 /// By default, performs semantic analysis to build the new statement.
969 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000970 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000971 getSema().ActOnCaseStmtBody(S, Body);
972 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000973 }
Mike Stump11289f42009-09-09 15:08:12 +0000974
Douglas Gregorebe10102009-08-20 07:17:43 +0000975 /// \brief Build a new default statement.
976 ///
977 /// By default, performs semantic analysis to build the new statement.
978 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000979 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000980 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000981 Stmt *SubStmt) {
982 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000983 /*CurScope=*/0);
984 }
Mike Stump11289f42009-09-09 15:08:12 +0000985
Douglas Gregorebe10102009-08-20 07:17:43 +0000986 /// \brief Build a new label statement.
987 ///
988 /// By default, performs semantic analysis to build the new statement.
989 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +0000990 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
991 SourceLocation ColonLoc, Stmt *SubStmt) {
992 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +0000993 }
Mike Stump11289f42009-09-09 15:08:12 +0000994
Douglas Gregorebe10102009-08-20 07:17:43 +0000995 /// \brief Build a new "if" statement.
996 ///
997 /// By default, performs semantic analysis to build the new statement.
998 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000999 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattnercab02a62011-02-17 20:34:02 +00001000 VarDecl *CondVar, Stmt *Then,
1001 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001002 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001003 }
Mike Stump11289f42009-09-09 15:08:12 +00001004
Douglas Gregorebe10102009-08-20 07:17:43 +00001005 /// \brief Start building a new switch statement.
1006 ///
1007 /// By default, performs semantic analysis to build the new statement.
1008 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001009 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001010 Expr *Cond, VarDecl *CondVar) {
John McCallb268a282010-08-23 23:25:46 +00001011 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001012 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001013 }
Mike Stump11289f42009-09-09 15:08:12 +00001014
Douglas Gregorebe10102009-08-20 07:17:43 +00001015 /// \brief Attach the body to the switch statement.
1016 ///
1017 /// By default, performs semantic analysis to build the new statement.
1018 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001019 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001020 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001021 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001022 }
1023
1024 /// \brief Build a new while statement.
1025 ///
1026 /// By default, performs semantic analysis to build the new statement.
1027 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001028 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1029 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001030 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001031 }
Mike Stump11289f42009-09-09 15:08:12 +00001032
Douglas Gregorebe10102009-08-20 07:17:43 +00001033 /// \brief Build a new do-while statement.
1034 ///
1035 /// By default, performs semantic analysis to build the new statement.
1036 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001037 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001038 SourceLocation WhileLoc, SourceLocation LParenLoc,
1039 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001040 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1041 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001042 }
1043
1044 /// \brief Build a new for statement.
1045 ///
1046 /// By default, performs semantic analysis to build the new statement.
1047 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001048 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1049 Stmt *Init, Sema::FullExprArg Cond,
1050 VarDecl *CondVar, Sema::FullExprArg Inc,
1051 SourceLocation RParenLoc, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001052 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001053 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001054 }
Mike Stump11289f42009-09-09 15:08:12 +00001055
Douglas Gregorebe10102009-08-20 07:17:43 +00001056 /// \brief Build a new goto statement.
1057 ///
1058 /// By default, performs semantic analysis to build the new statement.
1059 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001060 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1061 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001062 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001063 }
1064
1065 /// \brief Build a new indirect goto statement.
1066 ///
1067 /// By default, performs semantic analysis to build the new statement.
1068 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001069 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001070 SourceLocation StarLoc,
1071 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001072 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001073 }
Mike Stump11289f42009-09-09 15:08:12 +00001074
Douglas Gregorebe10102009-08-20 07:17:43 +00001075 /// \brief Build a new return statement.
1076 ///
1077 /// By default, performs semantic analysis to build the new statement.
1078 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001079 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001080 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001081 }
Mike Stump11289f42009-09-09 15:08:12 +00001082
Douglas Gregorebe10102009-08-20 07:17:43 +00001083 /// \brief Build a new declaration statement.
1084 ///
1085 /// By default, performs semantic analysis to build the new statement.
1086 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001087 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001088 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001089 SourceLocation EndLoc) {
Richard Smith2abf6762011-02-23 00:37:57 +00001090 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1091 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001092 }
Mike Stump11289f42009-09-09 15:08:12 +00001093
Anders Carlssonaaeef072010-01-24 05:50:09 +00001094 /// \brief Build a new inline asm statement.
1095 ///
1096 /// By default, performs semantic analysis to build the new statement.
1097 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001098 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001099 bool IsSimple,
1100 bool IsVolatile,
1101 unsigned NumOutputs,
1102 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001103 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001104 MultiExprArg Constraints,
1105 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001106 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001107 MultiExprArg Clobbers,
1108 SourceLocation RParenLoc,
1109 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001110 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001111 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001112 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001113 RParenLoc, MSAsm);
1114 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001115
1116 /// \brief Build a new Objective-C @try statement.
1117 ///
1118 /// By default, performs semantic analysis to build the new statement.
1119 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001120 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001121 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001122 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001123 Stmt *Finally) {
1124 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1125 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001126 }
1127
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001128 /// \brief Rebuild an Objective-C exception declaration.
1129 ///
1130 /// By default, performs semantic analysis to build the new declaration.
1131 /// Subclasses may override this routine to provide different behavior.
1132 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1133 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001134 return getSema().BuildObjCExceptionDecl(TInfo, T,
1135 ExceptionDecl->getInnerLocStart(),
1136 ExceptionDecl->getLocation(),
1137 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001138 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001139
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001140 /// \brief Build a new Objective-C @catch statement.
1141 ///
1142 /// By default, performs semantic analysis to build the new statement.
1143 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001144 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001145 SourceLocation RParenLoc,
1146 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001147 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001148 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001149 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001150 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001151
Douglas Gregor306de2f2010-04-22 23:59:56 +00001152 /// \brief Build a new Objective-C @finally statement.
1153 ///
1154 /// By default, performs semantic analysis to build the new statement.
1155 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001156 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001157 Stmt *Body) {
1158 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001159 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001160
Douglas Gregor6148de72010-04-22 22:01:21 +00001161 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001162 ///
1163 /// By default, performs semantic analysis to build the new statement.
1164 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001165 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001166 Expr *Operand) {
1167 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001168 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001169
Douglas Gregor6148de72010-04-22 22:01:21 +00001170 /// \brief Build a new Objective-C @synchronized statement.
1171 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001172 /// By default, performs semantic analysis to build the new statement.
1173 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001174 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001175 Expr *Object,
1176 Stmt *Body) {
1177 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1178 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001179 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001180
1181 /// \brief Build a new Objective-C fast enumeration statement.
1182 ///
1183 /// By default, performs semantic analysis to build the new statement.
1184 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001185 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001186 SourceLocation LParenLoc,
1187 Stmt *Element,
1188 Expr *Collection,
1189 SourceLocation RParenLoc,
1190 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001191 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001192 Element,
1193 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001194 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001195 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001196 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001197
Douglas Gregorebe10102009-08-20 07:17:43 +00001198 /// \brief Build a new C++ exception declaration.
1199 ///
1200 /// By default, performs semantic analysis to build the new decaration.
1201 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001202 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001203 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001204 SourceLocation StartLoc,
1205 SourceLocation IdLoc,
1206 IdentifierInfo *Id) {
Douglas Gregor40965fa2011-04-14 22:32:28 +00001207 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1208 StartLoc, IdLoc, Id);
1209 if (Var)
1210 getSema().CurContext->addDecl(Var);
1211 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001212 }
1213
1214 /// \brief Build a new C++ catch statement.
1215 ///
1216 /// By default, performs semantic analysis to build the new statement.
1217 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001218 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001219 VarDecl *ExceptionDecl,
1220 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001221 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1222 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001223 }
Mike Stump11289f42009-09-09 15:08:12 +00001224
Douglas Gregorebe10102009-08-20 07:17:43 +00001225 /// \brief Build a new C++ try statement.
1226 ///
1227 /// By default, performs semantic analysis to build the new statement.
1228 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001229 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001230 Stmt *TryBlock,
1231 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001232 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001233 }
Mike Stump11289f42009-09-09 15:08:12 +00001234
Richard Smith02e85f32011-04-14 22:09:26 +00001235 /// \brief Build a new C++0x range-based for statement.
1236 ///
1237 /// By default, performs semantic analysis to build the new statement.
1238 /// Subclasses may override this routine to provide different behavior.
1239 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1240 SourceLocation ColonLoc,
1241 Stmt *Range, Stmt *BeginEnd,
1242 Expr *Cond, Expr *Inc,
1243 Stmt *LoopVar,
1244 SourceLocation RParenLoc) {
1245 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1246 Cond, Inc, LoopVar, RParenLoc);
1247 }
1248
1249 /// \brief Attach body to a C++0x range-based for statement.
1250 ///
1251 /// By default, performs semantic analysis to finish the new statement.
1252 /// Subclasses may override this routine to provide different behavior.
1253 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1254 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1255 }
1256
Douglas Gregora16548e2009-08-11 05:31:07 +00001257 /// \brief Build a new expression that references a declaration.
1258 ///
1259 /// By default, performs semantic analysis to build the new expression.
1260 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001261 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001262 LookupResult &R,
1263 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001264 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1265 }
1266
1267
1268 /// \brief Build a new expression that references a declaration.
1269 ///
1270 /// By default, performs semantic analysis to build the new expression.
1271 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001272 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001273 ValueDecl *VD,
1274 const DeclarationNameInfo &NameInfo,
1275 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001276 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001277 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001278
1279 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001280
1281 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001282 }
Mike Stump11289f42009-09-09 15:08:12 +00001283
Douglas Gregora16548e2009-08-11 05:31:07 +00001284 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001285 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001286 /// By default, performs semantic analysis to build the new expression.
1287 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001288 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001289 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001290 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001291 }
1292
Douglas Gregorad8a3362009-09-04 17:36:40 +00001293 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001294 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001295 /// By default, performs semantic analysis to build the new expression.
1296 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001297 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001298 SourceLocation OperatorLoc,
1299 bool isArrow,
1300 CXXScopeSpec &SS,
1301 TypeSourceInfo *ScopeType,
1302 SourceLocation CCLoc,
1303 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001304 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001305
Douglas Gregora16548e2009-08-11 05:31:07 +00001306 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001307 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001308 /// By default, performs semantic analysis to build the new expression.
1309 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001310 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001311 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001312 Expr *SubExpr) {
1313 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001314 }
Mike Stump11289f42009-09-09 15:08:12 +00001315
Douglas Gregor882211c2010-04-28 22:16:22 +00001316 /// \brief Build a new builtin offsetof expression.
1317 ///
1318 /// By default, performs semantic analysis to build the new expression.
1319 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001320 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001321 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001322 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001323 unsigned NumComponents,
1324 SourceLocation RParenLoc) {
1325 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1326 NumComponents, RParenLoc);
1327 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001328
Peter Collingbournee190dee2011-03-11 19:24:49 +00001329 /// \brief Build a new sizeof, alignof or vec_step expression with a
1330 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001331 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 /// By default, performs semantic analysis to build the new expression.
1333 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001334 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1335 SourceLocation OpLoc,
1336 UnaryExprOrTypeTrait ExprKind,
1337 SourceRange R) {
1338 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001339 }
1340
Peter Collingbournee190dee2011-03-11 19:24:49 +00001341 /// \brief Build a new sizeof, alignof or vec step expression with an
1342 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001343 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001344 /// By default, performs semantic analysis to build the new expression.
1345 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001346 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1347 UnaryExprOrTypeTrait ExprKind,
1348 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001349 ExprResult Result
Peter Collingbournee190dee2011-03-11 19:24:49 +00001350 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001351 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001352 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001353
Douglas Gregora16548e2009-08-11 05:31:07 +00001354 return move(Result);
1355 }
Mike Stump11289f42009-09-09 15:08:12 +00001356
Douglas Gregora16548e2009-08-11 05:31:07 +00001357 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001358 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001359 /// By default, performs semantic analysis to build the new expression.
1360 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001361 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001362 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001363 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001364 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001365 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1366 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001367 RBracketLoc);
1368 }
1369
1370 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001371 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001372 /// By default, performs semantic analysis to build the new expression.
1373 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001374 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001375 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001376 SourceLocation RParenLoc,
1377 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001378 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001379 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001380 }
1381
1382 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001383 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001384 /// By default, performs semantic analysis to build the new expression.
1385 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001386 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001387 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001388 NestedNameSpecifierLoc QualifierLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001389 const DeclarationNameInfo &MemberNameInfo,
1390 ValueDecl *Member,
1391 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001392 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001393 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001394 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001395 // We have a reference to an unnamed field. This is always the
1396 // base of an anonymous struct/union member access, i.e. the
1397 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001398 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001399 assert(Member->getType()->isRecordType() &&
1400 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001401
John Wiegley01296292011-04-08 18:41:53 +00001402 ExprResult BaseResult =
1403 getSema().PerformObjectMemberConversion(Base,
1404 QualifierLoc.getNestedNameSpecifier(),
1405 FoundDecl, Member);
1406 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001407 return ExprError();
John Wiegley01296292011-04-08 18:41:53 +00001408 Base = BaseResult.take();
John McCall7decc9e2010-11-18 06:31:45 +00001409 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001410 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001411 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001412 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001413 cast<FieldDecl>(Member)->getType(),
1414 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001415 return getSema().Owned(ME);
1416 }
Mike Stump11289f42009-09-09 15:08:12 +00001417
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001418 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001419 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001420
John Wiegley01296292011-04-08 18:41:53 +00001421 ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base);
1422 if (BaseResult.isInvalid())
1423 return ExprError();
1424 Base = BaseResult.take();
John McCallb268a282010-08-23 23:25:46 +00001425 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001426
John McCall16df1e52010-03-30 21:47:33 +00001427 // FIXME: this involves duplicating earlier analysis in a lot of
1428 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001429 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001430 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001431 R.resolveKind();
1432
John McCallb268a282010-08-23 23:25:46 +00001433 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001434 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001435 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001436 }
Mike Stump11289f42009-09-09 15:08:12 +00001437
Douglas Gregora16548e2009-08-11 05:31:07 +00001438 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001439 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001440 /// By default, performs semantic analysis to build the new expression.
1441 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001442 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001443 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001444 Expr *LHS, Expr *RHS) {
1445 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001446 }
1447
1448 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001449 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001450 /// By default, performs semantic analysis to build the new expression.
1451 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001452 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001453 SourceLocation QuestionLoc,
1454 Expr *LHS,
1455 SourceLocation ColonLoc,
1456 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001457 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1458 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001459 }
1460
Douglas Gregora16548e2009-08-11 05:31:07 +00001461 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001462 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001463 /// By default, performs semantic analysis to build the new expression.
1464 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001465 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001466 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001467 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001468 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001469 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001470 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001471 }
Mike Stump11289f42009-09-09 15:08:12 +00001472
Douglas Gregora16548e2009-08-11 05:31:07 +00001473 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001474 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001475 /// By default, performs semantic analysis to build the new expression.
1476 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001477 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001478 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001479 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001480 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001481 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001482 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001483 }
Mike Stump11289f42009-09-09 15:08:12 +00001484
Douglas Gregora16548e2009-08-11 05:31:07 +00001485 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001486 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001487 /// By default, performs semantic analysis to build the new expression.
1488 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001489 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001490 SourceLocation OpLoc,
1491 SourceLocation AccessorLoc,
1492 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001493
John McCall10eae182009-11-30 22:42:35 +00001494 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001495 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001496 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001497 OpLoc, /*IsArrow*/ false,
1498 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001499 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001500 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001501 }
Mike Stump11289f42009-09-09 15:08:12 +00001502
Douglas Gregora16548e2009-08-11 05:31:07 +00001503 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001504 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001505 /// By default, performs semantic analysis to build the new expression.
1506 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001507 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001508 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001509 SourceLocation RBraceLoc,
1510 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001511 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001512 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1513 if (Result.isInvalid() || ResultTy->isDependentType())
1514 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001515
Douglas Gregord3d93062009-11-09 17:16:50 +00001516 // Patch in the result type we were given, which may have been computed
1517 // when the initial InitListExpr was built.
1518 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1519 ILE->setType(ResultTy);
1520 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001521 }
Mike Stump11289f42009-09-09 15:08:12 +00001522
Douglas Gregora16548e2009-08-11 05:31:07 +00001523 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001524 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001525 /// By default, performs semantic analysis to build the new expression.
1526 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001527 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001528 MultiExprArg ArrayExprs,
1529 SourceLocation EqualOrColonLoc,
1530 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001531 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001532 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001533 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001534 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001535 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001536 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001537
Douglas Gregora16548e2009-08-11 05:31:07 +00001538 ArrayExprs.release();
1539 return move(Result);
1540 }
Mike Stump11289f42009-09-09 15:08:12 +00001541
Douglas Gregora16548e2009-08-11 05:31:07 +00001542 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001543 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001544 /// By default, builds the implicit value initialization without performing
1545 /// any semantic analysis. Subclasses may override this routine to provide
1546 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001547 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001548 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1549 }
Mike Stump11289f42009-09-09 15:08:12 +00001550
Douglas Gregora16548e2009-08-11 05:31:07 +00001551 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001552 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001553 /// By default, performs semantic analysis to build the new expression.
1554 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001555 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001556 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001557 SourceLocation RParenLoc) {
1558 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001559 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001560 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001561 }
1562
1563 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001564 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001565 /// By default, performs semantic analysis to build the new expression.
1566 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001567 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001568 MultiExprArg SubExprs,
1569 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001570 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001571 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001572 }
Mike Stump11289f42009-09-09 15:08:12 +00001573
Douglas Gregora16548e2009-08-11 05:31:07 +00001574 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001575 ///
1576 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001577 /// rather than attempting to map the label statement itself.
1578 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001579 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001580 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001581 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001582 }
Mike Stump11289f42009-09-09 15:08:12 +00001583
Douglas Gregora16548e2009-08-11 05:31:07 +00001584 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001585 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001586 /// By default, performs semantic analysis to build the new expression.
1587 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001588 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001589 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001590 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001591 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001592 }
Mike Stump11289f42009-09-09 15:08:12 +00001593
Douglas Gregora16548e2009-08-11 05:31:07 +00001594 /// \brief Build a new __builtin_choose_expr expression.
1595 ///
1596 /// By default, performs semantic analysis to build the new expression.
1597 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001598 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001599 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001600 SourceLocation RParenLoc) {
1601 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001602 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001603 RParenLoc);
1604 }
Mike Stump11289f42009-09-09 15:08:12 +00001605
Peter Collingbourne91147592011-04-15 00:35:48 +00001606 /// \brief Build a new generic selection expression.
1607 ///
1608 /// By default, performs semantic analysis to build the new expression.
1609 /// Subclasses may override this routine to provide different behavior.
1610 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1611 SourceLocation DefaultLoc,
1612 SourceLocation RParenLoc,
1613 Expr *ControllingExpr,
1614 TypeSourceInfo **Types,
1615 Expr **Exprs,
1616 unsigned NumAssocs) {
1617 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1618 ControllingExpr, Types, Exprs,
1619 NumAssocs);
1620 }
1621
Douglas Gregora16548e2009-08-11 05:31:07 +00001622 /// \brief Build a new overloaded operator call expression.
1623 ///
1624 /// By default, performs semantic analysis to build the new expression.
1625 /// The semantic analysis provides the behavior of template instantiation,
1626 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001627 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001628 /// argument-dependent lookup, etc. Subclasses may override this routine to
1629 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001630 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001631 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001632 Expr *Callee,
1633 Expr *First,
1634 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001635
1636 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001637 /// reinterpret_cast.
1638 ///
1639 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001640 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001641 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001642 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001643 Stmt::StmtClass Class,
1644 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001645 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001646 SourceLocation RAngleLoc,
1647 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001648 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001649 SourceLocation RParenLoc) {
1650 switch (Class) {
1651 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001652 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001653 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001654 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001655
1656 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001657 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001658 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001659 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001660
Douglas Gregora16548e2009-08-11 05:31:07 +00001661 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001662 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001663 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001664 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001665 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001666
Douglas Gregora16548e2009-08-11 05:31:07 +00001667 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001668 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001669 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001670 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001671
Douglas Gregora16548e2009-08-11 05:31:07 +00001672 default:
1673 assert(false && "Invalid C++ named cast");
1674 break;
1675 }
Mike Stump11289f42009-09-09 15:08:12 +00001676
John McCallfaf5fb42010-08-26 23:41:50 +00001677 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001678 }
Mike Stump11289f42009-09-09 15:08:12 +00001679
Douglas Gregora16548e2009-08-11 05:31:07 +00001680 /// \brief Build a new C++ static_cast expression.
1681 ///
1682 /// By default, performs semantic analysis to build the new expression.
1683 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001684 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001685 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001686 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001687 SourceLocation RAngleLoc,
1688 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001689 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001690 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001691 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001692 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001693 SourceRange(LAngleLoc, RAngleLoc),
1694 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001695 }
1696
1697 /// \brief Build a new C++ dynamic_cast expression.
1698 ///
1699 /// By default, performs semantic analysis to build the new expression.
1700 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001701 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001702 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001703 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001704 SourceLocation RAngleLoc,
1705 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001706 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001707 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001708 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001709 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001710 SourceRange(LAngleLoc, RAngleLoc),
1711 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001712 }
1713
1714 /// \brief Build a new C++ reinterpret_cast expression.
1715 ///
1716 /// By default, performs semantic analysis to build the new expression.
1717 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001718 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001719 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001720 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001721 SourceLocation RAngleLoc,
1722 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001723 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001724 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001725 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001726 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001727 SourceRange(LAngleLoc, RAngleLoc),
1728 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001729 }
1730
1731 /// \brief Build a new C++ const_cast expression.
1732 ///
1733 /// By default, performs semantic analysis to build the new expression.
1734 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001735 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001736 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001737 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001738 SourceLocation RAngleLoc,
1739 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001740 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001741 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001742 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001743 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001744 SourceRange(LAngleLoc, RAngleLoc),
1745 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001746 }
Mike Stump11289f42009-09-09 15:08:12 +00001747
Douglas Gregora16548e2009-08-11 05:31:07 +00001748 /// \brief Build a new C++ functional-style cast expression.
1749 ///
1750 /// By default, performs semantic analysis to build the new expression.
1751 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001752 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1753 SourceLocation LParenLoc,
1754 Expr *Sub,
1755 SourceLocation RParenLoc) {
1756 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001757 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001758 RParenLoc);
1759 }
Mike Stump11289f42009-09-09 15:08:12 +00001760
Douglas Gregora16548e2009-08-11 05:31:07 +00001761 /// \brief Build a new C++ typeid(type) expression.
1762 ///
1763 /// By default, performs semantic analysis to build the new expression.
1764 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001765 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001766 SourceLocation TypeidLoc,
1767 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001768 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001769 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001770 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001771 }
Mike Stump11289f42009-09-09 15:08:12 +00001772
Francois Pichet9f4f2072010-09-08 12:20:18 +00001773
Douglas Gregora16548e2009-08-11 05:31:07 +00001774 /// \brief Build a new C++ typeid(expr) expression.
1775 ///
1776 /// By default, performs semantic analysis to build the new expression.
1777 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001778 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001779 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001780 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001781 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001782 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001783 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001784 }
1785
Francois Pichet9f4f2072010-09-08 12:20:18 +00001786 /// \brief Build a new C++ __uuidof(type) expression.
1787 ///
1788 /// By default, performs semantic analysis to build the new expression.
1789 /// Subclasses may override this routine to provide different behavior.
1790 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1791 SourceLocation TypeidLoc,
1792 TypeSourceInfo *Operand,
1793 SourceLocation RParenLoc) {
1794 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1795 RParenLoc);
1796 }
1797
1798 /// \brief Build a new C++ __uuidof(expr) expression.
1799 ///
1800 /// By default, performs semantic analysis to build the new expression.
1801 /// Subclasses may override this routine to provide different behavior.
1802 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1803 SourceLocation TypeidLoc,
1804 Expr *Operand,
1805 SourceLocation RParenLoc) {
1806 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1807 RParenLoc);
1808 }
1809
Douglas Gregora16548e2009-08-11 05:31:07 +00001810 /// \brief Build a new C++ "this" expression.
1811 ///
1812 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001813 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001814 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001815 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001816 QualType ThisType,
1817 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001818 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001819 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1820 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001821 }
1822
1823 /// \brief Build a new C++ throw expression.
1824 ///
1825 /// By default, performs semantic analysis to build the new expression.
1826 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001827 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001828 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001829 }
1830
1831 /// \brief Build a new C++ default-argument expression.
1832 ///
1833 /// By default, builds a new default-argument expression, which does not
1834 /// require any semantic analysis. Subclasses may override this routine to
1835 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001836 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001837 ParmVarDecl *Param) {
1838 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1839 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001840 }
1841
1842 /// \brief Build a new C++ zero-initialization expression.
1843 ///
1844 /// By default, performs semantic analysis to build the new expression.
1845 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001846 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1847 SourceLocation LParenLoc,
1848 SourceLocation RParenLoc) {
1849 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001850 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001851 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001852 }
Mike Stump11289f42009-09-09 15:08:12 +00001853
Douglas Gregora16548e2009-08-11 05:31:07 +00001854 /// \brief Build a new C++ "new" expression.
1855 ///
1856 /// By default, performs semantic analysis to build the new expression.
1857 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001858 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001859 bool UseGlobal,
1860 SourceLocation PlacementLParen,
1861 MultiExprArg PlacementArgs,
1862 SourceLocation PlacementRParen,
1863 SourceRange TypeIdParens,
1864 QualType AllocatedType,
1865 TypeSourceInfo *AllocatedTypeInfo,
1866 Expr *ArraySize,
1867 SourceLocation ConstructorLParen,
1868 MultiExprArg ConstructorArgs,
1869 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001870 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001871 PlacementLParen,
1872 move(PlacementArgs),
1873 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001874 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001875 AllocatedType,
1876 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001877 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001878 ConstructorLParen,
1879 move(ConstructorArgs),
1880 ConstructorRParen);
1881 }
Mike Stump11289f42009-09-09 15:08:12 +00001882
Douglas Gregora16548e2009-08-11 05:31:07 +00001883 /// \brief Build a new C++ "delete" expression.
1884 ///
1885 /// By default, performs semantic analysis to build the new expression.
1886 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001887 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001888 bool IsGlobalDelete,
1889 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001890 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001891 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001892 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001893 }
Mike Stump11289f42009-09-09 15:08:12 +00001894
Douglas Gregora16548e2009-08-11 05:31:07 +00001895 /// \brief Build a new unary type trait expression.
1896 ///
1897 /// By default, performs semantic analysis to build the new expression.
1898 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001899 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001900 SourceLocation StartLoc,
1901 TypeSourceInfo *T,
1902 SourceLocation RParenLoc) {
1903 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001904 }
1905
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001906 /// \brief Build a new binary type trait expression.
1907 ///
1908 /// By default, performs semantic analysis to build the new expression.
1909 /// Subclasses may override this routine to provide different behavior.
1910 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1911 SourceLocation StartLoc,
1912 TypeSourceInfo *LhsT,
1913 TypeSourceInfo *RhsT,
1914 SourceLocation RParenLoc) {
1915 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1916 }
1917
John Wiegleyf9f65842011-04-25 06:54:41 +00001918 /// \brief Build a new expression trait expression.
1919 ///
1920 /// By default, performs semantic analysis to build the new expression.
1921 /// Subclasses may override this routine to provide different behavior.
1922 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
1923 SourceLocation StartLoc,
1924 Expr *Queried,
1925 SourceLocation RParenLoc) {
1926 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
1927 }
1928
Mike Stump11289f42009-09-09 15:08:12 +00001929 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001930 /// expression.
1931 ///
1932 /// By default, performs semantic analysis to build the new expression.
1933 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001934 ExprResult RebuildDependentScopeDeclRefExpr(
1935 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001936 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001937 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001938 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001939 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00001940
1941 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001942 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001943 *TemplateArgs);
1944
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001945 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 }
1947
1948 /// \brief Build a new template-id expression.
1949 ///
1950 /// By default, performs semantic analysis to build the new expression.
1951 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001952 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001953 LookupResult &R,
1954 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001955 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001956 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001957 }
1958
1959 /// \brief Build a new object-construction expression.
1960 ///
1961 /// By default, performs semantic analysis to build the new expression.
1962 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001963 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001964 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001965 CXXConstructorDecl *Constructor,
1966 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001967 MultiExprArg Args,
1968 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001969 CXXConstructExpr::ConstructionKind ConstructKind,
1970 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001971 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001972 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001973 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001974 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001975
Douglas Gregordb121ba2009-12-14 16:27:04 +00001976 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001977 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001978 RequiresZeroInit, ConstructKind,
1979 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001980 }
1981
1982 /// \brief Build a new object-construction expression.
1983 ///
1984 /// By default, performs semantic analysis to build the new expression.
1985 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001986 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1987 SourceLocation LParenLoc,
1988 MultiExprArg Args,
1989 SourceLocation RParenLoc) {
1990 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001991 LParenLoc,
1992 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001993 RParenLoc);
1994 }
1995
1996 /// \brief Build a new object-construction expression.
1997 ///
1998 /// By default, performs semantic analysis to build the new expression.
1999 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002000 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2001 SourceLocation LParenLoc,
2002 MultiExprArg Args,
2003 SourceLocation RParenLoc) {
2004 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002005 LParenLoc,
2006 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002007 RParenLoc);
2008 }
Mike Stump11289f42009-09-09 15:08:12 +00002009
Douglas Gregora16548e2009-08-11 05:31:07 +00002010 /// \brief Build a new member reference expression.
2011 ///
2012 /// By default, performs semantic analysis to build the new expression.
2013 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002014 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002015 QualType BaseType,
2016 bool IsArrow,
2017 SourceLocation OperatorLoc,
2018 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00002019 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002020 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002021 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002022 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002023 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002024
John McCallb268a282010-08-23 23:25:46 +00002025 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002026 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00002027 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002028 MemberNameInfo,
2029 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002030 }
2031
John McCall10eae182009-11-30 22:42:35 +00002032 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002033 ///
2034 /// By default, performs semantic analysis to build the new expression.
2035 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002036 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00002037 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00002038 SourceLocation OperatorLoc,
2039 bool IsArrow,
Douglas Gregor0da1d432011-02-28 20:01:57 +00002040 NestedNameSpecifierLoc QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00002041 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00002042 LookupResult &R,
2043 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002044 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002045 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002046
John McCallb268a282010-08-23 23:25:46 +00002047 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002048 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00002049 SS, FirstQualifierInScope,
2050 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002051 }
Mike Stump11289f42009-09-09 15:08:12 +00002052
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002053 /// \brief Build a new noexcept expression.
2054 ///
2055 /// By default, performs semantic analysis to build the new expression.
2056 /// Subclasses may override this routine to provide different behavior.
2057 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2058 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2059 }
2060
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002061 /// \brief Build a new expression to compute the length of a parameter pack.
2062 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2063 SourceLocation PackLoc,
2064 SourceLocation RParenLoc,
2065 unsigned Length) {
2066 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2067 OperatorLoc, Pack, PackLoc,
2068 RParenLoc, Length);
2069 }
2070
Douglas Gregora16548e2009-08-11 05:31:07 +00002071 /// \brief Build a new Objective-C @encode expression.
2072 ///
2073 /// By default, performs semantic analysis to build the new expression.
2074 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002075 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002076 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002077 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002078 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002079 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002080 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002081
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002082 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002083 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002084 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002085 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002086 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002087 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002088 MultiExprArg Args,
2089 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002090 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2091 ReceiverTypeInfo->getType(),
2092 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002093 Sel, Method, LBracLoc, SelectorLoc,
2094 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002095 }
2096
2097 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002098 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002099 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002100 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002101 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002102 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002103 MultiExprArg Args,
2104 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002105 return SemaRef.BuildInstanceMessage(Receiver,
2106 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002107 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002108 Sel, Method, LBracLoc, SelectorLoc,
2109 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002110 }
2111
Douglas Gregord51d90d2010-04-26 20:11:03 +00002112 /// \brief Build a new Objective-C ivar reference expression.
2113 ///
2114 /// By default, performs semantic analysis to build the new expression.
2115 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002116 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002117 SourceLocation IvarLoc,
2118 bool IsArrow, bool IsFreeIvar) {
2119 // FIXME: We lose track of the IsFreeIvar bit.
2120 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002121 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002122 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2123 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002124 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002125 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002126 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002127 false);
John Wiegley01296292011-04-08 18:41:53 +00002128 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002129 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002130
Douglas Gregord51d90d2010-04-26 20:11:03 +00002131 if (Result.get())
2132 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002133
John Wiegley01296292011-04-08 18:41:53 +00002134 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002135 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002136 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002137 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002138 /*TemplateArgs=*/0);
2139 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002140
2141 /// \brief Build a new Objective-C property reference expression.
2142 ///
2143 /// By default, performs semantic analysis to build the new expression.
2144 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002145 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002146 ObjCPropertyDecl *Property,
2147 SourceLocation PropertyLoc) {
2148 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002149 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002150 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2151 Sema::LookupMemberName);
2152 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002153 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002154 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002155 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002156 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002157 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002158
Douglas Gregor9faee212010-04-26 20:47:02 +00002159 if (Result.get())
2160 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002161
John Wiegley01296292011-04-08 18:41:53 +00002162 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002163 /*FIXME:*/PropertyLoc, IsArrow,
2164 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002165 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002166 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002167 /*TemplateArgs=*/0);
2168 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002169
John McCallb7bd14f2010-12-02 01:19:52 +00002170 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002171 ///
2172 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002173 /// Subclasses may override this routine to provide different behavior.
2174 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2175 ObjCMethodDecl *Getter,
2176 ObjCMethodDecl *Setter,
2177 SourceLocation PropertyLoc) {
2178 // Since these expressions can only be value-dependent, we do not
2179 // need to perform semantic analysis again.
2180 return Owned(
2181 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2182 VK_LValue, OK_ObjCProperty,
2183 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002184 }
2185
Douglas Gregord51d90d2010-04-26 20:11:03 +00002186 /// \brief Build a new Objective-C "isa" expression.
2187 ///
2188 /// By default, performs semantic analysis to build the new expression.
2189 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002190 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002191 bool IsArrow) {
2192 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002193 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002194 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2195 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002196 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002197 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002198 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002199 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002200 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002201
Douglas Gregord51d90d2010-04-26 20:11:03 +00002202 if (Result.get())
2203 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002204
John Wiegley01296292011-04-08 18:41:53 +00002205 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002206 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002207 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002208 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002209 /*TemplateArgs=*/0);
2210 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002211
Douglas Gregora16548e2009-08-11 05:31:07 +00002212 /// \brief Build a new shuffle vector expression.
2213 ///
2214 /// By default, performs semantic analysis to build the new expression.
2215 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002216 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002217 MultiExprArg SubExprs,
2218 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002219 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002220 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002221 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2222 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2223 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2224 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002225
Douglas Gregora16548e2009-08-11 05:31:07 +00002226 // Build a reference to the __builtin_shufflevector builtin
2227 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley01296292011-04-08 18:41:53 +00002228 ExprResult Callee
2229 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2230 VK_LValue, BuiltinLoc));
2231 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2232 if (Callee.isInvalid())
2233 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002234
2235 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002236 unsigned NumSubExprs = SubExprs.size();
2237 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley01296292011-04-08 18:41:53 +00002238 ExprResult TheCall = SemaRef.Owned(
2239 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregora16548e2009-08-11 05:31:07 +00002240 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002241 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002242 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley01296292011-04-08 18:41:53 +00002243 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002244
Douglas Gregora16548e2009-08-11 05:31:07 +00002245 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002246 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002247 }
John McCall31f82722010-11-12 08:19:04 +00002248
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002249 /// \brief Build a new template argument pack expansion.
2250 ///
2251 /// By default, performs semantic analysis to build a new pack expansion
2252 /// for a template argument. Subclasses may override this routine to provide
2253 /// different behavior.
2254 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002255 SourceLocation EllipsisLoc,
2256 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002257 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002258 case TemplateArgument::Expression: {
2259 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002260 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2261 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002262 if (Result.isInvalid())
2263 return TemplateArgumentLoc();
2264
2265 return TemplateArgumentLoc(Result.get(), Result.get());
2266 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002267
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002268 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002269 return TemplateArgumentLoc(TemplateArgument(
2270 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002271 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002272 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002273 Pattern.getTemplateNameLoc(),
2274 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002275
2276 case TemplateArgument::Null:
2277 case TemplateArgument::Integral:
2278 case TemplateArgument::Declaration:
2279 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002280 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002281 llvm_unreachable("Pack expansion pattern has no parameter packs");
2282
2283 case TemplateArgument::Type:
2284 if (TypeSourceInfo *Expansion
2285 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002286 EllipsisLoc,
2287 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002288 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2289 Expansion);
2290 break;
2291 }
2292
2293 return TemplateArgumentLoc();
2294 }
2295
Douglas Gregor968f23a2011-01-03 19:31:53 +00002296 /// \brief Build a new expression pack expansion.
2297 ///
2298 /// By default, performs semantic analysis to build a new pack expansion
2299 /// for an expression. Subclasses may override this routine to provide
2300 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002301 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2302 llvm::Optional<unsigned> NumExpansions) {
2303 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002304 }
2305
John McCall31f82722010-11-12 08:19:04 +00002306private:
Douglas Gregor14454802011-02-25 02:25:35 +00002307 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2308 QualType ObjectType,
2309 NamedDecl *FirstQualifierInScope,
2310 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002311
2312 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2313 QualType ObjectType,
2314 NamedDecl *FirstQualifierInScope,
2315 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002316};
Douglas Gregora16548e2009-08-11 05:31:07 +00002317
Douglas Gregorebe10102009-08-20 07:17:43 +00002318template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002319StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002320 if (!S)
2321 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002322
Douglas Gregorebe10102009-08-20 07:17:43 +00002323 switch (S->getStmtClass()) {
2324 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002325
Douglas Gregorebe10102009-08-20 07:17:43 +00002326 // Transform individual statement nodes
2327#define STMT(Node, Parent) \
2328 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002329#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002330#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002331#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002332
Douglas Gregorebe10102009-08-20 07:17:43 +00002333 // Transform expressions by calling TransformExpr.
2334#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002335#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002336#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002337#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002338 {
John McCalldadc5752010-08-24 06:29:42 +00002339 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002340 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002341 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002342
John McCallb268a282010-08-23 23:25:46 +00002343 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002344 }
Mike Stump11289f42009-09-09 15:08:12 +00002345 }
2346
John McCallc3007a22010-10-26 07:05:15 +00002347 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002348}
Mike Stump11289f42009-09-09 15:08:12 +00002349
2350
Douglas Gregore922c772009-08-04 22:27:00 +00002351template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002352ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002353 if (!E)
2354 return SemaRef.Owned(E);
2355
2356 switch (E->getStmtClass()) {
2357 case Stmt::NoStmtClass: break;
2358#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002359#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002360#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002361 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002362#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002363 }
2364
John McCallc3007a22010-10-26 07:05:15 +00002365 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002366}
2367
2368template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002369bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2370 unsigned NumInputs,
2371 bool IsCall,
2372 llvm::SmallVectorImpl<Expr *> &Outputs,
2373 bool *ArgChanged) {
2374 for (unsigned I = 0; I != NumInputs; ++I) {
2375 // If requested, drop call arguments that need to be dropped.
2376 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2377 if (ArgChanged)
2378 *ArgChanged = true;
2379
2380 break;
2381 }
2382
Douglas Gregor968f23a2011-01-03 19:31:53 +00002383 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2384 Expr *Pattern = Expansion->getPattern();
2385
2386 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2387 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2388 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2389
2390 // Determine whether the set of unexpanded parameter packs can and should
2391 // be expanded.
2392 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002393 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002394 llvm::Optional<unsigned> OrigNumExpansions
2395 = Expansion->getNumExpansions();
2396 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002397 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2398 Pattern->getSourceRange(),
2399 Unexpanded.data(),
2400 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002401 Expand, RetainExpansion,
2402 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002403 return true;
2404
2405 if (!Expand) {
2406 // The transform has determined that we should perform a simple
2407 // transformation on the pack expansion, producing another pack
2408 // expansion.
2409 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2410 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2411 if (OutPattern.isInvalid())
2412 return true;
2413
2414 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002415 Expansion->getEllipsisLoc(),
2416 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002417 if (Out.isInvalid())
2418 return true;
2419
2420 if (ArgChanged)
2421 *ArgChanged = true;
2422 Outputs.push_back(Out.get());
2423 continue;
2424 }
2425
2426 // The transform has determined that we should perform an elementwise
2427 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002428 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002429 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2430 ExprResult Out = getDerived().TransformExpr(Pattern);
2431 if (Out.isInvalid())
2432 return true;
2433
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002434 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002435 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2436 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002437 if (Out.isInvalid())
2438 return true;
2439 }
2440
Douglas Gregor968f23a2011-01-03 19:31:53 +00002441 if (ArgChanged)
2442 *ArgChanged = true;
2443 Outputs.push_back(Out.get());
2444 }
2445
2446 continue;
2447 }
2448
Douglas Gregora3efea12011-01-03 19:04:46 +00002449 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2450 if (Result.isInvalid())
2451 return true;
2452
2453 if (Result.get() != Inputs[I] && ArgChanged)
2454 *ArgChanged = true;
2455
2456 Outputs.push_back(Result.get());
2457 }
2458
2459 return false;
2460}
2461
2462template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002463NestedNameSpecifierLoc
2464TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2465 NestedNameSpecifierLoc NNS,
2466 QualType ObjectType,
2467 NamedDecl *FirstQualifierInScope) {
2468 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2469 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2470 Qualifier = Qualifier.getPrefix())
2471 Qualifiers.push_back(Qualifier);
2472
2473 CXXScopeSpec SS;
2474 while (!Qualifiers.empty()) {
2475 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2476 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2477
2478 switch (QNNS->getKind()) {
2479 case NestedNameSpecifier::Identifier:
2480 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2481 *QNNS->getAsIdentifier(),
2482 Q.getLocalBeginLoc(),
2483 Q.getLocalEndLoc(),
2484 ObjectType, false, SS,
2485 FirstQualifierInScope, false))
2486 return NestedNameSpecifierLoc();
2487
2488 break;
2489
2490 case NestedNameSpecifier::Namespace: {
2491 NamespaceDecl *NS
2492 = cast_or_null<NamespaceDecl>(
2493 getDerived().TransformDecl(
2494 Q.getLocalBeginLoc(),
2495 QNNS->getAsNamespace()));
2496 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2497 break;
2498 }
2499
2500 case NestedNameSpecifier::NamespaceAlias: {
2501 NamespaceAliasDecl *Alias
2502 = cast_or_null<NamespaceAliasDecl>(
2503 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2504 QNNS->getAsNamespaceAlias()));
2505 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2506 Q.getLocalEndLoc());
2507 break;
2508 }
2509
2510 case NestedNameSpecifier::Global:
2511 // There is no meaningful transformation that one could perform on the
2512 // global scope.
2513 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2514 break;
2515
2516 case NestedNameSpecifier::TypeSpecWithTemplate:
2517 case NestedNameSpecifier::TypeSpec: {
2518 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2519 FirstQualifierInScope, SS);
2520
2521 if (!TL)
2522 return NestedNameSpecifierLoc();
2523
2524 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2525 (SemaRef.getLangOptions().CPlusPlus0x &&
2526 TL.getType()->isEnumeralType())) {
2527 assert(!TL.getType().hasLocalQualifiers() &&
2528 "Can't get cv-qualifiers here");
2529 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2530 Q.getLocalEndLoc());
2531 break;
2532 }
2533
2534 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2535 << TL.getType() << SS.getRange();
2536 return NestedNameSpecifierLoc();
2537 }
Douglas Gregore16af532011-02-28 18:50:33 +00002538 }
Douglas Gregor14454802011-02-25 02:25:35 +00002539
Douglas Gregore16af532011-02-28 18:50:33 +00002540 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002541 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002542 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002543 }
2544
2545 // Don't rebuild the nested-name-specifier if we don't have to.
2546 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2547 !getDerived().AlwaysRebuild())
2548 return NNS;
2549
2550 // If we can re-use the source-location data from the original
2551 // nested-name-specifier, do so.
2552 if (SS.location_size() == NNS.getDataLength() &&
2553 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2554 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2555
2556 // Allocate new nested-name-specifier location information.
2557 return SS.getWithLocInContext(SemaRef.Context);
2558}
2559
2560template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002561DeclarationNameInfo
2562TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002563::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002564 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002565 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002566 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002567
2568 switch (Name.getNameKind()) {
2569 case DeclarationName::Identifier:
2570 case DeclarationName::ObjCZeroArgSelector:
2571 case DeclarationName::ObjCOneArgSelector:
2572 case DeclarationName::ObjCMultiArgSelector:
2573 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002574 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002575 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002576 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002577
Douglas Gregorf816bd72009-09-03 22:13:48 +00002578 case DeclarationName::CXXConstructorName:
2579 case DeclarationName::CXXDestructorName:
2580 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002581 TypeSourceInfo *NewTInfo;
2582 CanQualType NewCanTy;
2583 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002584 NewTInfo = getDerived().TransformType(OldTInfo);
2585 if (!NewTInfo)
2586 return DeclarationNameInfo();
2587 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002588 }
2589 else {
2590 NewTInfo = 0;
2591 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002592 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002593 if (NewT.isNull())
2594 return DeclarationNameInfo();
2595 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2596 }
Mike Stump11289f42009-09-09 15:08:12 +00002597
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002598 DeclarationName NewName
2599 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2600 NewCanTy);
2601 DeclarationNameInfo NewNameInfo(NameInfo);
2602 NewNameInfo.setName(NewName);
2603 NewNameInfo.setNamedTypeInfo(NewTInfo);
2604 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002605 }
Mike Stump11289f42009-09-09 15:08:12 +00002606 }
2607
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002608 assert(0 && "Unknown name kind.");
2609 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002610}
2611
2612template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002613TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00002614TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2615 TemplateName Name,
2616 SourceLocation NameLoc,
2617 QualType ObjectType,
2618 NamedDecl *FirstQualifierInScope) {
2619 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2620 TemplateDecl *Template = QTN->getTemplateDecl();
2621 assert(Template && "qualified template name must refer to a template");
2622
2623 TemplateDecl *TransTemplate
2624 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2625 Template));
2626 if (!TransTemplate)
2627 return TemplateName();
2628
2629 if (!getDerived().AlwaysRebuild() &&
2630 SS.getScopeRep() == QTN->getQualifier() &&
2631 TransTemplate == Template)
2632 return Name;
2633
2634 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2635 TransTemplate);
2636 }
2637
2638 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2639 if (SS.getScopeRep()) {
2640 // These apply to the scope specifier, not the template.
2641 ObjectType = QualType();
2642 FirstQualifierInScope = 0;
2643 }
2644
2645 if (!getDerived().AlwaysRebuild() &&
2646 SS.getScopeRep() == DTN->getQualifier() &&
2647 ObjectType.isNull())
2648 return Name;
2649
2650 if (DTN->isIdentifier()) {
2651 return getDerived().RebuildTemplateName(SS,
2652 *DTN->getIdentifier(),
2653 NameLoc,
2654 ObjectType,
2655 FirstQualifierInScope);
2656 }
2657
2658 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2659 ObjectType);
2660 }
2661
2662 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2663 TemplateDecl *TransTemplate
2664 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2665 Template));
2666 if (!TransTemplate)
2667 return TemplateName();
2668
2669 if (!getDerived().AlwaysRebuild() &&
2670 TransTemplate == Template)
2671 return Name;
2672
2673 return TemplateName(TransTemplate);
2674 }
2675
2676 if (SubstTemplateTemplateParmPackStorage *SubstPack
2677 = Name.getAsSubstTemplateTemplateParmPack()) {
2678 TemplateTemplateParmDecl *TransParam
2679 = cast_or_null<TemplateTemplateParmDecl>(
2680 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2681 if (!TransParam)
2682 return TemplateName();
2683
2684 if (!getDerived().AlwaysRebuild() &&
2685 TransParam == SubstPack->getParameterPack())
2686 return Name;
2687
2688 return getDerived().RebuildTemplateName(TransParam,
2689 SubstPack->getArgumentPack());
2690 }
2691
2692 // These should be getting filtered out before they reach the AST.
2693 llvm_unreachable("overloaded function decl survived to here");
2694 return TemplateName();
2695}
2696
2697template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002698void TreeTransform<Derived>::InventTemplateArgumentLoc(
2699 const TemplateArgument &Arg,
2700 TemplateArgumentLoc &Output) {
2701 SourceLocation Loc = getDerived().getBaseLocation();
2702 switch (Arg.getKind()) {
2703 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002704 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002705 break;
2706
2707 case TemplateArgument::Type:
2708 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002709 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002710
John McCall0ad16662009-10-29 08:12:44 +00002711 break;
2712
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002713 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00002714 case TemplateArgument::TemplateExpansion: {
2715 NestedNameSpecifierLocBuilder Builder;
2716 TemplateName Template = Arg.getAsTemplate();
2717 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2718 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2719 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2720 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2721
2722 if (Arg.getKind() == TemplateArgument::Template)
2723 Output = TemplateArgumentLoc(Arg,
2724 Builder.getWithLocInContext(SemaRef.Context),
2725 Loc);
2726 else
2727 Output = TemplateArgumentLoc(Arg,
2728 Builder.getWithLocInContext(SemaRef.Context),
2729 Loc, Loc);
2730
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002731 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00002732 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002733
John McCall0ad16662009-10-29 08:12:44 +00002734 case TemplateArgument::Expression:
2735 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2736 break;
2737
2738 case TemplateArgument::Declaration:
2739 case TemplateArgument::Integral:
2740 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002741 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002742 break;
2743 }
2744}
2745
2746template<typename Derived>
2747bool TreeTransform<Derived>::TransformTemplateArgument(
2748 const TemplateArgumentLoc &Input,
2749 TemplateArgumentLoc &Output) {
2750 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002751 switch (Arg.getKind()) {
2752 case TemplateArgument::Null:
2753 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002754 Output = Input;
2755 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002756
Douglas Gregore922c772009-08-04 22:27:00 +00002757 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002758 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002759 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002760 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002761
2762 DI = getDerived().TransformType(DI);
2763 if (!DI) return true;
2764
2765 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2766 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002767 }
Mike Stump11289f42009-09-09 15:08:12 +00002768
Douglas Gregore922c772009-08-04 22:27:00 +00002769 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002770 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002771 DeclarationName Name;
2772 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2773 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002774 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002775 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002776 if (!D) return true;
2777
John McCall0d07eb32009-10-29 18:45:58 +00002778 Expr *SourceExpr = Input.getSourceDeclExpression();
2779 if (SourceExpr) {
2780 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002781 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002782 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002783 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002784 }
2785
2786 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002787 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002788 }
Mike Stump11289f42009-09-09 15:08:12 +00002789
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002790 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00002791 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2792 if (QualifierLoc) {
2793 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2794 if (!QualifierLoc)
2795 return true;
2796 }
2797
Douglas Gregordf846d12011-03-02 18:46:51 +00002798 CXXScopeSpec SS;
2799 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002800 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00002801 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2802 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002803 if (Template.isNull())
2804 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002805
Douglas Gregor9d802122011-03-02 17:09:35 +00002806 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002807 Input.getTemplateNameLoc());
2808 return false;
2809 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002810
2811 case TemplateArgument::TemplateExpansion:
2812 llvm_unreachable("Caller should expand pack expansions");
2813
Douglas Gregore922c772009-08-04 22:27:00 +00002814 case TemplateArgument::Expression: {
2815 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002816 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002817 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002818
John McCall0ad16662009-10-29 08:12:44 +00002819 Expr *InputExpr = Input.getSourceExpression();
2820 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2821
John McCalldadc5752010-08-24 06:29:42 +00002822 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002823 = getDerived().TransformExpr(InputExpr);
2824 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002825 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002826 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002827 }
Mike Stump11289f42009-09-09 15:08:12 +00002828
Douglas Gregore922c772009-08-04 22:27:00 +00002829 case TemplateArgument::Pack: {
2830 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2831 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002832 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002833 AEnd = Arg.pack_end();
2834 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002835
John McCall0ad16662009-10-29 08:12:44 +00002836 // FIXME: preserve source information here when we start
2837 // caring about parameter packs.
2838
John McCall0d07eb32009-10-29 18:45:58 +00002839 TemplateArgumentLoc InputArg;
2840 TemplateArgumentLoc OutputArg;
2841 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2842 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002843 return true;
2844
John McCall0d07eb32009-10-29 18:45:58 +00002845 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002846 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002847
2848 TemplateArgument *TransformedArgsPtr
2849 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2850 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2851 TransformedArgsPtr);
2852 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2853 TransformedArgs.size()),
2854 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002855 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002856 }
2857 }
Mike Stump11289f42009-09-09 15:08:12 +00002858
Douglas Gregore922c772009-08-04 22:27:00 +00002859 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002860 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002861}
2862
Douglas Gregorfe921a72010-12-20 23:36:19 +00002863/// \brief Iterator adaptor that invents template argument location information
2864/// for each of the template arguments in its underlying iterator.
2865template<typename Derived, typename InputIterator>
2866class TemplateArgumentLocInventIterator {
2867 TreeTransform<Derived> &Self;
2868 InputIterator Iter;
2869
2870public:
2871 typedef TemplateArgumentLoc value_type;
2872 typedef TemplateArgumentLoc reference;
2873 typedef typename std::iterator_traits<InputIterator>::difference_type
2874 difference_type;
2875 typedef std::input_iterator_tag iterator_category;
2876
2877 class pointer {
2878 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002879
Douglas Gregorfe921a72010-12-20 23:36:19 +00002880 public:
2881 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2882
2883 const TemplateArgumentLoc *operator->() const { return &Arg; }
2884 };
2885
2886 TemplateArgumentLocInventIterator() { }
2887
2888 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2889 InputIterator Iter)
2890 : Self(Self), Iter(Iter) { }
2891
2892 TemplateArgumentLocInventIterator &operator++() {
2893 ++Iter;
2894 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002895 }
2896
Douglas Gregorfe921a72010-12-20 23:36:19 +00002897 TemplateArgumentLocInventIterator operator++(int) {
2898 TemplateArgumentLocInventIterator Old(*this);
2899 ++(*this);
2900 return Old;
2901 }
2902
2903 reference operator*() const {
2904 TemplateArgumentLoc Result;
2905 Self.InventTemplateArgumentLoc(*Iter, Result);
2906 return Result;
2907 }
2908
2909 pointer operator->() const { return pointer(**this); }
2910
2911 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2912 const TemplateArgumentLocInventIterator &Y) {
2913 return X.Iter == Y.Iter;
2914 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002915
Douglas Gregorfe921a72010-12-20 23:36:19 +00002916 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2917 const TemplateArgumentLocInventIterator &Y) {
2918 return X.Iter != Y.Iter;
2919 }
2920};
2921
Douglas Gregor42cafa82010-12-20 17:42:22 +00002922template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002923template<typename InputIterator>
2924bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2925 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002926 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002927 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002928 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002929 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002930
2931 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2932 // Unpack argument packs, which we translate them into separate
2933 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002934 // FIXME: We could do much better if we could guarantee that the
2935 // TemplateArgumentLocInfo for the pack expansion would be usable for
2936 // all of the template arguments in the argument pack.
2937 typedef TemplateArgumentLocInventIterator<Derived,
2938 TemplateArgument::pack_iterator>
2939 PackLocIterator;
2940 if (TransformTemplateArguments(PackLocIterator(*this,
2941 In.getArgument().pack_begin()),
2942 PackLocIterator(*this,
2943 In.getArgument().pack_end()),
2944 Outputs))
2945 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002946
2947 continue;
2948 }
2949
2950 if (In.getArgument().isPackExpansion()) {
2951 // We have a pack expansion, for which we will be substituting into
2952 // the pattern.
2953 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002954 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002955 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002956 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2957 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002958
2959 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2960 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2961 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2962
2963 // Determine whether the set of unexpanded parameter packs can and should
2964 // be expanded.
2965 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002966 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002967 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002968 if (getDerived().TryExpandParameterPacks(Ellipsis,
2969 Pattern.getSourceRange(),
2970 Unexpanded.data(),
2971 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002972 Expand,
2973 RetainExpansion,
2974 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002975 return true;
2976
2977 if (!Expand) {
2978 // The transform has determined that we should perform a simple
2979 // transformation on the pack expansion, producing another pack
2980 // expansion.
2981 TemplateArgumentLoc OutPattern;
2982 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2983 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2984 return true;
2985
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002986 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
2987 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002988 if (Out.getArgument().isNull())
2989 return true;
2990
2991 Outputs.addArgument(Out);
2992 continue;
2993 }
2994
2995 // The transform has determined that we should perform an elementwise
2996 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002997 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002998 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2999
3000 if (getDerived().TransformTemplateArgument(Pattern, Out))
3001 return true;
3002
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003003 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003004 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3005 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003006 if (Out.getArgument().isNull())
3007 return true;
3008 }
3009
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003010 Outputs.addArgument(Out);
3011 }
3012
Douglas Gregor48d24112011-01-10 20:53:55 +00003013 // If we're supposed to retain a pack expansion, do so by temporarily
3014 // forgetting the partially-substituted parameter pack.
3015 if (RetainExpansion) {
3016 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3017
3018 if (getDerived().TransformTemplateArgument(Pattern, Out))
3019 return true;
3020
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003021 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3022 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003023 if (Out.getArgument().isNull())
3024 return true;
3025
3026 Outputs.addArgument(Out);
3027 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003028
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003029 continue;
3030 }
3031
3032 // The simple case:
3033 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003034 return true;
3035
3036 Outputs.addArgument(Out);
3037 }
3038
3039 return false;
3040
3041}
3042
Douglas Gregord6ff3322009-08-04 16:50:30 +00003043//===----------------------------------------------------------------------===//
3044// Type transformation
3045//===----------------------------------------------------------------------===//
3046
3047template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003048QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003049 if (getDerived().AlreadyTransformed(T))
3050 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003051
John McCall550e0c22009-10-21 00:40:46 +00003052 // Temporary workaround. All of these transformations should
3053 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003054 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3055 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003056
John McCall31f82722010-11-12 08:19:04 +00003057 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003058
John McCall550e0c22009-10-21 00:40:46 +00003059 if (!NewDI)
3060 return QualType();
3061
3062 return NewDI->getType();
3063}
3064
3065template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003066TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003067 if (getDerived().AlreadyTransformed(DI->getType()))
3068 return DI;
3069
3070 TypeLocBuilder TLB;
3071
3072 TypeLoc TL = DI->getTypeLoc();
3073 TLB.reserve(TL.getFullDataSize());
3074
John McCall31f82722010-11-12 08:19:04 +00003075 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003076 if (Result.isNull())
3077 return 0;
3078
John McCallbcd03502009-12-07 02:54:59 +00003079 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003080}
3081
3082template<typename Derived>
3083QualType
John McCall31f82722010-11-12 08:19:04 +00003084TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003085 switch (T.getTypeLocClass()) {
3086#define ABSTRACT_TYPELOC(CLASS, PARENT)
3087#define TYPELOC(CLASS, PARENT) \
3088 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003089 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003090#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003091 }
Mike Stump11289f42009-09-09 15:08:12 +00003092
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003093 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003094 return QualType();
3095}
3096
3097/// FIXME: By default, this routine adds type qualifiers only to types
3098/// that can have qualifiers, and silently suppresses those qualifiers
3099/// that are not permitted (e.g., qualifiers on reference or function
3100/// types). This is the right thing for template instantiation, but
3101/// probably not for other clients.
3102template<typename Derived>
3103QualType
3104TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003105 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003106 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003107
John McCall31f82722010-11-12 08:19:04 +00003108 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003109 if (Result.isNull())
3110 return QualType();
3111
3112 // Silently suppress qualifiers if the result type can't be qualified.
3113 // FIXME: this is the right thing for template instantiation, but
3114 // probably not for other clients.
3115 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003116 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003117
John McCallcb0f89a2010-06-05 06:41:15 +00003118 if (!Quals.empty()) {
3119 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3120 TLB.push<QualifiedTypeLoc>(Result);
3121 // No location information to preserve.
3122 }
John McCall550e0c22009-10-21 00:40:46 +00003123
3124 return Result;
3125}
3126
Douglas Gregor14454802011-02-25 02:25:35 +00003127template<typename Derived>
3128TypeLoc
3129TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3130 QualType ObjectType,
3131 NamedDecl *UnqualLookup,
3132 CXXScopeSpec &SS) {
Douglas Gregor14454802011-02-25 02:25:35 +00003133 QualType T = TL.getType();
3134 if (getDerived().AlreadyTransformed(T))
3135 return TL;
3136
3137 TypeLocBuilder TLB;
3138 QualType Result;
3139
3140 if (isa<TemplateSpecializationType>(T)) {
3141 TemplateSpecializationTypeLoc SpecTL
3142 = cast<TemplateSpecializationTypeLoc>(TL);
3143
3144 TemplateName Template =
Douglas Gregor9db53502011-03-02 18:07:45 +00003145 getDerived().TransformTemplateName(SS,
3146 SpecTL.getTypePtr()->getTemplateName(),
3147 SpecTL.getTemplateNameLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003148 ObjectType, UnqualLookup);
3149 if (Template.isNull())
3150 return TypeLoc();
3151
3152 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3153 Template);
3154 } else if (isa<DependentTemplateSpecializationType>(T)) {
3155 DependentTemplateSpecializationTypeLoc SpecTL
3156 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3157
Douglas Gregor5a064722011-02-28 17:23:35 +00003158 TemplateName Template
Douglas Gregor9db53502011-03-02 18:07:45 +00003159 = getDerived().RebuildTemplateName(SS,
Douglas Gregore16af532011-02-28 18:50:33 +00003160 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003161 SpecTL.getNameLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00003162 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003163 if (Template.isNull())
3164 return TypeLoc();
3165
Douglas Gregor14454802011-02-25 02:25:35 +00003166 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003167 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003168 Template,
3169 SS);
Douglas Gregor14454802011-02-25 02:25:35 +00003170 } else {
3171 // Nothing special needs to be done for these.
3172 Result = getDerived().TransformType(TLB, TL);
3173 }
3174
3175 if (Result.isNull())
3176 return TypeLoc();
3177
3178 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3179}
3180
Douglas Gregor579c15f2011-03-02 18:32:08 +00003181template<typename Derived>
3182TypeSourceInfo *
3183TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3184 QualType ObjectType,
3185 NamedDecl *UnqualLookup,
3186 CXXScopeSpec &SS) {
3187 // FIXME: Painfully copy-paste from the above!
3188
3189 QualType T = TSInfo->getType();
3190 if (getDerived().AlreadyTransformed(T))
3191 return TSInfo;
3192
3193 TypeLocBuilder TLB;
3194 QualType Result;
3195
3196 TypeLoc TL = TSInfo->getTypeLoc();
3197 if (isa<TemplateSpecializationType>(T)) {
3198 TemplateSpecializationTypeLoc SpecTL
3199 = cast<TemplateSpecializationTypeLoc>(TL);
3200
3201 TemplateName Template
3202 = getDerived().TransformTemplateName(SS,
3203 SpecTL.getTypePtr()->getTemplateName(),
3204 SpecTL.getTemplateNameLoc(),
3205 ObjectType, UnqualLookup);
3206 if (Template.isNull())
3207 return 0;
3208
3209 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3210 Template);
3211 } else if (isa<DependentTemplateSpecializationType>(T)) {
3212 DependentTemplateSpecializationTypeLoc SpecTL
3213 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3214
3215 TemplateName Template
3216 = getDerived().RebuildTemplateName(SS,
3217 *SpecTL.getTypePtr()->getIdentifier(),
3218 SpecTL.getNameLoc(),
3219 ObjectType, UnqualLookup);
3220 if (Template.isNull())
3221 return 0;
3222
3223 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3224 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003225 Template,
3226 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003227 } else {
3228 // Nothing special needs to be done for these.
3229 Result = getDerived().TransformType(TLB, TL);
3230 }
3231
3232 if (Result.isNull())
3233 return 0;
3234
3235 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3236}
3237
John McCall550e0c22009-10-21 00:40:46 +00003238template <class TyLoc> static inline
3239QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3240 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3241 NewT.setNameLoc(T.getNameLoc());
3242 return T.getType();
3243}
3244
John McCall550e0c22009-10-21 00:40:46 +00003245template<typename Derived>
3246QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003247 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003248 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3249 NewT.setBuiltinLoc(T.getBuiltinLoc());
3250 if (T.needsExtraLocalData())
3251 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3252 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003253}
Mike Stump11289f42009-09-09 15:08:12 +00003254
Douglas Gregord6ff3322009-08-04 16:50:30 +00003255template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003256QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003257 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003258 // FIXME: recurse?
3259 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003260}
Mike Stump11289f42009-09-09 15:08:12 +00003261
Douglas Gregord6ff3322009-08-04 16:50:30 +00003262template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003263QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003264 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003265 QualType PointeeType
3266 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003267 if (PointeeType.isNull())
3268 return QualType();
3269
3270 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003271 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003272 // A dependent pointer type 'T *' has is being transformed such
3273 // that an Objective-C class type is being replaced for 'T'. The
3274 // resulting pointer type is an ObjCObjectPointerType, not a
3275 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003276 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003277
John McCall8b07ec22010-05-15 11:32:37 +00003278 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3279 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003280 return Result;
3281 }
John McCall31f82722010-11-12 08:19:04 +00003282
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003283 if (getDerived().AlwaysRebuild() ||
3284 PointeeType != TL.getPointeeLoc().getType()) {
3285 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3286 if (Result.isNull())
3287 return QualType();
3288 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003289
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003290 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3291 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003292 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003293}
Mike Stump11289f42009-09-09 15:08:12 +00003294
3295template<typename Derived>
3296QualType
John McCall550e0c22009-10-21 00:40:46 +00003297TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003298 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003299 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003300 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3301 if (PointeeType.isNull())
3302 return QualType();
3303
3304 QualType Result = TL.getType();
3305 if (getDerived().AlwaysRebuild() ||
3306 PointeeType != TL.getPointeeLoc().getType()) {
3307 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003308 TL.getSigilLoc());
3309 if (Result.isNull())
3310 return QualType();
3311 }
3312
Douglas Gregor049211a2010-04-22 16:50:51 +00003313 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003314 NewT.setSigilLoc(TL.getSigilLoc());
3315 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003316}
3317
John McCall70dd5f62009-10-30 00:06:24 +00003318/// Transforms a reference type. Note that somewhat paradoxically we
3319/// don't care whether the type itself is an l-value type or an r-value
3320/// type; we only care if the type was *written* as an l-value type
3321/// or an r-value type.
3322template<typename Derived>
3323QualType
3324TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003325 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003326 const ReferenceType *T = TL.getTypePtr();
3327
3328 // Note that this works with the pointee-as-written.
3329 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3330 if (PointeeType.isNull())
3331 return QualType();
3332
3333 QualType Result = TL.getType();
3334 if (getDerived().AlwaysRebuild() ||
3335 PointeeType != T->getPointeeTypeAsWritten()) {
3336 Result = getDerived().RebuildReferenceType(PointeeType,
3337 T->isSpelledAsLValue(),
3338 TL.getSigilLoc());
3339 if (Result.isNull())
3340 return QualType();
3341 }
3342
3343 // r-value references can be rebuilt as l-value references.
3344 ReferenceTypeLoc NewTL;
3345 if (isa<LValueReferenceType>(Result))
3346 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3347 else
3348 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3349 NewTL.setSigilLoc(TL.getSigilLoc());
3350
3351 return Result;
3352}
3353
Mike Stump11289f42009-09-09 15:08:12 +00003354template<typename Derived>
3355QualType
John McCall550e0c22009-10-21 00:40:46 +00003356TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003357 LValueReferenceTypeLoc TL) {
3358 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003359}
3360
Mike Stump11289f42009-09-09 15:08:12 +00003361template<typename Derived>
3362QualType
John McCall550e0c22009-10-21 00:40:46 +00003363TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003364 RValueReferenceTypeLoc TL) {
3365 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003366}
Mike Stump11289f42009-09-09 15:08:12 +00003367
Douglas Gregord6ff3322009-08-04 16:50:30 +00003368template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003369QualType
John McCall550e0c22009-10-21 00:40:46 +00003370TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003371 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003372 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003373 if (PointeeType.isNull())
3374 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003375
Abramo Bagnara509357842011-03-05 14:42:21 +00003376 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3377 TypeSourceInfo* NewClsTInfo = 0;
3378 if (OldClsTInfo) {
3379 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3380 if (!NewClsTInfo)
3381 return QualType();
3382 }
3383
3384 const MemberPointerType *T = TL.getTypePtr();
3385 QualType OldClsType = QualType(T->getClass(), 0);
3386 QualType NewClsType;
3387 if (NewClsTInfo)
3388 NewClsType = NewClsTInfo->getType();
3389 else {
3390 NewClsType = getDerived().TransformType(OldClsType);
3391 if (NewClsType.isNull())
3392 return QualType();
3393 }
Mike Stump11289f42009-09-09 15:08:12 +00003394
John McCall550e0c22009-10-21 00:40:46 +00003395 QualType Result = TL.getType();
3396 if (getDerived().AlwaysRebuild() ||
3397 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003398 NewClsType != OldClsType) {
3399 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003400 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003401 if (Result.isNull())
3402 return QualType();
3403 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003404
John McCall550e0c22009-10-21 00:40:46 +00003405 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3406 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003407 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003408
3409 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003410}
3411
Mike Stump11289f42009-09-09 15:08:12 +00003412template<typename Derived>
3413QualType
John McCall550e0c22009-10-21 00:40:46 +00003414TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003415 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003416 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003417 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003418 if (ElementType.isNull())
3419 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003420
John McCall550e0c22009-10-21 00:40:46 +00003421 QualType Result = TL.getType();
3422 if (getDerived().AlwaysRebuild() ||
3423 ElementType != T->getElementType()) {
3424 Result = getDerived().RebuildConstantArrayType(ElementType,
3425 T->getSizeModifier(),
3426 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003427 T->getIndexTypeCVRQualifiers(),
3428 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003429 if (Result.isNull())
3430 return QualType();
3431 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003432
John McCall550e0c22009-10-21 00:40:46 +00003433 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3434 NewTL.setLBracketLoc(TL.getLBracketLoc());
3435 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003436
John McCall550e0c22009-10-21 00:40:46 +00003437 Expr *Size = TL.getSizeExpr();
3438 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003439 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003440 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3441 }
3442 NewTL.setSizeExpr(Size);
3443
3444 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003445}
Mike Stump11289f42009-09-09 15:08:12 +00003446
Douglas Gregord6ff3322009-08-04 16:50:30 +00003447template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003448QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003449 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003450 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003451 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003452 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003453 if (ElementType.isNull())
3454 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003455
John McCall550e0c22009-10-21 00:40:46 +00003456 QualType Result = TL.getType();
3457 if (getDerived().AlwaysRebuild() ||
3458 ElementType != T->getElementType()) {
3459 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003460 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003461 T->getIndexTypeCVRQualifiers(),
3462 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003463 if (Result.isNull())
3464 return QualType();
3465 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003466
John McCall550e0c22009-10-21 00:40:46 +00003467 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3468 NewTL.setLBracketLoc(TL.getLBracketLoc());
3469 NewTL.setRBracketLoc(TL.getRBracketLoc());
3470 NewTL.setSizeExpr(0);
3471
3472 return Result;
3473}
3474
3475template<typename Derived>
3476QualType
3477TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003478 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003479 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003480 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3481 if (ElementType.isNull())
3482 return QualType();
3483
3484 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003485 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003486
John McCalldadc5752010-08-24 06:29:42 +00003487 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003488 = getDerived().TransformExpr(T->getSizeExpr());
3489 if (SizeResult.isInvalid())
3490 return QualType();
3491
John McCallb268a282010-08-23 23:25:46 +00003492 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003493
3494 QualType Result = TL.getType();
3495 if (getDerived().AlwaysRebuild() ||
3496 ElementType != T->getElementType() ||
3497 Size != T->getSizeExpr()) {
3498 Result = getDerived().RebuildVariableArrayType(ElementType,
3499 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003500 Size,
John McCall550e0c22009-10-21 00:40:46 +00003501 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003502 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003503 if (Result.isNull())
3504 return QualType();
3505 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003506
John McCall550e0c22009-10-21 00:40:46 +00003507 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3508 NewTL.setLBracketLoc(TL.getLBracketLoc());
3509 NewTL.setRBracketLoc(TL.getRBracketLoc());
3510 NewTL.setSizeExpr(Size);
3511
3512 return Result;
3513}
3514
3515template<typename Derived>
3516QualType
3517TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003518 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003519 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003520 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3521 if (ElementType.isNull())
3522 return QualType();
3523
3524 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003525 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003526
John McCall33ddac02011-01-19 10:06:00 +00003527 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3528 Expr *origSize = TL.getSizeExpr();
3529 if (!origSize) origSize = T->getSizeExpr();
3530
3531 ExprResult sizeResult
3532 = getDerived().TransformExpr(origSize);
3533 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003534 return QualType();
3535
John McCall33ddac02011-01-19 10:06:00 +00003536 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003537
3538 QualType Result = TL.getType();
3539 if (getDerived().AlwaysRebuild() ||
3540 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003541 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003542 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3543 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003544 size,
John McCall550e0c22009-10-21 00:40:46 +00003545 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003546 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003547 if (Result.isNull())
3548 return QualType();
3549 }
John McCall550e0c22009-10-21 00:40:46 +00003550
3551 // We might have any sort of array type now, but fortunately they
3552 // all have the same location layout.
3553 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3554 NewTL.setLBracketLoc(TL.getLBracketLoc());
3555 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003556 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003557
3558 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003559}
Mike Stump11289f42009-09-09 15:08:12 +00003560
3561template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003562QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003563 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003564 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003565 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003566
3567 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003568 QualType ElementType = getDerived().TransformType(T->getElementType());
3569 if (ElementType.isNull())
3570 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003571
Douglas Gregore922c772009-08-04 22:27:00 +00003572 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003573 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003574
John McCalldadc5752010-08-24 06:29:42 +00003575 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003576 if (Size.isInvalid())
3577 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003578
John McCall550e0c22009-10-21 00:40:46 +00003579 QualType Result = TL.getType();
3580 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003581 ElementType != T->getElementType() ||
3582 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003583 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003584 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003585 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003586 if (Result.isNull())
3587 return QualType();
3588 }
John McCall550e0c22009-10-21 00:40:46 +00003589
3590 // Result might be dependent or not.
3591 if (isa<DependentSizedExtVectorType>(Result)) {
3592 DependentSizedExtVectorTypeLoc NewTL
3593 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3594 NewTL.setNameLoc(TL.getNameLoc());
3595 } else {
3596 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3597 NewTL.setNameLoc(TL.getNameLoc());
3598 }
3599
3600 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003601}
Mike Stump11289f42009-09-09 15:08:12 +00003602
3603template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003604QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003605 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003606 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003607 QualType ElementType = getDerived().TransformType(T->getElementType());
3608 if (ElementType.isNull())
3609 return QualType();
3610
John McCall550e0c22009-10-21 00:40:46 +00003611 QualType Result = TL.getType();
3612 if (getDerived().AlwaysRebuild() ||
3613 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003614 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003615 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003616 if (Result.isNull())
3617 return QualType();
3618 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003619
John McCall550e0c22009-10-21 00:40:46 +00003620 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3621 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003622
John McCall550e0c22009-10-21 00:40:46 +00003623 return Result;
3624}
3625
3626template<typename Derived>
3627QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003628 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003629 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003630 QualType ElementType = getDerived().TransformType(T->getElementType());
3631 if (ElementType.isNull())
3632 return QualType();
3633
3634 QualType Result = TL.getType();
3635 if (getDerived().AlwaysRebuild() ||
3636 ElementType != T->getElementType()) {
3637 Result = getDerived().RebuildExtVectorType(ElementType,
3638 T->getNumElements(),
3639 /*FIXME*/ SourceLocation());
3640 if (Result.isNull())
3641 return QualType();
3642 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003643
John McCall550e0c22009-10-21 00:40:46 +00003644 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3645 NewTL.setNameLoc(TL.getNameLoc());
3646
3647 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003648}
Mike Stump11289f42009-09-09 15:08:12 +00003649
3650template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003651ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003652TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3653 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003654 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003655 TypeSourceInfo *NewDI = 0;
3656
3657 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3658 // If we're substituting into a pack expansion type and we know the
3659 TypeLoc OldTL = OldDI->getTypeLoc();
3660 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3661
3662 TypeLocBuilder TLB;
3663 TypeLoc NewTL = OldDI->getTypeLoc();
3664 TLB.reserve(NewTL.getFullDataSize());
3665
3666 QualType Result = getDerived().TransformType(TLB,
3667 OldExpansionTL.getPatternLoc());
3668 if (Result.isNull())
3669 return 0;
3670
3671 Result = RebuildPackExpansionType(Result,
3672 OldExpansionTL.getPatternLoc().getSourceRange(),
3673 OldExpansionTL.getEllipsisLoc(),
3674 NumExpansions);
3675 if (Result.isNull())
3676 return 0;
3677
3678 PackExpansionTypeLoc NewExpansionTL
3679 = TLB.push<PackExpansionTypeLoc>(Result);
3680 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3681 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3682 } else
3683 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003684 if (!NewDI)
3685 return 0;
3686
3687 if (NewDI == OldDI)
3688 return OldParm;
3689 else
3690 return ParmVarDecl::Create(SemaRef.Context,
3691 OldParm->getDeclContext(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00003692 OldParm->getInnerLocStart(),
John McCall58f10c32010-03-11 09:03:00 +00003693 OldParm->getLocation(),
3694 OldParm->getIdentifier(),
3695 NewDI->getType(),
3696 NewDI,
3697 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003698 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003699 /* DefArg */ NULL);
3700}
3701
3702template<typename Derived>
3703bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003704 TransformFunctionTypeParams(SourceLocation Loc,
3705 ParmVarDecl **Params, unsigned NumParams,
3706 const QualType *ParamTypes,
3707 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3708 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3709 for (unsigned i = 0; i != NumParams; ++i) {
3710 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor715e4612011-01-14 22:40:04 +00003711 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003712 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00003713 if (OldParm->isParameterPack()) {
3714 // We have a function parameter pack that may need to be expanded.
3715 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003716
Douglas Gregor5499af42011-01-05 23:12:31 +00003717 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003718 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3719 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3720 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3721 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00003722 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3723
Douglas Gregor5499af42011-01-05 23:12:31 +00003724 // Determine whether we should expand the parameter packs.
3725 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003726 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003727 llvm::Optional<unsigned> OrigNumExpansions
3728 = ExpansionTL.getTypePtr()->getNumExpansions();
3729 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003730 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3731 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003732 Unexpanded.data(),
3733 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003734 ShouldExpand,
3735 RetainExpansion,
3736 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003737 return true;
3738 }
3739
3740 if (ShouldExpand) {
3741 // Expand the function parameter pack into multiple, separate
3742 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003743 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003744 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003745 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3746 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003747 = getDerived().TransformFunctionTypeParam(OldParm,
3748 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003749 if (!NewParm)
3750 return true;
3751
Douglas Gregordd472162011-01-07 00:20:55 +00003752 OutParamTypes.push_back(NewParm->getType());
3753 if (PVars)
3754 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003755 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003756
3757 // If we're supposed to retain a pack expansion, do so by temporarily
3758 // forgetting the partially-substituted parameter pack.
3759 if (RetainExpansion) {
3760 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3761 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003762 = getDerived().TransformFunctionTypeParam(OldParm,
3763 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003764 if (!NewParm)
3765 return true;
3766
3767 OutParamTypes.push_back(NewParm->getType());
3768 if (PVars)
3769 PVars->push_back(NewParm);
3770 }
3771
Douglas Gregor5499af42011-01-05 23:12:31 +00003772 // We're done with the pack expansion.
3773 continue;
3774 }
3775
3776 // We'll substitute the parameter now without expanding the pack
3777 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00003778 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3779 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3780 NumExpansions);
3781 } else {
3782 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3783 llvm::Optional<unsigned>());
Douglas Gregor5499af42011-01-05 23:12:31 +00003784 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00003785
John McCall58f10c32010-03-11 09:03:00 +00003786 if (!NewParm)
3787 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003788
Douglas Gregordd472162011-01-07 00:20:55 +00003789 OutParamTypes.push_back(NewParm->getType());
3790 if (PVars)
3791 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003792 continue;
3793 }
John McCall58f10c32010-03-11 09:03:00 +00003794
3795 // Deal with the possibility that we don't have a parameter
3796 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003797 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003798 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003799 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003800 QualType NewType;
Douglas Gregor5499af42011-01-05 23:12:31 +00003801 if (const PackExpansionType *Expansion
3802 = dyn_cast<PackExpansionType>(OldType)) {
3803 // We have a function parameter pack that may need to be expanded.
3804 QualType Pattern = Expansion->getPattern();
3805 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3806 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3807
3808 // Determine whether we should expand the parameter packs.
3809 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003810 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003811 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003812 Unexpanded.data(),
3813 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003814 ShouldExpand,
3815 RetainExpansion,
3816 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003817 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003818 }
3819
3820 if (ShouldExpand) {
3821 // Expand the function parameter pack into multiple, separate
3822 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003823 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003824 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3825 QualType NewType = getDerived().TransformType(Pattern);
3826 if (NewType.isNull())
3827 return true;
John McCall58f10c32010-03-11 09:03:00 +00003828
Douglas Gregordd472162011-01-07 00:20:55 +00003829 OutParamTypes.push_back(NewType);
3830 if (PVars)
3831 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003832 }
3833
3834 // We're done with the pack expansion.
3835 continue;
3836 }
3837
Douglas Gregor48d24112011-01-10 20:53:55 +00003838 // If we're supposed to retain a pack expansion, do so by temporarily
3839 // forgetting the partially-substituted parameter pack.
3840 if (RetainExpansion) {
3841 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3842 QualType NewType = getDerived().TransformType(Pattern);
3843 if (NewType.isNull())
3844 return true;
3845
3846 OutParamTypes.push_back(NewType);
3847 if (PVars)
3848 PVars->push_back(0);
3849 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003850
Douglas Gregor5499af42011-01-05 23:12:31 +00003851 // We'll substitute the parameter now without expanding the pack
3852 // expansion.
3853 OldType = Expansion->getPattern();
3854 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003855 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3856 NewType = getDerived().TransformType(OldType);
3857 } else {
3858 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00003859 }
3860
Douglas Gregor5499af42011-01-05 23:12:31 +00003861 if (NewType.isNull())
3862 return true;
3863
3864 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003865 NewType = getSema().Context.getPackExpansionType(NewType,
3866 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003867
Douglas Gregordd472162011-01-07 00:20:55 +00003868 OutParamTypes.push_back(NewType);
3869 if (PVars)
3870 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003871 }
3872
3873 return false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003874 }
John McCall58f10c32010-03-11 09:03:00 +00003875
3876template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003877QualType
John McCall550e0c22009-10-21 00:40:46 +00003878TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003879 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003880 // Transform the parameters and return type.
3881 //
3882 // We instantiate in source order, with the return type first followed by
3883 // the parameters, because users tend to expect this (even if they shouldn't
3884 // rely on it!).
3885 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003886 // When the function has a trailing return type, we instantiate the
3887 // parameters before the return type, since the return type can then refer
3888 // to the parameters themselves (via decltype, sizeof, etc.).
3889 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003890 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003891 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00003892 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003893
Douglas Gregor7fb25412010-10-01 18:44:50 +00003894 QualType ResultType;
3895
3896 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003897 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3898 TL.getParmArray(),
3899 TL.getNumArgs(),
3900 TL.getTypePtr()->arg_type_begin(),
3901 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003902 return QualType();
3903
3904 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3905 if (ResultType.isNull())
3906 return QualType();
3907 }
3908 else {
3909 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3910 if (ResultType.isNull())
3911 return QualType();
3912
Douglas Gregordd472162011-01-07 00:20:55 +00003913 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3914 TL.getParmArray(),
3915 TL.getNumArgs(),
3916 TL.getTypePtr()->arg_type_begin(),
3917 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003918 return QualType();
3919 }
3920
John McCall550e0c22009-10-21 00:40:46 +00003921 QualType Result = TL.getType();
3922 if (getDerived().AlwaysRebuild() ||
3923 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003924 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003925 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3926 Result = getDerived().RebuildFunctionProtoType(ResultType,
3927 ParamTypes.data(),
3928 ParamTypes.size(),
3929 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003930 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00003931 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003932 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003933 if (Result.isNull())
3934 return QualType();
3935 }
Mike Stump11289f42009-09-09 15:08:12 +00003936
John McCall550e0c22009-10-21 00:40:46 +00003937 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00003938 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
3939 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003940 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003941 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3942 NewTL.setArg(i, ParamDecls[i]);
3943
3944 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003945}
Mike Stump11289f42009-09-09 15:08:12 +00003946
Douglas Gregord6ff3322009-08-04 16:50:30 +00003947template<typename Derived>
3948QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003949 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003950 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003951 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003952 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3953 if (ResultType.isNull())
3954 return QualType();
3955
3956 QualType Result = TL.getType();
3957 if (getDerived().AlwaysRebuild() ||
3958 ResultType != T->getResultType())
3959 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3960
3961 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00003962 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
3963 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003964 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003965
3966 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003967}
Mike Stump11289f42009-09-09 15:08:12 +00003968
John McCallb96ec562009-12-04 22:46:56 +00003969template<typename Derived> QualType
3970TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003971 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003972 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003973 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003974 if (!D)
3975 return QualType();
3976
3977 QualType Result = TL.getType();
3978 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3979 Result = getDerived().RebuildUnresolvedUsingType(D);
3980 if (Result.isNull())
3981 return QualType();
3982 }
3983
3984 // We might get an arbitrary type spec type back. We should at
3985 // least always get a type spec type, though.
3986 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3987 NewTL.setNameLoc(TL.getNameLoc());
3988
3989 return Result;
3990}
3991
Douglas Gregord6ff3322009-08-04 16:50:30 +00003992template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003993QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003994 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003995 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00003996 TypedefNameDecl *Typedef
3997 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3998 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003999 if (!Typedef)
4000 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004001
John McCall550e0c22009-10-21 00:40:46 +00004002 QualType Result = TL.getType();
4003 if (getDerived().AlwaysRebuild() ||
4004 Typedef != T->getDecl()) {
4005 Result = getDerived().RebuildTypedefType(Typedef);
4006 if (Result.isNull())
4007 return QualType();
4008 }
Mike Stump11289f42009-09-09 15:08:12 +00004009
John McCall550e0c22009-10-21 00:40:46 +00004010 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4011 NewTL.setNameLoc(TL.getNameLoc());
4012
4013 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004014}
Mike Stump11289f42009-09-09 15:08:12 +00004015
Douglas Gregord6ff3322009-08-04 16:50:30 +00004016template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004017QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004018 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004019 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004020 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004021
John McCalldadc5752010-08-24 06:29:42 +00004022 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004023 if (E.isInvalid())
4024 return QualType();
4025
John McCall550e0c22009-10-21 00:40:46 +00004026 QualType Result = TL.getType();
4027 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004028 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004029 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004030 if (Result.isNull())
4031 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004032 }
John McCall550e0c22009-10-21 00:40:46 +00004033 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004034
John McCall550e0c22009-10-21 00:40:46 +00004035 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004036 NewTL.setTypeofLoc(TL.getTypeofLoc());
4037 NewTL.setLParenLoc(TL.getLParenLoc());
4038 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004039
4040 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004041}
Mike Stump11289f42009-09-09 15:08:12 +00004042
4043template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004044QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004045 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004046 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4047 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4048 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004049 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004050
John McCall550e0c22009-10-21 00:40:46 +00004051 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004052 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4053 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004054 if (Result.isNull())
4055 return QualType();
4056 }
Mike Stump11289f42009-09-09 15:08:12 +00004057
John McCall550e0c22009-10-21 00:40:46 +00004058 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004059 NewTL.setTypeofLoc(TL.getTypeofLoc());
4060 NewTL.setLParenLoc(TL.getLParenLoc());
4061 NewTL.setRParenLoc(TL.getRParenLoc());
4062 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004063
4064 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004065}
Mike Stump11289f42009-09-09 15:08:12 +00004066
4067template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004068QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004069 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004070 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004071
Douglas Gregore922c772009-08-04 22:27:00 +00004072 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004073 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004074
John McCalldadc5752010-08-24 06:29:42 +00004075 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004076 if (E.isInvalid())
4077 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004078
John McCall550e0c22009-10-21 00:40:46 +00004079 QualType Result = TL.getType();
4080 if (getDerived().AlwaysRebuild() ||
4081 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004082 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004083 if (Result.isNull())
4084 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004085 }
John McCall550e0c22009-10-21 00:40:46 +00004086 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004087
John McCall550e0c22009-10-21 00:40:46 +00004088 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4089 NewTL.setNameLoc(TL.getNameLoc());
4090
4091 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004092}
4093
4094template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004095QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4096 AutoTypeLoc TL) {
4097 const AutoType *T = TL.getTypePtr();
4098 QualType OldDeduced = T->getDeducedType();
4099 QualType NewDeduced;
4100 if (!OldDeduced.isNull()) {
4101 NewDeduced = getDerived().TransformType(OldDeduced);
4102 if (NewDeduced.isNull())
4103 return QualType();
4104 }
4105
4106 QualType Result = TL.getType();
4107 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4108 Result = getDerived().RebuildAutoType(NewDeduced);
4109 if (Result.isNull())
4110 return QualType();
4111 }
4112
4113 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4114 NewTL.setNameLoc(TL.getNameLoc());
4115
4116 return Result;
4117}
4118
4119template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004120QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004121 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004122 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004123 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004124 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4125 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004126 if (!Record)
4127 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004128
John McCall550e0c22009-10-21 00:40:46 +00004129 QualType Result = TL.getType();
4130 if (getDerived().AlwaysRebuild() ||
4131 Record != T->getDecl()) {
4132 Result = getDerived().RebuildRecordType(Record);
4133 if (Result.isNull())
4134 return QualType();
4135 }
Mike Stump11289f42009-09-09 15:08:12 +00004136
John McCall550e0c22009-10-21 00:40:46 +00004137 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4138 NewTL.setNameLoc(TL.getNameLoc());
4139
4140 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004141}
Mike Stump11289f42009-09-09 15:08:12 +00004142
4143template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004144QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004145 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004146 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004147 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004148 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4149 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004150 if (!Enum)
4151 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004152
John McCall550e0c22009-10-21 00:40:46 +00004153 QualType Result = TL.getType();
4154 if (getDerived().AlwaysRebuild() ||
4155 Enum != T->getDecl()) {
4156 Result = getDerived().RebuildEnumType(Enum);
4157 if (Result.isNull())
4158 return QualType();
4159 }
Mike Stump11289f42009-09-09 15:08:12 +00004160
John McCall550e0c22009-10-21 00:40:46 +00004161 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4162 NewTL.setNameLoc(TL.getNameLoc());
4163
4164 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004165}
John McCallfcc33b02009-09-05 00:15:47 +00004166
John McCalle78aac42010-03-10 03:28:59 +00004167template<typename Derived>
4168QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4169 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004170 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004171 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4172 TL.getTypePtr()->getDecl());
4173 if (!D) return QualType();
4174
4175 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4176 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4177 return T;
4178}
4179
Douglas Gregord6ff3322009-08-04 16:50:30 +00004180template<typename Derived>
4181QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004182 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004183 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004184 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004185}
4186
Mike Stump11289f42009-09-09 15:08:12 +00004187template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004188QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004189 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004190 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004191 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4192
4193 // Substitute into the replacement type, which itself might involve something
4194 // that needs to be transformed. This only tends to occur with default
4195 // template arguments of template template parameters.
4196 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4197 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4198 if (Replacement.isNull())
4199 return QualType();
4200
4201 // Always canonicalize the replacement type.
4202 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4203 QualType Result
4204 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4205 Replacement);
4206
4207 // Propagate type-source information.
4208 SubstTemplateTypeParmTypeLoc NewTL
4209 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4210 NewTL.setNameLoc(TL.getNameLoc());
4211 return Result;
4212
John McCallcebee162009-10-18 09:09:24 +00004213}
4214
4215template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004216QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4217 TypeLocBuilder &TLB,
4218 SubstTemplateTypeParmPackTypeLoc TL) {
4219 return TransformTypeSpecType(TLB, TL);
4220}
4221
4222template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004223QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004224 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004225 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004226 const TemplateSpecializationType *T = TL.getTypePtr();
4227
Douglas Gregordf846d12011-03-02 18:46:51 +00004228 // The nested-name-specifier never matters in a TemplateSpecializationType,
4229 // because we can't have a dependent nested-name-specifier anyway.
4230 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004231 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004232 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4233 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004234 if (Template.isNull())
4235 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004236
John McCall31f82722010-11-12 08:19:04 +00004237 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4238}
4239
Douglas Gregorfe921a72010-12-20 23:36:19 +00004240namespace {
4241 /// \brief Simple iterator that traverses the template arguments in a
4242 /// container that provides a \c getArgLoc() member function.
4243 ///
4244 /// This iterator is intended to be used with the iterator form of
4245 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4246 template<typename ArgLocContainer>
4247 class TemplateArgumentLocContainerIterator {
4248 ArgLocContainer *Container;
4249 unsigned Index;
4250
4251 public:
4252 typedef TemplateArgumentLoc value_type;
4253 typedef TemplateArgumentLoc reference;
4254 typedef int difference_type;
4255 typedef std::input_iterator_tag iterator_category;
4256
4257 class pointer {
4258 TemplateArgumentLoc Arg;
4259
4260 public:
4261 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4262
4263 const TemplateArgumentLoc *operator->() const {
4264 return &Arg;
4265 }
4266 };
4267
4268
4269 TemplateArgumentLocContainerIterator() {}
4270
4271 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4272 unsigned Index)
4273 : Container(&Container), Index(Index) { }
4274
4275 TemplateArgumentLocContainerIterator &operator++() {
4276 ++Index;
4277 return *this;
4278 }
4279
4280 TemplateArgumentLocContainerIterator operator++(int) {
4281 TemplateArgumentLocContainerIterator Old(*this);
4282 ++(*this);
4283 return Old;
4284 }
4285
4286 TemplateArgumentLoc operator*() const {
4287 return Container->getArgLoc(Index);
4288 }
4289
4290 pointer operator->() const {
4291 return pointer(Container->getArgLoc(Index));
4292 }
4293
4294 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004295 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004296 return X.Container == Y.Container && X.Index == Y.Index;
4297 }
4298
4299 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004300 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004301 return !(X == Y);
4302 }
4303 };
4304}
4305
4306
John McCall31f82722010-11-12 08:19:04 +00004307template <typename Derived>
4308QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4309 TypeLocBuilder &TLB,
4310 TemplateSpecializationTypeLoc TL,
4311 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004312 TemplateArgumentListInfo NewTemplateArgs;
4313 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4314 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004315 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4316 ArgIterator;
4317 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4318 ArgIterator(TL, TL.getNumArgs()),
4319 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004320 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004321
John McCall0ad16662009-10-29 08:12:44 +00004322 // FIXME: maybe don't rebuild if all the template arguments are the same.
4323
4324 QualType Result =
4325 getDerived().RebuildTemplateSpecializationType(Template,
4326 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004327 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004328
4329 if (!Result.isNull()) {
4330 TemplateSpecializationTypeLoc NewTL
4331 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4332 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4333 NewTL.setLAngleLoc(TL.getLAngleLoc());
4334 NewTL.setRAngleLoc(TL.getRAngleLoc());
4335 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4336 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004337 }
Mike Stump11289f42009-09-09 15:08:12 +00004338
John McCall0ad16662009-10-29 08:12:44 +00004339 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004340}
Mike Stump11289f42009-09-09 15:08:12 +00004341
Douglas Gregor5a064722011-02-28 17:23:35 +00004342template <typename Derived>
4343QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4344 TypeLocBuilder &TLB,
4345 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004346 TemplateName Template,
4347 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004348 TemplateArgumentListInfo NewTemplateArgs;
4349 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4350 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4351 typedef TemplateArgumentLocContainerIterator<
4352 DependentTemplateSpecializationTypeLoc> ArgIterator;
4353 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4354 ArgIterator(TL, TL.getNumArgs()),
4355 NewTemplateArgs))
4356 return QualType();
4357
4358 // FIXME: maybe don't rebuild if all the template arguments are the same.
4359
4360 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4361 QualType Result
4362 = getSema().Context.getDependentTemplateSpecializationType(
4363 TL.getTypePtr()->getKeyword(),
4364 DTN->getQualifier(),
4365 DTN->getIdentifier(),
4366 NewTemplateArgs);
4367
4368 DependentTemplateSpecializationTypeLoc NewTL
4369 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4370 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004371
Douglas Gregora7a795b2011-03-01 20:11:18 +00004372 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004373 NewTL.setNameLoc(TL.getNameLoc());
4374 NewTL.setLAngleLoc(TL.getLAngleLoc());
4375 NewTL.setRAngleLoc(TL.getRAngleLoc());
4376 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4377 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4378 return Result;
4379 }
4380
4381 QualType Result
4382 = getDerived().RebuildTemplateSpecializationType(Template,
4383 TL.getNameLoc(),
4384 NewTemplateArgs);
4385
4386 if (!Result.isNull()) {
4387 /// FIXME: Wrap this in an elaborated-type-specifier?
4388 TemplateSpecializationTypeLoc NewTL
4389 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4390 NewTL.setTemplateNameLoc(TL.getNameLoc());
4391 NewTL.setLAngleLoc(TL.getLAngleLoc());
4392 NewTL.setRAngleLoc(TL.getRAngleLoc());
4393 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4394 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4395 }
4396
4397 return Result;
4398}
4399
Mike Stump11289f42009-09-09 15:08:12 +00004400template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004401QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004402TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004403 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004404 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004405
Douglas Gregor844cb502011-03-01 18:12:44 +00004406 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004407 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004408 if (TL.getQualifierLoc()) {
4409 QualifierLoc
4410 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4411 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004412 return QualType();
4413 }
Mike Stump11289f42009-09-09 15:08:12 +00004414
John McCall31f82722010-11-12 08:19:04 +00004415 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4416 if (NamedT.isNull())
4417 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004418
John McCall550e0c22009-10-21 00:40:46 +00004419 QualType Result = TL.getType();
4420 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004421 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004422 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004423 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004424 T->getKeyword(),
4425 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004426 if (Result.isNull())
4427 return QualType();
4428 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004429
Abramo Bagnara6150c882010-05-11 21:36:43 +00004430 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004431 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004432 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004433 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004434}
Mike Stump11289f42009-09-09 15:08:12 +00004435
4436template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004437QualType TreeTransform<Derived>::TransformAttributedType(
4438 TypeLocBuilder &TLB,
4439 AttributedTypeLoc TL) {
4440 const AttributedType *oldType = TL.getTypePtr();
4441 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4442 if (modifiedType.isNull())
4443 return QualType();
4444
4445 QualType result = TL.getType();
4446
4447 // FIXME: dependent operand expressions?
4448 if (getDerived().AlwaysRebuild() ||
4449 modifiedType != oldType->getModifiedType()) {
4450 // TODO: this is really lame; we should really be rebuilding the
4451 // equivalent type from first principles.
4452 QualType equivalentType
4453 = getDerived().TransformType(oldType->getEquivalentType());
4454 if (equivalentType.isNull())
4455 return QualType();
4456 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4457 modifiedType,
4458 equivalentType);
4459 }
4460
4461 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4462 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4463 if (TL.hasAttrOperand())
4464 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4465 if (TL.hasAttrExprOperand())
4466 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4467 else if (TL.hasAttrEnumOperand())
4468 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4469
4470 return result;
4471}
4472
4473template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004474QualType
4475TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4476 ParenTypeLoc TL) {
4477 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4478 if (Inner.isNull())
4479 return QualType();
4480
4481 QualType Result = TL.getType();
4482 if (getDerived().AlwaysRebuild() ||
4483 Inner != TL.getInnerLoc().getType()) {
4484 Result = getDerived().RebuildParenType(Inner);
4485 if (Result.isNull())
4486 return QualType();
4487 }
4488
4489 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4490 NewTL.setLParenLoc(TL.getLParenLoc());
4491 NewTL.setRParenLoc(TL.getRParenLoc());
4492 return Result;
4493}
4494
4495template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004496QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004497 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004498 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004499
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004500 NestedNameSpecifierLoc QualifierLoc
4501 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4502 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004503 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004504
John McCallc392f372010-06-11 00:33:02 +00004505 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004506 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004507 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004508 QualifierLoc,
4509 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004510 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004511 if (Result.isNull())
4512 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004513
Abramo Bagnarad7548482010-05-19 21:37:53 +00004514 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4515 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004516 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4517
Abramo Bagnarad7548482010-05-19 21:37:53 +00004518 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4519 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004520 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004521 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004522 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4523 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004524 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004525 NewTL.setNameLoc(TL.getNameLoc());
4526 }
John McCall550e0c22009-10-21 00:40:46 +00004527 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004528}
Mike Stump11289f42009-09-09 15:08:12 +00004529
Douglas Gregord6ff3322009-08-04 16:50:30 +00004530template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004531QualType TreeTransform<Derived>::
4532 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004533 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004534 NestedNameSpecifierLoc QualifierLoc;
4535 if (TL.getQualifierLoc()) {
4536 QualifierLoc
4537 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4538 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004539 return QualType();
4540 }
4541
John McCall31f82722010-11-12 08:19:04 +00004542 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004543 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004544}
4545
4546template<typename Derived>
4547QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00004548TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4549 DependentTemplateSpecializationTypeLoc TL,
4550 NestedNameSpecifierLoc QualifierLoc) {
4551 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4552
4553 TemplateArgumentListInfo NewTemplateArgs;
4554 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4555 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4556
4557 typedef TemplateArgumentLocContainerIterator<
4558 DependentTemplateSpecializationTypeLoc> ArgIterator;
4559 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4560 ArgIterator(TL, TL.getNumArgs()),
4561 NewTemplateArgs))
4562 return QualType();
4563
4564 QualType Result
4565 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4566 QualifierLoc,
4567 T->getIdentifier(),
4568 TL.getNameLoc(),
4569 NewTemplateArgs);
4570 if (Result.isNull())
4571 return QualType();
4572
4573 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4574 QualType NamedT = ElabT->getNamedType();
4575
4576 // Copy information relevant to the template specialization.
4577 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00004578 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004579 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004580 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4581 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004582 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004583 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004584
4585 // Copy information relevant to the elaborated type.
4586 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4587 NewTL.setKeywordLoc(TL.getKeywordLoc());
4588 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00004589 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4590 DependentTemplateSpecializationTypeLoc SpecTL
4591 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor11ddf132011-03-07 15:13:34 +00004592 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004593 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004594 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004595 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4596 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004597 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004598 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004599 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00004600 TemplateSpecializationTypeLoc SpecTL
4601 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004602 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004603 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4604 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004605 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004606 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004607 }
4608 return Result;
4609}
4610
4611template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004612QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4613 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004614 QualType Pattern
4615 = getDerived().TransformType(TLB, TL.getPatternLoc());
4616 if (Pattern.isNull())
4617 return QualType();
4618
4619 QualType Result = TL.getType();
4620 if (getDerived().AlwaysRebuild() ||
4621 Pattern != TL.getPatternLoc().getType()) {
4622 Result = getDerived().RebuildPackExpansionType(Pattern,
4623 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004624 TL.getEllipsisLoc(),
4625 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004626 if (Result.isNull())
4627 return QualType();
4628 }
4629
4630 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4631 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4632 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004633}
4634
4635template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004636QualType
4637TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004638 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004639 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004640 TLB.pushFullCopy(TL);
4641 return TL.getType();
4642}
4643
4644template<typename Derived>
4645QualType
4646TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004647 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004648 // ObjCObjectType is never dependent.
4649 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004650 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004651}
Mike Stump11289f42009-09-09 15:08:12 +00004652
4653template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004654QualType
4655TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004656 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004657 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004658 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004659 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004660}
4661
Douglas Gregord6ff3322009-08-04 16:50:30 +00004662//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004663// Statement transformation
4664//===----------------------------------------------------------------------===//
4665template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004666StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004667TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004668 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004669}
4670
4671template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004672StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004673TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4674 return getDerived().TransformCompoundStmt(S, false);
4675}
4676
4677template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004678StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004679TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004680 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004681 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004682 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004683 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004684 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4685 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004686 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004687 if (Result.isInvalid()) {
4688 // Immediately fail if this was a DeclStmt, since it's very
4689 // likely that this will cause problems for future statements.
4690 if (isa<DeclStmt>(*B))
4691 return StmtError();
4692
4693 // Otherwise, just keep processing substatements and fail later.
4694 SubStmtInvalid = true;
4695 continue;
4696 }
Mike Stump11289f42009-09-09 15:08:12 +00004697
Douglas Gregorebe10102009-08-20 07:17:43 +00004698 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4699 Statements.push_back(Result.takeAs<Stmt>());
4700 }
Mike Stump11289f42009-09-09 15:08:12 +00004701
John McCall1ababa62010-08-27 19:56:05 +00004702 if (SubStmtInvalid)
4703 return StmtError();
4704
Douglas Gregorebe10102009-08-20 07:17:43 +00004705 if (!getDerived().AlwaysRebuild() &&
4706 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004707 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004708
4709 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4710 move_arg(Statements),
4711 S->getRBracLoc(),
4712 IsStmtExpr);
4713}
Mike Stump11289f42009-09-09 15:08:12 +00004714
Douglas Gregorebe10102009-08-20 07:17:43 +00004715template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004716StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004717TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004718 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004719 {
4720 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004721 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004722
Eli Friedman06577382009-11-19 03:14:00 +00004723 // Transform the left-hand case value.
4724 LHS = getDerived().TransformExpr(S->getLHS());
4725 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004726 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004727
Eli Friedman06577382009-11-19 03:14:00 +00004728 // Transform the right-hand case value (for the GNU case-range extension).
4729 RHS = getDerived().TransformExpr(S->getRHS());
4730 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004731 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004732 }
Mike Stump11289f42009-09-09 15:08:12 +00004733
Douglas Gregorebe10102009-08-20 07:17:43 +00004734 // Build the case statement.
4735 // Case statements are always rebuilt so that they will attached to their
4736 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004737 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004738 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004739 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004740 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004741 S->getColonLoc());
4742 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004743 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004744
Douglas Gregorebe10102009-08-20 07:17:43 +00004745 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004746 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004747 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004748 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004749
Douglas Gregorebe10102009-08-20 07:17:43 +00004750 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004751 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004752}
4753
4754template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004755StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004756TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004757 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004758 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004759 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004760 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004761
Douglas Gregorebe10102009-08-20 07:17:43 +00004762 // Default statements are always rebuilt
4763 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004764 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004765}
Mike Stump11289f42009-09-09 15:08:12 +00004766
Douglas Gregorebe10102009-08-20 07:17:43 +00004767template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004768StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004769TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004770 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004771 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004772 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004773
Chris Lattnercab02a62011-02-17 20:34:02 +00004774 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4775 S->getDecl());
4776 if (!LD)
4777 return StmtError();
4778
4779
Douglas Gregorebe10102009-08-20 07:17:43 +00004780 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004781 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004782 cast<LabelDecl>(LD), SourceLocation(),
4783 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004784}
Mike Stump11289f42009-09-09 15:08:12 +00004785
Douglas Gregorebe10102009-08-20 07:17:43 +00004786template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004787StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004788TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004789 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004790 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004791 VarDecl *ConditionVar = 0;
4792 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004793 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004794 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004795 getDerived().TransformDefinition(
4796 S->getConditionVariable()->getLocation(),
4797 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004798 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004799 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004800 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004801 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004802
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004803 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004804 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004805
4806 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004807 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004808 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4809 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004810 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004811 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004812
John McCallb268a282010-08-23 23:25:46 +00004813 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004814 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004815 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004816
John McCallb268a282010-08-23 23:25:46 +00004817 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4818 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004819 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004820
Douglas Gregorebe10102009-08-20 07:17:43 +00004821 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004822 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004823 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004824 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004825
Douglas Gregorebe10102009-08-20 07:17:43 +00004826 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004827 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004828 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004829 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004830
Douglas Gregorebe10102009-08-20 07:17:43 +00004831 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004832 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004833 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004834 Then.get() == S->getThen() &&
4835 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004836 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004837
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004838 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004839 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004840 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004841}
4842
4843template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004844StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004845TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004846 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004847 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004848 VarDecl *ConditionVar = 0;
4849 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004850 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004851 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004852 getDerived().TransformDefinition(
4853 S->getConditionVariable()->getLocation(),
4854 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004855 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004856 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004857 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004858 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004859
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004860 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004861 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004862 }
Mike Stump11289f42009-09-09 15:08:12 +00004863
Douglas Gregorebe10102009-08-20 07:17:43 +00004864 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004865 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004866 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004867 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004868 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004869 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004870
Douglas Gregorebe10102009-08-20 07:17:43 +00004871 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004872 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004873 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004874 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004875
Douglas Gregorebe10102009-08-20 07:17:43 +00004876 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004877 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4878 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004879}
Mike Stump11289f42009-09-09 15:08:12 +00004880
Douglas Gregorebe10102009-08-20 07:17:43 +00004881template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004882StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004883TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004884 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004885 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004886 VarDecl *ConditionVar = 0;
4887 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004888 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004889 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004890 getDerived().TransformDefinition(
4891 S->getConditionVariable()->getLocation(),
4892 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004893 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004894 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004895 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004896 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004897
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004898 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004899 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004900
4901 if (S->getCond()) {
4902 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004903 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4904 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004905 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004906 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004907 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004908 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004909 }
Mike Stump11289f42009-09-09 15:08:12 +00004910
John McCallb268a282010-08-23 23:25:46 +00004911 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4912 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004913 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004914
Douglas Gregorebe10102009-08-20 07:17:43 +00004915 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004916 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004917 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004918 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004919
Douglas Gregorebe10102009-08-20 07:17:43 +00004920 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004921 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004922 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004923 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004924 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004925
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004926 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004927 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004928}
Mike Stump11289f42009-09-09 15:08:12 +00004929
Douglas Gregorebe10102009-08-20 07:17:43 +00004930template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004931StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004932TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004933 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004934 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004935 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004936 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004937
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004938 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004939 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004940 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004941 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004942
Douglas Gregorebe10102009-08-20 07:17:43 +00004943 if (!getDerived().AlwaysRebuild() &&
4944 Cond.get() == S->getCond() &&
4945 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004946 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004947
John McCallb268a282010-08-23 23:25:46 +00004948 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4949 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004950 S->getRParenLoc());
4951}
Mike Stump11289f42009-09-09 15:08:12 +00004952
Douglas Gregorebe10102009-08-20 07:17:43 +00004953template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004954StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004955TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004956 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004957 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004958 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004959 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004960
Douglas Gregorebe10102009-08-20 07:17:43 +00004961 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004962 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004963 VarDecl *ConditionVar = 0;
4964 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004965 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004966 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004967 getDerived().TransformDefinition(
4968 S->getConditionVariable()->getLocation(),
4969 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004970 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004971 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004972 } else {
4973 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004974
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004975 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004976 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004977
4978 if (S->getCond()) {
4979 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004980 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4981 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004982 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004983 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004984
John McCallb268a282010-08-23 23:25:46 +00004985 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004986 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004987 }
Mike Stump11289f42009-09-09 15:08:12 +00004988
John McCallb268a282010-08-23 23:25:46 +00004989 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4990 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004991 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004992
Douglas Gregorebe10102009-08-20 07:17:43 +00004993 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00004994 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00004995 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004996 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004997
John McCallb268a282010-08-23 23:25:46 +00004998 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4999 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005000 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005001
Douglas Gregorebe10102009-08-20 07:17:43 +00005002 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005003 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005004 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005005 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005006
Douglas Gregorebe10102009-08-20 07:17:43 +00005007 if (!getDerived().AlwaysRebuild() &&
5008 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005009 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005010 Inc.get() == S->getInc() &&
5011 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005012 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005013
Douglas Gregorebe10102009-08-20 07:17:43 +00005014 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005015 Init.get(), FullCond, ConditionVar,
5016 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005017}
5018
5019template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005020StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005021TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005022 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5023 S->getLabel());
5024 if (!LD)
5025 return StmtError();
5026
Douglas Gregorebe10102009-08-20 07:17:43 +00005027 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005028 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005029 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005030}
5031
5032template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005033StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005034TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005035 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005036 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005037 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005038
Douglas Gregorebe10102009-08-20 07:17:43 +00005039 if (!getDerived().AlwaysRebuild() &&
5040 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005041 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005042
5043 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005044 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005045}
5046
5047template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005048StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005049TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005050 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005051}
Mike Stump11289f42009-09-09 15:08:12 +00005052
Douglas Gregorebe10102009-08-20 07:17:43 +00005053template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005054StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005055TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005056 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005057}
Mike Stump11289f42009-09-09 15:08:12 +00005058
Douglas Gregorebe10102009-08-20 07:17:43 +00005059template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005060StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005061TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005062 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005063 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005064 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005065
Mike Stump11289f42009-09-09 15:08:12 +00005066 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005067 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005068 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005069}
Mike Stump11289f42009-09-09 15:08:12 +00005070
Douglas Gregorebe10102009-08-20 07:17:43 +00005071template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005072StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005073TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005074 bool DeclChanged = false;
5075 llvm::SmallVector<Decl *, 4> Decls;
5076 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5077 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005078 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5079 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005080 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005081 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005082
Douglas Gregorebe10102009-08-20 07:17:43 +00005083 if (Transformed != *D)
5084 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005085
Douglas Gregorebe10102009-08-20 07:17:43 +00005086 Decls.push_back(Transformed);
5087 }
Mike Stump11289f42009-09-09 15:08:12 +00005088
Douglas Gregorebe10102009-08-20 07:17:43 +00005089 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005090 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005091
5092 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005093 S->getStartLoc(), S->getEndLoc());
5094}
Mike Stump11289f42009-09-09 15:08:12 +00005095
Douglas Gregorebe10102009-08-20 07:17:43 +00005096template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005097StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005098TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005099
John McCall37ad5512010-08-23 06:44:23 +00005100 ASTOwningVector<Expr*> Constraints(getSema());
5101 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00005102 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005103
John McCalldadc5752010-08-24 06:29:42 +00005104 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005105 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005106
5107 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005108
Anders Carlssonaaeef072010-01-24 05:50:09 +00005109 // Go through the outputs.
5110 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005111 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005112
Anders Carlssonaaeef072010-01-24 05:50:09 +00005113 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005114 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005115
Anders Carlssonaaeef072010-01-24 05:50:09 +00005116 // Transform the output expr.
5117 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005118 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005119 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005120 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005121
Anders Carlssonaaeef072010-01-24 05:50:09 +00005122 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005123
John McCallb268a282010-08-23 23:25:46 +00005124 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005125 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005126
Anders Carlssonaaeef072010-01-24 05:50:09 +00005127 // Go through the inputs.
5128 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005129 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005130
Anders Carlssonaaeef072010-01-24 05:50:09 +00005131 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005132 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005133
Anders Carlssonaaeef072010-01-24 05:50:09 +00005134 // Transform the input expr.
5135 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005136 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005137 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005138 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005139
Anders Carlssonaaeef072010-01-24 05:50:09 +00005140 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005141
John McCallb268a282010-08-23 23:25:46 +00005142 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005143 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005144
Anders Carlssonaaeef072010-01-24 05:50:09 +00005145 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005146 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005147
5148 // Go through the clobbers.
5149 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005150 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005151
5152 // No need to transform the asm string literal.
5153 AsmString = SemaRef.Owned(S->getAsmString());
5154
5155 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5156 S->isSimple(),
5157 S->isVolatile(),
5158 S->getNumOutputs(),
5159 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005160 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005161 move_arg(Constraints),
5162 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005163 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005164 move_arg(Clobbers),
5165 S->getRParenLoc(),
5166 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005167}
5168
5169
5170template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005171StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005172TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005173 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005174 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005175 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005176 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005177
Douglas Gregor96c79492010-04-23 22:50:49 +00005178 // Transform the @catch statements (if present).
5179 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005180 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005181 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005182 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005183 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005184 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005185 if (Catch.get() != S->getCatchStmt(I))
5186 AnyCatchChanged = true;
5187 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005188 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005189
Douglas Gregor306de2f2010-04-22 23:59:56 +00005190 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005191 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005192 if (S->getFinallyStmt()) {
5193 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5194 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005195 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005196 }
5197
5198 // If nothing changed, just retain this statement.
5199 if (!getDerived().AlwaysRebuild() &&
5200 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005201 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005202 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005203 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005204
Douglas Gregor306de2f2010-04-22 23:59:56 +00005205 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005206 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5207 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005208}
Mike Stump11289f42009-09-09 15:08:12 +00005209
Douglas Gregorebe10102009-08-20 07:17:43 +00005210template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005211StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005212TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005213 // Transform the @catch parameter, if there is one.
5214 VarDecl *Var = 0;
5215 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5216 TypeSourceInfo *TSInfo = 0;
5217 if (FromVar->getTypeSourceInfo()) {
5218 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5219 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005220 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005221 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005222
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005223 QualType T;
5224 if (TSInfo)
5225 T = TSInfo->getType();
5226 else {
5227 T = getDerived().TransformType(FromVar->getType());
5228 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005229 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005230 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005231
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005232 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5233 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005234 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005235 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005236
John McCalldadc5752010-08-24 06:29:42 +00005237 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005238 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005239 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005240
5241 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005242 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005243 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005244}
Mike Stump11289f42009-09-09 15:08:12 +00005245
Douglas Gregorebe10102009-08-20 07:17:43 +00005246template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005247StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005248TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005249 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005250 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005251 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005252 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005253
Douglas Gregor306de2f2010-04-22 23:59:56 +00005254 // If nothing changed, just retain this statement.
5255 if (!getDerived().AlwaysRebuild() &&
5256 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005257 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005258
5259 // Build a new statement.
5260 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005261 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005262}
Mike Stump11289f42009-09-09 15:08:12 +00005263
Douglas Gregorebe10102009-08-20 07:17:43 +00005264template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005265StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005266TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005267 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005268 if (S->getThrowExpr()) {
5269 Operand = getDerived().TransformExpr(S->getThrowExpr());
5270 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005271 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005272 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005273
Douglas Gregor2900c162010-04-22 21:44:01 +00005274 if (!getDerived().AlwaysRebuild() &&
5275 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005276 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005277
John McCallb268a282010-08-23 23:25:46 +00005278 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005279}
Mike Stump11289f42009-09-09 15:08:12 +00005280
Douglas Gregorebe10102009-08-20 07:17:43 +00005281template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005282StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005283TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005284 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005285 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005286 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005287 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005288 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005289
Douglas Gregor6148de72010-04-22 22:01:21 +00005290 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005291 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005292 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005293 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005294
Douglas Gregor6148de72010-04-22 22:01:21 +00005295 // If nothing change, just retain the current statement.
5296 if (!getDerived().AlwaysRebuild() &&
5297 Object.get() == S->getSynchExpr() &&
5298 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005299 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005300
5301 // Build a new statement.
5302 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005303 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005304}
5305
5306template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005307StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005308TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005309 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005310 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005311 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005312 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005313 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005314
Douglas Gregorf68a5082010-04-22 23:10:45 +00005315 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005316 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005317 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005318 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005319
Douglas Gregorf68a5082010-04-22 23:10:45 +00005320 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005321 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005322 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005323 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005324
Douglas Gregorf68a5082010-04-22 23:10:45 +00005325 // If nothing changed, just retain this statement.
5326 if (!getDerived().AlwaysRebuild() &&
5327 Element.get() == S->getElement() &&
5328 Collection.get() == S->getCollection() &&
5329 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005330 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005331
Douglas Gregorf68a5082010-04-22 23:10:45 +00005332 // Build a new statement.
5333 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5334 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005335 Element.get(),
5336 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005337 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005338 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005339}
5340
5341
5342template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005343StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005344TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5345 // Transform the exception declaration, if any.
5346 VarDecl *Var = 0;
5347 if (S->getExceptionDecl()) {
5348 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005349 TypeSourceInfo *T = getDerived().TransformType(
5350 ExceptionDecl->getTypeSourceInfo());
5351 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005352 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005353
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005354 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaradff19302011-03-08 08:55:46 +00005355 ExceptionDecl->getInnerLocStart(),
5356 ExceptionDecl->getLocation(),
5357 ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00005358 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005359 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005360 }
Mike Stump11289f42009-09-09 15:08:12 +00005361
Douglas Gregorebe10102009-08-20 07:17:43 +00005362 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005363 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005364 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005365 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005366
Douglas Gregorebe10102009-08-20 07:17:43 +00005367 if (!getDerived().AlwaysRebuild() &&
5368 !Var &&
5369 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005370 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005371
5372 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5373 Var,
John McCallb268a282010-08-23 23:25:46 +00005374 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005375}
Mike Stump11289f42009-09-09 15:08:12 +00005376
Douglas Gregorebe10102009-08-20 07:17:43 +00005377template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005378StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005379TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5380 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005381 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005382 = getDerived().TransformCompoundStmt(S->getTryBlock());
5383 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005384 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005385
Douglas Gregorebe10102009-08-20 07:17:43 +00005386 // Transform the handlers.
5387 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005388 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005389 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005390 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005391 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5392 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005393 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005394
Douglas Gregorebe10102009-08-20 07:17:43 +00005395 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5396 Handlers.push_back(Handler.takeAs<Stmt>());
5397 }
Mike Stump11289f42009-09-09 15:08:12 +00005398
Douglas Gregorebe10102009-08-20 07:17:43 +00005399 if (!getDerived().AlwaysRebuild() &&
5400 TryBlock.get() == S->getTryBlock() &&
5401 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005402 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005403
John McCallb268a282010-08-23 23:25:46 +00005404 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005405 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005406}
Mike Stump11289f42009-09-09 15:08:12 +00005407
Richard Smith02e85f32011-04-14 22:09:26 +00005408template<typename Derived>
5409StmtResult
5410TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5411 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5412 if (Range.isInvalid())
5413 return StmtError();
5414
5415 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5416 if (BeginEnd.isInvalid())
5417 return StmtError();
5418
5419 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5420 if (Cond.isInvalid())
5421 return StmtError();
5422
5423 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5424 if (Inc.isInvalid())
5425 return StmtError();
5426
5427 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5428 if (LoopVar.isInvalid())
5429 return StmtError();
5430
5431 StmtResult NewStmt = S;
5432 if (getDerived().AlwaysRebuild() ||
5433 Range.get() != S->getRangeStmt() ||
5434 BeginEnd.get() != S->getBeginEndStmt() ||
5435 Cond.get() != S->getCond() ||
5436 Inc.get() != S->getInc() ||
5437 LoopVar.get() != S->getLoopVarStmt())
5438 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5439 S->getColonLoc(), Range.get(),
5440 BeginEnd.get(), Cond.get(),
5441 Inc.get(), LoopVar.get(),
5442 S->getRParenLoc());
5443
5444 StmtResult Body = getDerived().TransformStmt(S->getBody());
5445 if (Body.isInvalid())
5446 return StmtError();
5447
5448 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5449 // it now so we have a new statement to attach the body to.
5450 if (Body.get() != S->getBody() && NewStmt.get() == S)
5451 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5452 S->getColonLoc(), Range.get(),
5453 BeginEnd.get(), Cond.get(),
5454 Inc.get(), LoopVar.get(),
5455 S->getRParenLoc());
5456
5457 if (NewStmt.get() == S)
5458 return SemaRef.Owned(S);
5459
5460 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5461}
5462
Douglas Gregorebe10102009-08-20 07:17:43 +00005463//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005464// Expression transformation
5465//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005466template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005467ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005468TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005469 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005470}
Mike Stump11289f42009-09-09 15:08:12 +00005471
5472template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005473ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005474TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005475 NestedNameSpecifierLoc QualifierLoc;
5476 if (E->getQualifierLoc()) {
5477 QualifierLoc
5478 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5479 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005480 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005481 }
John McCallce546572009-12-08 09:08:17 +00005482
5483 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005484 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5485 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005486 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005487 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005488
John McCall815039a2010-08-17 21:27:17 +00005489 DeclarationNameInfo NameInfo = E->getNameInfo();
5490 if (NameInfo.getName()) {
5491 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5492 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005493 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005494 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005495
5496 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005497 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005498 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005499 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005500 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005501
5502 // Mark it referenced in the new context regardless.
5503 // FIXME: this is a bit instantiation-specific.
5504 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5505
John McCallc3007a22010-10-26 07:05:15 +00005506 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005507 }
John McCallce546572009-12-08 09:08:17 +00005508
5509 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005510 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005511 TemplateArgs = &TransArgs;
5512 TransArgs.setLAngleLoc(E->getLAngleLoc());
5513 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005514 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5515 E->getNumTemplateArgs(),
5516 TransArgs))
5517 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005518 }
5519
Douglas Gregorea972d32011-02-28 21:54:11 +00005520 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5521 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005522}
Mike Stump11289f42009-09-09 15:08:12 +00005523
Douglas Gregora16548e2009-08-11 05:31:07 +00005524template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005525ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005526TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005527 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005528}
Mike Stump11289f42009-09-09 15:08:12 +00005529
Douglas Gregora16548e2009-08-11 05:31:07 +00005530template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005531ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005532TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005533 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005534}
Mike Stump11289f42009-09-09 15:08:12 +00005535
Douglas Gregora16548e2009-08-11 05:31:07 +00005536template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005537ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005538TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005539 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005540}
Mike Stump11289f42009-09-09 15:08:12 +00005541
Douglas Gregora16548e2009-08-11 05:31:07 +00005542template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005543ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005544TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005545 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005546}
Mike Stump11289f42009-09-09 15:08:12 +00005547
Douglas Gregora16548e2009-08-11 05:31:07 +00005548template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005549ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005550TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005551 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005552}
5553
5554template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005555ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00005556TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5557 ExprResult ControllingExpr =
5558 getDerived().TransformExpr(E->getControllingExpr());
5559 if (ControllingExpr.isInvalid())
5560 return ExprError();
5561
5562 llvm::SmallVector<Expr *, 4> AssocExprs;
5563 llvm::SmallVector<TypeSourceInfo *, 4> AssocTypes;
5564 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5565 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5566 if (TS) {
5567 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5568 if (!AssocType)
5569 return ExprError();
5570 AssocTypes.push_back(AssocType);
5571 } else {
5572 AssocTypes.push_back(0);
5573 }
5574
5575 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5576 if (AssocExpr.isInvalid())
5577 return ExprError();
5578 AssocExprs.push_back(AssocExpr.release());
5579 }
5580
5581 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5582 E->getDefaultLoc(),
5583 E->getRParenLoc(),
5584 ControllingExpr.release(),
5585 AssocTypes.data(),
5586 AssocExprs.data(),
5587 E->getNumAssocs());
5588}
5589
5590template<typename Derived>
5591ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005592TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005593 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005594 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005595 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005596
Douglas Gregora16548e2009-08-11 05:31:07 +00005597 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005598 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005599
John McCallb268a282010-08-23 23:25:46 +00005600 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005601 E->getRParen());
5602}
5603
Mike Stump11289f42009-09-09 15:08:12 +00005604template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005605ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005606TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005607 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005608 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005609 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005610
Douglas Gregora16548e2009-08-11 05:31:07 +00005611 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005612 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005613
Douglas Gregora16548e2009-08-11 05:31:07 +00005614 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5615 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005616 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005617}
Mike Stump11289f42009-09-09 15:08:12 +00005618
Douglas Gregora16548e2009-08-11 05:31:07 +00005619template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005620ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005621TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5622 // Transform the type.
5623 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5624 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005625 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005626
Douglas Gregor882211c2010-04-28 22:16:22 +00005627 // Transform all of the components into components similar to what the
5628 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005629 // FIXME: It would be slightly more efficient in the non-dependent case to
5630 // just map FieldDecls, rather than requiring the rebuilder to look for
5631 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005632 // template code that we don't care.
5633 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005634 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005635 typedef OffsetOfExpr::OffsetOfNode Node;
5636 llvm::SmallVector<Component, 4> Components;
5637 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5638 const Node &ON = E->getComponent(I);
5639 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005640 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00005641 Comp.LocStart = ON.getSourceRange().getBegin();
5642 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00005643 switch (ON.getKind()) {
5644 case Node::Array: {
5645 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005646 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005647 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005648 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005649
Douglas Gregor882211c2010-04-28 22:16:22 +00005650 ExprChanged = ExprChanged || Index.get() != FromIndex;
5651 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005652 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005653 break;
5654 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005655
Douglas Gregor882211c2010-04-28 22:16:22 +00005656 case Node::Field:
5657 case Node::Identifier:
5658 Comp.isBrackets = false;
5659 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005660 if (!Comp.U.IdentInfo)
5661 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005662
Douglas Gregor882211c2010-04-28 22:16:22 +00005663 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005664
Douglas Gregord1702062010-04-29 00:18:15 +00005665 case Node::Base:
5666 // Will be recomputed during the rebuild.
5667 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005668 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005669
Douglas Gregor882211c2010-04-28 22:16:22 +00005670 Components.push_back(Comp);
5671 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005672
Douglas Gregor882211c2010-04-28 22:16:22 +00005673 // If nothing changed, retain the existing expression.
5674 if (!getDerived().AlwaysRebuild() &&
5675 Type == E->getTypeSourceInfo() &&
5676 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005677 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005678
Douglas Gregor882211c2010-04-28 22:16:22 +00005679 // Build a new offsetof expression.
5680 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5681 Components.data(), Components.size(),
5682 E->getRParenLoc());
5683}
5684
5685template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005686ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005687TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5688 assert(getDerived().AlreadyTransformed(E->getType()) &&
5689 "opaque value expression requires transformation");
5690 return SemaRef.Owned(E);
5691}
5692
5693template<typename Derived>
5694ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00005695TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
5696 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005697 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005698 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005699
John McCallbcd03502009-12-07 02:54:59 +00005700 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005701 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005702 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005703
John McCall4c98fd82009-11-04 07:28:41 +00005704 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005705 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005706
Peter Collingbournee190dee2011-03-11 19:24:49 +00005707 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
5708 E->getKind(),
5709 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005710 }
Mike Stump11289f42009-09-09 15:08:12 +00005711
John McCalldadc5752010-08-24 06:29:42 +00005712 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005713 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005714 // C++0x [expr.sizeof]p1:
5715 // The operand is either an expression, which is an unevaluated operand
5716 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005717 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005718
Douglas Gregora16548e2009-08-11 05:31:07 +00005719 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5720 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005721 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005722
Douglas Gregora16548e2009-08-11 05:31:07 +00005723 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005724 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005725 }
Mike Stump11289f42009-09-09 15:08:12 +00005726
Peter Collingbournee190dee2011-03-11 19:24:49 +00005727 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
5728 E->getOperatorLoc(),
5729 E->getKind(),
5730 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005731}
Mike Stump11289f42009-09-09 15:08:12 +00005732
Douglas Gregora16548e2009-08-11 05:31:07 +00005733template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005734ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005735TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005736 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005737 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005738 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005739
John McCalldadc5752010-08-24 06:29:42 +00005740 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005741 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005742 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005743
5744
Douglas Gregora16548e2009-08-11 05:31:07 +00005745 if (!getDerived().AlwaysRebuild() &&
5746 LHS.get() == E->getLHS() &&
5747 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005748 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005749
John McCallb268a282010-08-23 23:25:46 +00005750 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005751 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005752 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005753 E->getRBracketLoc());
5754}
Mike Stump11289f42009-09-09 15:08:12 +00005755
5756template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005757ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005758TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005759 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005760 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005761 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005762 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005763
5764 // Transform arguments.
5765 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005766 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005767 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5768 &ArgChanged))
5769 return ExprError();
5770
Douglas Gregora16548e2009-08-11 05:31:07 +00005771 if (!getDerived().AlwaysRebuild() &&
5772 Callee.get() == E->getCallee() &&
5773 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005774 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005775
Douglas Gregora16548e2009-08-11 05:31:07 +00005776 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005777 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005778 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005779 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005780 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005781 E->getRParenLoc());
5782}
Mike Stump11289f42009-09-09 15:08:12 +00005783
5784template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005785ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005786TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005787 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005788 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005789 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005790
Douglas Gregorea972d32011-02-28 21:54:11 +00005791 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005792 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005793 QualifierLoc
5794 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5795
5796 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005797 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005798 }
Mike Stump11289f42009-09-09 15:08:12 +00005799
Eli Friedman2cfcef62009-12-04 06:40:45 +00005800 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005801 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5802 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005803 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005804 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005805
John McCall16df1e52010-03-30 21:47:33 +00005806 NamedDecl *FoundDecl = E->getFoundDecl();
5807 if (FoundDecl == E->getMemberDecl()) {
5808 FoundDecl = Member;
5809 } else {
5810 FoundDecl = cast_or_null<NamedDecl>(
5811 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5812 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005813 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005814 }
5815
Douglas Gregora16548e2009-08-11 05:31:07 +00005816 if (!getDerived().AlwaysRebuild() &&
5817 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005818 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005819 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005820 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005821 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005822
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005823 // Mark it referenced in the new context regardless.
5824 // FIXME: this is a bit instantiation-specific.
5825 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005826 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005827 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005828
John McCall6b51f282009-11-23 01:53:49 +00005829 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005830 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005831 TransArgs.setLAngleLoc(E->getLAngleLoc());
5832 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005833 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5834 E->getNumTemplateArgs(),
5835 TransArgs))
5836 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005837 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005838
Douglas Gregora16548e2009-08-11 05:31:07 +00005839 // FIXME: Bogus source location for the operator
5840 SourceLocation FakeOperatorLoc
5841 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5842
John McCall38836f02010-01-15 08:34:02 +00005843 // FIXME: to do this check properly, we will need to preserve the
5844 // first-qualifier-in-scope here, just in case we had a dependent
5845 // base (and therefore couldn't do the check) and a
5846 // nested-name-qualifier (and therefore could do the lookup).
5847 NamedDecl *FirstQualifierInScope = 0;
5848
John McCallb268a282010-08-23 23:25:46 +00005849 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005850 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00005851 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005852 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005853 Member,
John McCall16df1e52010-03-30 21:47:33 +00005854 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005855 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005856 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005857 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005858}
Mike Stump11289f42009-09-09 15:08:12 +00005859
Douglas Gregora16548e2009-08-11 05:31:07 +00005860template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005861ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005862TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005863 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005864 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005865 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005866
John McCalldadc5752010-08-24 06:29:42 +00005867 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005868 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005869 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005870
Douglas Gregora16548e2009-08-11 05:31:07 +00005871 if (!getDerived().AlwaysRebuild() &&
5872 LHS.get() == E->getLHS() &&
5873 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005874 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005875
Douglas Gregora16548e2009-08-11 05:31:07 +00005876 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005877 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005878}
5879
Mike Stump11289f42009-09-09 15:08:12 +00005880template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005881ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005882TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005883 CompoundAssignOperator *E) {
5884 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005885}
Mike Stump11289f42009-09-09 15:08:12 +00005886
Douglas Gregora16548e2009-08-11 05:31:07 +00005887template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00005888ExprResult TreeTransform<Derived>::
5889TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
5890 // Just rebuild the common and RHS expressions and see whether we
5891 // get any changes.
5892
5893 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
5894 if (commonExpr.isInvalid())
5895 return ExprError();
5896
5897 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
5898 if (rhs.isInvalid())
5899 return ExprError();
5900
5901 if (!getDerived().AlwaysRebuild() &&
5902 commonExpr.get() == e->getCommon() &&
5903 rhs.get() == e->getFalseExpr())
5904 return SemaRef.Owned(e);
5905
5906 return getDerived().RebuildConditionalOperator(commonExpr.take(),
5907 e->getQuestionLoc(),
5908 0,
5909 e->getColonLoc(),
5910 rhs.get());
5911}
5912
5913template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005914ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005915TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005916 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005917 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005918 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005919
John McCalldadc5752010-08-24 06:29:42 +00005920 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005921 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005922 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005923
John McCalldadc5752010-08-24 06:29:42 +00005924 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005925 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005926 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005927
Douglas Gregora16548e2009-08-11 05:31:07 +00005928 if (!getDerived().AlwaysRebuild() &&
5929 Cond.get() == E->getCond() &&
5930 LHS.get() == E->getLHS() &&
5931 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005932 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005933
John McCallb268a282010-08-23 23:25:46 +00005934 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005935 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005936 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005937 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005938 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005939}
Mike Stump11289f42009-09-09 15:08:12 +00005940
5941template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005942ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005943TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005944 // Implicit casts are eliminated during transformation, since they
5945 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005946 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005947}
Mike Stump11289f42009-09-09 15:08:12 +00005948
Douglas Gregora16548e2009-08-11 05:31:07 +00005949template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005950ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005951TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005952 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5953 if (!Type)
5954 return ExprError();
5955
John McCalldadc5752010-08-24 06:29:42 +00005956 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005957 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005958 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005959 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005960
Douglas Gregora16548e2009-08-11 05:31:07 +00005961 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005962 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005963 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005964 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005965
John McCall97513962010-01-15 18:39:57 +00005966 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005967 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005968 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005969 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005970}
Mike Stump11289f42009-09-09 15:08:12 +00005971
Douglas Gregora16548e2009-08-11 05:31:07 +00005972template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005973ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005974TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005975 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5976 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5977 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005978 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005979
John McCalldadc5752010-08-24 06:29:42 +00005980 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005981 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005982 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005983
Douglas Gregora16548e2009-08-11 05:31:07 +00005984 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005985 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005986 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005987 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005988
John McCall5d7aa7f2010-01-19 22:33:45 +00005989 // Note: the expression type doesn't necessarily match the
5990 // type-as-written, but that's okay, because it should always be
5991 // derivable from the initializer.
5992
John McCalle15bbff2010-01-18 19:35:47 +00005993 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005994 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005995 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005996}
Mike Stump11289f42009-09-09 15:08:12 +00005997
Douglas Gregora16548e2009-08-11 05:31:07 +00005998template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005999ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006000TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006001 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006002 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006003 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006004
Douglas Gregora16548e2009-08-11 05:31:07 +00006005 if (!getDerived().AlwaysRebuild() &&
6006 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006007 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006008
Douglas Gregora16548e2009-08-11 05:31:07 +00006009 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00006010 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006011 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00006012 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006013 E->getAccessorLoc(),
6014 E->getAccessor());
6015}
Mike Stump11289f42009-09-09 15:08:12 +00006016
Douglas Gregora16548e2009-08-11 05:31:07 +00006017template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006018ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006019TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006020 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00006021
John McCall37ad5512010-08-23 06:44:23 +00006022 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006023 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6024 Inits, &InitChanged))
6025 return ExprError();
6026
Douglas Gregora16548e2009-08-11 05:31:07 +00006027 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00006028 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006029
Douglas Gregora16548e2009-08-11 05:31:07 +00006030 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00006031 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00006032}
Mike Stump11289f42009-09-09 15:08:12 +00006033
Douglas Gregora16548e2009-08-11 05:31:07 +00006034template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006035ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006036TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006037 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00006038
Douglas Gregorebe10102009-08-20 07:17:43 +00006039 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00006040 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006041 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006042 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006043
Douglas Gregorebe10102009-08-20 07:17:43 +00006044 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00006045 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006046 bool ExprChanged = false;
6047 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6048 DEnd = E->designators_end();
6049 D != DEnd; ++D) {
6050 if (D->isFieldDesignator()) {
6051 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6052 D->getDotLoc(),
6053 D->getFieldLoc()));
6054 continue;
6055 }
Mike Stump11289f42009-09-09 15:08:12 +00006056
Douglas Gregora16548e2009-08-11 05:31:07 +00006057 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00006058 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006059 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006060 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006061
6062 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006063 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006064
Douglas Gregora16548e2009-08-11 05:31:07 +00006065 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6066 ArrayExprs.push_back(Index.release());
6067 continue;
6068 }
Mike Stump11289f42009-09-09 15:08:12 +00006069
Douglas Gregora16548e2009-08-11 05:31:07 +00006070 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00006071 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00006072 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6073 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006074 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006075
John McCalldadc5752010-08-24 06:29:42 +00006076 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006077 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006078 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006079
6080 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006081 End.get(),
6082 D->getLBracketLoc(),
6083 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006084
Douglas Gregora16548e2009-08-11 05:31:07 +00006085 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6086 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00006087
Douglas Gregora16548e2009-08-11 05:31:07 +00006088 ArrayExprs.push_back(Start.release());
6089 ArrayExprs.push_back(End.release());
6090 }
Mike Stump11289f42009-09-09 15:08:12 +00006091
Douglas Gregora16548e2009-08-11 05:31:07 +00006092 if (!getDerived().AlwaysRebuild() &&
6093 Init.get() == E->getInit() &&
6094 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006095 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006096
Douglas Gregora16548e2009-08-11 05:31:07 +00006097 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6098 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006099 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006100}
Mike Stump11289f42009-09-09 15:08:12 +00006101
Douglas Gregora16548e2009-08-11 05:31:07 +00006102template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006103ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006104TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006105 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00006106 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006107
Douglas Gregor3da3c062009-10-28 00:29:27 +00006108 // FIXME: Will we ever have proper type location here? Will we actually
6109 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00006110 QualType T = getDerived().TransformType(E->getType());
6111 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006112 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006113
Douglas Gregora16548e2009-08-11 05:31:07 +00006114 if (!getDerived().AlwaysRebuild() &&
6115 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006116 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006117
Douglas Gregora16548e2009-08-11 05:31:07 +00006118 return getDerived().RebuildImplicitValueInitExpr(T);
6119}
Mike Stump11289f42009-09-09 15:08:12 +00006120
Douglas Gregora16548e2009-08-11 05:31:07 +00006121template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006122ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006123TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00006124 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6125 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006126 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006127
John McCalldadc5752010-08-24 06:29:42 +00006128 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006129 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006130 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006131
Douglas Gregora16548e2009-08-11 05:31:07 +00006132 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00006133 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006134 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006135 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006136
John McCallb268a282010-08-23 23:25:46 +00006137 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00006138 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006139}
6140
6141template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006142ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006143TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006144 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006145 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006146 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6147 &ArgumentChanged))
6148 return ExprError();
6149
Douglas Gregora16548e2009-08-11 05:31:07 +00006150 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6151 move_arg(Inits),
6152 E->getRParenLoc());
6153}
Mike Stump11289f42009-09-09 15:08:12 +00006154
Douglas Gregora16548e2009-08-11 05:31:07 +00006155/// \brief Transform an address-of-label expression.
6156///
6157/// By default, the transformation of an address-of-label expression always
6158/// rebuilds the expression, so that the label identifier can be resolved to
6159/// the corresponding label statement by semantic analysis.
6160template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006161ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006162TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006163 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6164 E->getLabel());
6165 if (!LD)
6166 return ExprError();
6167
Douglas Gregora16548e2009-08-11 05:31:07 +00006168 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006169 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006170}
Mike Stump11289f42009-09-09 15:08:12 +00006171
6172template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006173ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006174TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006175 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006176 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6177 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006178 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006179
Douglas Gregora16548e2009-08-11 05:31:07 +00006180 if (!getDerived().AlwaysRebuild() &&
6181 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006182 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006183
6184 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006185 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006186 E->getRParenLoc());
6187}
Mike Stump11289f42009-09-09 15:08:12 +00006188
Douglas Gregora16548e2009-08-11 05:31:07 +00006189template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006190ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006191TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006192 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006193 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006194 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006195
John McCalldadc5752010-08-24 06:29:42 +00006196 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006197 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006198 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006199
John McCalldadc5752010-08-24 06:29:42 +00006200 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006201 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006202 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006203
Douglas Gregora16548e2009-08-11 05:31:07 +00006204 if (!getDerived().AlwaysRebuild() &&
6205 Cond.get() == E->getCond() &&
6206 LHS.get() == E->getLHS() &&
6207 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006208 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006209
Douglas Gregora16548e2009-08-11 05:31:07 +00006210 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006211 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006212 E->getRParenLoc());
6213}
Mike Stump11289f42009-09-09 15:08:12 +00006214
Douglas Gregora16548e2009-08-11 05:31:07 +00006215template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006216ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006217TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006218 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006219}
6220
6221template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006222ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006223TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006224 switch (E->getOperator()) {
6225 case OO_New:
6226 case OO_Delete:
6227 case OO_Array_New:
6228 case OO_Array_Delete:
6229 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006230 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006231
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006232 case OO_Call: {
6233 // This is a call to an object's operator().
6234 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6235
6236 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006237 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006238 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006239 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006240
6241 // FIXME: Poor location information
6242 SourceLocation FakeLParenLoc
6243 = SemaRef.PP.getLocForEndOfToken(
6244 static_cast<Expr *>(Object.get())->getLocEnd());
6245
6246 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006247 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006248 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6249 Args))
6250 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006251
John McCallb268a282010-08-23 23:25:46 +00006252 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006253 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006254 E->getLocEnd());
6255 }
6256
6257#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6258 case OO_##Name:
6259#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6260#include "clang/Basic/OperatorKinds.def"
6261 case OO_Subscript:
6262 // Handled below.
6263 break;
6264
6265 case OO_Conditional:
6266 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006267 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006268
6269 case OO_None:
6270 case NUM_OVERLOADED_OPERATORS:
6271 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006272 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006273 }
6274
John McCalldadc5752010-08-24 06:29:42 +00006275 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006276 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006277 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006278
John McCalldadc5752010-08-24 06:29:42 +00006279 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006280 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006281 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006282
John McCalldadc5752010-08-24 06:29:42 +00006283 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006284 if (E->getNumArgs() == 2) {
6285 Second = getDerived().TransformExpr(E->getArg(1));
6286 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006287 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006288 }
Mike Stump11289f42009-09-09 15:08:12 +00006289
Douglas Gregora16548e2009-08-11 05:31:07 +00006290 if (!getDerived().AlwaysRebuild() &&
6291 Callee.get() == E->getCallee() &&
6292 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006293 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006294 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006295
Douglas Gregora16548e2009-08-11 05:31:07 +00006296 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6297 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006298 Callee.get(),
6299 First.get(),
6300 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006301}
Mike Stump11289f42009-09-09 15:08:12 +00006302
Douglas Gregora16548e2009-08-11 05:31:07 +00006303template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006304ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006305TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6306 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006307}
Mike Stump11289f42009-09-09 15:08:12 +00006308
Douglas Gregora16548e2009-08-11 05:31:07 +00006309template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006310ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006311TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6312 // Transform the callee.
6313 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6314 if (Callee.isInvalid())
6315 return ExprError();
6316
6317 // Transform exec config.
6318 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6319 if (EC.isInvalid())
6320 return ExprError();
6321
6322 // Transform arguments.
6323 bool ArgChanged = false;
6324 ASTOwningVector<Expr*> Args(SemaRef);
6325 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6326 &ArgChanged))
6327 return ExprError();
6328
6329 if (!getDerived().AlwaysRebuild() &&
6330 Callee.get() == E->getCallee() &&
6331 !ArgChanged)
6332 return SemaRef.Owned(E);
6333
6334 // FIXME: Wrong source location information for the '('.
6335 SourceLocation FakeLParenLoc
6336 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6337 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6338 move_arg(Args),
6339 E->getRParenLoc(), EC.get());
6340}
6341
6342template<typename Derived>
6343ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006344TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006345 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6346 if (!Type)
6347 return ExprError();
6348
John McCalldadc5752010-08-24 06:29:42 +00006349 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006350 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006351 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006352 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006353
Douglas Gregora16548e2009-08-11 05:31:07 +00006354 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006355 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006356 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006357 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006358
Douglas Gregora16548e2009-08-11 05:31:07 +00006359 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006360 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006361 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6362 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6363 SourceLocation FakeRParenLoc
6364 = SemaRef.PP.getLocForEndOfToken(
6365 E->getSubExpr()->getSourceRange().getEnd());
6366 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006367 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006368 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006369 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006370 FakeRAngleLoc,
6371 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006372 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006373 FakeRParenLoc);
6374}
Mike Stump11289f42009-09-09 15:08:12 +00006375
Douglas Gregora16548e2009-08-11 05:31:07 +00006376template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006377ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006378TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6379 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006380}
Mike Stump11289f42009-09-09 15:08:12 +00006381
6382template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006383ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006384TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6385 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006386}
6387
Douglas Gregora16548e2009-08-11 05:31:07 +00006388template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006389ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006390TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006391 CXXReinterpretCastExpr *E) {
6392 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006393}
Mike Stump11289f42009-09-09 15:08:12 +00006394
Douglas Gregora16548e2009-08-11 05:31:07 +00006395template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006396ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006397TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6398 return getDerived().TransformCXXNamedCastExpr(E);
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
Douglas Gregora16548e2009-08-11 05:31:07 +00006403TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006404 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006405 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6406 if (!Type)
6407 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006408
John McCalldadc5752010-08-24 06:29:42 +00006409 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006410 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006411 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006412 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006413
Douglas Gregora16548e2009-08-11 05:31:07 +00006414 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006415 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006416 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006417 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006418
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006419 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006420 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006421 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006422 E->getRParenLoc());
6423}
Mike Stump11289f42009-09-09 15:08:12 +00006424
Douglas Gregora16548e2009-08-11 05:31:07 +00006425template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006426ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006427TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006428 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006429 TypeSourceInfo *TInfo
6430 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6431 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006432 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006433
Douglas Gregora16548e2009-08-11 05:31:07 +00006434 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006435 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006436 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006437
Douglas Gregor9da64192010-04-26 22:37:10 +00006438 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6439 E->getLocStart(),
6440 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006441 E->getLocEnd());
6442 }
Mike Stump11289f42009-09-09 15:08:12 +00006443
Douglas Gregora16548e2009-08-11 05:31:07 +00006444 // We don't know whether the expression is potentially evaluated until
6445 // after we perform semantic analysis, so the expression is potentially
6446 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006447 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006448 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006449
John McCalldadc5752010-08-24 06:29:42 +00006450 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006451 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006452 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006453
Douglas Gregora16548e2009-08-11 05:31:07 +00006454 if (!getDerived().AlwaysRebuild() &&
6455 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006456 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006457
Douglas Gregor9da64192010-04-26 22:37:10 +00006458 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6459 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006460 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006461 E->getLocEnd());
6462}
6463
6464template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006465ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006466TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6467 if (E->isTypeOperand()) {
6468 TypeSourceInfo *TInfo
6469 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6470 if (!TInfo)
6471 return ExprError();
6472
6473 if (!getDerived().AlwaysRebuild() &&
6474 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006475 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006476
Douglas Gregor69735112011-03-06 17:40:41 +00006477 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00006478 E->getLocStart(),
6479 TInfo,
6480 E->getLocEnd());
6481 }
6482
6483 // We don't know whether the expression is potentially evaluated until
6484 // after we perform semantic analysis, so the expression is potentially
6485 // potentially evaluated.
6486 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6487
6488 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6489 if (SubExpr.isInvalid())
6490 return ExprError();
6491
6492 if (!getDerived().AlwaysRebuild() &&
6493 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006494 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006495
6496 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6497 E->getLocStart(),
6498 SubExpr.get(),
6499 E->getLocEnd());
6500}
6501
6502template<typename Derived>
6503ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006504TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006505 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006506}
Mike Stump11289f42009-09-09 15:08:12 +00006507
Douglas Gregora16548e2009-08-11 05:31:07 +00006508template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006509ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006510TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006511 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006512 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006513}
Mike Stump11289f42009-09-09 15:08:12 +00006514
Douglas Gregora16548e2009-08-11 05:31:07 +00006515template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006516ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006517TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006518 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6519 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6520 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006521
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006522 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006523 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006524
Douglas Gregorb15af892010-01-07 23:12:05 +00006525 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006526}
Mike Stump11289f42009-09-09 15:08:12 +00006527
Douglas Gregora16548e2009-08-11 05:31:07 +00006528template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006529ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006530TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006531 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006532 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006533 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006534
Douglas Gregora16548e2009-08-11 05:31:07 +00006535 if (!getDerived().AlwaysRebuild() &&
6536 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006537 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006538
John McCallb268a282010-08-23 23:25:46 +00006539 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006540}
Mike Stump11289f42009-09-09 15:08:12 +00006541
Douglas Gregora16548e2009-08-11 05:31:07 +00006542template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006543ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006544TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006545 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006546 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6547 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006548 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006549 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006550
Chandler Carruth794da4c2010-02-08 06:42:49 +00006551 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006552 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006553 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006554
Douglas Gregor033f6752009-12-23 23:03:06 +00006555 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006556}
Mike Stump11289f42009-09-09 15:08:12 +00006557
Douglas Gregora16548e2009-08-11 05:31:07 +00006558template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006559ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006560TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6561 CXXScalarValueInitExpr *E) {
6562 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6563 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006564 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006565
Douglas Gregora16548e2009-08-11 05:31:07 +00006566 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006567 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006568 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006569
Douglas Gregor2b88c112010-09-08 00:15:04 +00006570 return getDerived().RebuildCXXScalarValueInitExpr(T,
6571 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006572 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006573}
Mike Stump11289f42009-09-09 15:08:12 +00006574
Douglas Gregora16548e2009-08-11 05:31:07 +00006575template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006576ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006577TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006578 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006579 TypeSourceInfo *AllocTypeInfo
6580 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6581 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006582 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006583
Douglas Gregora16548e2009-08-11 05:31:07 +00006584 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006585 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006586 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006587 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006588
Douglas Gregora16548e2009-08-11 05:31:07 +00006589 // Transform the placement arguments (if any).
6590 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006591 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006592 if (getDerived().TransformExprs(E->getPlacementArgs(),
6593 E->getNumPlacementArgs(), true,
6594 PlacementArgs, &ArgumentChanged))
6595 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006596
Douglas Gregorebe10102009-08-20 07:17:43 +00006597 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006598 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006599 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6600 ConstructorArgs, &ArgumentChanged))
6601 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006602
Douglas Gregord2d9da02010-02-26 00:38:10 +00006603 // Transform constructor, new operator, and delete operator.
6604 CXXConstructorDecl *Constructor = 0;
6605 if (E->getConstructor()) {
6606 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006607 getDerived().TransformDecl(E->getLocStart(),
6608 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006609 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006610 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006611 }
6612
6613 FunctionDecl *OperatorNew = 0;
6614 if (E->getOperatorNew()) {
6615 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006616 getDerived().TransformDecl(E->getLocStart(),
6617 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006618 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006619 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006620 }
6621
6622 FunctionDecl *OperatorDelete = 0;
6623 if (E->getOperatorDelete()) {
6624 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006625 getDerived().TransformDecl(E->getLocStart(),
6626 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006627 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006628 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006629 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006630
Douglas Gregora16548e2009-08-11 05:31:07 +00006631 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006632 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006633 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006634 Constructor == E->getConstructor() &&
6635 OperatorNew == E->getOperatorNew() &&
6636 OperatorDelete == E->getOperatorDelete() &&
6637 !ArgumentChanged) {
6638 // Mark any declarations we need as referenced.
6639 // FIXME: instantiation-specific.
6640 if (Constructor)
6641 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6642 if (OperatorNew)
6643 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6644 if (OperatorDelete)
6645 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006646 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006647 }
Mike Stump11289f42009-09-09 15:08:12 +00006648
Douglas Gregor0744ef62010-09-07 21:49:58 +00006649 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006650 if (!ArraySize.get()) {
6651 // If no array size was specified, but the new expression was
6652 // instantiated with an array type (e.g., "new T" where T is
6653 // instantiated with "int[4]"), extract the outer bound from the
6654 // array type as our array size. We do this with constant and
6655 // dependently-sized array types.
6656 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6657 if (!ArrayT) {
6658 // Do nothing
6659 } else if (const ConstantArrayType *ConsArrayT
6660 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006661 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006662 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6663 ConsArrayT->getSize(),
6664 SemaRef.Context.getSizeType(),
6665 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006666 AllocType = ConsArrayT->getElementType();
6667 } else if (const DependentSizedArrayType *DepArrayT
6668 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6669 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006670 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006671 AllocType = DepArrayT->getElementType();
6672 }
6673 }
6674 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006675
Douglas Gregora16548e2009-08-11 05:31:07 +00006676 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6677 E->isGlobalNew(),
6678 /*FIXME:*/E->getLocStart(),
6679 move_arg(PlacementArgs),
6680 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006681 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006682 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006683 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006684 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006685 /*FIXME:*/E->getLocStart(),
6686 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006687 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006688}
Mike Stump11289f42009-09-09 15:08:12 +00006689
Douglas Gregora16548e2009-08-11 05:31:07 +00006690template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006691ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006692TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006693 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006694 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006695 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006696
Douglas Gregord2d9da02010-02-26 00:38:10 +00006697 // Transform the delete operator, if known.
6698 FunctionDecl *OperatorDelete = 0;
6699 if (E->getOperatorDelete()) {
6700 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006701 getDerived().TransformDecl(E->getLocStart(),
6702 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006703 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006704 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006705 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006706
Douglas Gregora16548e2009-08-11 05:31:07 +00006707 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006708 Operand.get() == E->getArgument() &&
6709 OperatorDelete == E->getOperatorDelete()) {
6710 // Mark any declarations we need as referenced.
6711 // FIXME: instantiation-specific.
6712 if (OperatorDelete)
6713 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006714
6715 if (!E->getArgument()->isTypeDependent()) {
6716 QualType Destroyed = SemaRef.Context.getBaseElementType(
6717 E->getDestroyedType());
6718 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6719 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6720 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6721 SemaRef.LookupDestructor(Record));
6722 }
6723 }
6724
John McCallc3007a22010-10-26 07:05:15 +00006725 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006726 }
Mike Stump11289f42009-09-09 15:08:12 +00006727
Douglas Gregora16548e2009-08-11 05:31:07 +00006728 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6729 E->isGlobalDelete(),
6730 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006731 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006732}
Mike Stump11289f42009-09-09 15:08:12 +00006733
Douglas Gregora16548e2009-08-11 05:31:07 +00006734template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006735ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006736TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006737 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006738 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006739 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006740 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006741
John McCallba7bf592010-08-24 05:47:05 +00006742 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006743 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006744 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006745 E->getOperatorLoc(),
6746 E->isArrow()? tok::arrow : tok::period,
6747 ObjectTypePtr,
6748 MayBePseudoDestructor);
6749 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006750 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006751
John McCallba7bf592010-08-24 05:47:05 +00006752 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00006753 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6754 if (QualifierLoc) {
6755 QualifierLoc
6756 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6757 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00006758 return ExprError();
6759 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00006760 CXXScopeSpec SS;
6761 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00006762
Douglas Gregor678f90d2010-02-25 01:56:36 +00006763 PseudoDestructorTypeStorage Destroyed;
6764 if (E->getDestroyedTypeInfo()) {
6765 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006766 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00006767 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00006768 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006769 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006770 Destroyed = DestroyedTypeInfo;
6771 } else if (ObjectType->isDependentType()) {
6772 // We aren't likely to be able to resolve the identifier down to a type
6773 // now anyway, so just retain the identifier.
6774 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6775 E->getDestroyedTypeLoc());
6776 } else {
6777 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00006778 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006779 *E->getDestroyedTypeIdentifier(),
6780 E->getDestroyedTypeLoc(),
6781 /*Scope=*/0,
6782 SS, ObjectTypePtr,
6783 false);
6784 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006785 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006786
Douglas Gregor678f90d2010-02-25 01:56:36 +00006787 Destroyed
6788 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6789 E->getDestroyedTypeLoc());
6790 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006791
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006792 TypeSourceInfo *ScopeTypeInfo = 0;
6793 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006794 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006795 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006796 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006797 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006798
John McCallb268a282010-08-23 23:25:46 +00006799 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006800 E->getOperatorLoc(),
6801 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006802 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006803 ScopeTypeInfo,
6804 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006805 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006806 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006807}
Mike Stump11289f42009-09-09 15:08:12 +00006808
Douglas Gregorad8a3362009-09-04 17:36:40 +00006809template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006810ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006811TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006812 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006813 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6814 Sema::LookupOrdinaryName);
6815
6816 // Transform all the decls.
6817 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6818 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006819 NamedDecl *InstD = static_cast<NamedDecl*>(
6820 getDerived().TransformDecl(Old->getNameLoc(),
6821 *I));
John McCall84d87672009-12-10 09:41:52 +00006822 if (!InstD) {
6823 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6824 // This can happen because of dependent hiding.
6825 if (isa<UsingShadowDecl>(*I))
6826 continue;
6827 else
John McCallfaf5fb42010-08-26 23:41:50 +00006828 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006829 }
John McCalle66edc12009-11-24 19:00:30 +00006830
6831 // Expand using declarations.
6832 if (isa<UsingDecl>(InstD)) {
6833 UsingDecl *UD = cast<UsingDecl>(InstD);
6834 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6835 E = UD->shadow_end(); I != E; ++I)
6836 R.addDecl(*I);
6837 continue;
6838 }
6839
6840 R.addDecl(InstD);
6841 }
6842
6843 // Resolve a kind, but don't do any further analysis. If it's
6844 // ambiguous, the callee needs to deal with it.
6845 R.resolveKind();
6846
6847 // Rebuild the nested-name qualifier, if present.
6848 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00006849 if (Old->getQualifierLoc()) {
6850 NestedNameSpecifierLoc QualifierLoc
6851 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
6852 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006853 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006854
Douglas Gregor0da1d432011-02-28 20:01:57 +00006855 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006856 }
6857
Douglas Gregor9262f472010-04-27 18:19:34 +00006858 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006859 CXXRecordDecl *NamingClass
6860 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6861 Old->getNameLoc(),
6862 Old->getNamingClass()));
6863 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006864 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006865
Douglas Gregorda7be082010-04-27 16:10:10 +00006866 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006867 }
6868
6869 // If we have no template arguments, it's a normal declaration name.
6870 if (!Old->hasExplicitTemplateArgs())
6871 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6872
6873 // If we have template arguments, rebuild them, then rebuild the
6874 // templateid expression.
6875 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006876 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6877 Old->getNumTemplateArgs(),
6878 TransArgs))
6879 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006880
6881 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6882 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006883}
Mike Stump11289f42009-09-09 15:08:12 +00006884
Douglas Gregora16548e2009-08-11 05:31:07 +00006885template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006886ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006887TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006888 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6889 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006890 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006891
Douglas Gregora16548e2009-08-11 05:31:07 +00006892 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006893 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006894 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006895
Mike Stump11289f42009-09-09 15:08:12 +00006896 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006897 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006898 T,
6899 E->getLocEnd());
6900}
Mike Stump11289f42009-09-09 15:08:12 +00006901
Douglas Gregora16548e2009-08-11 05:31:07 +00006902template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006903ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006904TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6905 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6906 if (!LhsT)
6907 return ExprError();
6908
6909 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6910 if (!RhsT)
6911 return ExprError();
6912
6913 if (!getDerived().AlwaysRebuild() &&
6914 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6915 return SemaRef.Owned(E);
6916
6917 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6918 E->getLocStart(),
6919 LhsT, RhsT,
6920 E->getLocEnd());
6921}
6922
6923template<typename Derived>
6924ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00006925TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
6926 ExprResult SubExpr;
6927 {
6928 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6929 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
6930 if (SubExpr.isInvalid())
6931 return ExprError();
6932
6933 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
6934 return SemaRef.Owned(E);
6935 }
6936
6937 return getDerived().RebuildExpressionTrait(
6938 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
6939}
6940
6941template<typename Derived>
6942ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006943TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006944 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006945 NestedNameSpecifierLoc QualifierLoc
6946 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6947 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006948 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006949
John McCall31f82722010-11-12 08:19:04 +00006950 // TODO: If this is a conversion-function-id, verify that the
6951 // destination type name (if present) resolves the same way after
6952 // instantiation as it did in the local scope.
6953
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006954 DeclarationNameInfo NameInfo
6955 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6956 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006957 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006958
John McCalle66edc12009-11-24 19:00:30 +00006959 if (!E->hasExplicitTemplateArgs()) {
6960 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006961 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006962 // Note: it is sufficient to compare the Name component of NameInfo:
6963 // if name has not changed, DNLoc has not changed either.
6964 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006965 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006966
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006967 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006968 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006969 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006970 }
John McCall6b51f282009-11-23 01:53:49 +00006971
6972 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006973 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6974 E->getNumTemplateArgs(),
6975 TransArgs))
6976 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006977
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006978 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006979 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006980 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006981}
6982
6983template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006984ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006985TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006986 // CXXConstructExprs are always implicit, so when we have a
6987 // 1-argument construction we just transform that argument.
6988 if (E->getNumArgs() == 1 ||
6989 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6990 return getDerived().TransformExpr(E->getArg(0));
6991
Douglas Gregora16548e2009-08-11 05:31:07 +00006992 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6993
6994 QualType T = getDerived().TransformType(E->getType());
6995 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006996 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006997
6998 CXXConstructorDecl *Constructor
6999 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007000 getDerived().TransformDecl(E->getLocStart(),
7001 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007002 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007003 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007004
Douglas Gregora16548e2009-08-11 05:31:07 +00007005 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007006 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007007 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7008 &ArgumentChanged))
7009 return ExprError();
7010
Douglas Gregora16548e2009-08-11 05:31:07 +00007011 if (!getDerived().AlwaysRebuild() &&
7012 T == E->getType() &&
7013 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00007014 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00007015 // Mark the constructor as referenced.
7016 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00007017 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007018 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00007019 }
Mike Stump11289f42009-09-09 15:08:12 +00007020
Douglas Gregordb121ba2009-12-14 16:27:04 +00007021 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7022 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00007023 move_arg(Args),
7024 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00007025 E->getConstructionKind(),
7026 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007027}
Mike Stump11289f42009-09-09 15:08:12 +00007028
Douglas Gregora16548e2009-08-11 05:31:07 +00007029/// \brief Transform a C++ temporary-binding expression.
7030///
Douglas Gregor363b1512009-12-24 18:51:59 +00007031/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7032/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007033template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007034ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007035TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007036 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007037}
Mike Stump11289f42009-09-09 15:08:12 +00007038
John McCall5d413782010-12-06 08:20:24 +00007039/// \brief Transform a C++ expression that contains cleanups that should
7040/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00007041///
John McCall5d413782010-12-06 08:20:24 +00007042/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00007043/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007044template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007045ExprResult
John McCall5d413782010-12-06 08:20:24 +00007046TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007047 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007048}
Mike Stump11289f42009-09-09 15:08:12 +00007049
Douglas Gregora16548e2009-08-11 05:31:07 +00007050template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007051ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007052TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00007053 CXXTemporaryObjectExpr *E) {
7054 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7055 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007056 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007057
Douglas Gregora16548e2009-08-11 05:31:07 +00007058 CXXConstructorDecl *Constructor
7059 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00007060 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007061 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007062 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007063 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007064
Douglas Gregora16548e2009-08-11 05:31:07 +00007065 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007066 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00007067 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00007068 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7069 &ArgumentChanged))
7070 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007071
Douglas Gregora16548e2009-08-11 05:31:07 +00007072 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007073 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007074 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007075 !ArgumentChanged) {
7076 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00007077 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007078 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007079 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00007080
7081 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7082 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007083 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007084 E->getLocEnd());
7085}
Mike Stump11289f42009-09-09 15:08:12 +00007086
Douglas Gregora16548e2009-08-11 05:31:07 +00007087template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007088ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007089TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007090 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00007091 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7092 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007093 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007094
Douglas Gregora16548e2009-08-11 05:31:07 +00007095 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007096 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007097 Args.reserve(E->arg_size());
7098 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7099 &ArgumentChanged))
7100 return ExprError();
7101
Douglas Gregora16548e2009-08-11 05:31:07 +00007102 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007103 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007104 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007105 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007106
Douglas Gregora16548e2009-08-11 05:31:07 +00007107 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00007108 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00007109 E->getLParenLoc(),
7110 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007111 E->getRParenLoc());
7112}
Mike Stump11289f42009-09-09 15:08:12 +00007113
Douglas Gregora16548e2009-08-11 05:31:07 +00007114template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007115ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007116TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007117 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007118 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007119 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007120 Expr *OldBase;
7121 QualType BaseType;
7122 QualType ObjectType;
7123 if (!E->isImplicitAccess()) {
7124 OldBase = E->getBase();
7125 Base = getDerived().TransformExpr(OldBase);
7126 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007127 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007128
John McCall2d74de92009-12-01 22:10:20 +00007129 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00007130 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00007131 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007132 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007133 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007134 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00007135 ObjectTy,
7136 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00007137 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007138 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007139
John McCallba7bf592010-08-24 05:47:05 +00007140 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00007141 BaseType = ((Expr*) Base.get())->getType();
7142 } else {
7143 OldBase = 0;
7144 BaseType = getDerived().TransformType(E->getBaseType());
7145 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7146 }
Mike Stump11289f42009-09-09 15:08:12 +00007147
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007148 // Transform the first part of the nested-name-specifier that qualifies
7149 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007150 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007151 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00007152 E->getFirstQualifierFoundInScope(),
7153 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00007154
Douglas Gregore16af532011-02-28 18:50:33 +00007155 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007156 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00007157 QualifierLoc
7158 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7159 ObjectType,
7160 FirstQualifierInScope);
7161 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007162 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007163 }
Mike Stump11289f42009-09-09 15:08:12 +00007164
John McCall31f82722010-11-12 08:19:04 +00007165 // TODO: If this is a conversion-function-id, verify that the
7166 // destination type name (if present) resolves the same way after
7167 // instantiation as it did in the local scope.
7168
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007169 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007170 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007171 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007172 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007173
John McCall2d74de92009-12-01 22:10:20 +00007174 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007175 // This is a reference to a member without an explicitly-specified
7176 // template argument list. Optimize for this common case.
7177 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007178 Base.get() == OldBase &&
7179 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007180 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007181 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007182 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007183 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007184
John McCallb268a282010-08-23 23:25:46 +00007185 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007186 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007187 E->isArrow(),
7188 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007189 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007190 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007191 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007192 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007193 }
7194
John McCall6b51f282009-11-23 01:53:49 +00007195 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007196 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7197 E->getNumTemplateArgs(),
7198 TransArgs))
7199 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007200
John McCallb268a282010-08-23 23:25:46 +00007201 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007202 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007203 E->isArrow(),
7204 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007205 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007206 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007207 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007208 &TransArgs);
7209}
7210
7211template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007212ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007213TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007214 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007215 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007216 QualType BaseType;
7217 if (!Old->isImplicitAccess()) {
7218 Base = getDerived().TransformExpr(Old->getBase());
7219 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007220 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007221 BaseType = ((Expr*) Base.get())->getType();
7222 } else {
7223 BaseType = getDerived().TransformType(Old->getBaseType());
7224 }
John McCall10eae182009-11-30 22:42:35 +00007225
Douglas Gregor0da1d432011-02-28 20:01:57 +00007226 NestedNameSpecifierLoc QualifierLoc;
7227 if (Old->getQualifierLoc()) {
7228 QualifierLoc
7229 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7230 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007231 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007232 }
7233
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007234 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007235 Sema::LookupOrdinaryName);
7236
7237 // Transform all the decls.
7238 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7239 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007240 NamedDecl *InstD = static_cast<NamedDecl*>(
7241 getDerived().TransformDecl(Old->getMemberLoc(),
7242 *I));
John McCall84d87672009-12-10 09:41:52 +00007243 if (!InstD) {
7244 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7245 // This can happen because of dependent hiding.
7246 if (isa<UsingShadowDecl>(*I))
7247 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007248 else {
7249 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007250 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007251 }
John McCall84d87672009-12-10 09:41:52 +00007252 }
John McCall10eae182009-11-30 22:42:35 +00007253
7254 // Expand using declarations.
7255 if (isa<UsingDecl>(InstD)) {
7256 UsingDecl *UD = cast<UsingDecl>(InstD);
7257 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7258 E = UD->shadow_end(); I != E; ++I)
7259 R.addDecl(*I);
7260 continue;
7261 }
7262
7263 R.addDecl(InstD);
7264 }
7265
7266 R.resolveKind();
7267
Douglas Gregor9262f472010-04-27 18:19:34 +00007268 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007269 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007270 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007271 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007272 Old->getMemberLoc(),
7273 Old->getNamingClass()));
7274 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007275 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007276
Douglas Gregorda7be082010-04-27 16:10:10 +00007277 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007278 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007279
John McCall10eae182009-11-30 22:42:35 +00007280 TemplateArgumentListInfo TransArgs;
7281 if (Old->hasExplicitTemplateArgs()) {
7282 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7283 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007284 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7285 Old->getNumTemplateArgs(),
7286 TransArgs))
7287 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007288 }
John McCall38836f02010-01-15 08:34:02 +00007289
7290 // FIXME: to do this check properly, we will need to preserve the
7291 // first-qualifier-in-scope here, just in case we had a dependent
7292 // base (and therefore couldn't do the check) and a
7293 // nested-name-qualifier (and therefore could do the lookup).
7294 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007295
John McCallb268a282010-08-23 23:25:46 +00007296 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007297 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007298 Old->getOperatorLoc(),
7299 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007300 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007301 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007302 R,
7303 (Old->hasExplicitTemplateArgs()
7304 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007305}
7306
7307template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007308ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007309TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7310 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7311 if (SubExpr.isInvalid())
7312 return ExprError();
7313
7314 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007315 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007316
7317 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7318}
7319
7320template<typename Derived>
7321ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007322TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007323 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7324 if (Pattern.isInvalid())
7325 return ExprError();
7326
7327 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7328 return SemaRef.Owned(E);
7329
Douglas Gregorb8840002011-01-14 21:20:45 +00007330 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7331 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007332}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007333
7334template<typename Derived>
7335ExprResult
7336TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7337 // If E is not value-dependent, then nothing will change when we transform it.
7338 // Note: This is an instantiation-centric view.
7339 if (!E->isValueDependent())
7340 return SemaRef.Owned(E);
7341
7342 // Note: None of the implementations of TryExpandParameterPacks can ever
7343 // produce a diagnostic when given only a single unexpanded parameter pack,
7344 // so
7345 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7346 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007347 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007348 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007349 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7350 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007351 ShouldExpand, RetainExpansion,
7352 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007353 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007354
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007355 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007356 return SemaRef.Owned(E);
7357
7358 // We now know the length of the parameter pack, so build a new expression
7359 // that stores that length.
7360 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7361 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007362 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007363}
7364
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007365template<typename Derived>
7366ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007367TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7368 SubstNonTypeTemplateParmPackExpr *E) {
7369 // Default behavior is to do nothing with this transformation.
7370 return SemaRef.Owned(E);
7371}
7372
7373template<typename Derived>
7374ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007375TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007376 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007377}
7378
Mike Stump11289f42009-09-09 15:08:12 +00007379template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007380ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007381TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007382 TypeSourceInfo *EncodedTypeInfo
7383 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7384 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007385 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007386
Douglas Gregora16548e2009-08-11 05:31:07 +00007387 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007388 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007389 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007390
7391 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007392 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007393 E->getRParenLoc());
7394}
Mike Stump11289f42009-09-09 15:08:12 +00007395
Douglas Gregora16548e2009-08-11 05:31:07 +00007396template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007397ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007398TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007399 // Transform arguments.
7400 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007401 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007402 Args.reserve(E->getNumArgs());
7403 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7404 &ArgChanged))
7405 return ExprError();
7406
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007407 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7408 // Class message: transform the receiver type.
7409 TypeSourceInfo *ReceiverTypeInfo
7410 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7411 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007412 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007413
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007414 // If nothing changed, just retain the existing message send.
7415 if (!getDerived().AlwaysRebuild() &&
7416 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007417 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007418
7419 // Build a new class message send.
7420 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7421 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007422 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007423 E->getMethodDecl(),
7424 E->getLeftLoc(),
7425 move_arg(Args),
7426 E->getRightLoc());
7427 }
7428
7429 // Instance message: transform the receiver
7430 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7431 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007432 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007433 = getDerived().TransformExpr(E->getInstanceReceiver());
7434 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007435 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007436
7437 // If nothing changed, just retain the existing message send.
7438 if (!getDerived().AlwaysRebuild() &&
7439 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007440 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007441
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007442 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007443 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007444 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007445 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007446 E->getMethodDecl(),
7447 E->getLeftLoc(),
7448 move_arg(Args),
7449 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007450}
7451
Mike Stump11289f42009-09-09 15:08:12 +00007452template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007453ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007454TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007455 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007456}
7457
Mike Stump11289f42009-09-09 15:08:12 +00007458template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007459ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007460TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007461 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007462}
7463
Mike Stump11289f42009-09-09 15:08:12 +00007464template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007465ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007466TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007467 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007468 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007469 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007470 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007471
7472 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007473
Douglas Gregord51d90d2010-04-26 20:11:03 +00007474 // If nothing changed, just retain the existing expression.
7475 if (!getDerived().AlwaysRebuild() &&
7476 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007477 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007478
John McCallb268a282010-08-23 23:25:46 +00007479 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007480 E->getLocation(),
7481 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007482}
7483
Mike Stump11289f42009-09-09 15:08:12 +00007484template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007485ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007486TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007487 // 'super' and types never change. Property never changes. Just
7488 // retain the existing expression.
7489 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007490 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007491
Douglas Gregor9faee212010-04-26 20:47:02 +00007492 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007493 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007494 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007495 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007496
Douglas Gregor9faee212010-04-26 20:47:02 +00007497 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007498
Douglas Gregor9faee212010-04-26 20:47:02 +00007499 // If nothing changed, just retain the existing expression.
7500 if (!getDerived().AlwaysRebuild() &&
7501 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007502 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007503
John McCallb7bd14f2010-12-02 01:19:52 +00007504 if (E->isExplicitProperty())
7505 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7506 E->getExplicitProperty(),
7507 E->getLocation());
7508
7509 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7510 E->getType(),
7511 E->getImplicitPropertyGetter(),
7512 E->getImplicitPropertySetter(),
7513 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007514}
7515
Mike Stump11289f42009-09-09 15:08:12 +00007516template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007517ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007518TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007519 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007520 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007521 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007522 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007523
Douglas Gregord51d90d2010-04-26 20:11:03 +00007524 // If nothing changed, just retain the existing expression.
7525 if (!getDerived().AlwaysRebuild() &&
7526 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007527 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007528
John McCallb268a282010-08-23 23:25:46 +00007529 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007530 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007531}
7532
Mike Stump11289f42009-09-09 15:08:12 +00007533template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007534ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007535TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007536 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007537 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007538 SubExprs.reserve(E->getNumSubExprs());
7539 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7540 SubExprs, &ArgumentChanged))
7541 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007542
Douglas Gregora16548e2009-08-11 05:31:07 +00007543 if (!getDerived().AlwaysRebuild() &&
7544 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007545 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007546
Douglas Gregora16548e2009-08-11 05:31:07 +00007547 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7548 move_arg(SubExprs),
7549 E->getRParenLoc());
7550}
7551
Mike Stump11289f42009-09-09 15:08:12 +00007552template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007553ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007554TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007555 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007556
John McCall490112f2011-02-04 18:33:18 +00007557 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7558 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7559
7560 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7561 llvm::SmallVector<ParmVarDecl*, 4> params;
7562 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007563
7564 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007565 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7566 oldBlock->param_begin(),
7567 oldBlock->param_size(),
7568 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007569 return true;
John McCall490112f2011-02-04 18:33:18 +00007570
7571 const FunctionType *exprFunctionType = E->getFunctionType();
7572 QualType exprResultType = exprFunctionType->getResultType();
7573 if (!exprResultType.isNull()) {
7574 if (!exprResultType->isDependentType())
7575 blockScope->ReturnType = exprResultType;
7576 else if (exprResultType != getSema().Context.DependentTy)
7577 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007578 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007579
7580 // If the return type has not been determined yet, leave it as a dependent
7581 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007582 if (blockScope->ReturnType.isNull())
7583 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007584
7585 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007586 if (blockScope->ReturnType->isObjCObjectType()) {
7587 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007588 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007589 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007590 return ExprError();
7591 }
John McCall3882ace2011-01-05 12:14:39 +00007592
John McCall490112f2011-02-04 18:33:18 +00007593 QualType functionType = getDerived().RebuildFunctionProtoType(
7594 blockScope->ReturnType,
7595 paramTypes.data(),
7596 paramTypes.size(),
7597 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007598 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007599 exprFunctionType->getExtInfo());
7600 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007601
7602 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007603 if (!params.empty())
7604 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007605
7606 // If the return type wasn't explicitly set, it will have been marked as a
7607 // dependent type (DependentTy); clear out the return type setting so
7608 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007609 if (blockScope->ReturnType == getSema().Context.DependentTy)
7610 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007611
John McCall3882ace2011-01-05 12:14:39 +00007612 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007613 StmtResult body = getDerived().TransformStmt(E->getBody());
7614 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007615 return ExprError();
7616
John McCall490112f2011-02-04 18:33:18 +00007617#ifndef NDEBUG
7618 // In builds with assertions, make sure that we captured everything we
7619 // captured before.
7620
7621 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7622
7623 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7624 e = oldBlock->capture_end(); i != e; ++i) {
John McCall351762c2011-02-07 10:33:21 +00007625 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007626
7627 // Ignore parameter packs.
7628 if (isa<ParmVarDecl>(oldCapture) &&
7629 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7630 continue;
7631
7632 VarDecl *newCapture =
7633 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7634 oldCapture));
John McCall351762c2011-02-07 10:33:21 +00007635 assert(blockScope->CaptureMap.count(newCapture));
John McCall490112f2011-02-04 18:33:18 +00007636 }
7637#endif
7638
7639 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7640 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007641}
7642
Mike Stump11289f42009-09-09 15:08:12 +00007643template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007644ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007645TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007646 ValueDecl *ND
7647 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7648 E->getDecl()));
7649 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007650 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007651
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007652 if (!getDerived().AlwaysRebuild() &&
7653 ND == E->getDecl()) {
7654 // Mark it referenced in the new context regardless.
7655 // FIXME: this is a bit instantiation-specific.
7656 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7657
John McCallc3007a22010-10-26 07:05:15 +00007658 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007659 }
7660
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007661 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00007662 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007663 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007664}
Mike Stump11289f42009-09-09 15:08:12 +00007665
Douglas Gregora16548e2009-08-11 05:31:07 +00007666//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007667// Type reconstruction
7668//===----------------------------------------------------------------------===//
7669
Mike Stump11289f42009-09-09 15:08:12 +00007670template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007671QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7672 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007673 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007674 getDerived().getBaseEntity());
7675}
7676
Mike Stump11289f42009-09-09 15:08:12 +00007677template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007678QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7679 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007680 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007681 getDerived().getBaseEntity());
7682}
7683
Mike Stump11289f42009-09-09 15:08:12 +00007684template<typename Derived>
7685QualType
John McCall70dd5f62009-10-30 00:06:24 +00007686TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7687 bool WrittenAsLValue,
7688 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007689 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007690 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007691}
7692
7693template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007694QualType
John McCall70dd5f62009-10-30 00:06:24 +00007695TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7696 QualType ClassType,
7697 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007698 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007699 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007700}
7701
7702template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007703QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007704TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7705 ArrayType::ArraySizeModifier SizeMod,
7706 const llvm::APInt *Size,
7707 Expr *SizeExpr,
7708 unsigned IndexTypeQuals,
7709 SourceRange BracketsRange) {
7710 if (SizeExpr || !Size)
7711 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7712 IndexTypeQuals, BracketsRange,
7713 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007714
7715 QualType Types[] = {
7716 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7717 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7718 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007719 };
7720 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7721 QualType SizeType;
7722 for (unsigned I = 0; I != NumTypes; ++I)
7723 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7724 SizeType = Types[I];
7725 break;
7726 }
Mike Stump11289f42009-09-09 15:08:12 +00007727
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007728 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7729 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007730 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007731 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007732 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007733}
Mike Stump11289f42009-09-09 15:08:12 +00007734
Douglas Gregord6ff3322009-08-04 16:50:30 +00007735template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007736QualType
7737TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007738 ArrayType::ArraySizeModifier SizeMod,
7739 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007740 unsigned IndexTypeQuals,
7741 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007742 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007743 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007744}
7745
7746template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007747QualType
Mike Stump11289f42009-09-09 15:08:12 +00007748TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007749 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007750 unsigned IndexTypeQuals,
7751 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007752 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007753 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007754}
Mike Stump11289f42009-09-09 15:08:12 +00007755
Douglas Gregord6ff3322009-08-04 16:50:30 +00007756template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007757QualType
7758TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007759 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007760 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007761 unsigned IndexTypeQuals,
7762 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007763 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007764 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007765 IndexTypeQuals, BracketsRange);
7766}
7767
7768template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007769QualType
7770TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007771 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007772 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007773 unsigned IndexTypeQuals,
7774 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007775 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007776 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007777 IndexTypeQuals, BracketsRange);
7778}
7779
7780template<typename Derived>
7781QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007782 unsigned NumElements,
7783 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007784 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007785 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007786}
Mike Stump11289f42009-09-09 15:08:12 +00007787
Douglas Gregord6ff3322009-08-04 16:50:30 +00007788template<typename Derived>
7789QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7790 unsigned NumElements,
7791 SourceLocation AttributeLoc) {
7792 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7793 NumElements, true);
7794 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007795 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7796 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007797 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007798}
Mike Stump11289f42009-09-09 15:08:12 +00007799
Douglas Gregord6ff3322009-08-04 16:50:30 +00007800template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007801QualType
7802TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007803 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007804 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007805 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007806}
Mike Stump11289f42009-09-09 15:08:12 +00007807
Douglas Gregord6ff3322009-08-04 16:50:30 +00007808template<typename Derived>
7809QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007810 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007811 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007812 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007813 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007814 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00007815 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007816 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007817 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007818 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007819 getDerived().getBaseEntity(),
7820 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007821}
Mike Stump11289f42009-09-09 15:08:12 +00007822
Douglas Gregord6ff3322009-08-04 16:50:30 +00007823template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007824QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7825 return SemaRef.Context.getFunctionNoProtoType(T);
7826}
7827
7828template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007829QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7830 assert(D && "no decl found");
7831 if (D->isInvalidDecl()) return QualType();
7832
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007833 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007834 TypeDecl *Ty;
7835 if (isa<UsingDecl>(D)) {
7836 UsingDecl *Using = cast<UsingDecl>(D);
7837 assert(Using->isTypeName() &&
7838 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7839
7840 // A valid resolved using typename decl points to exactly one type decl.
7841 assert(++Using->shadow_begin() == Using->shadow_end());
7842 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007843
John McCallb96ec562009-12-04 22:46:56 +00007844 } else {
7845 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7846 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7847 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7848 }
7849
7850 return SemaRef.Context.getTypeDeclType(Ty);
7851}
7852
7853template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007854QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7855 SourceLocation Loc) {
7856 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007857}
7858
7859template<typename Derived>
7860QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7861 return SemaRef.Context.getTypeOfType(Underlying);
7862}
7863
7864template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007865QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7866 SourceLocation Loc) {
7867 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007868}
7869
7870template<typename Derived>
7871QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007872 TemplateName Template,
7873 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00007874 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00007875 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007876}
Mike Stump11289f42009-09-09 15:08:12 +00007877
Douglas Gregor1135c352009-08-06 05:28:30 +00007878template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007879TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007880TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007881 bool TemplateKW,
7882 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00007883 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007884 Template);
7885}
7886
7887template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007888TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007889TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
7890 const IdentifierInfo &Name,
7891 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00007892 QualType ObjectType,
7893 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00007894 UnqualifiedId TemplateName;
7895 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00007896 Sema::TemplateTy Template;
7897 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00007898 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007899 SS,
Douglas Gregor9db53502011-03-02 18:07:45 +00007900 TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00007901 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007902 /*EnteringContext=*/false,
7903 Template);
John McCall31f82722010-11-12 08:19:04 +00007904 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007905}
Mike Stump11289f42009-09-09 15:08:12 +00007906
Douglas Gregora16548e2009-08-11 05:31:07 +00007907template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007908TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007909TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007910 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00007911 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007912 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00007913 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00007914 // FIXME: Bogus location information.
7915 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
7916 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007917 Sema::TemplateTy Template;
7918 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00007919 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007920 SS,
7921 Name,
John McCallba7bf592010-08-24 05:47:05 +00007922 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007923 /*EnteringContext=*/false,
7924 Template);
7925 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007926}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007927
Douglas Gregor71395fa2009-11-04 00:56:37 +00007928template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007929ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007930TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7931 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007932 Expr *OrigCallee,
7933 Expr *First,
7934 Expr *Second) {
7935 Expr *Callee = OrigCallee->IgnoreParenCasts();
7936 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007937
Douglas Gregora16548e2009-08-11 05:31:07 +00007938 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007939 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007940 if (!First->getType()->isOverloadableType() &&
7941 !Second->getType()->isOverloadableType())
7942 return getSema().CreateBuiltinArraySubscriptExpr(First,
7943 Callee->getLocStart(),
7944 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007945 } else if (Op == OO_Arrow) {
7946 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007947 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7948 } else if (Second == 0 || isPostIncDec) {
7949 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007950 // The argument is not of overloadable type, so try to create a
7951 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007952 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007953 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007954
John McCallb268a282010-08-23 23:25:46 +00007955 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007956 }
7957 } else {
John McCallb268a282010-08-23 23:25:46 +00007958 if (!First->getType()->isOverloadableType() &&
7959 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007960 // Neither of the arguments is an overloadable type, so try to
7961 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007962 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007963 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007964 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007965 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007966 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007967
Douglas Gregora16548e2009-08-11 05:31:07 +00007968 return move(Result);
7969 }
7970 }
Mike Stump11289f42009-09-09 15:08:12 +00007971
7972 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007973 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007974 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007975
John McCallb268a282010-08-23 23:25:46 +00007976 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007977 assert(ULE->requiresADL());
7978
7979 // FIXME: Do we have to check
7980 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007981 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007982 } else {
John McCallb268a282010-08-23 23:25:46 +00007983 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007984 }
Mike Stump11289f42009-09-09 15:08:12 +00007985
Douglas Gregora16548e2009-08-11 05:31:07 +00007986 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007987 Expr *Args[2] = { First, Second };
7988 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007989
Douglas Gregora16548e2009-08-11 05:31:07 +00007990 // Create the overloaded operator invocation for unary operators.
7991 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007992 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007993 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007994 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007995 }
Mike Stump11289f42009-09-09 15:08:12 +00007996
Sebastian Redladba46e2009-10-29 20:17:01 +00007997 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007998 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007999 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008000 First,
8001 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00008002
Douglas Gregora16548e2009-08-11 05:31:07 +00008003 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00008004 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008005 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00008006 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8007 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008008 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008009
Mike Stump11289f42009-09-09 15:08:12 +00008010 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00008011}
Mike Stump11289f42009-09-09 15:08:12 +00008012
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008013template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008014ExprResult
John McCallb268a282010-08-23 23:25:46 +00008015TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008016 SourceLocation OperatorLoc,
8017 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00008018 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008019 TypeSourceInfo *ScopeType,
8020 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008021 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008022 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00008023 QualType BaseType = Base->getType();
8024 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008025 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00008026 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00008027 !BaseType->getAs<PointerType>()->getPointeeType()
8028 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008029 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00008030 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008031 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008032 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008033 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008034 /*FIXME?*/true);
8035 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008036
Douglas Gregor678f90d2010-02-25 01:56:36 +00008037 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008038 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8039 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8040 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8041 NameInfo.setNamedTypeInfo(DestroyedType);
8042
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008043 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008044
John McCallb268a282010-08-23 23:25:46 +00008045 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008046 OperatorLoc, isArrow,
8047 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008048 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008049 /*TemplateArgs*/ 0);
8050}
8051
Douglas Gregord6ff3322009-08-04 16:50:30 +00008052} // end namespace clang
8053
8054#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H