blob: dc96e59420b3b77e8504071b36db02899e3c4d81 [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
Mike Stump11289f42009-09-09 15:08:12 +00001918 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001919 /// expression.
1920 ///
1921 /// By default, performs semantic analysis to build the new expression.
1922 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001923 ExprResult RebuildDependentScopeDeclRefExpr(
1924 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001925 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001926 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001928 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00001929
1930 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001931 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001932 *TemplateArgs);
1933
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001934 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 }
1936
1937 /// \brief Build a new template-id expression.
1938 ///
1939 /// By default, performs semantic analysis to build the new expression.
1940 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001941 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001942 LookupResult &R,
1943 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001944 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001945 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 }
1947
1948 /// \brief Build a new object-construction 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 RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001953 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001954 CXXConstructorDecl *Constructor,
1955 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001956 MultiExprArg Args,
1957 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001958 CXXConstructExpr::ConstructionKind ConstructKind,
1959 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001960 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001961 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001962 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001963 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001964
Douglas Gregordb121ba2009-12-14 16:27:04 +00001965 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001966 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001967 RequiresZeroInit, ConstructKind,
1968 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001969 }
1970
1971 /// \brief Build a new object-construction expression.
1972 ///
1973 /// By default, performs semantic analysis to build the new expression.
1974 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001975 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1976 SourceLocation LParenLoc,
1977 MultiExprArg Args,
1978 SourceLocation RParenLoc) {
1979 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001980 LParenLoc,
1981 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001982 RParenLoc);
1983 }
1984
1985 /// \brief Build a new object-construction expression.
1986 ///
1987 /// By default, performs semantic analysis to build the new expression.
1988 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001989 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1990 SourceLocation LParenLoc,
1991 MultiExprArg Args,
1992 SourceLocation RParenLoc) {
1993 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001994 LParenLoc,
1995 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001996 RParenLoc);
1997 }
Mike Stump11289f42009-09-09 15:08:12 +00001998
Douglas Gregora16548e2009-08-11 05:31:07 +00001999 /// \brief Build a new member reference expression.
2000 ///
2001 /// By default, performs semantic analysis to build the new expression.
2002 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002003 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002004 QualType BaseType,
2005 bool IsArrow,
2006 SourceLocation OperatorLoc,
2007 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00002008 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002009 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002010 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002011 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002012 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002013
John McCallb268a282010-08-23 23:25:46 +00002014 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002015 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00002016 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002017 MemberNameInfo,
2018 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002019 }
2020
John McCall10eae182009-11-30 22:42:35 +00002021 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002022 ///
2023 /// By default, performs semantic analysis to build the new expression.
2024 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002025 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00002026 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00002027 SourceLocation OperatorLoc,
2028 bool IsArrow,
Douglas Gregor0da1d432011-02-28 20:01:57 +00002029 NestedNameSpecifierLoc QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00002030 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00002031 LookupResult &R,
2032 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002033 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002034 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002035
John McCallb268a282010-08-23 23:25:46 +00002036 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002037 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00002038 SS, FirstQualifierInScope,
2039 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002040 }
Mike Stump11289f42009-09-09 15:08:12 +00002041
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002042 /// \brief Build a new noexcept expression.
2043 ///
2044 /// By default, performs semantic analysis to build the new expression.
2045 /// Subclasses may override this routine to provide different behavior.
2046 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2047 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2048 }
2049
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002050 /// \brief Build a new expression to compute the length of a parameter pack.
2051 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2052 SourceLocation PackLoc,
2053 SourceLocation RParenLoc,
2054 unsigned Length) {
2055 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2056 OperatorLoc, Pack, PackLoc,
2057 RParenLoc, Length);
2058 }
2059
Douglas Gregora16548e2009-08-11 05:31:07 +00002060 /// \brief Build a new Objective-C @encode expression.
2061 ///
2062 /// By default, performs semantic analysis to build the new expression.
2063 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002064 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002065 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002066 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002067 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002068 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002069 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002070
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002071 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002072 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002073 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002074 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002075 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002076 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002077 MultiExprArg Args,
2078 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002079 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2080 ReceiverTypeInfo->getType(),
2081 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002082 Sel, Method, LBracLoc, SelectorLoc,
2083 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002084 }
2085
2086 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002087 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002088 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002089 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002090 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002091 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002092 MultiExprArg Args,
2093 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002094 return SemaRef.BuildInstanceMessage(Receiver,
2095 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002096 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002097 Sel, Method, LBracLoc, SelectorLoc,
2098 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002099 }
2100
Douglas Gregord51d90d2010-04-26 20:11:03 +00002101 /// \brief Build a new Objective-C ivar reference expression.
2102 ///
2103 /// By default, performs semantic analysis to build the new expression.
2104 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002105 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002106 SourceLocation IvarLoc,
2107 bool IsArrow, bool IsFreeIvar) {
2108 // FIXME: We lose track of the IsFreeIvar bit.
2109 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002110 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002111 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2112 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002113 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002114 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002115 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002116 false);
John Wiegley01296292011-04-08 18:41:53 +00002117 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002118 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002119
Douglas Gregord51d90d2010-04-26 20:11:03 +00002120 if (Result.get())
2121 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002122
John Wiegley01296292011-04-08 18:41:53 +00002123 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002124 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002125 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002126 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002127 /*TemplateArgs=*/0);
2128 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002129
2130 /// \brief Build a new Objective-C property reference expression.
2131 ///
2132 /// By default, performs semantic analysis to build the new expression.
2133 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002134 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002135 ObjCPropertyDecl *Property,
2136 SourceLocation PropertyLoc) {
2137 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002138 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002139 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2140 Sema::LookupMemberName);
2141 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002142 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002143 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002144 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002145 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002146 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002147
Douglas Gregor9faee212010-04-26 20:47:02 +00002148 if (Result.get())
2149 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002150
John Wiegley01296292011-04-08 18:41:53 +00002151 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002152 /*FIXME:*/PropertyLoc, IsArrow,
2153 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002154 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002155 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002156 /*TemplateArgs=*/0);
2157 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002158
John McCallb7bd14f2010-12-02 01:19:52 +00002159 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002160 ///
2161 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002162 /// Subclasses may override this routine to provide different behavior.
2163 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2164 ObjCMethodDecl *Getter,
2165 ObjCMethodDecl *Setter,
2166 SourceLocation PropertyLoc) {
2167 // Since these expressions can only be value-dependent, we do not
2168 // need to perform semantic analysis again.
2169 return Owned(
2170 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2171 VK_LValue, OK_ObjCProperty,
2172 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002173 }
2174
Douglas Gregord51d90d2010-04-26 20:11:03 +00002175 /// \brief Build a new Objective-C "isa" expression.
2176 ///
2177 /// By default, performs semantic analysis to build the new expression.
2178 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002179 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002180 bool IsArrow) {
2181 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002182 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002183 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2184 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002185 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002186 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002187 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002188 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002189 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002190
Douglas Gregord51d90d2010-04-26 20:11:03 +00002191 if (Result.get())
2192 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002193
John Wiegley01296292011-04-08 18:41:53 +00002194 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002195 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002196 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002197 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002198 /*TemplateArgs=*/0);
2199 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002200
Douglas Gregora16548e2009-08-11 05:31:07 +00002201 /// \brief Build a new shuffle vector expression.
2202 ///
2203 /// By default, performs semantic analysis to build the new expression.
2204 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002205 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002206 MultiExprArg SubExprs,
2207 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002208 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002209 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002210 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2211 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2212 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2213 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002214
Douglas Gregora16548e2009-08-11 05:31:07 +00002215 // Build a reference to the __builtin_shufflevector builtin
2216 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley01296292011-04-08 18:41:53 +00002217 ExprResult Callee
2218 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2219 VK_LValue, BuiltinLoc));
2220 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2221 if (Callee.isInvalid())
2222 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002223
2224 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002225 unsigned NumSubExprs = SubExprs.size();
2226 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley01296292011-04-08 18:41:53 +00002227 ExprResult TheCall = SemaRef.Owned(
2228 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregora16548e2009-08-11 05:31:07 +00002229 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002230 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002231 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley01296292011-04-08 18:41:53 +00002232 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002233
Douglas Gregora16548e2009-08-11 05:31:07 +00002234 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002235 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002236 }
John McCall31f82722010-11-12 08:19:04 +00002237
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002238 /// \brief Build a new template argument pack expansion.
2239 ///
2240 /// By default, performs semantic analysis to build a new pack expansion
2241 /// for a template argument. Subclasses may override this routine to provide
2242 /// different behavior.
2243 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002244 SourceLocation EllipsisLoc,
2245 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002246 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002247 case TemplateArgument::Expression: {
2248 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002249 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2250 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002251 if (Result.isInvalid())
2252 return TemplateArgumentLoc();
2253
2254 return TemplateArgumentLoc(Result.get(), Result.get());
2255 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002256
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002257 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002258 return TemplateArgumentLoc(TemplateArgument(
2259 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002260 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002261 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002262 Pattern.getTemplateNameLoc(),
2263 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002264
2265 case TemplateArgument::Null:
2266 case TemplateArgument::Integral:
2267 case TemplateArgument::Declaration:
2268 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002269 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002270 llvm_unreachable("Pack expansion pattern has no parameter packs");
2271
2272 case TemplateArgument::Type:
2273 if (TypeSourceInfo *Expansion
2274 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002275 EllipsisLoc,
2276 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002277 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2278 Expansion);
2279 break;
2280 }
2281
2282 return TemplateArgumentLoc();
2283 }
2284
Douglas Gregor968f23a2011-01-03 19:31:53 +00002285 /// \brief Build a new expression pack expansion.
2286 ///
2287 /// By default, performs semantic analysis to build a new pack expansion
2288 /// for an expression. Subclasses may override this routine to provide
2289 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002290 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2291 llvm::Optional<unsigned> NumExpansions) {
2292 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002293 }
2294
John McCall31f82722010-11-12 08:19:04 +00002295private:
Douglas Gregor14454802011-02-25 02:25:35 +00002296 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2297 QualType ObjectType,
2298 NamedDecl *FirstQualifierInScope,
2299 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002300
2301 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2302 QualType ObjectType,
2303 NamedDecl *FirstQualifierInScope,
2304 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002305};
Douglas Gregora16548e2009-08-11 05:31:07 +00002306
Douglas Gregorebe10102009-08-20 07:17:43 +00002307template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002308StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002309 if (!S)
2310 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002311
Douglas Gregorebe10102009-08-20 07:17:43 +00002312 switch (S->getStmtClass()) {
2313 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002314
Douglas Gregorebe10102009-08-20 07:17:43 +00002315 // Transform individual statement nodes
2316#define STMT(Node, Parent) \
2317 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002318#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002319#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002320#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002321
Douglas Gregorebe10102009-08-20 07:17:43 +00002322 // Transform expressions by calling TransformExpr.
2323#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002324#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002325#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002326#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002327 {
John McCalldadc5752010-08-24 06:29:42 +00002328 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002329 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002330 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002331
John McCallb268a282010-08-23 23:25:46 +00002332 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002333 }
Mike Stump11289f42009-09-09 15:08:12 +00002334 }
2335
John McCallc3007a22010-10-26 07:05:15 +00002336 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002337}
Mike Stump11289f42009-09-09 15:08:12 +00002338
2339
Douglas Gregore922c772009-08-04 22:27:00 +00002340template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002341ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002342 if (!E)
2343 return SemaRef.Owned(E);
2344
2345 switch (E->getStmtClass()) {
2346 case Stmt::NoStmtClass: break;
2347#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002348#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002349#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002350 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002351#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002352 }
2353
John McCallc3007a22010-10-26 07:05:15 +00002354 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002355}
2356
2357template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002358bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2359 unsigned NumInputs,
2360 bool IsCall,
2361 llvm::SmallVectorImpl<Expr *> &Outputs,
2362 bool *ArgChanged) {
2363 for (unsigned I = 0; I != NumInputs; ++I) {
2364 // If requested, drop call arguments that need to be dropped.
2365 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2366 if (ArgChanged)
2367 *ArgChanged = true;
2368
2369 break;
2370 }
2371
Douglas Gregor968f23a2011-01-03 19:31:53 +00002372 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2373 Expr *Pattern = Expansion->getPattern();
2374
2375 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2376 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2377 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2378
2379 // Determine whether the set of unexpanded parameter packs can and should
2380 // be expanded.
2381 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002382 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002383 llvm::Optional<unsigned> OrigNumExpansions
2384 = Expansion->getNumExpansions();
2385 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002386 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2387 Pattern->getSourceRange(),
2388 Unexpanded.data(),
2389 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002390 Expand, RetainExpansion,
2391 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002392 return true;
2393
2394 if (!Expand) {
2395 // The transform has determined that we should perform a simple
2396 // transformation on the pack expansion, producing another pack
2397 // expansion.
2398 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2399 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2400 if (OutPattern.isInvalid())
2401 return true;
2402
2403 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002404 Expansion->getEllipsisLoc(),
2405 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002406 if (Out.isInvalid())
2407 return true;
2408
2409 if (ArgChanged)
2410 *ArgChanged = true;
2411 Outputs.push_back(Out.get());
2412 continue;
2413 }
2414
2415 // The transform has determined that we should perform an elementwise
2416 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002417 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002418 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2419 ExprResult Out = getDerived().TransformExpr(Pattern);
2420 if (Out.isInvalid())
2421 return true;
2422
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002423 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002424 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2425 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002426 if (Out.isInvalid())
2427 return true;
2428 }
2429
Douglas Gregor968f23a2011-01-03 19:31:53 +00002430 if (ArgChanged)
2431 *ArgChanged = true;
2432 Outputs.push_back(Out.get());
2433 }
2434
2435 continue;
2436 }
2437
Douglas Gregora3efea12011-01-03 19:04:46 +00002438 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2439 if (Result.isInvalid())
2440 return true;
2441
2442 if (Result.get() != Inputs[I] && ArgChanged)
2443 *ArgChanged = true;
2444
2445 Outputs.push_back(Result.get());
2446 }
2447
2448 return false;
2449}
2450
2451template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002452NestedNameSpecifierLoc
2453TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2454 NestedNameSpecifierLoc NNS,
2455 QualType ObjectType,
2456 NamedDecl *FirstQualifierInScope) {
2457 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2458 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2459 Qualifier = Qualifier.getPrefix())
2460 Qualifiers.push_back(Qualifier);
2461
2462 CXXScopeSpec SS;
2463 while (!Qualifiers.empty()) {
2464 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2465 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2466
2467 switch (QNNS->getKind()) {
2468 case NestedNameSpecifier::Identifier:
2469 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2470 *QNNS->getAsIdentifier(),
2471 Q.getLocalBeginLoc(),
2472 Q.getLocalEndLoc(),
2473 ObjectType, false, SS,
2474 FirstQualifierInScope, false))
2475 return NestedNameSpecifierLoc();
2476
2477 break;
2478
2479 case NestedNameSpecifier::Namespace: {
2480 NamespaceDecl *NS
2481 = cast_or_null<NamespaceDecl>(
2482 getDerived().TransformDecl(
2483 Q.getLocalBeginLoc(),
2484 QNNS->getAsNamespace()));
2485 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2486 break;
2487 }
2488
2489 case NestedNameSpecifier::NamespaceAlias: {
2490 NamespaceAliasDecl *Alias
2491 = cast_or_null<NamespaceAliasDecl>(
2492 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2493 QNNS->getAsNamespaceAlias()));
2494 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2495 Q.getLocalEndLoc());
2496 break;
2497 }
2498
2499 case NestedNameSpecifier::Global:
2500 // There is no meaningful transformation that one could perform on the
2501 // global scope.
2502 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2503 break;
2504
2505 case NestedNameSpecifier::TypeSpecWithTemplate:
2506 case NestedNameSpecifier::TypeSpec: {
2507 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2508 FirstQualifierInScope, SS);
2509
2510 if (!TL)
2511 return NestedNameSpecifierLoc();
2512
2513 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2514 (SemaRef.getLangOptions().CPlusPlus0x &&
2515 TL.getType()->isEnumeralType())) {
2516 assert(!TL.getType().hasLocalQualifiers() &&
2517 "Can't get cv-qualifiers here");
2518 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2519 Q.getLocalEndLoc());
2520 break;
2521 }
2522
2523 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2524 << TL.getType() << SS.getRange();
2525 return NestedNameSpecifierLoc();
2526 }
Douglas Gregore16af532011-02-28 18:50:33 +00002527 }
Douglas Gregor14454802011-02-25 02:25:35 +00002528
Douglas Gregore16af532011-02-28 18:50:33 +00002529 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002530 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002531 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002532 }
2533
2534 // Don't rebuild the nested-name-specifier if we don't have to.
2535 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2536 !getDerived().AlwaysRebuild())
2537 return NNS;
2538
2539 // If we can re-use the source-location data from the original
2540 // nested-name-specifier, do so.
2541 if (SS.location_size() == NNS.getDataLength() &&
2542 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2543 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2544
2545 // Allocate new nested-name-specifier location information.
2546 return SS.getWithLocInContext(SemaRef.Context);
2547}
2548
2549template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002550DeclarationNameInfo
2551TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002552::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002553 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002554 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002555 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002556
2557 switch (Name.getNameKind()) {
2558 case DeclarationName::Identifier:
2559 case DeclarationName::ObjCZeroArgSelector:
2560 case DeclarationName::ObjCOneArgSelector:
2561 case DeclarationName::ObjCMultiArgSelector:
2562 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002563 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002564 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002565 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002566
Douglas Gregorf816bd72009-09-03 22:13:48 +00002567 case DeclarationName::CXXConstructorName:
2568 case DeclarationName::CXXDestructorName:
2569 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002570 TypeSourceInfo *NewTInfo;
2571 CanQualType NewCanTy;
2572 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002573 NewTInfo = getDerived().TransformType(OldTInfo);
2574 if (!NewTInfo)
2575 return DeclarationNameInfo();
2576 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002577 }
2578 else {
2579 NewTInfo = 0;
2580 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002581 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002582 if (NewT.isNull())
2583 return DeclarationNameInfo();
2584 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2585 }
Mike Stump11289f42009-09-09 15:08:12 +00002586
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002587 DeclarationName NewName
2588 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2589 NewCanTy);
2590 DeclarationNameInfo NewNameInfo(NameInfo);
2591 NewNameInfo.setName(NewName);
2592 NewNameInfo.setNamedTypeInfo(NewTInfo);
2593 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002594 }
Mike Stump11289f42009-09-09 15:08:12 +00002595 }
2596
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002597 assert(0 && "Unknown name kind.");
2598 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002599}
2600
2601template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002602TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00002603TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2604 TemplateName Name,
2605 SourceLocation NameLoc,
2606 QualType ObjectType,
2607 NamedDecl *FirstQualifierInScope) {
2608 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2609 TemplateDecl *Template = QTN->getTemplateDecl();
2610 assert(Template && "qualified template name must refer to a template");
2611
2612 TemplateDecl *TransTemplate
2613 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2614 Template));
2615 if (!TransTemplate)
2616 return TemplateName();
2617
2618 if (!getDerived().AlwaysRebuild() &&
2619 SS.getScopeRep() == QTN->getQualifier() &&
2620 TransTemplate == Template)
2621 return Name;
2622
2623 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2624 TransTemplate);
2625 }
2626
2627 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2628 if (SS.getScopeRep()) {
2629 // These apply to the scope specifier, not the template.
2630 ObjectType = QualType();
2631 FirstQualifierInScope = 0;
2632 }
2633
2634 if (!getDerived().AlwaysRebuild() &&
2635 SS.getScopeRep() == DTN->getQualifier() &&
2636 ObjectType.isNull())
2637 return Name;
2638
2639 if (DTN->isIdentifier()) {
2640 return getDerived().RebuildTemplateName(SS,
2641 *DTN->getIdentifier(),
2642 NameLoc,
2643 ObjectType,
2644 FirstQualifierInScope);
2645 }
2646
2647 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2648 ObjectType);
2649 }
2650
2651 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2652 TemplateDecl *TransTemplate
2653 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2654 Template));
2655 if (!TransTemplate)
2656 return TemplateName();
2657
2658 if (!getDerived().AlwaysRebuild() &&
2659 TransTemplate == Template)
2660 return Name;
2661
2662 return TemplateName(TransTemplate);
2663 }
2664
2665 if (SubstTemplateTemplateParmPackStorage *SubstPack
2666 = Name.getAsSubstTemplateTemplateParmPack()) {
2667 TemplateTemplateParmDecl *TransParam
2668 = cast_or_null<TemplateTemplateParmDecl>(
2669 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2670 if (!TransParam)
2671 return TemplateName();
2672
2673 if (!getDerived().AlwaysRebuild() &&
2674 TransParam == SubstPack->getParameterPack())
2675 return Name;
2676
2677 return getDerived().RebuildTemplateName(TransParam,
2678 SubstPack->getArgumentPack());
2679 }
2680
2681 // These should be getting filtered out before they reach the AST.
2682 llvm_unreachable("overloaded function decl survived to here");
2683 return TemplateName();
2684}
2685
2686template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002687void TreeTransform<Derived>::InventTemplateArgumentLoc(
2688 const TemplateArgument &Arg,
2689 TemplateArgumentLoc &Output) {
2690 SourceLocation Loc = getDerived().getBaseLocation();
2691 switch (Arg.getKind()) {
2692 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002693 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002694 break;
2695
2696 case TemplateArgument::Type:
2697 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002698 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002699
John McCall0ad16662009-10-29 08:12:44 +00002700 break;
2701
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002702 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00002703 case TemplateArgument::TemplateExpansion: {
2704 NestedNameSpecifierLocBuilder Builder;
2705 TemplateName Template = Arg.getAsTemplate();
2706 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2707 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2708 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2709 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2710
2711 if (Arg.getKind() == TemplateArgument::Template)
2712 Output = TemplateArgumentLoc(Arg,
2713 Builder.getWithLocInContext(SemaRef.Context),
2714 Loc);
2715 else
2716 Output = TemplateArgumentLoc(Arg,
2717 Builder.getWithLocInContext(SemaRef.Context),
2718 Loc, Loc);
2719
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002720 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00002721 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002722
John McCall0ad16662009-10-29 08:12:44 +00002723 case TemplateArgument::Expression:
2724 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2725 break;
2726
2727 case TemplateArgument::Declaration:
2728 case TemplateArgument::Integral:
2729 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002730 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002731 break;
2732 }
2733}
2734
2735template<typename Derived>
2736bool TreeTransform<Derived>::TransformTemplateArgument(
2737 const TemplateArgumentLoc &Input,
2738 TemplateArgumentLoc &Output) {
2739 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002740 switch (Arg.getKind()) {
2741 case TemplateArgument::Null:
2742 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002743 Output = Input;
2744 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002745
Douglas Gregore922c772009-08-04 22:27:00 +00002746 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002747 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002748 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002749 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002750
2751 DI = getDerived().TransformType(DI);
2752 if (!DI) return true;
2753
2754 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2755 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002756 }
Mike Stump11289f42009-09-09 15:08:12 +00002757
Douglas Gregore922c772009-08-04 22:27:00 +00002758 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002759 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002760 DeclarationName Name;
2761 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2762 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002763 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002764 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002765 if (!D) return true;
2766
John McCall0d07eb32009-10-29 18:45:58 +00002767 Expr *SourceExpr = Input.getSourceDeclExpression();
2768 if (SourceExpr) {
2769 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002770 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002771 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002772 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002773 }
2774
2775 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002776 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002777 }
Mike Stump11289f42009-09-09 15:08:12 +00002778
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002779 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00002780 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2781 if (QualifierLoc) {
2782 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2783 if (!QualifierLoc)
2784 return true;
2785 }
2786
Douglas Gregordf846d12011-03-02 18:46:51 +00002787 CXXScopeSpec SS;
2788 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002789 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00002790 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2791 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002792 if (Template.isNull())
2793 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002794
Douglas Gregor9d802122011-03-02 17:09:35 +00002795 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002796 Input.getTemplateNameLoc());
2797 return false;
2798 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002799
2800 case TemplateArgument::TemplateExpansion:
2801 llvm_unreachable("Caller should expand pack expansions");
2802
Douglas Gregore922c772009-08-04 22:27:00 +00002803 case TemplateArgument::Expression: {
2804 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002805 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002806 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002807
John McCall0ad16662009-10-29 08:12:44 +00002808 Expr *InputExpr = Input.getSourceExpression();
2809 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2810
John McCalldadc5752010-08-24 06:29:42 +00002811 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002812 = getDerived().TransformExpr(InputExpr);
2813 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002814 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002815 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002816 }
Mike Stump11289f42009-09-09 15:08:12 +00002817
Douglas Gregore922c772009-08-04 22:27:00 +00002818 case TemplateArgument::Pack: {
2819 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2820 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002821 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002822 AEnd = Arg.pack_end();
2823 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002824
John McCall0ad16662009-10-29 08:12:44 +00002825 // FIXME: preserve source information here when we start
2826 // caring about parameter packs.
2827
John McCall0d07eb32009-10-29 18:45:58 +00002828 TemplateArgumentLoc InputArg;
2829 TemplateArgumentLoc OutputArg;
2830 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2831 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002832 return true;
2833
John McCall0d07eb32009-10-29 18:45:58 +00002834 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002835 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002836
2837 TemplateArgument *TransformedArgsPtr
2838 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2839 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2840 TransformedArgsPtr);
2841 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2842 TransformedArgs.size()),
2843 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002844 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002845 }
2846 }
Mike Stump11289f42009-09-09 15:08:12 +00002847
Douglas Gregore922c772009-08-04 22:27:00 +00002848 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002849 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002850}
2851
Douglas Gregorfe921a72010-12-20 23:36:19 +00002852/// \brief Iterator adaptor that invents template argument location information
2853/// for each of the template arguments in its underlying iterator.
2854template<typename Derived, typename InputIterator>
2855class TemplateArgumentLocInventIterator {
2856 TreeTransform<Derived> &Self;
2857 InputIterator Iter;
2858
2859public:
2860 typedef TemplateArgumentLoc value_type;
2861 typedef TemplateArgumentLoc reference;
2862 typedef typename std::iterator_traits<InputIterator>::difference_type
2863 difference_type;
2864 typedef std::input_iterator_tag iterator_category;
2865
2866 class pointer {
2867 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002868
Douglas Gregorfe921a72010-12-20 23:36:19 +00002869 public:
2870 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2871
2872 const TemplateArgumentLoc *operator->() const { return &Arg; }
2873 };
2874
2875 TemplateArgumentLocInventIterator() { }
2876
2877 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2878 InputIterator Iter)
2879 : Self(Self), Iter(Iter) { }
2880
2881 TemplateArgumentLocInventIterator &operator++() {
2882 ++Iter;
2883 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002884 }
2885
Douglas Gregorfe921a72010-12-20 23:36:19 +00002886 TemplateArgumentLocInventIterator operator++(int) {
2887 TemplateArgumentLocInventIterator Old(*this);
2888 ++(*this);
2889 return Old;
2890 }
2891
2892 reference operator*() const {
2893 TemplateArgumentLoc Result;
2894 Self.InventTemplateArgumentLoc(*Iter, Result);
2895 return Result;
2896 }
2897
2898 pointer operator->() const { return pointer(**this); }
2899
2900 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2901 const TemplateArgumentLocInventIterator &Y) {
2902 return X.Iter == Y.Iter;
2903 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002904
Douglas Gregorfe921a72010-12-20 23:36:19 +00002905 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2906 const TemplateArgumentLocInventIterator &Y) {
2907 return X.Iter != Y.Iter;
2908 }
2909};
2910
Douglas Gregor42cafa82010-12-20 17:42:22 +00002911template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002912template<typename InputIterator>
2913bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2914 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002915 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002916 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002917 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002918 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002919
2920 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2921 // Unpack argument packs, which we translate them into separate
2922 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002923 // FIXME: We could do much better if we could guarantee that the
2924 // TemplateArgumentLocInfo for the pack expansion would be usable for
2925 // all of the template arguments in the argument pack.
2926 typedef TemplateArgumentLocInventIterator<Derived,
2927 TemplateArgument::pack_iterator>
2928 PackLocIterator;
2929 if (TransformTemplateArguments(PackLocIterator(*this,
2930 In.getArgument().pack_begin()),
2931 PackLocIterator(*this,
2932 In.getArgument().pack_end()),
2933 Outputs))
2934 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002935
2936 continue;
2937 }
2938
2939 if (In.getArgument().isPackExpansion()) {
2940 // We have a pack expansion, for which we will be substituting into
2941 // the pattern.
2942 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002943 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002944 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002945 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2946 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002947
2948 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2949 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2950 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2951
2952 // Determine whether the set of unexpanded parameter packs can and should
2953 // be expanded.
2954 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002955 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002956 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002957 if (getDerived().TryExpandParameterPacks(Ellipsis,
2958 Pattern.getSourceRange(),
2959 Unexpanded.data(),
2960 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002961 Expand,
2962 RetainExpansion,
2963 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002964 return true;
2965
2966 if (!Expand) {
2967 // The transform has determined that we should perform a simple
2968 // transformation on the pack expansion, producing another pack
2969 // expansion.
2970 TemplateArgumentLoc OutPattern;
2971 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2972 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2973 return true;
2974
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002975 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
2976 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002977 if (Out.getArgument().isNull())
2978 return true;
2979
2980 Outputs.addArgument(Out);
2981 continue;
2982 }
2983
2984 // The transform has determined that we should perform an elementwise
2985 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002986 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002987 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2988
2989 if (getDerived().TransformTemplateArgument(Pattern, Out))
2990 return true;
2991
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002992 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002993 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2994 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002995 if (Out.getArgument().isNull())
2996 return true;
2997 }
2998
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002999 Outputs.addArgument(Out);
3000 }
3001
Douglas Gregor48d24112011-01-10 20:53:55 +00003002 // If we're supposed to retain a pack expansion, do so by temporarily
3003 // forgetting the partially-substituted parameter pack.
3004 if (RetainExpansion) {
3005 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3006
3007 if (getDerived().TransformTemplateArgument(Pattern, Out))
3008 return true;
3009
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003010 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3011 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003012 if (Out.getArgument().isNull())
3013 return true;
3014
3015 Outputs.addArgument(Out);
3016 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003017
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003018 continue;
3019 }
3020
3021 // The simple case:
3022 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003023 return true;
3024
3025 Outputs.addArgument(Out);
3026 }
3027
3028 return false;
3029
3030}
3031
Douglas Gregord6ff3322009-08-04 16:50:30 +00003032//===----------------------------------------------------------------------===//
3033// Type transformation
3034//===----------------------------------------------------------------------===//
3035
3036template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003037QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003038 if (getDerived().AlreadyTransformed(T))
3039 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003040
John McCall550e0c22009-10-21 00:40:46 +00003041 // Temporary workaround. All of these transformations should
3042 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003043 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3044 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003045
John McCall31f82722010-11-12 08:19:04 +00003046 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003047
John McCall550e0c22009-10-21 00:40:46 +00003048 if (!NewDI)
3049 return QualType();
3050
3051 return NewDI->getType();
3052}
3053
3054template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003055TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003056 if (getDerived().AlreadyTransformed(DI->getType()))
3057 return DI;
3058
3059 TypeLocBuilder TLB;
3060
3061 TypeLoc TL = DI->getTypeLoc();
3062 TLB.reserve(TL.getFullDataSize());
3063
John McCall31f82722010-11-12 08:19:04 +00003064 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003065 if (Result.isNull())
3066 return 0;
3067
John McCallbcd03502009-12-07 02:54:59 +00003068 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003069}
3070
3071template<typename Derived>
3072QualType
John McCall31f82722010-11-12 08:19:04 +00003073TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003074 switch (T.getTypeLocClass()) {
3075#define ABSTRACT_TYPELOC(CLASS, PARENT)
3076#define TYPELOC(CLASS, PARENT) \
3077 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003078 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003079#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003080 }
Mike Stump11289f42009-09-09 15:08:12 +00003081
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003082 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003083 return QualType();
3084}
3085
3086/// FIXME: By default, this routine adds type qualifiers only to types
3087/// that can have qualifiers, and silently suppresses those qualifiers
3088/// that are not permitted (e.g., qualifiers on reference or function
3089/// types). This is the right thing for template instantiation, but
3090/// probably not for other clients.
3091template<typename Derived>
3092QualType
3093TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003094 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003095 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003096
John McCall31f82722010-11-12 08:19:04 +00003097 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003098 if (Result.isNull())
3099 return QualType();
3100
3101 // Silently suppress qualifiers if the result type can't be qualified.
3102 // FIXME: this is the right thing for template instantiation, but
3103 // probably not for other clients.
3104 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003105 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003106
John McCallcb0f89a2010-06-05 06:41:15 +00003107 if (!Quals.empty()) {
3108 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3109 TLB.push<QualifiedTypeLoc>(Result);
3110 // No location information to preserve.
3111 }
John McCall550e0c22009-10-21 00:40:46 +00003112
3113 return Result;
3114}
3115
Douglas Gregor14454802011-02-25 02:25:35 +00003116template<typename Derived>
3117TypeLoc
3118TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3119 QualType ObjectType,
3120 NamedDecl *UnqualLookup,
3121 CXXScopeSpec &SS) {
Douglas Gregor14454802011-02-25 02:25:35 +00003122 QualType T = TL.getType();
3123 if (getDerived().AlreadyTransformed(T))
3124 return TL;
3125
3126 TypeLocBuilder TLB;
3127 QualType Result;
3128
3129 if (isa<TemplateSpecializationType>(T)) {
3130 TemplateSpecializationTypeLoc SpecTL
3131 = cast<TemplateSpecializationTypeLoc>(TL);
3132
3133 TemplateName Template =
Douglas Gregor9db53502011-03-02 18:07:45 +00003134 getDerived().TransformTemplateName(SS,
3135 SpecTL.getTypePtr()->getTemplateName(),
3136 SpecTL.getTemplateNameLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003137 ObjectType, UnqualLookup);
3138 if (Template.isNull())
3139 return TypeLoc();
3140
3141 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3142 Template);
3143 } else if (isa<DependentTemplateSpecializationType>(T)) {
3144 DependentTemplateSpecializationTypeLoc SpecTL
3145 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3146
Douglas Gregor5a064722011-02-28 17:23:35 +00003147 TemplateName Template
Douglas Gregor9db53502011-03-02 18:07:45 +00003148 = getDerived().RebuildTemplateName(SS,
Douglas Gregore16af532011-02-28 18:50:33 +00003149 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003150 SpecTL.getNameLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00003151 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003152 if (Template.isNull())
3153 return TypeLoc();
3154
Douglas Gregor14454802011-02-25 02:25:35 +00003155 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003156 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003157 Template,
3158 SS);
Douglas Gregor14454802011-02-25 02:25:35 +00003159 } else {
3160 // Nothing special needs to be done for these.
3161 Result = getDerived().TransformType(TLB, TL);
3162 }
3163
3164 if (Result.isNull())
3165 return TypeLoc();
3166
3167 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3168}
3169
Douglas Gregor579c15f2011-03-02 18:32:08 +00003170template<typename Derived>
3171TypeSourceInfo *
3172TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3173 QualType ObjectType,
3174 NamedDecl *UnqualLookup,
3175 CXXScopeSpec &SS) {
3176 // FIXME: Painfully copy-paste from the above!
3177
3178 QualType T = TSInfo->getType();
3179 if (getDerived().AlreadyTransformed(T))
3180 return TSInfo;
3181
3182 TypeLocBuilder TLB;
3183 QualType Result;
3184
3185 TypeLoc TL = TSInfo->getTypeLoc();
3186 if (isa<TemplateSpecializationType>(T)) {
3187 TemplateSpecializationTypeLoc SpecTL
3188 = cast<TemplateSpecializationTypeLoc>(TL);
3189
3190 TemplateName Template
3191 = getDerived().TransformTemplateName(SS,
3192 SpecTL.getTypePtr()->getTemplateName(),
3193 SpecTL.getTemplateNameLoc(),
3194 ObjectType, UnqualLookup);
3195 if (Template.isNull())
3196 return 0;
3197
3198 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3199 Template);
3200 } else if (isa<DependentTemplateSpecializationType>(T)) {
3201 DependentTemplateSpecializationTypeLoc SpecTL
3202 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3203
3204 TemplateName Template
3205 = getDerived().RebuildTemplateName(SS,
3206 *SpecTL.getTypePtr()->getIdentifier(),
3207 SpecTL.getNameLoc(),
3208 ObjectType, UnqualLookup);
3209 if (Template.isNull())
3210 return 0;
3211
3212 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3213 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003214 Template,
3215 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003216 } else {
3217 // Nothing special needs to be done for these.
3218 Result = getDerived().TransformType(TLB, TL);
3219 }
3220
3221 if (Result.isNull())
3222 return 0;
3223
3224 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3225}
3226
John McCall550e0c22009-10-21 00:40:46 +00003227template <class TyLoc> static inline
3228QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3229 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3230 NewT.setNameLoc(T.getNameLoc());
3231 return T.getType();
3232}
3233
John McCall550e0c22009-10-21 00:40:46 +00003234template<typename Derived>
3235QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003236 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003237 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3238 NewT.setBuiltinLoc(T.getBuiltinLoc());
3239 if (T.needsExtraLocalData())
3240 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3241 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003242}
Mike Stump11289f42009-09-09 15:08:12 +00003243
Douglas Gregord6ff3322009-08-04 16:50:30 +00003244template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003245QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003246 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003247 // FIXME: recurse?
3248 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003249}
Mike Stump11289f42009-09-09 15:08:12 +00003250
Douglas Gregord6ff3322009-08-04 16:50:30 +00003251template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003252QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003253 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003254 QualType PointeeType
3255 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003256 if (PointeeType.isNull())
3257 return QualType();
3258
3259 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003260 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003261 // A dependent pointer type 'T *' has is being transformed such
3262 // that an Objective-C class type is being replaced for 'T'. The
3263 // resulting pointer type is an ObjCObjectPointerType, not a
3264 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003265 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003266
John McCall8b07ec22010-05-15 11:32:37 +00003267 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3268 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003269 return Result;
3270 }
John McCall31f82722010-11-12 08:19:04 +00003271
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003272 if (getDerived().AlwaysRebuild() ||
3273 PointeeType != TL.getPointeeLoc().getType()) {
3274 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3275 if (Result.isNull())
3276 return QualType();
3277 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003278
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003279 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3280 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003281 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003282}
Mike Stump11289f42009-09-09 15:08:12 +00003283
3284template<typename Derived>
3285QualType
John McCall550e0c22009-10-21 00:40:46 +00003286TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003287 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003288 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003289 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3290 if (PointeeType.isNull())
3291 return QualType();
3292
3293 QualType Result = TL.getType();
3294 if (getDerived().AlwaysRebuild() ||
3295 PointeeType != TL.getPointeeLoc().getType()) {
3296 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003297 TL.getSigilLoc());
3298 if (Result.isNull())
3299 return QualType();
3300 }
3301
Douglas Gregor049211a2010-04-22 16:50:51 +00003302 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003303 NewT.setSigilLoc(TL.getSigilLoc());
3304 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003305}
3306
John McCall70dd5f62009-10-30 00:06:24 +00003307/// Transforms a reference type. Note that somewhat paradoxically we
3308/// don't care whether the type itself is an l-value type or an r-value
3309/// type; we only care if the type was *written* as an l-value type
3310/// or an r-value type.
3311template<typename Derived>
3312QualType
3313TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003314 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003315 const ReferenceType *T = TL.getTypePtr();
3316
3317 // Note that this works with the pointee-as-written.
3318 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3319 if (PointeeType.isNull())
3320 return QualType();
3321
3322 QualType Result = TL.getType();
3323 if (getDerived().AlwaysRebuild() ||
3324 PointeeType != T->getPointeeTypeAsWritten()) {
3325 Result = getDerived().RebuildReferenceType(PointeeType,
3326 T->isSpelledAsLValue(),
3327 TL.getSigilLoc());
3328 if (Result.isNull())
3329 return QualType();
3330 }
3331
3332 // r-value references can be rebuilt as l-value references.
3333 ReferenceTypeLoc NewTL;
3334 if (isa<LValueReferenceType>(Result))
3335 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3336 else
3337 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3338 NewTL.setSigilLoc(TL.getSigilLoc());
3339
3340 return Result;
3341}
3342
Mike Stump11289f42009-09-09 15:08:12 +00003343template<typename Derived>
3344QualType
John McCall550e0c22009-10-21 00:40:46 +00003345TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003346 LValueReferenceTypeLoc TL) {
3347 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003348}
3349
Mike Stump11289f42009-09-09 15:08:12 +00003350template<typename Derived>
3351QualType
John McCall550e0c22009-10-21 00:40:46 +00003352TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003353 RValueReferenceTypeLoc TL) {
3354 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003355}
Mike Stump11289f42009-09-09 15:08:12 +00003356
Douglas Gregord6ff3322009-08-04 16:50:30 +00003357template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003358QualType
John McCall550e0c22009-10-21 00:40:46 +00003359TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003360 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003361 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003362 if (PointeeType.isNull())
3363 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003364
Abramo Bagnara509357842011-03-05 14:42:21 +00003365 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3366 TypeSourceInfo* NewClsTInfo = 0;
3367 if (OldClsTInfo) {
3368 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3369 if (!NewClsTInfo)
3370 return QualType();
3371 }
3372
3373 const MemberPointerType *T = TL.getTypePtr();
3374 QualType OldClsType = QualType(T->getClass(), 0);
3375 QualType NewClsType;
3376 if (NewClsTInfo)
3377 NewClsType = NewClsTInfo->getType();
3378 else {
3379 NewClsType = getDerived().TransformType(OldClsType);
3380 if (NewClsType.isNull())
3381 return QualType();
3382 }
Mike Stump11289f42009-09-09 15:08:12 +00003383
John McCall550e0c22009-10-21 00:40:46 +00003384 QualType Result = TL.getType();
3385 if (getDerived().AlwaysRebuild() ||
3386 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003387 NewClsType != OldClsType) {
3388 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003389 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003390 if (Result.isNull())
3391 return QualType();
3392 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003393
John McCall550e0c22009-10-21 00:40:46 +00003394 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3395 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003396 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003397
3398 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003399}
3400
Mike Stump11289f42009-09-09 15:08:12 +00003401template<typename Derived>
3402QualType
John McCall550e0c22009-10-21 00:40:46 +00003403TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003404 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003405 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003406 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003407 if (ElementType.isNull())
3408 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003409
John McCall550e0c22009-10-21 00:40:46 +00003410 QualType Result = TL.getType();
3411 if (getDerived().AlwaysRebuild() ||
3412 ElementType != T->getElementType()) {
3413 Result = getDerived().RebuildConstantArrayType(ElementType,
3414 T->getSizeModifier(),
3415 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003416 T->getIndexTypeCVRQualifiers(),
3417 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003418 if (Result.isNull())
3419 return QualType();
3420 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003421
John McCall550e0c22009-10-21 00:40:46 +00003422 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3423 NewTL.setLBracketLoc(TL.getLBracketLoc());
3424 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003425
John McCall550e0c22009-10-21 00:40:46 +00003426 Expr *Size = TL.getSizeExpr();
3427 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003428 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003429 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3430 }
3431 NewTL.setSizeExpr(Size);
3432
3433 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003434}
Mike Stump11289f42009-09-09 15:08:12 +00003435
Douglas Gregord6ff3322009-08-04 16:50:30 +00003436template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003437QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003438 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003439 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003440 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003441 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003442 if (ElementType.isNull())
3443 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003444
John McCall550e0c22009-10-21 00:40:46 +00003445 QualType Result = TL.getType();
3446 if (getDerived().AlwaysRebuild() ||
3447 ElementType != T->getElementType()) {
3448 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003449 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003450 T->getIndexTypeCVRQualifiers(),
3451 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003452 if (Result.isNull())
3453 return QualType();
3454 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003455
John McCall550e0c22009-10-21 00:40:46 +00003456 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3457 NewTL.setLBracketLoc(TL.getLBracketLoc());
3458 NewTL.setRBracketLoc(TL.getRBracketLoc());
3459 NewTL.setSizeExpr(0);
3460
3461 return Result;
3462}
3463
3464template<typename Derived>
3465QualType
3466TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003467 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003468 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003469 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3470 if (ElementType.isNull())
3471 return QualType();
3472
3473 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003474 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003475
John McCalldadc5752010-08-24 06:29:42 +00003476 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003477 = getDerived().TransformExpr(T->getSizeExpr());
3478 if (SizeResult.isInvalid())
3479 return QualType();
3480
John McCallb268a282010-08-23 23:25:46 +00003481 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003482
3483 QualType Result = TL.getType();
3484 if (getDerived().AlwaysRebuild() ||
3485 ElementType != T->getElementType() ||
3486 Size != T->getSizeExpr()) {
3487 Result = getDerived().RebuildVariableArrayType(ElementType,
3488 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003489 Size,
John McCall550e0c22009-10-21 00:40:46 +00003490 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003491 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003492 if (Result.isNull())
3493 return QualType();
3494 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003495
John McCall550e0c22009-10-21 00:40:46 +00003496 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3497 NewTL.setLBracketLoc(TL.getLBracketLoc());
3498 NewTL.setRBracketLoc(TL.getRBracketLoc());
3499 NewTL.setSizeExpr(Size);
3500
3501 return Result;
3502}
3503
3504template<typename Derived>
3505QualType
3506TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003507 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003508 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003509 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3510 if (ElementType.isNull())
3511 return QualType();
3512
3513 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003514 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003515
John McCall33ddac02011-01-19 10:06:00 +00003516 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3517 Expr *origSize = TL.getSizeExpr();
3518 if (!origSize) origSize = T->getSizeExpr();
3519
3520 ExprResult sizeResult
3521 = getDerived().TransformExpr(origSize);
3522 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003523 return QualType();
3524
John McCall33ddac02011-01-19 10:06:00 +00003525 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003526
3527 QualType Result = TL.getType();
3528 if (getDerived().AlwaysRebuild() ||
3529 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003530 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003531 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3532 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003533 size,
John McCall550e0c22009-10-21 00:40:46 +00003534 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003535 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003536 if (Result.isNull())
3537 return QualType();
3538 }
John McCall550e0c22009-10-21 00:40:46 +00003539
3540 // We might have any sort of array type now, but fortunately they
3541 // all have the same location layout.
3542 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3543 NewTL.setLBracketLoc(TL.getLBracketLoc());
3544 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003545 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003546
3547 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003548}
Mike Stump11289f42009-09-09 15:08:12 +00003549
3550template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003551QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003552 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003553 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003554 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003555
3556 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003557 QualType ElementType = getDerived().TransformType(T->getElementType());
3558 if (ElementType.isNull())
3559 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003560
Douglas Gregore922c772009-08-04 22:27:00 +00003561 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003562 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003563
John McCalldadc5752010-08-24 06:29:42 +00003564 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003565 if (Size.isInvalid())
3566 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003567
John McCall550e0c22009-10-21 00:40:46 +00003568 QualType Result = TL.getType();
3569 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003570 ElementType != T->getElementType() ||
3571 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003572 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003573 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003574 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003575 if (Result.isNull())
3576 return QualType();
3577 }
John McCall550e0c22009-10-21 00:40:46 +00003578
3579 // Result might be dependent or not.
3580 if (isa<DependentSizedExtVectorType>(Result)) {
3581 DependentSizedExtVectorTypeLoc NewTL
3582 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3583 NewTL.setNameLoc(TL.getNameLoc());
3584 } else {
3585 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3586 NewTL.setNameLoc(TL.getNameLoc());
3587 }
3588
3589 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003590}
Mike Stump11289f42009-09-09 15:08:12 +00003591
3592template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003593QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003594 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003595 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003596 QualType ElementType = getDerived().TransformType(T->getElementType());
3597 if (ElementType.isNull())
3598 return QualType();
3599
John McCall550e0c22009-10-21 00:40:46 +00003600 QualType Result = TL.getType();
3601 if (getDerived().AlwaysRebuild() ||
3602 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003603 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003604 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003605 if (Result.isNull())
3606 return QualType();
3607 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003608
John McCall550e0c22009-10-21 00:40:46 +00003609 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3610 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003611
John McCall550e0c22009-10-21 00:40:46 +00003612 return Result;
3613}
3614
3615template<typename Derived>
3616QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003617 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003618 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003619 QualType ElementType = getDerived().TransformType(T->getElementType());
3620 if (ElementType.isNull())
3621 return QualType();
3622
3623 QualType Result = TL.getType();
3624 if (getDerived().AlwaysRebuild() ||
3625 ElementType != T->getElementType()) {
3626 Result = getDerived().RebuildExtVectorType(ElementType,
3627 T->getNumElements(),
3628 /*FIXME*/ SourceLocation());
3629 if (Result.isNull())
3630 return QualType();
3631 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003632
John McCall550e0c22009-10-21 00:40:46 +00003633 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3634 NewTL.setNameLoc(TL.getNameLoc());
3635
3636 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003637}
Mike Stump11289f42009-09-09 15:08:12 +00003638
3639template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003640ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003641TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3642 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003643 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003644 TypeSourceInfo *NewDI = 0;
3645
3646 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3647 // If we're substituting into a pack expansion type and we know the
3648 TypeLoc OldTL = OldDI->getTypeLoc();
3649 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3650
3651 TypeLocBuilder TLB;
3652 TypeLoc NewTL = OldDI->getTypeLoc();
3653 TLB.reserve(NewTL.getFullDataSize());
3654
3655 QualType Result = getDerived().TransformType(TLB,
3656 OldExpansionTL.getPatternLoc());
3657 if (Result.isNull())
3658 return 0;
3659
3660 Result = RebuildPackExpansionType(Result,
3661 OldExpansionTL.getPatternLoc().getSourceRange(),
3662 OldExpansionTL.getEllipsisLoc(),
3663 NumExpansions);
3664 if (Result.isNull())
3665 return 0;
3666
3667 PackExpansionTypeLoc NewExpansionTL
3668 = TLB.push<PackExpansionTypeLoc>(Result);
3669 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3670 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3671 } else
3672 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003673 if (!NewDI)
3674 return 0;
3675
3676 if (NewDI == OldDI)
3677 return OldParm;
3678 else
3679 return ParmVarDecl::Create(SemaRef.Context,
3680 OldParm->getDeclContext(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00003681 OldParm->getInnerLocStart(),
John McCall58f10c32010-03-11 09:03:00 +00003682 OldParm->getLocation(),
3683 OldParm->getIdentifier(),
3684 NewDI->getType(),
3685 NewDI,
3686 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003687 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003688 /* DefArg */ NULL);
3689}
3690
3691template<typename Derived>
3692bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003693 TransformFunctionTypeParams(SourceLocation Loc,
3694 ParmVarDecl **Params, unsigned NumParams,
3695 const QualType *ParamTypes,
3696 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3697 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3698 for (unsigned i = 0; i != NumParams; ++i) {
3699 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor715e4612011-01-14 22:40:04 +00003700 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003701 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00003702 if (OldParm->isParameterPack()) {
3703 // We have a function parameter pack that may need to be expanded.
3704 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003705
Douglas Gregor5499af42011-01-05 23:12:31 +00003706 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003707 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3708 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3709 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3710 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00003711 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3712
Douglas Gregor5499af42011-01-05 23:12:31 +00003713 // Determine whether we should expand the parameter packs.
3714 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003715 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003716 llvm::Optional<unsigned> OrigNumExpansions
3717 = ExpansionTL.getTypePtr()->getNumExpansions();
3718 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003719 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3720 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003721 Unexpanded.data(),
3722 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003723 ShouldExpand,
3724 RetainExpansion,
3725 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003726 return true;
3727 }
3728
3729 if (ShouldExpand) {
3730 // Expand the function parameter pack into multiple, separate
3731 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003732 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003733 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003734 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3735 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003736 = getDerived().TransformFunctionTypeParam(OldParm,
3737 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003738 if (!NewParm)
3739 return true;
3740
Douglas Gregordd472162011-01-07 00:20:55 +00003741 OutParamTypes.push_back(NewParm->getType());
3742 if (PVars)
3743 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003744 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003745
3746 // If we're supposed to retain a pack expansion, do so by temporarily
3747 // forgetting the partially-substituted parameter pack.
3748 if (RetainExpansion) {
3749 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3750 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003751 = getDerived().TransformFunctionTypeParam(OldParm,
3752 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003753 if (!NewParm)
3754 return true;
3755
3756 OutParamTypes.push_back(NewParm->getType());
3757 if (PVars)
3758 PVars->push_back(NewParm);
3759 }
3760
Douglas Gregor5499af42011-01-05 23:12:31 +00003761 // We're done with the pack expansion.
3762 continue;
3763 }
3764
3765 // We'll substitute the parameter now without expanding the pack
3766 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00003767 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3768 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3769 NumExpansions);
3770 } else {
3771 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3772 llvm::Optional<unsigned>());
Douglas Gregor5499af42011-01-05 23:12:31 +00003773 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00003774
John McCall58f10c32010-03-11 09:03:00 +00003775 if (!NewParm)
3776 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003777
Douglas Gregordd472162011-01-07 00:20:55 +00003778 OutParamTypes.push_back(NewParm->getType());
3779 if (PVars)
3780 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003781 continue;
3782 }
John McCall58f10c32010-03-11 09:03:00 +00003783
3784 // Deal with the possibility that we don't have a parameter
3785 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003786 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003787 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003788 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003789 QualType NewType;
Douglas Gregor5499af42011-01-05 23:12:31 +00003790 if (const PackExpansionType *Expansion
3791 = dyn_cast<PackExpansionType>(OldType)) {
3792 // We have a function parameter pack that may need to be expanded.
3793 QualType Pattern = Expansion->getPattern();
3794 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3795 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3796
3797 // Determine whether we should expand the parameter packs.
3798 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003799 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003800 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003801 Unexpanded.data(),
3802 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003803 ShouldExpand,
3804 RetainExpansion,
3805 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003806 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003807 }
3808
3809 if (ShouldExpand) {
3810 // Expand the function parameter pack into multiple, separate
3811 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003812 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003813 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3814 QualType NewType = getDerived().TransformType(Pattern);
3815 if (NewType.isNull())
3816 return true;
John McCall58f10c32010-03-11 09:03:00 +00003817
Douglas Gregordd472162011-01-07 00:20:55 +00003818 OutParamTypes.push_back(NewType);
3819 if (PVars)
3820 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003821 }
3822
3823 // We're done with the pack expansion.
3824 continue;
3825 }
3826
Douglas Gregor48d24112011-01-10 20:53:55 +00003827 // If we're supposed to retain a pack expansion, do so by temporarily
3828 // forgetting the partially-substituted parameter pack.
3829 if (RetainExpansion) {
3830 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3831 QualType NewType = getDerived().TransformType(Pattern);
3832 if (NewType.isNull())
3833 return true;
3834
3835 OutParamTypes.push_back(NewType);
3836 if (PVars)
3837 PVars->push_back(0);
3838 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003839
Douglas Gregor5499af42011-01-05 23:12:31 +00003840 // We'll substitute the parameter now without expanding the pack
3841 // expansion.
3842 OldType = Expansion->getPattern();
3843 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003844 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3845 NewType = getDerived().TransformType(OldType);
3846 } else {
3847 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00003848 }
3849
Douglas Gregor5499af42011-01-05 23:12:31 +00003850 if (NewType.isNull())
3851 return true;
3852
3853 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003854 NewType = getSema().Context.getPackExpansionType(NewType,
3855 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003856
Douglas Gregordd472162011-01-07 00:20:55 +00003857 OutParamTypes.push_back(NewType);
3858 if (PVars)
3859 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003860 }
3861
3862 return false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003863 }
John McCall58f10c32010-03-11 09:03:00 +00003864
3865template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003866QualType
John McCall550e0c22009-10-21 00:40:46 +00003867TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003868 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003869 // Transform the parameters and return type.
3870 //
3871 // We instantiate in source order, with the return type first followed by
3872 // the parameters, because users tend to expect this (even if they shouldn't
3873 // rely on it!).
3874 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003875 // When the function has a trailing return type, we instantiate the
3876 // parameters before the return type, since the return type can then refer
3877 // to the parameters themselves (via decltype, sizeof, etc.).
3878 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003879 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003880 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00003881 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003882
Douglas Gregor7fb25412010-10-01 18:44:50 +00003883 QualType ResultType;
3884
3885 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003886 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3887 TL.getParmArray(),
3888 TL.getNumArgs(),
3889 TL.getTypePtr()->arg_type_begin(),
3890 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003891 return QualType();
3892
3893 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3894 if (ResultType.isNull())
3895 return QualType();
3896 }
3897 else {
3898 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3899 if (ResultType.isNull())
3900 return QualType();
3901
Douglas Gregordd472162011-01-07 00:20:55 +00003902 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3903 TL.getParmArray(),
3904 TL.getNumArgs(),
3905 TL.getTypePtr()->arg_type_begin(),
3906 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003907 return QualType();
3908 }
3909
John McCall550e0c22009-10-21 00:40:46 +00003910 QualType Result = TL.getType();
3911 if (getDerived().AlwaysRebuild() ||
3912 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003913 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003914 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3915 Result = getDerived().RebuildFunctionProtoType(ResultType,
3916 ParamTypes.data(),
3917 ParamTypes.size(),
3918 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003919 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00003920 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003921 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003922 if (Result.isNull())
3923 return QualType();
3924 }
Mike Stump11289f42009-09-09 15:08:12 +00003925
John McCall550e0c22009-10-21 00:40:46 +00003926 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00003927 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
3928 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003929 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003930 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3931 NewTL.setArg(i, ParamDecls[i]);
3932
3933 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003934}
Mike Stump11289f42009-09-09 15:08:12 +00003935
Douglas Gregord6ff3322009-08-04 16:50:30 +00003936template<typename Derived>
3937QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003938 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003939 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003940 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003941 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3942 if (ResultType.isNull())
3943 return QualType();
3944
3945 QualType Result = TL.getType();
3946 if (getDerived().AlwaysRebuild() ||
3947 ResultType != T->getResultType())
3948 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3949
3950 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00003951 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
3952 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003953 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003954
3955 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003956}
Mike Stump11289f42009-09-09 15:08:12 +00003957
John McCallb96ec562009-12-04 22:46:56 +00003958template<typename Derived> QualType
3959TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003960 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003961 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003962 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003963 if (!D)
3964 return QualType();
3965
3966 QualType Result = TL.getType();
3967 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3968 Result = getDerived().RebuildUnresolvedUsingType(D);
3969 if (Result.isNull())
3970 return QualType();
3971 }
3972
3973 // We might get an arbitrary type spec type back. We should at
3974 // least always get a type spec type, though.
3975 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3976 NewTL.setNameLoc(TL.getNameLoc());
3977
3978 return Result;
3979}
3980
Douglas Gregord6ff3322009-08-04 16:50:30 +00003981template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003982QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003983 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003984 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00003985 TypedefNameDecl *Typedef
3986 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3987 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003988 if (!Typedef)
3989 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003990
John McCall550e0c22009-10-21 00:40:46 +00003991 QualType Result = TL.getType();
3992 if (getDerived().AlwaysRebuild() ||
3993 Typedef != T->getDecl()) {
3994 Result = getDerived().RebuildTypedefType(Typedef);
3995 if (Result.isNull())
3996 return QualType();
3997 }
Mike Stump11289f42009-09-09 15:08:12 +00003998
John McCall550e0c22009-10-21 00:40:46 +00003999 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4000 NewTL.setNameLoc(TL.getNameLoc());
4001
4002 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004003}
Mike Stump11289f42009-09-09 15:08:12 +00004004
Douglas Gregord6ff3322009-08-04 16:50:30 +00004005template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004006QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004007 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004008 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004009 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004010
John McCalldadc5752010-08-24 06:29:42 +00004011 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004012 if (E.isInvalid())
4013 return QualType();
4014
John McCall550e0c22009-10-21 00:40:46 +00004015 QualType Result = TL.getType();
4016 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004017 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004018 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004019 if (Result.isNull())
4020 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004021 }
John McCall550e0c22009-10-21 00:40:46 +00004022 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004023
John McCall550e0c22009-10-21 00:40:46 +00004024 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004025 NewTL.setTypeofLoc(TL.getTypeofLoc());
4026 NewTL.setLParenLoc(TL.getLParenLoc());
4027 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004028
4029 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004030}
Mike Stump11289f42009-09-09 15:08:12 +00004031
4032template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004033QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004034 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004035 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4036 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4037 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004038 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004039
John McCall550e0c22009-10-21 00:40:46 +00004040 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004041 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4042 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004043 if (Result.isNull())
4044 return QualType();
4045 }
Mike Stump11289f42009-09-09 15:08:12 +00004046
John McCall550e0c22009-10-21 00:40:46 +00004047 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004048 NewTL.setTypeofLoc(TL.getTypeofLoc());
4049 NewTL.setLParenLoc(TL.getLParenLoc());
4050 NewTL.setRParenLoc(TL.getRParenLoc());
4051 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004052
4053 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004054}
Mike Stump11289f42009-09-09 15:08:12 +00004055
4056template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004057QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004058 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004059 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004060
Douglas Gregore922c772009-08-04 22:27:00 +00004061 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004062 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004063
John McCalldadc5752010-08-24 06:29:42 +00004064 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004065 if (E.isInvalid())
4066 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004067
John McCall550e0c22009-10-21 00:40:46 +00004068 QualType Result = TL.getType();
4069 if (getDerived().AlwaysRebuild() ||
4070 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004071 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004072 if (Result.isNull())
4073 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004074 }
John McCall550e0c22009-10-21 00:40:46 +00004075 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004076
John McCall550e0c22009-10-21 00:40:46 +00004077 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4078 NewTL.setNameLoc(TL.getNameLoc());
4079
4080 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004081}
4082
4083template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004084QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4085 AutoTypeLoc TL) {
4086 const AutoType *T = TL.getTypePtr();
4087 QualType OldDeduced = T->getDeducedType();
4088 QualType NewDeduced;
4089 if (!OldDeduced.isNull()) {
4090 NewDeduced = getDerived().TransformType(OldDeduced);
4091 if (NewDeduced.isNull())
4092 return QualType();
4093 }
4094
4095 QualType Result = TL.getType();
4096 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4097 Result = getDerived().RebuildAutoType(NewDeduced);
4098 if (Result.isNull())
4099 return QualType();
4100 }
4101
4102 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4103 NewTL.setNameLoc(TL.getNameLoc());
4104
4105 return Result;
4106}
4107
4108template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004109QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004110 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004111 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004112 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004113 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4114 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004115 if (!Record)
4116 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004117
John McCall550e0c22009-10-21 00:40:46 +00004118 QualType Result = TL.getType();
4119 if (getDerived().AlwaysRebuild() ||
4120 Record != T->getDecl()) {
4121 Result = getDerived().RebuildRecordType(Record);
4122 if (Result.isNull())
4123 return QualType();
4124 }
Mike Stump11289f42009-09-09 15:08:12 +00004125
John McCall550e0c22009-10-21 00:40:46 +00004126 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4127 NewTL.setNameLoc(TL.getNameLoc());
4128
4129 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004130}
Mike Stump11289f42009-09-09 15:08:12 +00004131
4132template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004133QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004134 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004135 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004136 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004137 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4138 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004139 if (!Enum)
4140 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004141
John McCall550e0c22009-10-21 00:40:46 +00004142 QualType Result = TL.getType();
4143 if (getDerived().AlwaysRebuild() ||
4144 Enum != T->getDecl()) {
4145 Result = getDerived().RebuildEnumType(Enum);
4146 if (Result.isNull())
4147 return QualType();
4148 }
Mike Stump11289f42009-09-09 15:08:12 +00004149
John McCall550e0c22009-10-21 00:40:46 +00004150 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4151 NewTL.setNameLoc(TL.getNameLoc());
4152
4153 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004154}
John McCallfcc33b02009-09-05 00:15:47 +00004155
John McCalle78aac42010-03-10 03:28:59 +00004156template<typename Derived>
4157QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4158 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004159 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004160 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4161 TL.getTypePtr()->getDecl());
4162 if (!D) return QualType();
4163
4164 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4165 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4166 return T;
4167}
4168
Douglas Gregord6ff3322009-08-04 16:50:30 +00004169template<typename Derived>
4170QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004171 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004172 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004173 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004174}
4175
Mike Stump11289f42009-09-09 15:08:12 +00004176template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004177QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004178 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004179 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004180 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4181
4182 // Substitute into the replacement type, which itself might involve something
4183 // that needs to be transformed. This only tends to occur with default
4184 // template arguments of template template parameters.
4185 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4186 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4187 if (Replacement.isNull())
4188 return QualType();
4189
4190 // Always canonicalize the replacement type.
4191 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4192 QualType Result
4193 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4194 Replacement);
4195
4196 // Propagate type-source information.
4197 SubstTemplateTypeParmTypeLoc NewTL
4198 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4199 NewTL.setNameLoc(TL.getNameLoc());
4200 return Result;
4201
John McCallcebee162009-10-18 09:09:24 +00004202}
4203
4204template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004205QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4206 TypeLocBuilder &TLB,
4207 SubstTemplateTypeParmPackTypeLoc TL) {
4208 return TransformTypeSpecType(TLB, TL);
4209}
4210
4211template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004212QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004213 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004214 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004215 const TemplateSpecializationType *T = TL.getTypePtr();
4216
Douglas Gregordf846d12011-03-02 18:46:51 +00004217 // The nested-name-specifier never matters in a TemplateSpecializationType,
4218 // because we can't have a dependent nested-name-specifier anyway.
4219 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004220 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004221 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4222 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004223 if (Template.isNull())
4224 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004225
John McCall31f82722010-11-12 08:19:04 +00004226 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4227}
4228
Douglas Gregorfe921a72010-12-20 23:36:19 +00004229namespace {
4230 /// \brief Simple iterator that traverses the template arguments in a
4231 /// container that provides a \c getArgLoc() member function.
4232 ///
4233 /// This iterator is intended to be used with the iterator form of
4234 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4235 template<typename ArgLocContainer>
4236 class TemplateArgumentLocContainerIterator {
4237 ArgLocContainer *Container;
4238 unsigned Index;
4239
4240 public:
4241 typedef TemplateArgumentLoc value_type;
4242 typedef TemplateArgumentLoc reference;
4243 typedef int difference_type;
4244 typedef std::input_iterator_tag iterator_category;
4245
4246 class pointer {
4247 TemplateArgumentLoc Arg;
4248
4249 public:
4250 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4251
4252 const TemplateArgumentLoc *operator->() const {
4253 return &Arg;
4254 }
4255 };
4256
4257
4258 TemplateArgumentLocContainerIterator() {}
4259
4260 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4261 unsigned Index)
4262 : Container(&Container), Index(Index) { }
4263
4264 TemplateArgumentLocContainerIterator &operator++() {
4265 ++Index;
4266 return *this;
4267 }
4268
4269 TemplateArgumentLocContainerIterator operator++(int) {
4270 TemplateArgumentLocContainerIterator Old(*this);
4271 ++(*this);
4272 return Old;
4273 }
4274
4275 TemplateArgumentLoc operator*() const {
4276 return Container->getArgLoc(Index);
4277 }
4278
4279 pointer operator->() const {
4280 return pointer(Container->getArgLoc(Index));
4281 }
4282
4283 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004284 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004285 return X.Container == Y.Container && X.Index == Y.Index;
4286 }
4287
4288 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004289 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004290 return !(X == Y);
4291 }
4292 };
4293}
4294
4295
John McCall31f82722010-11-12 08:19:04 +00004296template <typename Derived>
4297QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4298 TypeLocBuilder &TLB,
4299 TemplateSpecializationTypeLoc TL,
4300 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004301 TemplateArgumentListInfo NewTemplateArgs;
4302 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4303 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004304 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4305 ArgIterator;
4306 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4307 ArgIterator(TL, TL.getNumArgs()),
4308 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004309 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004310
John McCall0ad16662009-10-29 08:12:44 +00004311 // FIXME: maybe don't rebuild if all the template arguments are the same.
4312
4313 QualType Result =
4314 getDerived().RebuildTemplateSpecializationType(Template,
4315 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004316 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004317
4318 if (!Result.isNull()) {
4319 TemplateSpecializationTypeLoc NewTL
4320 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4321 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4322 NewTL.setLAngleLoc(TL.getLAngleLoc());
4323 NewTL.setRAngleLoc(TL.getRAngleLoc());
4324 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4325 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004326 }
Mike Stump11289f42009-09-09 15:08:12 +00004327
John McCall0ad16662009-10-29 08:12:44 +00004328 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004329}
Mike Stump11289f42009-09-09 15:08:12 +00004330
Douglas Gregor5a064722011-02-28 17:23:35 +00004331template <typename Derived>
4332QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4333 TypeLocBuilder &TLB,
4334 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004335 TemplateName Template,
4336 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004337 TemplateArgumentListInfo NewTemplateArgs;
4338 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4339 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4340 typedef TemplateArgumentLocContainerIterator<
4341 DependentTemplateSpecializationTypeLoc> ArgIterator;
4342 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4343 ArgIterator(TL, TL.getNumArgs()),
4344 NewTemplateArgs))
4345 return QualType();
4346
4347 // FIXME: maybe don't rebuild if all the template arguments are the same.
4348
4349 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4350 QualType Result
4351 = getSema().Context.getDependentTemplateSpecializationType(
4352 TL.getTypePtr()->getKeyword(),
4353 DTN->getQualifier(),
4354 DTN->getIdentifier(),
4355 NewTemplateArgs);
4356
4357 DependentTemplateSpecializationTypeLoc NewTL
4358 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4359 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004360
Douglas Gregora7a795b2011-03-01 20:11:18 +00004361 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004362 NewTL.setNameLoc(TL.getNameLoc());
4363 NewTL.setLAngleLoc(TL.getLAngleLoc());
4364 NewTL.setRAngleLoc(TL.getRAngleLoc());
4365 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4366 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4367 return Result;
4368 }
4369
4370 QualType Result
4371 = getDerived().RebuildTemplateSpecializationType(Template,
4372 TL.getNameLoc(),
4373 NewTemplateArgs);
4374
4375 if (!Result.isNull()) {
4376 /// FIXME: Wrap this in an elaborated-type-specifier?
4377 TemplateSpecializationTypeLoc NewTL
4378 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4379 NewTL.setTemplateNameLoc(TL.getNameLoc());
4380 NewTL.setLAngleLoc(TL.getLAngleLoc());
4381 NewTL.setRAngleLoc(TL.getRAngleLoc());
4382 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4383 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4384 }
4385
4386 return Result;
4387}
4388
Mike Stump11289f42009-09-09 15:08:12 +00004389template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004390QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004391TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004392 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004393 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004394
Douglas Gregor844cb502011-03-01 18:12:44 +00004395 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004396 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004397 if (TL.getQualifierLoc()) {
4398 QualifierLoc
4399 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4400 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004401 return QualType();
4402 }
Mike Stump11289f42009-09-09 15:08:12 +00004403
John McCall31f82722010-11-12 08:19:04 +00004404 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4405 if (NamedT.isNull())
4406 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004407
John McCall550e0c22009-10-21 00:40:46 +00004408 QualType Result = TL.getType();
4409 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004410 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004411 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004412 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004413 T->getKeyword(),
4414 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004415 if (Result.isNull())
4416 return QualType();
4417 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004418
Abramo Bagnara6150c882010-05-11 21:36:43 +00004419 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004420 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004421 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004422 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004423}
Mike Stump11289f42009-09-09 15:08:12 +00004424
4425template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004426QualType TreeTransform<Derived>::TransformAttributedType(
4427 TypeLocBuilder &TLB,
4428 AttributedTypeLoc TL) {
4429 const AttributedType *oldType = TL.getTypePtr();
4430 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4431 if (modifiedType.isNull())
4432 return QualType();
4433
4434 QualType result = TL.getType();
4435
4436 // FIXME: dependent operand expressions?
4437 if (getDerived().AlwaysRebuild() ||
4438 modifiedType != oldType->getModifiedType()) {
4439 // TODO: this is really lame; we should really be rebuilding the
4440 // equivalent type from first principles.
4441 QualType equivalentType
4442 = getDerived().TransformType(oldType->getEquivalentType());
4443 if (equivalentType.isNull())
4444 return QualType();
4445 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4446 modifiedType,
4447 equivalentType);
4448 }
4449
4450 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4451 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4452 if (TL.hasAttrOperand())
4453 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4454 if (TL.hasAttrExprOperand())
4455 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4456 else if (TL.hasAttrEnumOperand())
4457 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4458
4459 return result;
4460}
4461
4462template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004463QualType
4464TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4465 ParenTypeLoc TL) {
4466 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4467 if (Inner.isNull())
4468 return QualType();
4469
4470 QualType Result = TL.getType();
4471 if (getDerived().AlwaysRebuild() ||
4472 Inner != TL.getInnerLoc().getType()) {
4473 Result = getDerived().RebuildParenType(Inner);
4474 if (Result.isNull())
4475 return QualType();
4476 }
4477
4478 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4479 NewTL.setLParenLoc(TL.getLParenLoc());
4480 NewTL.setRParenLoc(TL.getRParenLoc());
4481 return Result;
4482}
4483
4484template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004485QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004486 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004487 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004488
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004489 NestedNameSpecifierLoc QualifierLoc
4490 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4491 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004492 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004493
John McCallc392f372010-06-11 00:33:02 +00004494 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004495 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004496 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004497 QualifierLoc,
4498 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004499 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004500 if (Result.isNull())
4501 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004502
Abramo Bagnarad7548482010-05-19 21:37:53 +00004503 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4504 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004505 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4506
Abramo Bagnarad7548482010-05-19 21:37:53 +00004507 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4508 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004509 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004510 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004511 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4512 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004513 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004514 NewTL.setNameLoc(TL.getNameLoc());
4515 }
John McCall550e0c22009-10-21 00:40:46 +00004516 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004517}
Mike Stump11289f42009-09-09 15:08:12 +00004518
Douglas Gregord6ff3322009-08-04 16:50:30 +00004519template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004520QualType TreeTransform<Derived>::
4521 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004522 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004523 NestedNameSpecifierLoc QualifierLoc;
4524 if (TL.getQualifierLoc()) {
4525 QualifierLoc
4526 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4527 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004528 return QualType();
4529 }
4530
John McCall31f82722010-11-12 08:19:04 +00004531 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004532 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004533}
4534
4535template<typename Derived>
4536QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00004537TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4538 DependentTemplateSpecializationTypeLoc TL,
4539 NestedNameSpecifierLoc QualifierLoc) {
4540 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4541
4542 TemplateArgumentListInfo NewTemplateArgs;
4543 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4544 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4545
4546 typedef TemplateArgumentLocContainerIterator<
4547 DependentTemplateSpecializationTypeLoc> ArgIterator;
4548 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4549 ArgIterator(TL, TL.getNumArgs()),
4550 NewTemplateArgs))
4551 return QualType();
4552
4553 QualType Result
4554 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4555 QualifierLoc,
4556 T->getIdentifier(),
4557 TL.getNameLoc(),
4558 NewTemplateArgs);
4559 if (Result.isNull())
4560 return QualType();
4561
4562 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4563 QualType NamedT = ElabT->getNamedType();
4564
4565 // Copy information relevant to the template specialization.
4566 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00004567 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004568 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004569 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4570 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004571 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004572 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004573
4574 // Copy information relevant to the elaborated type.
4575 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4576 NewTL.setKeywordLoc(TL.getKeywordLoc());
4577 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00004578 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4579 DependentTemplateSpecializationTypeLoc SpecTL
4580 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor11ddf132011-03-07 15:13:34 +00004581 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004582 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004583 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004584 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4585 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004586 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004587 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004588 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00004589 TemplateSpecializationTypeLoc SpecTL
4590 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004591 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004592 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4593 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004594 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004595 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004596 }
4597 return Result;
4598}
4599
4600template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004601QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4602 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004603 QualType Pattern
4604 = getDerived().TransformType(TLB, TL.getPatternLoc());
4605 if (Pattern.isNull())
4606 return QualType();
4607
4608 QualType Result = TL.getType();
4609 if (getDerived().AlwaysRebuild() ||
4610 Pattern != TL.getPatternLoc().getType()) {
4611 Result = getDerived().RebuildPackExpansionType(Pattern,
4612 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004613 TL.getEllipsisLoc(),
4614 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004615 if (Result.isNull())
4616 return QualType();
4617 }
4618
4619 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4620 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4621 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004622}
4623
4624template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004625QualType
4626TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004627 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004628 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004629 TLB.pushFullCopy(TL);
4630 return TL.getType();
4631}
4632
4633template<typename Derived>
4634QualType
4635TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004636 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004637 // ObjCObjectType is never dependent.
4638 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004639 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004640}
Mike Stump11289f42009-09-09 15:08:12 +00004641
4642template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004643QualType
4644TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004645 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004646 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004647 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004648 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004649}
4650
Douglas Gregord6ff3322009-08-04 16:50:30 +00004651//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004652// Statement transformation
4653//===----------------------------------------------------------------------===//
4654template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004655StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004656TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004657 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004658}
4659
4660template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004661StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004662TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4663 return getDerived().TransformCompoundStmt(S, false);
4664}
4665
4666template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004667StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004668TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004669 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004670 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004671 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004672 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004673 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4674 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004675 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004676 if (Result.isInvalid()) {
4677 // Immediately fail if this was a DeclStmt, since it's very
4678 // likely that this will cause problems for future statements.
4679 if (isa<DeclStmt>(*B))
4680 return StmtError();
4681
4682 // Otherwise, just keep processing substatements and fail later.
4683 SubStmtInvalid = true;
4684 continue;
4685 }
Mike Stump11289f42009-09-09 15:08:12 +00004686
Douglas Gregorebe10102009-08-20 07:17:43 +00004687 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4688 Statements.push_back(Result.takeAs<Stmt>());
4689 }
Mike Stump11289f42009-09-09 15:08:12 +00004690
John McCall1ababa62010-08-27 19:56:05 +00004691 if (SubStmtInvalid)
4692 return StmtError();
4693
Douglas Gregorebe10102009-08-20 07:17:43 +00004694 if (!getDerived().AlwaysRebuild() &&
4695 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004696 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004697
4698 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4699 move_arg(Statements),
4700 S->getRBracLoc(),
4701 IsStmtExpr);
4702}
Mike Stump11289f42009-09-09 15:08:12 +00004703
Douglas Gregorebe10102009-08-20 07:17:43 +00004704template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004705StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004706TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004707 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004708 {
4709 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004710 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004711
Eli Friedman06577382009-11-19 03:14:00 +00004712 // Transform the left-hand case value.
4713 LHS = getDerived().TransformExpr(S->getLHS());
4714 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004715 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004716
Eli Friedman06577382009-11-19 03:14:00 +00004717 // Transform the right-hand case value (for the GNU case-range extension).
4718 RHS = getDerived().TransformExpr(S->getRHS());
4719 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004720 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004721 }
Mike Stump11289f42009-09-09 15:08:12 +00004722
Douglas Gregorebe10102009-08-20 07:17:43 +00004723 // Build the case statement.
4724 // Case statements are always rebuilt so that they will attached to their
4725 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004726 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004727 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004728 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004729 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004730 S->getColonLoc());
4731 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004732 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004733
Douglas Gregorebe10102009-08-20 07:17:43 +00004734 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004735 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004736 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004737 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004738
Douglas Gregorebe10102009-08-20 07:17:43 +00004739 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004740 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004741}
4742
4743template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004744StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004745TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004746 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004747 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004748 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004749 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004750
Douglas Gregorebe10102009-08-20 07:17:43 +00004751 // Default statements are always rebuilt
4752 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004753 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004754}
Mike Stump11289f42009-09-09 15:08:12 +00004755
Douglas Gregorebe10102009-08-20 07:17:43 +00004756template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004757StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004758TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004759 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004760 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004761 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004762
Chris Lattnercab02a62011-02-17 20:34:02 +00004763 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4764 S->getDecl());
4765 if (!LD)
4766 return StmtError();
4767
4768
Douglas Gregorebe10102009-08-20 07:17:43 +00004769 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004770 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004771 cast<LabelDecl>(LD), SourceLocation(),
4772 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004773}
Mike Stump11289f42009-09-09 15:08:12 +00004774
Douglas Gregorebe10102009-08-20 07:17:43 +00004775template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004776StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004777TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004778 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004779 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004780 VarDecl *ConditionVar = 0;
4781 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004782 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004783 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004784 getDerived().TransformDefinition(
4785 S->getConditionVariable()->getLocation(),
4786 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004787 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004788 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004789 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004790 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004791
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004792 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004793 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004794
4795 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004796 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004797 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4798 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004799 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004800 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004801
John McCallb268a282010-08-23 23:25:46 +00004802 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004803 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004804 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004805
John McCallb268a282010-08-23 23:25:46 +00004806 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4807 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004808 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004809
Douglas Gregorebe10102009-08-20 07:17:43 +00004810 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004811 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004812 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004813 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004814
Douglas Gregorebe10102009-08-20 07:17:43 +00004815 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004816 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004817 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004818 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004819
Douglas Gregorebe10102009-08-20 07:17:43 +00004820 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004821 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004822 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004823 Then.get() == S->getThen() &&
4824 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004825 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004826
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004827 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004828 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004829 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004830}
4831
4832template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004833StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004834TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004835 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004836 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004837 VarDecl *ConditionVar = 0;
4838 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004839 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004840 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004841 getDerived().TransformDefinition(
4842 S->getConditionVariable()->getLocation(),
4843 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004844 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004845 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004846 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004847 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004848
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004849 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004850 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004851 }
Mike Stump11289f42009-09-09 15:08:12 +00004852
Douglas Gregorebe10102009-08-20 07:17:43 +00004853 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004854 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004855 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004856 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004857 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004858 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004859
Douglas Gregorebe10102009-08-20 07:17:43 +00004860 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004861 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004862 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004863 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004864
Douglas Gregorebe10102009-08-20 07:17:43 +00004865 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004866 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4867 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004868}
Mike Stump11289f42009-09-09 15:08:12 +00004869
Douglas Gregorebe10102009-08-20 07:17:43 +00004870template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004871StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004872TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004873 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004874 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004875 VarDecl *ConditionVar = 0;
4876 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004877 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004878 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004879 getDerived().TransformDefinition(
4880 S->getConditionVariable()->getLocation(),
4881 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004882 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004883 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004884 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004885 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004886
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004887 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004888 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004889
4890 if (S->getCond()) {
4891 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004892 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4893 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004894 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004895 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004896 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004897 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004898 }
Mike Stump11289f42009-09-09 15:08:12 +00004899
John McCallb268a282010-08-23 23:25:46 +00004900 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4901 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004902 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004903
Douglas Gregorebe10102009-08-20 07:17:43 +00004904 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004905 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004906 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004907 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004908
Douglas Gregorebe10102009-08-20 07:17:43 +00004909 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004910 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004911 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004912 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004913 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004914
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004915 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004916 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004917}
Mike Stump11289f42009-09-09 15:08:12 +00004918
Douglas Gregorebe10102009-08-20 07:17:43 +00004919template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004920StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004921TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004922 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004923 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004924 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004925 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004926
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004927 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004928 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004929 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004930 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004931
Douglas Gregorebe10102009-08-20 07:17:43 +00004932 if (!getDerived().AlwaysRebuild() &&
4933 Cond.get() == S->getCond() &&
4934 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004935 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004936
John McCallb268a282010-08-23 23:25:46 +00004937 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4938 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004939 S->getRParenLoc());
4940}
Mike Stump11289f42009-09-09 15:08:12 +00004941
Douglas Gregorebe10102009-08-20 07:17:43 +00004942template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004943StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004944TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004945 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004946 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004947 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004948 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004949
Douglas Gregorebe10102009-08-20 07:17:43 +00004950 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004951 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004952 VarDecl *ConditionVar = 0;
4953 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004954 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004955 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004956 getDerived().TransformDefinition(
4957 S->getConditionVariable()->getLocation(),
4958 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004959 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004960 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004961 } else {
4962 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004963
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004964 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004965 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004966
4967 if (S->getCond()) {
4968 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004969 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4970 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004971 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004972 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004973
John McCallb268a282010-08-23 23:25:46 +00004974 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004975 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004976 }
Mike Stump11289f42009-09-09 15:08:12 +00004977
John McCallb268a282010-08-23 23:25:46 +00004978 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4979 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004980 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004981
Douglas Gregorebe10102009-08-20 07:17:43 +00004982 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00004983 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00004984 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004985 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004986
John McCallb268a282010-08-23 23:25:46 +00004987 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4988 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004989 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004990
Douglas Gregorebe10102009-08-20 07:17:43 +00004991 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004992 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004993 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004994 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004995
Douglas Gregorebe10102009-08-20 07:17:43 +00004996 if (!getDerived().AlwaysRebuild() &&
4997 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00004998 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004999 Inc.get() == S->getInc() &&
5000 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005001 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005002
Douglas Gregorebe10102009-08-20 07:17:43 +00005003 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005004 Init.get(), FullCond, ConditionVar,
5005 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005006}
5007
5008template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005009StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005010TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005011 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5012 S->getLabel());
5013 if (!LD)
5014 return StmtError();
5015
Douglas Gregorebe10102009-08-20 07:17:43 +00005016 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005017 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005018 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005019}
5020
5021template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005022StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005023TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005024 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005025 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005026 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005027
Douglas Gregorebe10102009-08-20 07:17:43 +00005028 if (!getDerived().AlwaysRebuild() &&
5029 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005030 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005031
5032 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005033 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005034}
5035
5036template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005037StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005038TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005039 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005040}
Mike Stump11289f42009-09-09 15:08:12 +00005041
Douglas Gregorebe10102009-08-20 07:17:43 +00005042template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005043StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005044TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005045 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005046}
Mike Stump11289f42009-09-09 15:08:12 +00005047
Douglas Gregorebe10102009-08-20 07:17:43 +00005048template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005049StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005050TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005051 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005052 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005053 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005054
Mike Stump11289f42009-09-09 15:08:12 +00005055 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005056 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005057 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005058}
Mike Stump11289f42009-09-09 15:08:12 +00005059
Douglas Gregorebe10102009-08-20 07:17:43 +00005060template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005061StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005062TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005063 bool DeclChanged = false;
5064 llvm::SmallVector<Decl *, 4> Decls;
5065 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5066 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005067 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5068 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005069 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005070 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005071
Douglas Gregorebe10102009-08-20 07:17:43 +00005072 if (Transformed != *D)
5073 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005074
Douglas Gregorebe10102009-08-20 07:17:43 +00005075 Decls.push_back(Transformed);
5076 }
Mike Stump11289f42009-09-09 15:08:12 +00005077
Douglas Gregorebe10102009-08-20 07:17:43 +00005078 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005079 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005080
5081 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005082 S->getStartLoc(), S->getEndLoc());
5083}
Mike Stump11289f42009-09-09 15:08:12 +00005084
Douglas Gregorebe10102009-08-20 07:17:43 +00005085template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005086StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005087TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005088
John McCall37ad5512010-08-23 06:44:23 +00005089 ASTOwningVector<Expr*> Constraints(getSema());
5090 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00005091 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005092
John McCalldadc5752010-08-24 06:29:42 +00005093 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005094 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005095
5096 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005097
Anders Carlssonaaeef072010-01-24 05:50:09 +00005098 // Go through the outputs.
5099 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005100 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005101
Anders Carlssonaaeef072010-01-24 05:50:09 +00005102 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005103 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005104
Anders Carlssonaaeef072010-01-24 05:50:09 +00005105 // Transform the output expr.
5106 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005107 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005108 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005109 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005110
Anders Carlssonaaeef072010-01-24 05:50:09 +00005111 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005112
John McCallb268a282010-08-23 23:25:46 +00005113 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005114 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005115
Anders Carlssonaaeef072010-01-24 05:50:09 +00005116 // Go through the inputs.
5117 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005118 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005119
Anders Carlssonaaeef072010-01-24 05:50:09 +00005120 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005121 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005122
Anders Carlssonaaeef072010-01-24 05:50:09 +00005123 // Transform the input expr.
5124 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005125 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005126 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005127 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005128
Anders Carlssonaaeef072010-01-24 05:50:09 +00005129 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005130
John McCallb268a282010-08-23 23:25:46 +00005131 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005132 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005133
Anders Carlssonaaeef072010-01-24 05:50:09 +00005134 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005135 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005136
5137 // Go through the clobbers.
5138 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005139 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005140
5141 // No need to transform the asm string literal.
5142 AsmString = SemaRef.Owned(S->getAsmString());
5143
5144 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5145 S->isSimple(),
5146 S->isVolatile(),
5147 S->getNumOutputs(),
5148 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005149 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005150 move_arg(Constraints),
5151 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005152 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005153 move_arg(Clobbers),
5154 S->getRParenLoc(),
5155 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005156}
5157
5158
5159template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005160StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005161TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005162 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005163 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005164 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005165 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005166
Douglas Gregor96c79492010-04-23 22:50:49 +00005167 // Transform the @catch statements (if present).
5168 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005169 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005170 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005171 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005172 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005173 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005174 if (Catch.get() != S->getCatchStmt(I))
5175 AnyCatchChanged = true;
5176 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005177 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005178
Douglas Gregor306de2f2010-04-22 23:59:56 +00005179 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005180 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005181 if (S->getFinallyStmt()) {
5182 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5183 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005184 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005185 }
5186
5187 // If nothing changed, just retain this statement.
5188 if (!getDerived().AlwaysRebuild() &&
5189 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005190 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005191 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005192 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005193
Douglas Gregor306de2f2010-04-22 23:59:56 +00005194 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005195 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5196 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005197}
Mike Stump11289f42009-09-09 15:08:12 +00005198
Douglas Gregorebe10102009-08-20 07:17:43 +00005199template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005200StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005201TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005202 // Transform the @catch parameter, if there is one.
5203 VarDecl *Var = 0;
5204 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5205 TypeSourceInfo *TSInfo = 0;
5206 if (FromVar->getTypeSourceInfo()) {
5207 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5208 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005209 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005210 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005211
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005212 QualType T;
5213 if (TSInfo)
5214 T = TSInfo->getType();
5215 else {
5216 T = getDerived().TransformType(FromVar->getType());
5217 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005218 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005219 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005220
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005221 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5222 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005223 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005224 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005225
John McCalldadc5752010-08-24 06:29:42 +00005226 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005227 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005228 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005229
5230 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005231 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005232 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005233}
Mike Stump11289f42009-09-09 15:08:12 +00005234
Douglas Gregorebe10102009-08-20 07:17:43 +00005235template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005236StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005237TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005238 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005239 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005240 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005241 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005242
Douglas Gregor306de2f2010-04-22 23:59:56 +00005243 // If nothing changed, just retain this statement.
5244 if (!getDerived().AlwaysRebuild() &&
5245 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005246 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005247
5248 // Build a new statement.
5249 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005250 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005251}
Mike Stump11289f42009-09-09 15:08:12 +00005252
Douglas Gregorebe10102009-08-20 07:17:43 +00005253template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005254StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005255TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005256 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005257 if (S->getThrowExpr()) {
5258 Operand = getDerived().TransformExpr(S->getThrowExpr());
5259 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005260 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005261 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005262
Douglas Gregor2900c162010-04-22 21:44:01 +00005263 if (!getDerived().AlwaysRebuild() &&
5264 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005265 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005266
John McCallb268a282010-08-23 23:25:46 +00005267 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005268}
Mike Stump11289f42009-09-09 15:08:12 +00005269
Douglas Gregorebe10102009-08-20 07:17:43 +00005270template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005271StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005272TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005273 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005274 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005275 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005276 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005277 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005278
Douglas Gregor6148de72010-04-22 22:01:21 +00005279 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005280 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005281 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005282 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005283
Douglas Gregor6148de72010-04-22 22:01:21 +00005284 // If nothing change, just retain the current statement.
5285 if (!getDerived().AlwaysRebuild() &&
5286 Object.get() == S->getSynchExpr() &&
5287 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005288 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005289
5290 // Build a new statement.
5291 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005292 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005293}
5294
5295template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005296StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005297TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005298 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005299 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005300 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005301 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005302 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005303
Douglas Gregorf68a5082010-04-22 23:10:45 +00005304 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005305 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005306 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005307 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005308
Douglas Gregorf68a5082010-04-22 23:10:45 +00005309 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005310 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005311 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005312 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005313
Douglas Gregorf68a5082010-04-22 23:10:45 +00005314 // If nothing changed, just retain this statement.
5315 if (!getDerived().AlwaysRebuild() &&
5316 Element.get() == S->getElement() &&
5317 Collection.get() == S->getCollection() &&
5318 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005319 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005320
Douglas Gregorf68a5082010-04-22 23:10:45 +00005321 // Build a new statement.
5322 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5323 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005324 Element.get(),
5325 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005326 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005327 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005328}
5329
5330
5331template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005332StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005333TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5334 // Transform the exception declaration, if any.
5335 VarDecl *Var = 0;
5336 if (S->getExceptionDecl()) {
5337 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005338 TypeSourceInfo *T = getDerived().TransformType(
5339 ExceptionDecl->getTypeSourceInfo());
5340 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005341 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005342
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005343 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaradff19302011-03-08 08:55:46 +00005344 ExceptionDecl->getInnerLocStart(),
5345 ExceptionDecl->getLocation(),
5346 ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00005347 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005348 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005349 }
Mike Stump11289f42009-09-09 15:08:12 +00005350
Douglas Gregorebe10102009-08-20 07:17:43 +00005351 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005352 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005353 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005354 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005355
Douglas Gregorebe10102009-08-20 07:17:43 +00005356 if (!getDerived().AlwaysRebuild() &&
5357 !Var &&
5358 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005359 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005360
5361 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5362 Var,
John McCallb268a282010-08-23 23:25:46 +00005363 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005364}
Mike Stump11289f42009-09-09 15:08:12 +00005365
Douglas Gregorebe10102009-08-20 07:17:43 +00005366template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005367StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005368TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5369 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005370 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005371 = getDerived().TransformCompoundStmt(S->getTryBlock());
5372 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005373 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005374
Douglas Gregorebe10102009-08-20 07:17:43 +00005375 // Transform the handlers.
5376 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005377 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005378 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005379 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005380 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5381 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005382 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005383
Douglas Gregorebe10102009-08-20 07:17:43 +00005384 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5385 Handlers.push_back(Handler.takeAs<Stmt>());
5386 }
Mike Stump11289f42009-09-09 15:08:12 +00005387
Douglas Gregorebe10102009-08-20 07:17:43 +00005388 if (!getDerived().AlwaysRebuild() &&
5389 TryBlock.get() == S->getTryBlock() &&
5390 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005391 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005392
John McCallb268a282010-08-23 23:25:46 +00005393 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005394 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005395}
Mike Stump11289f42009-09-09 15:08:12 +00005396
Richard Smith02e85f32011-04-14 22:09:26 +00005397template<typename Derived>
5398StmtResult
5399TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5400 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5401 if (Range.isInvalid())
5402 return StmtError();
5403
5404 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5405 if (BeginEnd.isInvalid())
5406 return StmtError();
5407
5408 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5409 if (Cond.isInvalid())
5410 return StmtError();
5411
5412 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5413 if (Inc.isInvalid())
5414 return StmtError();
5415
5416 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5417 if (LoopVar.isInvalid())
5418 return StmtError();
5419
5420 StmtResult NewStmt = S;
5421 if (getDerived().AlwaysRebuild() ||
5422 Range.get() != S->getRangeStmt() ||
5423 BeginEnd.get() != S->getBeginEndStmt() ||
5424 Cond.get() != S->getCond() ||
5425 Inc.get() != S->getInc() ||
5426 LoopVar.get() != S->getLoopVarStmt())
5427 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5428 S->getColonLoc(), Range.get(),
5429 BeginEnd.get(), Cond.get(),
5430 Inc.get(), LoopVar.get(),
5431 S->getRParenLoc());
5432
5433 StmtResult Body = getDerived().TransformStmt(S->getBody());
5434 if (Body.isInvalid())
5435 return StmtError();
5436
5437 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5438 // it now so we have a new statement to attach the body to.
5439 if (Body.get() != S->getBody() && NewStmt.get() == S)
5440 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5441 S->getColonLoc(), Range.get(),
5442 BeginEnd.get(), Cond.get(),
5443 Inc.get(), LoopVar.get(),
5444 S->getRParenLoc());
5445
5446 if (NewStmt.get() == S)
5447 return SemaRef.Owned(S);
5448
5449 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5450}
5451
Douglas Gregorebe10102009-08-20 07:17:43 +00005452//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005453// Expression transformation
5454//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005455template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005456ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005457TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005458 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005459}
Mike Stump11289f42009-09-09 15:08:12 +00005460
5461template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005462ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005463TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005464 NestedNameSpecifierLoc QualifierLoc;
5465 if (E->getQualifierLoc()) {
5466 QualifierLoc
5467 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5468 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005469 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005470 }
John McCallce546572009-12-08 09:08:17 +00005471
5472 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005473 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5474 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005475 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005476 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005477
John McCall815039a2010-08-17 21:27:17 +00005478 DeclarationNameInfo NameInfo = E->getNameInfo();
5479 if (NameInfo.getName()) {
5480 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5481 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005482 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005483 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005484
5485 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005486 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005487 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005488 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005489 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005490
5491 // Mark it referenced in the new context regardless.
5492 // FIXME: this is a bit instantiation-specific.
5493 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5494
John McCallc3007a22010-10-26 07:05:15 +00005495 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005496 }
John McCallce546572009-12-08 09:08:17 +00005497
5498 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005499 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005500 TemplateArgs = &TransArgs;
5501 TransArgs.setLAngleLoc(E->getLAngleLoc());
5502 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005503 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5504 E->getNumTemplateArgs(),
5505 TransArgs))
5506 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005507 }
5508
Douglas Gregorea972d32011-02-28 21:54:11 +00005509 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5510 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005511}
Mike Stump11289f42009-09-09 15:08:12 +00005512
Douglas Gregora16548e2009-08-11 05:31:07 +00005513template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005514ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005515TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005516 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005517}
Mike Stump11289f42009-09-09 15:08:12 +00005518
Douglas Gregora16548e2009-08-11 05:31:07 +00005519template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005520ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005521TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005522 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005523}
Mike Stump11289f42009-09-09 15:08:12 +00005524
Douglas Gregora16548e2009-08-11 05:31:07 +00005525template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005526ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005527TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005528 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005529}
Mike Stump11289f42009-09-09 15:08:12 +00005530
Douglas Gregora16548e2009-08-11 05:31:07 +00005531template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005532ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005533TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005534 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005535}
Mike Stump11289f42009-09-09 15:08:12 +00005536
Douglas Gregora16548e2009-08-11 05:31:07 +00005537template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005538ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005539TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005540 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005541}
5542
5543template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005544ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00005545TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5546 ExprResult ControllingExpr =
5547 getDerived().TransformExpr(E->getControllingExpr());
5548 if (ControllingExpr.isInvalid())
5549 return ExprError();
5550
5551 llvm::SmallVector<Expr *, 4> AssocExprs;
5552 llvm::SmallVector<TypeSourceInfo *, 4> AssocTypes;
5553 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5554 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5555 if (TS) {
5556 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5557 if (!AssocType)
5558 return ExprError();
5559 AssocTypes.push_back(AssocType);
5560 } else {
5561 AssocTypes.push_back(0);
5562 }
5563
5564 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5565 if (AssocExpr.isInvalid())
5566 return ExprError();
5567 AssocExprs.push_back(AssocExpr.release());
5568 }
5569
5570 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5571 E->getDefaultLoc(),
5572 E->getRParenLoc(),
5573 ControllingExpr.release(),
5574 AssocTypes.data(),
5575 AssocExprs.data(),
5576 E->getNumAssocs());
5577}
5578
5579template<typename Derived>
5580ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005581TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005582 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005583 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005584 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005585
Douglas Gregora16548e2009-08-11 05:31:07 +00005586 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005587 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005588
John McCallb268a282010-08-23 23:25:46 +00005589 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005590 E->getRParen());
5591}
5592
Mike Stump11289f42009-09-09 15:08:12 +00005593template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005594ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005595TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005596 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005597 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005598 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005599
Douglas Gregora16548e2009-08-11 05:31:07 +00005600 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005601 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005602
Douglas Gregora16548e2009-08-11 05:31:07 +00005603 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5604 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005605 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005606}
Mike Stump11289f42009-09-09 15:08:12 +00005607
Douglas Gregora16548e2009-08-11 05:31:07 +00005608template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005609ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005610TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5611 // Transform the type.
5612 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5613 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005614 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005615
Douglas Gregor882211c2010-04-28 22:16:22 +00005616 // Transform all of the components into components similar to what the
5617 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005618 // FIXME: It would be slightly more efficient in the non-dependent case to
5619 // just map FieldDecls, rather than requiring the rebuilder to look for
5620 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005621 // template code that we don't care.
5622 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005623 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005624 typedef OffsetOfExpr::OffsetOfNode Node;
5625 llvm::SmallVector<Component, 4> Components;
5626 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5627 const Node &ON = E->getComponent(I);
5628 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005629 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00005630 Comp.LocStart = ON.getSourceRange().getBegin();
5631 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00005632 switch (ON.getKind()) {
5633 case Node::Array: {
5634 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005635 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005636 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005637 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005638
Douglas Gregor882211c2010-04-28 22:16:22 +00005639 ExprChanged = ExprChanged || Index.get() != FromIndex;
5640 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005641 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005642 break;
5643 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005644
Douglas Gregor882211c2010-04-28 22:16:22 +00005645 case Node::Field:
5646 case Node::Identifier:
5647 Comp.isBrackets = false;
5648 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005649 if (!Comp.U.IdentInfo)
5650 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005651
Douglas Gregor882211c2010-04-28 22:16:22 +00005652 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005653
Douglas Gregord1702062010-04-29 00:18:15 +00005654 case Node::Base:
5655 // Will be recomputed during the rebuild.
5656 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005657 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005658
Douglas Gregor882211c2010-04-28 22:16:22 +00005659 Components.push_back(Comp);
5660 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005661
Douglas Gregor882211c2010-04-28 22:16:22 +00005662 // If nothing changed, retain the existing expression.
5663 if (!getDerived().AlwaysRebuild() &&
5664 Type == E->getTypeSourceInfo() &&
5665 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005666 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005667
Douglas Gregor882211c2010-04-28 22:16:22 +00005668 // Build a new offsetof expression.
5669 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5670 Components.data(), Components.size(),
5671 E->getRParenLoc());
5672}
5673
5674template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005675ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005676TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5677 assert(getDerived().AlreadyTransformed(E->getType()) &&
5678 "opaque value expression requires transformation");
5679 return SemaRef.Owned(E);
5680}
5681
5682template<typename Derived>
5683ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00005684TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
5685 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005686 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005687 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005688
John McCallbcd03502009-12-07 02:54:59 +00005689 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005690 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005691 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005692
John McCall4c98fd82009-11-04 07:28:41 +00005693 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005694 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005695
Peter Collingbournee190dee2011-03-11 19:24:49 +00005696 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
5697 E->getKind(),
5698 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005699 }
Mike Stump11289f42009-09-09 15:08:12 +00005700
John McCalldadc5752010-08-24 06:29:42 +00005701 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005702 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005703 // C++0x [expr.sizeof]p1:
5704 // The operand is either an expression, which is an unevaluated operand
5705 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005706 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005707
Douglas Gregora16548e2009-08-11 05:31:07 +00005708 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5709 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005710 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005711
Douglas Gregora16548e2009-08-11 05:31:07 +00005712 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005713 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005714 }
Mike Stump11289f42009-09-09 15:08:12 +00005715
Peter Collingbournee190dee2011-03-11 19:24:49 +00005716 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
5717 E->getOperatorLoc(),
5718 E->getKind(),
5719 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005720}
Mike Stump11289f42009-09-09 15:08:12 +00005721
Douglas Gregora16548e2009-08-11 05:31:07 +00005722template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005723ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005724TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005725 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005726 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005727 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005728
John McCalldadc5752010-08-24 06:29:42 +00005729 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005730 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005731 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005732
5733
Douglas Gregora16548e2009-08-11 05:31:07 +00005734 if (!getDerived().AlwaysRebuild() &&
5735 LHS.get() == E->getLHS() &&
5736 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005737 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005738
John McCallb268a282010-08-23 23:25:46 +00005739 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005740 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005741 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005742 E->getRBracketLoc());
5743}
Mike Stump11289f42009-09-09 15:08:12 +00005744
5745template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005746ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005747TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005748 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005749 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005750 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005751 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005752
5753 // Transform arguments.
5754 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005755 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005756 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5757 &ArgChanged))
5758 return ExprError();
5759
Douglas Gregora16548e2009-08-11 05:31:07 +00005760 if (!getDerived().AlwaysRebuild() &&
5761 Callee.get() == E->getCallee() &&
5762 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005763 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005764
Douglas Gregora16548e2009-08-11 05:31:07 +00005765 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005766 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005767 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005768 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005769 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005770 E->getRParenLoc());
5771}
Mike Stump11289f42009-09-09 15:08:12 +00005772
5773template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005774ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005775TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005776 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005777 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005778 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005779
Douglas Gregorea972d32011-02-28 21:54:11 +00005780 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005781 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005782 QualifierLoc
5783 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5784
5785 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005786 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005787 }
Mike Stump11289f42009-09-09 15:08:12 +00005788
Eli Friedman2cfcef62009-12-04 06:40:45 +00005789 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005790 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5791 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005792 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005793 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005794
John McCall16df1e52010-03-30 21:47:33 +00005795 NamedDecl *FoundDecl = E->getFoundDecl();
5796 if (FoundDecl == E->getMemberDecl()) {
5797 FoundDecl = Member;
5798 } else {
5799 FoundDecl = cast_or_null<NamedDecl>(
5800 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5801 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005802 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005803 }
5804
Douglas Gregora16548e2009-08-11 05:31:07 +00005805 if (!getDerived().AlwaysRebuild() &&
5806 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005807 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005808 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005809 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005810 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005811
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005812 // Mark it referenced in the new context regardless.
5813 // FIXME: this is a bit instantiation-specific.
5814 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005815 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005816 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005817
John McCall6b51f282009-11-23 01:53:49 +00005818 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005819 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005820 TransArgs.setLAngleLoc(E->getLAngleLoc());
5821 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005822 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5823 E->getNumTemplateArgs(),
5824 TransArgs))
5825 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005826 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005827
Douglas Gregora16548e2009-08-11 05:31:07 +00005828 // FIXME: Bogus source location for the operator
5829 SourceLocation FakeOperatorLoc
5830 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5831
John McCall38836f02010-01-15 08:34:02 +00005832 // FIXME: to do this check properly, we will need to preserve the
5833 // first-qualifier-in-scope here, just in case we had a dependent
5834 // base (and therefore couldn't do the check) and a
5835 // nested-name-qualifier (and therefore could do the lookup).
5836 NamedDecl *FirstQualifierInScope = 0;
5837
John McCallb268a282010-08-23 23:25:46 +00005838 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005839 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00005840 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005841 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005842 Member,
John McCall16df1e52010-03-30 21:47:33 +00005843 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005844 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005845 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005846 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005847}
Mike Stump11289f42009-09-09 15:08:12 +00005848
Douglas Gregora16548e2009-08-11 05:31:07 +00005849template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005850ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005851TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005852 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005853 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005854 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005855
John McCalldadc5752010-08-24 06:29:42 +00005856 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005857 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005858 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005859
Douglas Gregora16548e2009-08-11 05:31:07 +00005860 if (!getDerived().AlwaysRebuild() &&
5861 LHS.get() == E->getLHS() &&
5862 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005863 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005864
Douglas Gregora16548e2009-08-11 05:31:07 +00005865 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005866 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005867}
5868
Mike Stump11289f42009-09-09 15:08:12 +00005869template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005870ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005871TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005872 CompoundAssignOperator *E) {
5873 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005874}
Mike Stump11289f42009-09-09 15:08:12 +00005875
Douglas Gregora16548e2009-08-11 05:31:07 +00005876template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00005877ExprResult TreeTransform<Derived>::
5878TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
5879 // Just rebuild the common and RHS expressions and see whether we
5880 // get any changes.
5881
5882 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
5883 if (commonExpr.isInvalid())
5884 return ExprError();
5885
5886 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
5887 if (rhs.isInvalid())
5888 return ExprError();
5889
5890 if (!getDerived().AlwaysRebuild() &&
5891 commonExpr.get() == e->getCommon() &&
5892 rhs.get() == e->getFalseExpr())
5893 return SemaRef.Owned(e);
5894
5895 return getDerived().RebuildConditionalOperator(commonExpr.take(),
5896 e->getQuestionLoc(),
5897 0,
5898 e->getColonLoc(),
5899 rhs.get());
5900}
5901
5902template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005903ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005904TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005905 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005906 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005907 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005908
John McCalldadc5752010-08-24 06:29:42 +00005909 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005910 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005911 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005912
John McCalldadc5752010-08-24 06:29:42 +00005913 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005914 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005915 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005916
Douglas Gregora16548e2009-08-11 05:31:07 +00005917 if (!getDerived().AlwaysRebuild() &&
5918 Cond.get() == E->getCond() &&
5919 LHS.get() == E->getLHS() &&
5920 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005921 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005922
John McCallb268a282010-08-23 23:25:46 +00005923 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005924 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005925 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005926 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005927 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005928}
Mike Stump11289f42009-09-09 15:08:12 +00005929
5930template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005931ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005932TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005933 // Implicit casts are eliminated during transformation, since they
5934 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005935 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005936}
Mike Stump11289f42009-09-09 15:08:12 +00005937
Douglas Gregora16548e2009-08-11 05:31:07 +00005938template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005939ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005940TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005941 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5942 if (!Type)
5943 return ExprError();
5944
John McCalldadc5752010-08-24 06:29:42 +00005945 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005946 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005947 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005948 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005949
Douglas Gregora16548e2009-08-11 05:31:07 +00005950 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005951 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005952 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005953 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005954
John McCall97513962010-01-15 18:39:57 +00005955 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005956 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005957 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005958 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005959}
Mike Stump11289f42009-09-09 15:08:12 +00005960
Douglas Gregora16548e2009-08-11 05:31:07 +00005961template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005962ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005963TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005964 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5965 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5966 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005967 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005968
John McCalldadc5752010-08-24 06:29:42 +00005969 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005970 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005971 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005972
Douglas Gregora16548e2009-08-11 05:31:07 +00005973 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005974 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005975 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005976 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005977
John McCall5d7aa7f2010-01-19 22:33:45 +00005978 // Note: the expression type doesn't necessarily match the
5979 // type-as-written, but that's okay, because it should always be
5980 // derivable from the initializer.
5981
John McCalle15bbff2010-01-18 19:35:47 +00005982 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005983 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005984 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005985}
Mike Stump11289f42009-09-09 15:08:12 +00005986
Douglas Gregora16548e2009-08-11 05:31:07 +00005987template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005988ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005989TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005990 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005991 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005992 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005993
Douglas Gregora16548e2009-08-11 05:31:07 +00005994 if (!getDerived().AlwaysRebuild() &&
5995 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00005996 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005997
Douglas Gregora16548e2009-08-11 05:31:07 +00005998 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005999 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006000 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00006001 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006002 E->getAccessorLoc(),
6003 E->getAccessor());
6004}
Mike Stump11289f42009-09-09 15:08:12 +00006005
Douglas Gregora16548e2009-08-11 05:31:07 +00006006template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006007ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006008TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006009 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00006010
John McCall37ad5512010-08-23 06:44:23 +00006011 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006012 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6013 Inits, &InitChanged))
6014 return ExprError();
6015
Douglas Gregora16548e2009-08-11 05:31:07 +00006016 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00006017 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006018
Douglas Gregora16548e2009-08-11 05:31:07 +00006019 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00006020 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00006021}
Mike Stump11289f42009-09-09 15:08:12 +00006022
Douglas Gregora16548e2009-08-11 05:31:07 +00006023template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006024ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006025TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006026 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00006027
Douglas Gregorebe10102009-08-20 07:17:43 +00006028 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00006029 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006030 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006031 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006032
Douglas Gregorebe10102009-08-20 07:17:43 +00006033 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00006034 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006035 bool ExprChanged = false;
6036 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6037 DEnd = E->designators_end();
6038 D != DEnd; ++D) {
6039 if (D->isFieldDesignator()) {
6040 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6041 D->getDotLoc(),
6042 D->getFieldLoc()));
6043 continue;
6044 }
Mike Stump11289f42009-09-09 15:08:12 +00006045
Douglas Gregora16548e2009-08-11 05:31:07 +00006046 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00006047 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006048 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006049 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006050
6051 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006052 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006053
Douglas Gregora16548e2009-08-11 05:31:07 +00006054 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6055 ArrayExprs.push_back(Index.release());
6056 continue;
6057 }
Mike Stump11289f42009-09-09 15:08:12 +00006058
Douglas Gregora16548e2009-08-11 05:31:07 +00006059 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00006060 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00006061 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6062 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006063 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006064
John McCalldadc5752010-08-24 06:29:42 +00006065 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006066 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006067 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006068
6069 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006070 End.get(),
6071 D->getLBracketLoc(),
6072 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006073
Douglas Gregora16548e2009-08-11 05:31:07 +00006074 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6075 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00006076
Douglas Gregora16548e2009-08-11 05:31:07 +00006077 ArrayExprs.push_back(Start.release());
6078 ArrayExprs.push_back(End.release());
6079 }
Mike Stump11289f42009-09-09 15:08:12 +00006080
Douglas Gregora16548e2009-08-11 05:31:07 +00006081 if (!getDerived().AlwaysRebuild() &&
6082 Init.get() == E->getInit() &&
6083 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006084 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006085
Douglas Gregora16548e2009-08-11 05:31:07 +00006086 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6087 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006088 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006089}
Mike Stump11289f42009-09-09 15:08:12 +00006090
Douglas Gregora16548e2009-08-11 05:31:07 +00006091template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006092ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006093TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006094 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00006095 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006096
Douglas Gregor3da3c062009-10-28 00:29:27 +00006097 // FIXME: Will we ever have proper type location here? Will we actually
6098 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00006099 QualType T = getDerived().TransformType(E->getType());
6100 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006101 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006102
Douglas Gregora16548e2009-08-11 05:31:07 +00006103 if (!getDerived().AlwaysRebuild() &&
6104 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006105 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006106
Douglas Gregora16548e2009-08-11 05:31:07 +00006107 return getDerived().RebuildImplicitValueInitExpr(T);
6108}
Mike Stump11289f42009-09-09 15:08:12 +00006109
Douglas Gregora16548e2009-08-11 05:31:07 +00006110template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006111ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006112TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00006113 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6114 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006115 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006116
John McCalldadc5752010-08-24 06:29:42 +00006117 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006118 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006119 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006120
Douglas Gregora16548e2009-08-11 05:31:07 +00006121 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00006122 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006123 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006124 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006125
John McCallb268a282010-08-23 23:25:46 +00006126 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00006127 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006128}
6129
6130template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006131ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006132TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006133 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006134 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006135 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6136 &ArgumentChanged))
6137 return ExprError();
6138
Douglas Gregora16548e2009-08-11 05:31:07 +00006139 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6140 move_arg(Inits),
6141 E->getRParenLoc());
6142}
Mike Stump11289f42009-09-09 15:08:12 +00006143
Douglas Gregora16548e2009-08-11 05:31:07 +00006144/// \brief Transform an address-of-label expression.
6145///
6146/// By default, the transformation of an address-of-label expression always
6147/// rebuilds the expression, so that the label identifier can be resolved to
6148/// the corresponding label statement by semantic analysis.
6149template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006150ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006151TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006152 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6153 E->getLabel());
6154 if (!LD)
6155 return ExprError();
6156
Douglas Gregora16548e2009-08-11 05:31:07 +00006157 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006158 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006159}
Mike Stump11289f42009-09-09 15:08:12 +00006160
6161template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006162ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006163TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006164 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006165 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6166 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006167 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006168
Douglas Gregora16548e2009-08-11 05:31:07 +00006169 if (!getDerived().AlwaysRebuild() &&
6170 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006171 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006172
6173 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006174 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006175 E->getRParenLoc());
6176}
Mike Stump11289f42009-09-09 15:08:12 +00006177
Douglas Gregora16548e2009-08-11 05:31:07 +00006178template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006179ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006180TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006181 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006182 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006183 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006184
John McCalldadc5752010-08-24 06:29:42 +00006185 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006186 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006187 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006188
John McCalldadc5752010-08-24 06:29:42 +00006189 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006190 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006191 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006192
Douglas Gregora16548e2009-08-11 05:31:07 +00006193 if (!getDerived().AlwaysRebuild() &&
6194 Cond.get() == E->getCond() &&
6195 LHS.get() == E->getLHS() &&
6196 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006197 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006198
Douglas Gregora16548e2009-08-11 05:31:07 +00006199 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006200 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006201 E->getRParenLoc());
6202}
Mike Stump11289f42009-09-09 15:08:12 +00006203
Douglas Gregora16548e2009-08-11 05:31:07 +00006204template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006205ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006206TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006207 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006208}
6209
6210template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006211ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006212TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006213 switch (E->getOperator()) {
6214 case OO_New:
6215 case OO_Delete:
6216 case OO_Array_New:
6217 case OO_Array_Delete:
6218 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006219 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006220
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006221 case OO_Call: {
6222 // This is a call to an object's operator().
6223 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6224
6225 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006226 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006227 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006228 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006229
6230 // FIXME: Poor location information
6231 SourceLocation FakeLParenLoc
6232 = SemaRef.PP.getLocForEndOfToken(
6233 static_cast<Expr *>(Object.get())->getLocEnd());
6234
6235 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006236 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006237 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6238 Args))
6239 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006240
John McCallb268a282010-08-23 23:25:46 +00006241 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006242 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006243 E->getLocEnd());
6244 }
6245
6246#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6247 case OO_##Name:
6248#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6249#include "clang/Basic/OperatorKinds.def"
6250 case OO_Subscript:
6251 // Handled below.
6252 break;
6253
6254 case OO_Conditional:
6255 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006256 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006257
6258 case OO_None:
6259 case NUM_OVERLOADED_OPERATORS:
6260 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006261 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006262 }
6263
John McCalldadc5752010-08-24 06:29:42 +00006264 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006265 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006266 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006267
John McCalldadc5752010-08-24 06:29:42 +00006268 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006269 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006270 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006271
John McCalldadc5752010-08-24 06:29:42 +00006272 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006273 if (E->getNumArgs() == 2) {
6274 Second = getDerived().TransformExpr(E->getArg(1));
6275 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006276 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006277 }
Mike Stump11289f42009-09-09 15:08:12 +00006278
Douglas Gregora16548e2009-08-11 05:31:07 +00006279 if (!getDerived().AlwaysRebuild() &&
6280 Callee.get() == E->getCallee() &&
6281 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006282 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006283 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006284
Douglas Gregora16548e2009-08-11 05:31:07 +00006285 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6286 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006287 Callee.get(),
6288 First.get(),
6289 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006290}
Mike Stump11289f42009-09-09 15:08:12 +00006291
Douglas Gregora16548e2009-08-11 05:31:07 +00006292template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006293ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006294TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6295 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006296}
Mike Stump11289f42009-09-09 15:08:12 +00006297
Douglas Gregora16548e2009-08-11 05:31:07 +00006298template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006299ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006300TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6301 // Transform the callee.
6302 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6303 if (Callee.isInvalid())
6304 return ExprError();
6305
6306 // Transform exec config.
6307 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6308 if (EC.isInvalid())
6309 return ExprError();
6310
6311 // Transform arguments.
6312 bool ArgChanged = false;
6313 ASTOwningVector<Expr*> Args(SemaRef);
6314 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6315 &ArgChanged))
6316 return ExprError();
6317
6318 if (!getDerived().AlwaysRebuild() &&
6319 Callee.get() == E->getCallee() &&
6320 !ArgChanged)
6321 return SemaRef.Owned(E);
6322
6323 // FIXME: Wrong source location information for the '('.
6324 SourceLocation FakeLParenLoc
6325 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6326 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6327 move_arg(Args),
6328 E->getRParenLoc(), EC.get());
6329}
6330
6331template<typename Derived>
6332ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006333TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006334 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6335 if (!Type)
6336 return ExprError();
6337
John McCalldadc5752010-08-24 06:29:42 +00006338 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006339 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006340 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006341 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006342
Douglas Gregora16548e2009-08-11 05:31:07 +00006343 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006344 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006345 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006346 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006347
Douglas Gregora16548e2009-08-11 05:31:07 +00006348 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006349 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006350 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6351 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6352 SourceLocation FakeRParenLoc
6353 = SemaRef.PP.getLocForEndOfToken(
6354 E->getSubExpr()->getSourceRange().getEnd());
6355 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006356 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006357 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006358 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006359 FakeRAngleLoc,
6360 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006361 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006362 FakeRParenLoc);
6363}
Mike Stump11289f42009-09-09 15:08:12 +00006364
Douglas Gregora16548e2009-08-11 05:31:07 +00006365template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006366ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006367TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6368 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006369}
Mike Stump11289f42009-09-09 15:08:12 +00006370
6371template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006372ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006373TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6374 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006375}
6376
Douglas Gregora16548e2009-08-11 05:31:07 +00006377template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006378ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006379TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006380 CXXReinterpretCastExpr *E) {
6381 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006382}
Mike Stump11289f42009-09-09 15:08:12 +00006383
Douglas Gregora16548e2009-08-11 05:31:07 +00006384template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006385ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006386TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6387 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006388}
Mike Stump11289f42009-09-09 15:08:12 +00006389
Douglas Gregora16548e2009-08-11 05:31:07 +00006390template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006391ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006392TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006393 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006394 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6395 if (!Type)
6396 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006397
John McCalldadc5752010-08-24 06:29:42 +00006398 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006399 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006400 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006401 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006402
Douglas Gregora16548e2009-08-11 05:31:07 +00006403 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006404 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006405 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006406 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006407
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006408 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006409 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006410 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006411 E->getRParenLoc());
6412}
Mike Stump11289f42009-09-09 15:08:12 +00006413
Douglas Gregora16548e2009-08-11 05:31:07 +00006414template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006415ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006416TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006417 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006418 TypeSourceInfo *TInfo
6419 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6420 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006421 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006422
Douglas Gregora16548e2009-08-11 05:31:07 +00006423 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006424 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006425 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006426
Douglas Gregor9da64192010-04-26 22:37:10 +00006427 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6428 E->getLocStart(),
6429 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006430 E->getLocEnd());
6431 }
Mike Stump11289f42009-09-09 15:08:12 +00006432
Douglas Gregora16548e2009-08-11 05:31:07 +00006433 // We don't know whether the expression is potentially evaluated until
6434 // after we perform semantic analysis, so the expression is potentially
6435 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006436 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006437 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006438
John McCalldadc5752010-08-24 06:29:42 +00006439 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006440 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006441 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006442
Douglas Gregora16548e2009-08-11 05:31:07 +00006443 if (!getDerived().AlwaysRebuild() &&
6444 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006445 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006446
Douglas Gregor9da64192010-04-26 22:37:10 +00006447 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6448 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006449 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006450 E->getLocEnd());
6451}
6452
6453template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006454ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006455TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6456 if (E->isTypeOperand()) {
6457 TypeSourceInfo *TInfo
6458 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6459 if (!TInfo)
6460 return ExprError();
6461
6462 if (!getDerived().AlwaysRebuild() &&
6463 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006464 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006465
Douglas Gregor69735112011-03-06 17:40:41 +00006466 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00006467 E->getLocStart(),
6468 TInfo,
6469 E->getLocEnd());
6470 }
6471
6472 // We don't know whether the expression is potentially evaluated until
6473 // after we perform semantic analysis, so the expression is potentially
6474 // potentially evaluated.
6475 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6476
6477 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6478 if (SubExpr.isInvalid())
6479 return ExprError();
6480
6481 if (!getDerived().AlwaysRebuild() &&
6482 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006483 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006484
6485 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6486 E->getLocStart(),
6487 SubExpr.get(),
6488 E->getLocEnd());
6489}
6490
6491template<typename Derived>
6492ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006493TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006494 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006495}
Mike Stump11289f42009-09-09 15:08:12 +00006496
Douglas Gregora16548e2009-08-11 05:31:07 +00006497template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006498ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006499TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006500 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006501 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006502}
Mike Stump11289f42009-09-09 15:08:12 +00006503
Douglas Gregora16548e2009-08-11 05:31:07 +00006504template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006505ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006506TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006507 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6508 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6509 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006510
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006511 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006512 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006513
Douglas Gregorb15af892010-01-07 23:12:05 +00006514 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006515}
Mike Stump11289f42009-09-09 15:08:12 +00006516
Douglas Gregora16548e2009-08-11 05:31:07 +00006517template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006518ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006519TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006520 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006521 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006522 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006523
Douglas Gregora16548e2009-08-11 05:31:07 +00006524 if (!getDerived().AlwaysRebuild() &&
6525 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006526 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006527
John McCallb268a282010-08-23 23:25:46 +00006528 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006529}
Mike Stump11289f42009-09-09 15:08:12 +00006530
Douglas Gregora16548e2009-08-11 05:31:07 +00006531template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006532ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006533TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006534 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006535 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6536 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006537 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006538 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006539
Chandler Carruth794da4c2010-02-08 06:42:49 +00006540 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006541 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006542 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006543
Douglas Gregor033f6752009-12-23 23:03:06 +00006544 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006545}
Mike Stump11289f42009-09-09 15:08:12 +00006546
Douglas Gregora16548e2009-08-11 05:31:07 +00006547template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006548ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006549TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6550 CXXScalarValueInitExpr *E) {
6551 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6552 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006553 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006554
Douglas Gregora16548e2009-08-11 05:31:07 +00006555 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006556 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006557 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006558
Douglas Gregor2b88c112010-09-08 00:15:04 +00006559 return getDerived().RebuildCXXScalarValueInitExpr(T,
6560 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006561 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006562}
Mike Stump11289f42009-09-09 15:08:12 +00006563
Douglas Gregora16548e2009-08-11 05:31:07 +00006564template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006565ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006566TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006567 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006568 TypeSourceInfo *AllocTypeInfo
6569 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6570 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006571 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006572
Douglas Gregora16548e2009-08-11 05:31:07 +00006573 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006574 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006575 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006576 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006577
Douglas Gregora16548e2009-08-11 05:31:07 +00006578 // Transform the placement arguments (if any).
6579 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006580 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006581 if (getDerived().TransformExprs(E->getPlacementArgs(),
6582 E->getNumPlacementArgs(), true,
6583 PlacementArgs, &ArgumentChanged))
6584 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006585
Douglas Gregorebe10102009-08-20 07:17:43 +00006586 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006587 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006588 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6589 ConstructorArgs, &ArgumentChanged))
6590 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006591
Douglas Gregord2d9da02010-02-26 00:38:10 +00006592 // Transform constructor, new operator, and delete operator.
6593 CXXConstructorDecl *Constructor = 0;
6594 if (E->getConstructor()) {
6595 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006596 getDerived().TransformDecl(E->getLocStart(),
6597 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006598 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006599 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006600 }
6601
6602 FunctionDecl *OperatorNew = 0;
6603 if (E->getOperatorNew()) {
6604 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006605 getDerived().TransformDecl(E->getLocStart(),
6606 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006607 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006608 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006609 }
6610
6611 FunctionDecl *OperatorDelete = 0;
6612 if (E->getOperatorDelete()) {
6613 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006614 getDerived().TransformDecl(E->getLocStart(),
6615 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006616 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006617 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006618 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006619
Douglas Gregora16548e2009-08-11 05:31:07 +00006620 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006621 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006622 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006623 Constructor == E->getConstructor() &&
6624 OperatorNew == E->getOperatorNew() &&
6625 OperatorDelete == E->getOperatorDelete() &&
6626 !ArgumentChanged) {
6627 // Mark any declarations we need as referenced.
6628 // FIXME: instantiation-specific.
6629 if (Constructor)
6630 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6631 if (OperatorNew)
6632 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6633 if (OperatorDelete)
6634 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006635 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006636 }
Mike Stump11289f42009-09-09 15:08:12 +00006637
Douglas Gregor0744ef62010-09-07 21:49:58 +00006638 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006639 if (!ArraySize.get()) {
6640 // If no array size was specified, but the new expression was
6641 // instantiated with an array type (e.g., "new T" where T is
6642 // instantiated with "int[4]"), extract the outer bound from the
6643 // array type as our array size. We do this with constant and
6644 // dependently-sized array types.
6645 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6646 if (!ArrayT) {
6647 // Do nothing
6648 } else if (const ConstantArrayType *ConsArrayT
6649 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006650 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006651 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6652 ConsArrayT->getSize(),
6653 SemaRef.Context.getSizeType(),
6654 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006655 AllocType = ConsArrayT->getElementType();
6656 } else if (const DependentSizedArrayType *DepArrayT
6657 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6658 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006659 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006660 AllocType = DepArrayT->getElementType();
6661 }
6662 }
6663 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006664
Douglas Gregora16548e2009-08-11 05:31:07 +00006665 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6666 E->isGlobalNew(),
6667 /*FIXME:*/E->getLocStart(),
6668 move_arg(PlacementArgs),
6669 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006670 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006671 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006672 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006673 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006674 /*FIXME:*/E->getLocStart(),
6675 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006676 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006677}
Mike Stump11289f42009-09-09 15:08:12 +00006678
Douglas Gregora16548e2009-08-11 05:31:07 +00006679template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006680ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006681TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006682 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006683 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006684 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006685
Douglas Gregord2d9da02010-02-26 00:38:10 +00006686 // Transform the delete operator, if known.
6687 FunctionDecl *OperatorDelete = 0;
6688 if (E->getOperatorDelete()) {
6689 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006690 getDerived().TransformDecl(E->getLocStart(),
6691 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006692 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006693 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006694 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006695
Douglas Gregora16548e2009-08-11 05:31:07 +00006696 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006697 Operand.get() == E->getArgument() &&
6698 OperatorDelete == E->getOperatorDelete()) {
6699 // Mark any declarations we need as referenced.
6700 // FIXME: instantiation-specific.
6701 if (OperatorDelete)
6702 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006703
6704 if (!E->getArgument()->isTypeDependent()) {
6705 QualType Destroyed = SemaRef.Context.getBaseElementType(
6706 E->getDestroyedType());
6707 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6708 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6709 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6710 SemaRef.LookupDestructor(Record));
6711 }
6712 }
6713
John McCallc3007a22010-10-26 07:05:15 +00006714 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006715 }
Mike Stump11289f42009-09-09 15:08:12 +00006716
Douglas Gregora16548e2009-08-11 05:31:07 +00006717 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6718 E->isGlobalDelete(),
6719 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006720 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006721}
Mike Stump11289f42009-09-09 15:08:12 +00006722
Douglas Gregora16548e2009-08-11 05:31:07 +00006723template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006724ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006725TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006726 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006727 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006728 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006729 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006730
John McCallba7bf592010-08-24 05:47:05 +00006731 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006732 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006733 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006734 E->getOperatorLoc(),
6735 E->isArrow()? tok::arrow : tok::period,
6736 ObjectTypePtr,
6737 MayBePseudoDestructor);
6738 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006739 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006740
John McCallba7bf592010-08-24 05:47:05 +00006741 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00006742 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6743 if (QualifierLoc) {
6744 QualifierLoc
6745 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6746 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00006747 return ExprError();
6748 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00006749 CXXScopeSpec SS;
6750 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00006751
Douglas Gregor678f90d2010-02-25 01:56:36 +00006752 PseudoDestructorTypeStorage Destroyed;
6753 if (E->getDestroyedTypeInfo()) {
6754 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006755 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00006756 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00006757 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006758 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006759 Destroyed = DestroyedTypeInfo;
6760 } else if (ObjectType->isDependentType()) {
6761 // We aren't likely to be able to resolve the identifier down to a type
6762 // now anyway, so just retain the identifier.
6763 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6764 E->getDestroyedTypeLoc());
6765 } else {
6766 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00006767 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006768 *E->getDestroyedTypeIdentifier(),
6769 E->getDestroyedTypeLoc(),
6770 /*Scope=*/0,
6771 SS, ObjectTypePtr,
6772 false);
6773 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006774 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006775
Douglas Gregor678f90d2010-02-25 01:56:36 +00006776 Destroyed
6777 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6778 E->getDestroyedTypeLoc());
6779 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006780
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006781 TypeSourceInfo *ScopeTypeInfo = 0;
6782 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006783 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006784 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006785 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006786 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006787
John McCallb268a282010-08-23 23:25:46 +00006788 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006789 E->getOperatorLoc(),
6790 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006791 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006792 ScopeTypeInfo,
6793 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006794 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006795 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006796}
Mike Stump11289f42009-09-09 15:08:12 +00006797
Douglas Gregorad8a3362009-09-04 17:36:40 +00006798template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006799ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006800TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006801 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006802 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6803 Sema::LookupOrdinaryName);
6804
6805 // Transform all the decls.
6806 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6807 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006808 NamedDecl *InstD = static_cast<NamedDecl*>(
6809 getDerived().TransformDecl(Old->getNameLoc(),
6810 *I));
John McCall84d87672009-12-10 09:41:52 +00006811 if (!InstD) {
6812 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6813 // This can happen because of dependent hiding.
6814 if (isa<UsingShadowDecl>(*I))
6815 continue;
6816 else
John McCallfaf5fb42010-08-26 23:41:50 +00006817 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006818 }
John McCalle66edc12009-11-24 19:00:30 +00006819
6820 // Expand using declarations.
6821 if (isa<UsingDecl>(InstD)) {
6822 UsingDecl *UD = cast<UsingDecl>(InstD);
6823 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6824 E = UD->shadow_end(); I != E; ++I)
6825 R.addDecl(*I);
6826 continue;
6827 }
6828
6829 R.addDecl(InstD);
6830 }
6831
6832 // Resolve a kind, but don't do any further analysis. If it's
6833 // ambiguous, the callee needs to deal with it.
6834 R.resolveKind();
6835
6836 // Rebuild the nested-name qualifier, if present.
6837 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00006838 if (Old->getQualifierLoc()) {
6839 NestedNameSpecifierLoc QualifierLoc
6840 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
6841 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006842 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006843
Douglas Gregor0da1d432011-02-28 20:01:57 +00006844 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006845 }
6846
Douglas Gregor9262f472010-04-27 18:19:34 +00006847 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006848 CXXRecordDecl *NamingClass
6849 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6850 Old->getNameLoc(),
6851 Old->getNamingClass()));
6852 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006853 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006854
Douglas Gregorda7be082010-04-27 16:10:10 +00006855 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006856 }
6857
6858 // If we have no template arguments, it's a normal declaration name.
6859 if (!Old->hasExplicitTemplateArgs())
6860 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6861
6862 // If we have template arguments, rebuild them, then rebuild the
6863 // templateid expression.
6864 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006865 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6866 Old->getNumTemplateArgs(),
6867 TransArgs))
6868 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006869
6870 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6871 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006872}
Mike Stump11289f42009-09-09 15:08:12 +00006873
Douglas Gregora16548e2009-08-11 05:31:07 +00006874template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006875ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006876TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006877 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6878 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006879 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006880
Douglas Gregora16548e2009-08-11 05:31:07 +00006881 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006882 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006883 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006884
Mike Stump11289f42009-09-09 15:08:12 +00006885 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006886 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006887 T,
6888 E->getLocEnd());
6889}
Mike Stump11289f42009-09-09 15:08:12 +00006890
Douglas Gregora16548e2009-08-11 05:31:07 +00006891template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006892ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006893TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6894 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6895 if (!LhsT)
6896 return ExprError();
6897
6898 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6899 if (!RhsT)
6900 return ExprError();
6901
6902 if (!getDerived().AlwaysRebuild() &&
6903 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6904 return SemaRef.Owned(E);
6905
6906 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6907 E->getLocStart(),
6908 LhsT, RhsT,
6909 E->getLocEnd());
6910}
6911
6912template<typename Derived>
6913ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006914TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006915 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006916 NestedNameSpecifierLoc QualifierLoc
6917 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6918 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006919 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006920
John McCall31f82722010-11-12 08:19:04 +00006921 // TODO: If this is a conversion-function-id, verify that the
6922 // destination type name (if present) resolves the same way after
6923 // instantiation as it did in the local scope.
6924
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006925 DeclarationNameInfo NameInfo
6926 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6927 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006928 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006929
John McCalle66edc12009-11-24 19:00:30 +00006930 if (!E->hasExplicitTemplateArgs()) {
6931 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006932 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006933 // Note: it is sufficient to compare the Name component of NameInfo:
6934 // if name has not changed, DNLoc has not changed either.
6935 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006936 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006937
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006938 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006939 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006940 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006941 }
John McCall6b51f282009-11-23 01:53:49 +00006942
6943 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006944 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6945 E->getNumTemplateArgs(),
6946 TransArgs))
6947 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006948
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006949 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006950 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006951 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006952}
6953
6954template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006955ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006956TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006957 // CXXConstructExprs are always implicit, so when we have a
6958 // 1-argument construction we just transform that argument.
6959 if (E->getNumArgs() == 1 ||
6960 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6961 return getDerived().TransformExpr(E->getArg(0));
6962
Douglas Gregora16548e2009-08-11 05:31:07 +00006963 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6964
6965 QualType T = getDerived().TransformType(E->getType());
6966 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006967 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006968
6969 CXXConstructorDecl *Constructor
6970 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006971 getDerived().TransformDecl(E->getLocStart(),
6972 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006973 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006974 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006975
Douglas Gregora16548e2009-08-11 05:31:07 +00006976 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006977 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006978 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6979 &ArgumentChanged))
6980 return ExprError();
6981
Douglas Gregora16548e2009-08-11 05:31:07 +00006982 if (!getDerived().AlwaysRebuild() &&
6983 T == E->getType() &&
6984 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006985 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006986 // Mark the constructor as referenced.
6987 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006988 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006989 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006990 }
Mike Stump11289f42009-09-09 15:08:12 +00006991
Douglas Gregordb121ba2009-12-14 16:27:04 +00006992 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6993 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006994 move_arg(Args),
6995 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006996 E->getConstructionKind(),
6997 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006998}
Mike Stump11289f42009-09-09 15:08:12 +00006999
Douglas Gregora16548e2009-08-11 05:31:07 +00007000/// \brief Transform a C++ temporary-binding expression.
7001///
Douglas Gregor363b1512009-12-24 18:51:59 +00007002/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7003/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007004template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007005ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007006TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007007 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007008}
Mike Stump11289f42009-09-09 15:08:12 +00007009
John McCall5d413782010-12-06 08:20:24 +00007010/// \brief Transform a C++ expression that contains cleanups that should
7011/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00007012///
John McCall5d413782010-12-06 08:20:24 +00007013/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00007014/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007015template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007016ExprResult
John McCall5d413782010-12-06 08:20:24 +00007017TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007018 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007019}
Mike Stump11289f42009-09-09 15:08:12 +00007020
Douglas Gregora16548e2009-08-11 05:31:07 +00007021template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007022ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007023TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00007024 CXXTemporaryObjectExpr *E) {
7025 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7026 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007027 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007028
Douglas Gregora16548e2009-08-11 05:31:07 +00007029 CXXConstructorDecl *Constructor
7030 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00007031 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007032 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007033 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007034 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007035
Douglas Gregora16548e2009-08-11 05:31:07 +00007036 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007037 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00007038 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00007039 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7040 &ArgumentChanged))
7041 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007042
Douglas Gregora16548e2009-08-11 05:31:07 +00007043 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007044 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007045 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007046 !ArgumentChanged) {
7047 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00007048 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007049 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007050 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00007051
7052 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7053 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007054 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007055 E->getLocEnd());
7056}
Mike Stump11289f42009-09-09 15:08:12 +00007057
Douglas Gregora16548e2009-08-11 05:31:07 +00007058template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007059ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007060TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007061 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00007062 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7063 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007064 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007065
Douglas Gregora16548e2009-08-11 05:31:07 +00007066 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007067 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007068 Args.reserve(E->arg_size());
7069 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7070 &ArgumentChanged))
7071 return ExprError();
7072
Douglas Gregora16548e2009-08-11 05:31:07 +00007073 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007074 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007075 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007076 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007077
Douglas Gregora16548e2009-08-11 05:31:07 +00007078 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00007079 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00007080 E->getLParenLoc(),
7081 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007082 E->getRParenLoc());
7083}
Mike Stump11289f42009-09-09 15:08:12 +00007084
Douglas Gregora16548e2009-08-11 05:31:07 +00007085template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007086ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007087TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007088 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007089 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007090 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007091 Expr *OldBase;
7092 QualType BaseType;
7093 QualType ObjectType;
7094 if (!E->isImplicitAccess()) {
7095 OldBase = E->getBase();
7096 Base = getDerived().TransformExpr(OldBase);
7097 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007098 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007099
John McCall2d74de92009-12-01 22:10:20 +00007100 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00007101 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00007102 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007103 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007104 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007105 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00007106 ObjectTy,
7107 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00007108 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007109 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007110
John McCallba7bf592010-08-24 05:47:05 +00007111 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00007112 BaseType = ((Expr*) Base.get())->getType();
7113 } else {
7114 OldBase = 0;
7115 BaseType = getDerived().TransformType(E->getBaseType());
7116 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7117 }
Mike Stump11289f42009-09-09 15:08:12 +00007118
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007119 // Transform the first part of the nested-name-specifier that qualifies
7120 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007121 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007122 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00007123 E->getFirstQualifierFoundInScope(),
7124 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00007125
Douglas Gregore16af532011-02-28 18:50:33 +00007126 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007127 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00007128 QualifierLoc
7129 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7130 ObjectType,
7131 FirstQualifierInScope);
7132 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007133 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007134 }
Mike Stump11289f42009-09-09 15:08:12 +00007135
John McCall31f82722010-11-12 08:19:04 +00007136 // TODO: If this is a conversion-function-id, verify that the
7137 // destination type name (if present) resolves the same way after
7138 // instantiation as it did in the local scope.
7139
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007140 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007141 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007142 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007143 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007144
John McCall2d74de92009-12-01 22:10:20 +00007145 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007146 // This is a reference to a member without an explicitly-specified
7147 // template argument list. Optimize for this common case.
7148 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007149 Base.get() == OldBase &&
7150 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007151 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007152 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007153 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007154 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007155
John McCallb268a282010-08-23 23:25:46 +00007156 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007157 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007158 E->isArrow(),
7159 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007160 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007161 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007162 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007163 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007164 }
7165
John McCall6b51f282009-11-23 01:53:49 +00007166 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007167 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7168 E->getNumTemplateArgs(),
7169 TransArgs))
7170 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007171
John McCallb268a282010-08-23 23:25:46 +00007172 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007173 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007174 E->isArrow(),
7175 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007176 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007177 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007178 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007179 &TransArgs);
7180}
7181
7182template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007183ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007184TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007185 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007186 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007187 QualType BaseType;
7188 if (!Old->isImplicitAccess()) {
7189 Base = getDerived().TransformExpr(Old->getBase());
7190 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007191 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007192 BaseType = ((Expr*) Base.get())->getType();
7193 } else {
7194 BaseType = getDerived().TransformType(Old->getBaseType());
7195 }
John McCall10eae182009-11-30 22:42:35 +00007196
Douglas Gregor0da1d432011-02-28 20:01:57 +00007197 NestedNameSpecifierLoc QualifierLoc;
7198 if (Old->getQualifierLoc()) {
7199 QualifierLoc
7200 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7201 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007202 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007203 }
7204
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007205 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007206 Sema::LookupOrdinaryName);
7207
7208 // Transform all the decls.
7209 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7210 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007211 NamedDecl *InstD = static_cast<NamedDecl*>(
7212 getDerived().TransformDecl(Old->getMemberLoc(),
7213 *I));
John McCall84d87672009-12-10 09:41:52 +00007214 if (!InstD) {
7215 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7216 // This can happen because of dependent hiding.
7217 if (isa<UsingShadowDecl>(*I))
7218 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007219 else {
7220 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007221 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007222 }
John McCall84d87672009-12-10 09:41:52 +00007223 }
John McCall10eae182009-11-30 22:42:35 +00007224
7225 // Expand using declarations.
7226 if (isa<UsingDecl>(InstD)) {
7227 UsingDecl *UD = cast<UsingDecl>(InstD);
7228 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7229 E = UD->shadow_end(); I != E; ++I)
7230 R.addDecl(*I);
7231 continue;
7232 }
7233
7234 R.addDecl(InstD);
7235 }
7236
7237 R.resolveKind();
7238
Douglas Gregor9262f472010-04-27 18:19:34 +00007239 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007240 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007241 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007242 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007243 Old->getMemberLoc(),
7244 Old->getNamingClass()));
7245 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007246 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007247
Douglas Gregorda7be082010-04-27 16:10:10 +00007248 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007249 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007250
John McCall10eae182009-11-30 22:42:35 +00007251 TemplateArgumentListInfo TransArgs;
7252 if (Old->hasExplicitTemplateArgs()) {
7253 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7254 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007255 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7256 Old->getNumTemplateArgs(),
7257 TransArgs))
7258 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007259 }
John McCall38836f02010-01-15 08:34:02 +00007260
7261 // FIXME: to do this check properly, we will need to preserve the
7262 // first-qualifier-in-scope here, just in case we had a dependent
7263 // base (and therefore couldn't do the check) and a
7264 // nested-name-qualifier (and therefore could do the lookup).
7265 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007266
John McCallb268a282010-08-23 23:25:46 +00007267 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007268 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007269 Old->getOperatorLoc(),
7270 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007271 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007272 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007273 R,
7274 (Old->hasExplicitTemplateArgs()
7275 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007276}
7277
7278template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007279ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007280TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7281 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7282 if (SubExpr.isInvalid())
7283 return ExprError();
7284
7285 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007286 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007287
7288 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7289}
7290
7291template<typename Derived>
7292ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007293TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007294 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7295 if (Pattern.isInvalid())
7296 return ExprError();
7297
7298 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7299 return SemaRef.Owned(E);
7300
Douglas Gregorb8840002011-01-14 21:20:45 +00007301 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7302 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007303}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007304
7305template<typename Derived>
7306ExprResult
7307TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7308 // If E is not value-dependent, then nothing will change when we transform it.
7309 // Note: This is an instantiation-centric view.
7310 if (!E->isValueDependent())
7311 return SemaRef.Owned(E);
7312
7313 // Note: None of the implementations of TryExpandParameterPacks can ever
7314 // produce a diagnostic when given only a single unexpanded parameter pack,
7315 // so
7316 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7317 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007318 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007319 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007320 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7321 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007322 ShouldExpand, RetainExpansion,
7323 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007324 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007325
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007326 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007327 return SemaRef.Owned(E);
7328
7329 // We now know the length of the parameter pack, so build a new expression
7330 // that stores that length.
7331 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7332 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007333 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007334}
7335
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007336template<typename Derived>
7337ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007338TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7339 SubstNonTypeTemplateParmPackExpr *E) {
7340 // Default behavior is to do nothing with this transformation.
7341 return SemaRef.Owned(E);
7342}
7343
7344template<typename Derived>
7345ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007346TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007347 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007348}
7349
Mike Stump11289f42009-09-09 15:08:12 +00007350template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007351ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007352TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007353 TypeSourceInfo *EncodedTypeInfo
7354 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7355 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007356 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007357
Douglas Gregora16548e2009-08-11 05:31:07 +00007358 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007359 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007360 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007361
7362 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007363 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007364 E->getRParenLoc());
7365}
Mike Stump11289f42009-09-09 15:08:12 +00007366
Douglas Gregora16548e2009-08-11 05:31:07 +00007367template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007368ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007369TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007370 // Transform arguments.
7371 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007372 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007373 Args.reserve(E->getNumArgs());
7374 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7375 &ArgChanged))
7376 return ExprError();
7377
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007378 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7379 // Class message: transform the receiver type.
7380 TypeSourceInfo *ReceiverTypeInfo
7381 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7382 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007383 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007384
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007385 // If nothing changed, just retain the existing message send.
7386 if (!getDerived().AlwaysRebuild() &&
7387 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007388 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007389
7390 // Build a new class message send.
7391 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7392 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007393 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007394 E->getMethodDecl(),
7395 E->getLeftLoc(),
7396 move_arg(Args),
7397 E->getRightLoc());
7398 }
7399
7400 // Instance message: transform the receiver
7401 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7402 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007403 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007404 = getDerived().TransformExpr(E->getInstanceReceiver());
7405 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007406 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007407
7408 // If nothing changed, just retain the existing message send.
7409 if (!getDerived().AlwaysRebuild() &&
7410 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007411 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007412
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007413 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007414 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007415 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007416 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007417 E->getMethodDecl(),
7418 E->getLeftLoc(),
7419 move_arg(Args),
7420 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007421}
7422
Mike Stump11289f42009-09-09 15:08:12 +00007423template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007424ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007425TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007426 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007427}
7428
Mike Stump11289f42009-09-09 15:08:12 +00007429template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007430ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007431TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007432 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007433}
7434
Mike Stump11289f42009-09-09 15:08:12 +00007435template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007436ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007437TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007438 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007439 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007440 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007441 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007442
7443 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007444
Douglas Gregord51d90d2010-04-26 20:11:03 +00007445 // If nothing changed, just retain the existing expression.
7446 if (!getDerived().AlwaysRebuild() &&
7447 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007448 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007449
John McCallb268a282010-08-23 23:25:46 +00007450 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007451 E->getLocation(),
7452 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007453}
7454
Mike Stump11289f42009-09-09 15:08:12 +00007455template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007456ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007457TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007458 // 'super' and types never change. Property never changes. Just
7459 // retain the existing expression.
7460 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007461 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007462
Douglas Gregor9faee212010-04-26 20:47:02 +00007463 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007464 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007465 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007466 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007467
Douglas Gregor9faee212010-04-26 20:47:02 +00007468 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007469
Douglas Gregor9faee212010-04-26 20:47:02 +00007470 // If nothing changed, just retain the existing expression.
7471 if (!getDerived().AlwaysRebuild() &&
7472 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007473 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007474
John McCallb7bd14f2010-12-02 01:19:52 +00007475 if (E->isExplicitProperty())
7476 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7477 E->getExplicitProperty(),
7478 E->getLocation());
7479
7480 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7481 E->getType(),
7482 E->getImplicitPropertyGetter(),
7483 E->getImplicitPropertySetter(),
7484 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007485}
7486
Mike Stump11289f42009-09-09 15:08:12 +00007487template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007488ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007489TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007490 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007491 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007492 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007493 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007494
Douglas Gregord51d90d2010-04-26 20:11:03 +00007495 // If nothing changed, just retain the existing expression.
7496 if (!getDerived().AlwaysRebuild() &&
7497 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007498 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007499
John McCallb268a282010-08-23 23:25:46 +00007500 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007501 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007502}
7503
Mike Stump11289f42009-09-09 15:08:12 +00007504template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007505ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007506TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007507 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007508 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007509 SubExprs.reserve(E->getNumSubExprs());
7510 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7511 SubExprs, &ArgumentChanged))
7512 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007513
Douglas Gregora16548e2009-08-11 05:31:07 +00007514 if (!getDerived().AlwaysRebuild() &&
7515 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007516 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007517
Douglas Gregora16548e2009-08-11 05:31:07 +00007518 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7519 move_arg(SubExprs),
7520 E->getRParenLoc());
7521}
7522
Mike Stump11289f42009-09-09 15:08:12 +00007523template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007524ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007525TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007526 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007527
John McCall490112f2011-02-04 18:33:18 +00007528 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7529 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7530
7531 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7532 llvm::SmallVector<ParmVarDecl*, 4> params;
7533 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007534
7535 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007536 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7537 oldBlock->param_begin(),
7538 oldBlock->param_size(),
7539 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007540 return true;
John McCall490112f2011-02-04 18:33:18 +00007541
7542 const FunctionType *exprFunctionType = E->getFunctionType();
7543 QualType exprResultType = exprFunctionType->getResultType();
7544 if (!exprResultType.isNull()) {
7545 if (!exprResultType->isDependentType())
7546 blockScope->ReturnType = exprResultType;
7547 else if (exprResultType != getSema().Context.DependentTy)
7548 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007549 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007550
7551 // If the return type has not been determined yet, leave it as a dependent
7552 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007553 if (blockScope->ReturnType.isNull())
7554 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007555
7556 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007557 if (blockScope->ReturnType->isObjCObjectType()) {
7558 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007559 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007560 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007561 return ExprError();
7562 }
John McCall3882ace2011-01-05 12:14:39 +00007563
John McCall490112f2011-02-04 18:33:18 +00007564 QualType functionType = getDerived().RebuildFunctionProtoType(
7565 blockScope->ReturnType,
7566 paramTypes.data(),
7567 paramTypes.size(),
7568 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007569 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007570 exprFunctionType->getExtInfo());
7571 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007572
7573 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007574 if (!params.empty())
7575 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007576
7577 // If the return type wasn't explicitly set, it will have been marked as a
7578 // dependent type (DependentTy); clear out the return type setting so
7579 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007580 if (blockScope->ReturnType == getSema().Context.DependentTy)
7581 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007582
John McCall3882ace2011-01-05 12:14:39 +00007583 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007584 StmtResult body = getDerived().TransformStmt(E->getBody());
7585 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007586 return ExprError();
7587
John McCall490112f2011-02-04 18:33:18 +00007588#ifndef NDEBUG
7589 // In builds with assertions, make sure that we captured everything we
7590 // captured before.
7591
7592 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7593
7594 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7595 e = oldBlock->capture_end(); i != e; ++i) {
John McCall351762c2011-02-07 10:33:21 +00007596 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007597
7598 // Ignore parameter packs.
7599 if (isa<ParmVarDecl>(oldCapture) &&
7600 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7601 continue;
7602
7603 VarDecl *newCapture =
7604 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7605 oldCapture));
John McCall351762c2011-02-07 10:33:21 +00007606 assert(blockScope->CaptureMap.count(newCapture));
John McCall490112f2011-02-04 18:33:18 +00007607 }
7608#endif
7609
7610 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7611 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007612}
7613
Mike Stump11289f42009-09-09 15:08:12 +00007614template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007615ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007616TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007617 ValueDecl *ND
7618 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7619 E->getDecl()));
7620 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007621 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007622
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007623 if (!getDerived().AlwaysRebuild() &&
7624 ND == E->getDecl()) {
7625 // Mark it referenced in the new context regardless.
7626 // FIXME: this is a bit instantiation-specific.
7627 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7628
John McCallc3007a22010-10-26 07:05:15 +00007629 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007630 }
7631
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007632 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00007633 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007634 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007635}
Mike Stump11289f42009-09-09 15:08:12 +00007636
Douglas Gregora16548e2009-08-11 05:31:07 +00007637//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007638// Type reconstruction
7639//===----------------------------------------------------------------------===//
7640
Mike Stump11289f42009-09-09 15:08:12 +00007641template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007642QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7643 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007644 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007645 getDerived().getBaseEntity());
7646}
7647
Mike Stump11289f42009-09-09 15:08:12 +00007648template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007649QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7650 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007651 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007652 getDerived().getBaseEntity());
7653}
7654
Mike Stump11289f42009-09-09 15:08:12 +00007655template<typename Derived>
7656QualType
John McCall70dd5f62009-10-30 00:06:24 +00007657TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7658 bool WrittenAsLValue,
7659 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007660 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007661 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007662}
7663
7664template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007665QualType
John McCall70dd5f62009-10-30 00:06:24 +00007666TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7667 QualType ClassType,
7668 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007669 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007670 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007671}
7672
7673template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007674QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007675TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7676 ArrayType::ArraySizeModifier SizeMod,
7677 const llvm::APInt *Size,
7678 Expr *SizeExpr,
7679 unsigned IndexTypeQuals,
7680 SourceRange BracketsRange) {
7681 if (SizeExpr || !Size)
7682 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7683 IndexTypeQuals, BracketsRange,
7684 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007685
7686 QualType Types[] = {
7687 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7688 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7689 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007690 };
7691 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7692 QualType SizeType;
7693 for (unsigned I = 0; I != NumTypes; ++I)
7694 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7695 SizeType = Types[I];
7696 break;
7697 }
Mike Stump11289f42009-09-09 15:08:12 +00007698
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007699 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7700 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007701 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007702 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007703 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007704}
Mike Stump11289f42009-09-09 15:08:12 +00007705
Douglas Gregord6ff3322009-08-04 16:50:30 +00007706template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007707QualType
7708TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007709 ArrayType::ArraySizeModifier SizeMod,
7710 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007711 unsigned IndexTypeQuals,
7712 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007713 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007714 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007715}
7716
7717template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007718QualType
Mike Stump11289f42009-09-09 15:08:12 +00007719TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007720 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007721 unsigned IndexTypeQuals,
7722 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007723 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007724 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007725}
Mike Stump11289f42009-09-09 15:08:12 +00007726
Douglas Gregord6ff3322009-08-04 16:50:30 +00007727template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007728QualType
7729TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007730 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007731 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007732 unsigned IndexTypeQuals,
7733 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007734 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007735 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007736 IndexTypeQuals, BracketsRange);
7737}
7738
7739template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007740QualType
7741TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007742 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007743 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007744 unsigned IndexTypeQuals,
7745 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007746 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007747 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007748 IndexTypeQuals, BracketsRange);
7749}
7750
7751template<typename Derived>
7752QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007753 unsigned NumElements,
7754 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007755 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007756 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007757}
Mike Stump11289f42009-09-09 15:08:12 +00007758
Douglas Gregord6ff3322009-08-04 16:50:30 +00007759template<typename Derived>
7760QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7761 unsigned NumElements,
7762 SourceLocation AttributeLoc) {
7763 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7764 NumElements, true);
7765 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007766 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7767 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007768 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007769}
Mike Stump11289f42009-09-09 15:08:12 +00007770
Douglas Gregord6ff3322009-08-04 16:50:30 +00007771template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007772QualType
7773TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007774 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007775 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007776 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007777}
Mike Stump11289f42009-09-09 15:08:12 +00007778
Douglas Gregord6ff3322009-08-04 16:50:30 +00007779template<typename Derived>
7780QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007781 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007782 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007783 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007784 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007785 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00007786 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007787 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007788 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007789 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007790 getDerived().getBaseEntity(),
7791 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007792}
Mike Stump11289f42009-09-09 15:08:12 +00007793
Douglas Gregord6ff3322009-08-04 16:50:30 +00007794template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007795QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7796 return SemaRef.Context.getFunctionNoProtoType(T);
7797}
7798
7799template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007800QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7801 assert(D && "no decl found");
7802 if (D->isInvalidDecl()) return QualType();
7803
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007804 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007805 TypeDecl *Ty;
7806 if (isa<UsingDecl>(D)) {
7807 UsingDecl *Using = cast<UsingDecl>(D);
7808 assert(Using->isTypeName() &&
7809 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7810
7811 // A valid resolved using typename decl points to exactly one type decl.
7812 assert(++Using->shadow_begin() == Using->shadow_end());
7813 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007814
John McCallb96ec562009-12-04 22:46:56 +00007815 } else {
7816 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7817 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7818 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7819 }
7820
7821 return SemaRef.Context.getTypeDeclType(Ty);
7822}
7823
7824template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007825QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7826 SourceLocation Loc) {
7827 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007828}
7829
7830template<typename Derived>
7831QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7832 return SemaRef.Context.getTypeOfType(Underlying);
7833}
7834
7835template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007836QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7837 SourceLocation Loc) {
7838 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007839}
7840
7841template<typename Derived>
7842QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007843 TemplateName Template,
7844 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00007845 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00007846 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007847}
Mike Stump11289f42009-09-09 15:08:12 +00007848
Douglas Gregor1135c352009-08-06 05:28:30 +00007849template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007850TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007851TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007852 bool TemplateKW,
7853 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00007854 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007855 Template);
7856}
7857
7858template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007859TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007860TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
7861 const IdentifierInfo &Name,
7862 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00007863 QualType ObjectType,
7864 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00007865 UnqualifiedId TemplateName;
7866 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00007867 Sema::TemplateTy Template;
7868 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00007869 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007870 SS,
Douglas Gregor9db53502011-03-02 18:07:45 +00007871 TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00007872 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007873 /*EnteringContext=*/false,
7874 Template);
John McCall31f82722010-11-12 08:19:04 +00007875 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007876}
Mike Stump11289f42009-09-09 15:08:12 +00007877
Douglas Gregora16548e2009-08-11 05:31:07 +00007878template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007879TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007880TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007881 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00007882 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007883 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00007884 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00007885 // FIXME: Bogus location information.
7886 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
7887 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007888 Sema::TemplateTy Template;
7889 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00007890 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007891 SS,
7892 Name,
John McCallba7bf592010-08-24 05:47:05 +00007893 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007894 /*EnteringContext=*/false,
7895 Template);
7896 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007897}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007898
Douglas Gregor71395fa2009-11-04 00:56:37 +00007899template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007900ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007901TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7902 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007903 Expr *OrigCallee,
7904 Expr *First,
7905 Expr *Second) {
7906 Expr *Callee = OrigCallee->IgnoreParenCasts();
7907 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007908
Douglas Gregora16548e2009-08-11 05:31:07 +00007909 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007910 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007911 if (!First->getType()->isOverloadableType() &&
7912 !Second->getType()->isOverloadableType())
7913 return getSema().CreateBuiltinArraySubscriptExpr(First,
7914 Callee->getLocStart(),
7915 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007916 } else if (Op == OO_Arrow) {
7917 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007918 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7919 } else if (Second == 0 || isPostIncDec) {
7920 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007921 // The argument is not of overloadable type, so try to create a
7922 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007923 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007924 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007925
John McCallb268a282010-08-23 23:25:46 +00007926 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007927 }
7928 } else {
John McCallb268a282010-08-23 23:25:46 +00007929 if (!First->getType()->isOverloadableType() &&
7930 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007931 // Neither of the arguments is an overloadable type, so try to
7932 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007933 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007934 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007935 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007936 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007937 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007938
Douglas Gregora16548e2009-08-11 05:31:07 +00007939 return move(Result);
7940 }
7941 }
Mike Stump11289f42009-09-09 15:08:12 +00007942
7943 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007944 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007945 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007946
John McCallb268a282010-08-23 23:25:46 +00007947 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007948 assert(ULE->requiresADL());
7949
7950 // FIXME: Do we have to check
7951 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007952 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007953 } else {
John McCallb268a282010-08-23 23:25:46 +00007954 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007955 }
Mike Stump11289f42009-09-09 15:08:12 +00007956
Douglas Gregora16548e2009-08-11 05:31:07 +00007957 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007958 Expr *Args[2] = { First, Second };
7959 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007960
Douglas Gregora16548e2009-08-11 05:31:07 +00007961 // Create the overloaded operator invocation for unary operators.
7962 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007963 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007964 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007965 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007966 }
Mike Stump11289f42009-09-09 15:08:12 +00007967
Sebastian Redladba46e2009-10-29 20:17:01 +00007968 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007969 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007970 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007971 First,
7972 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007973
Douglas Gregora16548e2009-08-11 05:31:07 +00007974 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007975 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007976 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007977 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7978 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007979 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007980
Mike Stump11289f42009-09-09 15:08:12 +00007981 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007982}
Mike Stump11289f42009-09-09 15:08:12 +00007983
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007984template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007985ExprResult
John McCallb268a282010-08-23 23:25:46 +00007986TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007987 SourceLocation OperatorLoc,
7988 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00007989 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007990 TypeSourceInfo *ScopeType,
7991 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007992 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007993 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00007994 QualType BaseType = Base->getType();
7995 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007996 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007997 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007998 !BaseType->getAs<PointerType>()->getPointeeType()
7999 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008000 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00008001 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008002 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008003 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008004 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008005 /*FIXME?*/true);
8006 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008007
Douglas Gregor678f90d2010-02-25 01:56:36 +00008008 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008009 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8010 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8011 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8012 NameInfo.setNamedTypeInfo(DestroyedType);
8013
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008014 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008015
John McCallb268a282010-08-23 23:25:46 +00008016 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008017 OperatorLoc, isArrow,
8018 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008019 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008020 /*TemplateArgs*/ 0);
8021}
8022
Douglas Gregord6ff3322009-08-04 16:50:30 +00008023} // end namespace clang
8024
8025#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H