blob: a7dc920f84897b770cf3376b2ed487d1470c76d5 [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.
672 QualType RebuildTypedefType(TypedefDecl *Typedef) {
673 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;
854 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2;
855 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
856 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
857 break;
858 }
859 default:
860 // FIXME: Would be nice to highlight just the source range.
861 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
862 << Kind << Id << DC;
863 break;
864 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000865 return QualType();
866 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000867
Abramo Bagnarad7548482010-05-19 21:37:53 +0000868 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
869 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000870 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
871 return QualType();
872 }
873
874 // Build the elaborated-type-specifier type.
875 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000876 return SemaRef.Context.getElaboratedType(Keyword,
877 QualifierLoc.getNestedNameSpecifier(),
878 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000879 }
Mike Stump11289f42009-09-09 15:08:12 +0000880
Douglas Gregor822d0302011-01-12 17:07:58 +0000881 /// \brief Build a new pack expansion type.
882 ///
883 /// By default, builds a new PackExpansionType type from the given pattern.
884 /// Subclasses may override this routine to provide different behavior.
885 QualType RebuildPackExpansionType(QualType Pattern,
886 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000887 SourceLocation EllipsisLoc,
888 llvm::Optional<unsigned> NumExpansions) {
889 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
890 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000891 }
892
Douglas Gregor71dc5092009-08-06 06:41:21 +0000893 /// \brief Build a new template name given a nested name specifier, a flag
894 /// indicating whether the "template" keyword was provided, and the template
895 /// that the template name refers to.
896 ///
897 /// By default, builds the new template name directly. Subclasses may override
898 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000899 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +0000900 bool TemplateKW,
901 TemplateDecl *Template);
902
Douglas Gregor71dc5092009-08-06 06:41:21 +0000903 /// \brief Build a new template name given a nested name specifier and the
904 /// name that is referred to as a template.
905 ///
906 /// By default, performs semantic analysis to determine whether the name can
907 /// be resolved to a specific template, then builds the appropriate kind of
908 /// template name. Subclasses may override this routine to provide different
909 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000910 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
911 const IdentifierInfo &Name,
912 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +0000913 QualType ObjectType,
914 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000915
Douglas Gregor71395fa2009-11-04 00:56:37 +0000916 /// \brief Build a new template name given a nested name specifier and the
917 /// overloaded operator name that is referred to as a template.
918 ///
919 /// By default, performs semantic analysis to determine whether the name can
920 /// be resolved to a specific template, then builds the appropriate kind of
921 /// template name. Subclasses may override this routine to provide different
922 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000923 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000924 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +0000925 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000926 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000927
928 /// \brief Build a new template name given a template template parameter pack
929 /// and the
930 ///
931 /// By default, performs semantic analysis to determine whether the name can
932 /// be resolved to a specific template, then builds the appropriate kind of
933 /// template name. Subclasses may override this routine to provide different
934 /// behavior.
935 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
936 const TemplateArgument &ArgPack) {
937 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
938 }
939
Douglas Gregorebe10102009-08-20 07:17:43 +0000940 /// \brief Build a new compound statement.
941 ///
942 /// By default, performs semantic analysis to build the new statement.
943 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000944 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000945 MultiStmtArg Statements,
946 SourceLocation RBraceLoc,
947 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000948 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000949 IsStmtExpr);
950 }
951
952 /// \brief Build a new case statement.
953 ///
954 /// By default, performs semantic analysis to build the new statement.
955 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000956 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000957 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000958 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000959 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000960 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000961 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000962 ColonLoc);
963 }
Mike Stump11289f42009-09-09 15:08:12 +0000964
Douglas Gregorebe10102009-08-20 07:17:43 +0000965 /// \brief Attach the body to a new case statement.
966 ///
967 /// By default, performs semantic analysis to build the new statement.
968 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000969 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000970 getSema().ActOnCaseStmtBody(S, Body);
971 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000972 }
Mike Stump11289f42009-09-09 15:08:12 +0000973
Douglas Gregorebe10102009-08-20 07:17:43 +0000974 /// \brief Build a new default statement.
975 ///
976 /// By default, performs semantic analysis to build the new statement.
977 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000978 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000979 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000980 Stmt *SubStmt) {
981 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000982 /*CurScope=*/0);
983 }
Mike Stump11289f42009-09-09 15:08:12 +0000984
Douglas Gregorebe10102009-08-20 07:17:43 +0000985 /// \brief Build a new label statement.
986 ///
987 /// By default, performs semantic analysis to build the new statement.
988 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +0000989 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
990 SourceLocation ColonLoc, Stmt *SubStmt) {
991 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +0000992 }
Mike Stump11289f42009-09-09 15:08:12 +0000993
Douglas Gregorebe10102009-08-20 07:17:43 +0000994 /// \brief Build a new "if" statement.
995 ///
996 /// By default, performs semantic analysis to build the new statement.
997 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000998 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattnercab02a62011-02-17 20:34:02 +0000999 VarDecl *CondVar, Stmt *Then,
1000 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001001 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001002 }
Mike Stump11289f42009-09-09 15:08:12 +00001003
Douglas Gregorebe10102009-08-20 07:17:43 +00001004 /// \brief Start building a new switch statement.
1005 ///
1006 /// By default, performs semantic analysis to build the new statement.
1007 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001008 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001009 Expr *Cond, VarDecl *CondVar) {
John McCallb268a282010-08-23 23:25:46 +00001010 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001011 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001012 }
Mike Stump11289f42009-09-09 15:08:12 +00001013
Douglas Gregorebe10102009-08-20 07:17:43 +00001014 /// \brief Attach the body to the switch statement.
1015 ///
1016 /// By default, performs semantic analysis to build the new statement.
1017 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001018 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001019 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001020 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001021 }
1022
1023 /// \brief Build a new while statement.
1024 ///
1025 /// By default, performs semantic analysis to build the new statement.
1026 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001027 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1028 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001029 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001030 }
Mike Stump11289f42009-09-09 15:08:12 +00001031
Douglas Gregorebe10102009-08-20 07:17:43 +00001032 /// \brief Build a new do-while statement.
1033 ///
1034 /// By default, performs semantic analysis to build the new statement.
1035 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001036 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001037 SourceLocation WhileLoc, SourceLocation LParenLoc,
1038 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001039 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1040 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001041 }
1042
1043 /// \brief Build a new for statement.
1044 ///
1045 /// By default, performs semantic analysis to build the new statement.
1046 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001047 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1048 Stmt *Init, Sema::FullExprArg Cond,
1049 VarDecl *CondVar, Sema::FullExprArg Inc,
1050 SourceLocation RParenLoc, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001051 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001052 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001053 }
Mike Stump11289f42009-09-09 15:08:12 +00001054
Douglas Gregorebe10102009-08-20 07:17:43 +00001055 /// \brief Build a new goto statement.
1056 ///
1057 /// By default, performs semantic analysis to build the new statement.
1058 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001059 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1060 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001061 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001062 }
1063
1064 /// \brief Build a new indirect goto statement.
1065 ///
1066 /// By default, performs semantic analysis to build the new statement.
1067 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001068 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001069 SourceLocation StarLoc,
1070 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001071 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001072 }
Mike Stump11289f42009-09-09 15:08:12 +00001073
Douglas Gregorebe10102009-08-20 07:17:43 +00001074 /// \brief Build a new return statement.
1075 ///
1076 /// By default, performs semantic analysis to build the new statement.
1077 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001078 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001079 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001080 }
Mike Stump11289f42009-09-09 15:08:12 +00001081
Douglas Gregorebe10102009-08-20 07:17:43 +00001082 /// \brief Build a new declaration statement.
1083 ///
1084 /// By default, performs semantic analysis to build the new statement.
1085 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001086 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001087 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001088 SourceLocation EndLoc) {
Richard Smith2abf6762011-02-23 00:37:57 +00001089 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1090 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001091 }
Mike Stump11289f42009-09-09 15:08:12 +00001092
Anders Carlssonaaeef072010-01-24 05:50:09 +00001093 /// \brief Build a new inline asm statement.
1094 ///
1095 /// By default, performs semantic analysis to build the new statement.
1096 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001097 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001098 bool IsSimple,
1099 bool IsVolatile,
1100 unsigned NumOutputs,
1101 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001102 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001103 MultiExprArg Constraints,
1104 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001105 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001106 MultiExprArg Clobbers,
1107 SourceLocation RParenLoc,
1108 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001109 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001110 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001111 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001112 RParenLoc, MSAsm);
1113 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001114
1115 /// \brief Build a new Objective-C @try statement.
1116 ///
1117 /// By default, performs semantic analysis to build the new statement.
1118 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001119 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001120 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001121 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001122 Stmt *Finally) {
1123 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1124 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001125 }
1126
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001127 /// \brief Rebuild an Objective-C exception declaration.
1128 ///
1129 /// By default, performs semantic analysis to build the new declaration.
1130 /// Subclasses may override this routine to provide different behavior.
1131 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1132 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001133 return getSema().BuildObjCExceptionDecl(TInfo, T,
1134 ExceptionDecl->getInnerLocStart(),
1135 ExceptionDecl->getLocation(),
1136 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001137 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001138
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001139 /// \brief Build a new Objective-C @catch statement.
1140 ///
1141 /// By default, performs semantic analysis to build the new statement.
1142 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001143 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001144 SourceLocation RParenLoc,
1145 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001146 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001147 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001148 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001149 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001150
Douglas Gregor306de2f2010-04-22 23:59:56 +00001151 /// \brief Build a new Objective-C @finally statement.
1152 ///
1153 /// By default, performs semantic analysis to build the new statement.
1154 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001155 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001156 Stmt *Body) {
1157 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001158 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001159
Douglas Gregor6148de72010-04-22 22:01:21 +00001160 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001161 ///
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001164 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001165 Expr *Operand) {
1166 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001167 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001168
Douglas Gregor6148de72010-04-22 22:01:21 +00001169 /// \brief Build a new Objective-C @synchronized statement.
1170 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001171 /// By default, performs semantic analysis to build the new statement.
1172 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001173 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001174 Expr *Object,
1175 Stmt *Body) {
1176 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1177 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001178 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001179
1180 /// \brief Build a new Objective-C fast enumeration statement.
1181 ///
1182 /// By default, performs semantic analysis to build the new statement.
1183 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001184 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001185 SourceLocation LParenLoc,
1186 Stmt *Element,
1187 Expr *Collection,
1188 SourceLocation RParenLoc,
1189 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001190 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001191 Element,
1192 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001193 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001194 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001195 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001196
Douglas Gregorebe10102009-08-20 07:17:43 +00001197 /// \brief Build a new C++ exception declaration.
1198 ///
1199 /// By default, performs semantic analysis to build the new decaration.
1200 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001201 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001202 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001203 SourceLocation StartLoc,
1204 SourceLocation IdLoc,
1205 IdentifierInfo *Id) {
1206 return getSema().BuildExceptionDeclaration(0, Declarator,
1207 StartLoc, IdLoc, Id);
Douglas Gregorebe10102009-08-20 07:17:43 +00001208 }
1209
1210 /// \brief Build a new C++ catch statement.
1211 ///
1212 /// By default, performs semantic analysis to build the new statement.
1213 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001214 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001215 VarDecl *ExceptionDecl,
1216 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001217 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1218 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001219 }
Mike Stump11289f42009-09-09 15:08:12 +00001220
Douglas Gregorebe10102009-08-20 07:17:43 +00001221 /// \brief Build a new C++ try statement.
1222 ///
1223 /// By default, performs semantic analysis to build the new statement.
1224 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001225 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001226 Stmt *TryBlock,
1227 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001228 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001229 }
Mike Stump11289f42009-09-09 15:08:12 +00001230
Douglas Gregora16548e2009-08-11 05:31:07 +00001231 /// \brief Build a new expression that references a declaration.
1232 ///
1233 /// By default, performs semantic analysis to build the new expression.
1234 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001235 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001236 LookupResult &R,
1237 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001238 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1239 }
1240
1241
1242 /// \brief Build a new expression that references a declaration.
1243 ///
1244 /// By default, performs semantic analysis to build the new expression.
1245 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001246 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001247 ValueDecl *VD,
1248 const DeclarationNameInfo &NameInfo,
1249 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001250 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001251 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001252
1253 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001254
1255 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001256 }
Mike Stump11289f42009-09-09 15:08:12 +00001257
Douglas Gregora16548e2009-08-11 05:31:07 +00001258 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001259 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001260 /// By default, performs semantic analysis to build the new expression.
1261 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001262 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001263 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001264 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001265 }
1266
Douglas Gregorad8a3362009-09-04 17:36:40 +00001267 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001268 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001269 /// By default, performs semantic analysis to build the new expression.
1270 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001271 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001272 SourceLocation OperatorLoc,
1273 bool isArrow,
1274 CXXScopeSpec &SS,
1275 TypeSourceInfo *ScopeType,
1276 SourceLocation CCLoc,
1277 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001278 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001279
Douglas Gregora16548e2009-08-11 05:31:07 +00001280 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001281 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001282 /// By default, performs semantic analysis to build the new expression.
1283 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001284 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001285 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001286 Expr *SubExpr) {
1287 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001288 }
Mike Stump11289f42009-09-09 15:08:12 +00001289
Douglas Gregor882211c2010-04-28 22:16:22 +00001290 /// \brief Build a new builtin offsetof expression.
1291 ///
1292 /// By default, performs semantic analysis to build the new expression.
1293 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001294 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001295 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001296 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001297 unsigned NumComponents,
1298 SourceLocation RParenLoc) {
1299 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1300 NumComponents, RParenLoc);
1301 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001302
Peter Collingbournee190dee2011-03-11 19:24:49 +00001303 /// \brief Build a new sizeof, alignof or vec_step expression with a
1304 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001305 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001306 /// By default, performs semantic analysis to build the new expression.
1307 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001308 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1309 SourceLocation OpLoc,
1310 UnaryExprOrTypeTrait ExprKind,
1311 SourceRange R) {
1312 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001313 }
1314
Peter Collingbournee190dee2011-03-11 19:24:49 +00001315 /// \brief Build a new sizeof, alignof or vec step expression with an
1316 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001317 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001318 /// By default, performs semantic analysis to build the new expression.
1319 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001320 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1321 UnaryExprOrTypeTrait ExprKind,
1322 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001323 ExprResult Result
Peter Collingbournee190dee2011-03-11 19:24:49 +00001324 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001325 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001326 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001327
Douglas Gregora16548e2009-08-11 05:31:07 +00001328 return move(Result);
1329 }
Mike Stump11289f42009-09-09 15:08:12 +00001330
Douglas Gregora16548e2009-08-11 05:31:07 +00001331 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001332 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 /// By default, performs semantic analysis to build the new expression.
1334 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001335 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001336 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001337 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001338 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001339 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1340 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001341 RBracketLoc);
1342 }
1343
1344 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001345 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001346 /// By default, performs semantic analysis to build the new expression.
1347 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001348 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001349 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001350 SourceLocation RParenLoc,
1351 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001352 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001353 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001354 }
1355
1356 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001357 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001358 /// By default, performs semantic analysis to build the new expression.
1359 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001360 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001361 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001362 NestedNameSpecifierLoc QualifierLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001363 const DeclarationNameInfo &MemberNameInfo,
1364 ValueDecl *Member,
1365 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001366 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001367 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001368 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001369 // We have a reference to an unnamed field. This is always the
1370 // base of an anonymous struct/union member access, i.e. the
1371 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001372 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001373 assert(Member->getType()->isRecordType() &&
1374 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001375
John Wiegley01296292011-04-08 18:41:53 +00001376 ExprResult BaseResult =
1377 getSema().PerformObjectMemberConversion(Base,
1378 QualifierLoc.getNestedNameSpecifier(),
1379 FoundDecl, Member);
1380 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001381 return ExprError();
John Wiegley01296292011-04-08 18:41:53 +00001382 Base = BaseResult.take();
John McCall7decc9e2010-11-18 06:31:45 +00001383 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001384 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001385 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001386 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001387 cast<FieldDecl>(Member)->getType(),
1388 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001389 return getSema().Owned(ME);
1390 }
Mike Stump11289f42009-09-09 15:08:12 +00001391
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001392 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001393 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001394
John Wiegley01296292011-04-08 18:41:53 +00001395 ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base);
1396 if (BaseResult.isInvalid())
1397 return ExprError();
1398 Base = BaseResult.take();
John McCallb268a282010-08-23 23:25:46 +00001399 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001400
John McCall16df1e52010-03-30 21:47:33 +00001401 // FIXME: this involves duplicating earlier analysis in a lot of
1402 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001403 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001404 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001405 R.resolveKind();
1406
John McCallb268a282010-08-23 23:25:46 +00001407 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001408 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001409 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001410 }
Mike Stump11289f42009-09-09 15:08:12 +00001411
Douglas Gregora16548e2009-08-11 05:31:07 +00001412 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001413 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001414 /// By default, performs semantic analysis to build the new expression.
1415 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001416 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001417 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001418 Expr *LHS, Expr *RHS) {
1419 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001420 }
1421
1422 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001423 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001424 /// By default, performs semantic analysis to build the new expression.
1425 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001426 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001427 SourceLocation QuestionLoc,
1428 Expr *LHS,
1429 SourceLocation ColonLoc,
1430 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001431 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1432 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001433 }
1434
Douglas Gregora16548e2009-08-11 05:31:07 +00001435 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001436 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001437 /// By default, performs semantic analysis to build the new expression.
1438 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001439 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001440 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001441 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001442 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001443 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001444 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001445 }
Mike Stump11289f42009-09-09 15:08:12 +00001446
Douglas Gregora16548e2009-08-11 05:31:07 +00001447 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001448 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001449 /// By default, performs semantic analysis to build the new expression.
1450 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001451 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001452 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001453 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001454 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001455 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001456 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001457 }
Mike Stump11289f42009-09-09 15:08:12 +00001458
Douglas Gregora16548e2009-08-11 05:31:07 +00001459 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001460 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001461 /// By default, performs semantic analysis to build the new expression.
1462 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001463 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001464 SourceLocation OpLoc,
1465 SourceLocation AccessorLoc,
1466 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001467
John McCall10eae182009-11-30 22:42:35 +00001468 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001469 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001470 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001471 OpLoc, /*IsArrow*/ false,
1472 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001473 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001474 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001475 }
Mike Stump11289f42009-09-09 15:08:12 +00001476
Douglas Gregora16548e2009-08-11 05:31:07 +00001477 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001478 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001479 /// By default, performs semantic analysis to build the new expression.
1480 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001481 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001482 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001483 SourceLocation RBraceLoc,
1484 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001485 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001486 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1487 if (Result.isInvalid() || ResultTy->isDependentType())
1488 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001489
Douglas Gregord3d93062009-11-09 17:16:50 +00001490 // Patch in the result type we were given, which may have been computed
1491 // when the initial InitListExpr was built.
1492 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1493 ILE->setType(ResultTy);
1494 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001495 }
Mike Stump11289f42009-09-09 15:08:12 +00001496
Douglas Gregora16548e2009-08-11 05:31:07 +00001497 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001498 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001499 /// By default, performs semantic analysis to build the new expression.
1500 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001501 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001502 MultiExprArg ArrayExprs,
1503 SourceLocation EqualOrColonLoc,
1504 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001505 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001506 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001507 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001508 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001509 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001510 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001511
Douglas Gregora16548e2009-08-11 05:31:07 +00001512 ArrayExprs.release();
1513 return move(Result);
1514 }
Mike Stump11289f42009-09-09 15:08:12 +00001515
Douglas Gregora16548e2009-08-11 05:31:07 +00001516 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001517 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001518 /// By default, builds the implicit value initialization without performing
1519 /// any semantic analysis. Subclasses may override this routine to provide
1520 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001521 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1523 }
Mike Stump11289f42009-09-09 15:08:12 +00001524
Douglas Gregora16548e2009-08-11 05:31:07 +00001525 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001526 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001527 /// By default, performs semantic analysis to build the new expression.
1528 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001529 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001530 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001531 SourceLocation RParenLoc) {
1532 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001533 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001534 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001535 }
1536
1537 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001538 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001539 /// By default, performs semantic analysis to build the new expression.
1540 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001541 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001542 MultiExprArg SubExprs,
1543 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001544 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001545 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001546 }
Mike Stump11289f42009-09-09 15:08:12 +00001547
Douglas Gregora16548e2009-08-11 05:31:07 +00001548 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001549 ///
1550 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001551 /// rather than attempting to map the label statement itself.
1552 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001553 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001554 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001555 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001556 }
Mike Stump11289f42009-09-09 15:08:12 +00001557
Douglas Gregora16548e2009-08-11 05:31:07 +00001558 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001559 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001560 /// By default, performs semantic analysis to build the new expression.
1561 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001562 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001563 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001564 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001565 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001566 }
Mike Stump11289f42009-09-09 15:08:12 +00001567
Douglas Gregora16548e2009-08-11 05:31:07 +00001568 /// \brief Build a new __builtin_choose_expr expression.
1569 ///
1570 /// By default, performs semantic analysis to build the new expression.
1571 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001572 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001573 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001574 SourceLocation RParenLoc) {
1575 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001576 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001577 RParenLoc);
1578 }
Mike Stump11289f42009-09-09 15:08:12 +00001579
Douglas Gregora16548e2009-08-11 05:31:07 +00001580 /// \brief Build a new overloaded operator call expression.
1581 ///
1582 /// By default, performs semantic analysis to build the new expression.
1583 /// The semantic analysis provides the behavior of template instantiation,
1584 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001585 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001586 /// argument-dependent lookup, etc. Subclasses may override this routine to
1587 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001588 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001589 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001590 Expr *Callee,
1591 Expr *First,
1592 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001593
1594 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001595 /// reinterpret_cast.
1596 ///
1597 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001598 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001599 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001600 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001601 Stmt::StmtClass Class,
1602 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001603 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001604 SourceLocation RAngleLoc,
1605 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001606 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001607 SourceLocation RParenLoc) {
1608 switch (Class) {
1609 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001610 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001611 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001612 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001613
1614 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001615 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001616 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001617 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001618
Douglas Gregora16548e2009-08-11 05:31:07 +00001619 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001620 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001621 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001622 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001623 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001624
Douglas Gregora16548e2009-08-11 05:31:07 +00001625 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001626 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001627 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001628 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001629
Douglas Gregora16548e2009-08-11 05:31:07 +00001630 default:
1631 assert(false && "Invalid C++ named cast");
1632 break;
1633 }
Mike Stump11289f42009-09-09 15:08:12 +00001634
John McCallfaf5fb42010-08-26 23:41:50 +00001635 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001636 }
Mike Stump11289f42009-09-09 15:08:12 +00001637
Douglas Gregora16548e2009-08-11 05:31:07 +00001638 /// \brief Build a new C++ static_cast expression.
1639 ///
1640 /// By default, performs semantic analysis to build the new expression.
1641 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001642 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001643 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001644 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001645 SourceLocation RAngleLoc,
1646 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001647 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001648 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001649 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001650 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001651 SourceRange(LAngleLoc, RAngleLoc),
1652 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001653 }
1654
1655 /// \brief Build a new C++ dynamic_cast expression.
1656 ///
1657 /// By default, performs semantic analysis to build the new expression.
1658 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001659 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001660 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001661 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001662 SourceLocation RAngleLoc,
1663 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001664 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001665 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001666 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001667 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001668 SourceRange(LAngleLoc, RAngleLoc),
1669 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001670 }
1671
1672 /// \brief Build a new C++ reinterpret_cast expression.
1673 ///
1674 /// By default, performs semantic analysis to build the new expression.
1675 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001676 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001677 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001678 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001679 SourceLocation RAngleLoc,
1680 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001681 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001682 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001683 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001684 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001685 SourceRange(LAngleLoc, RAngleLoc),
1686 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001687 }
1688
1689 /// \brief Build a new C++ const_cast expression.
1690 ///
1691 /// By default, performs semantic analysis to build the new expression.
1692 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001693 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001694 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001695 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001696 SourceLocation RAngleLoc,
1697 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001698 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001699 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001700 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001701 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001702 SourceRange(LAngleLoc, RAngleLoc),
1703 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001704 }
Mike Stump11289f42009-09-09 15:08:12 +00001705
Douglas Gregora16548e2009-08-11 05:31:07 +00001706 /// \brief Build a new C++ functional-style cast expression.
1707 ///
1708 /// By default, performs semantic analysis to build the new expression.
1709 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001710 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1711 SourceLocation LParenLoc,
1712 Expr *Sub,
1713 SourceLocation RParenLoc) {
1714 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001715 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001716 RParenLoc);
1717 }
Mike Stump11289f42009-09-09 15:08:12 +00001718
Douglas Gregora16548e2009-08-11 05:31:07 +00001719 /// \brief Build a new C++ typeid(type) expression.
1720 ///
1721 /// By default, performs semantic analysis to build the new expression.
1722 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001723 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001724 SourceLocation TypeidLoc,
1725 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001726 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001727 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001728 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001729 }
Mike Stump11289f42009-09-09 15:08:12 +00001730
Francois Pichet9f4f2072010-09-08 12:20:18 +00001731
Douglas Gregora16548e2009-08-11 05:31:07 +00001732 /// \brief Build a new C++ typeid(expr) expression.
1733 ///
1734 /// By default, performs semantic analysis to build the new expression.
1735 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001736 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001737 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001738 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001739 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001740 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001741 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001742 }
1743
Francois Pichet9f4f2072010-09-08 12:20:18 +00001744 /// \brief Build a new C++ __uuidof(type) expression.
1745 ///
1746 /// By default, performs semantic analysis to build the new expression.
1747 /// Subclasses may override this routine to provide different behavior.
1748 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1749 SourceLocation TypeidLoc,
1750 TypeSourceInfo *Operand,
1751 SourceLocation RParenLoc) {
1752 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1753 RParenLoc);
1754 }
1755
1756 /// \brief Build a new C++ __uuidof(expr) expression.
1757 ///
1758 /// By default, performs semantic analysis to build the new expression.
1759 /// Subclasses may override this routine to provide different behavior.
1760 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1761 SourceLocation TypeidLoc,
1762 Expr *Operand,
1763 SourceLocation RParenLoc) {
1764 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1765 RParenLoc);
1766 }
1767
Douglas Gregora16548e2009-08-11 05:31:07 +00001768 /// \brief Build a new C++ "this" expression.
1769 ///
1770 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001771 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001772 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001773 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001774 QualType ThisType,
1775 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001776 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001777 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1778 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001779 }
1780
1781 /// \brief Build a new C++ throw expression.
1782 ///
1783 /// By default, performs semantic analysis to build the new expression.
1784 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001785 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001786 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001787 }
1788
1789 /// \brief Build a new C++ default-argument expression.
1790 ///
1791 /// By default, builds a new default-argument expression, which does not
1792 /// require any semantic analysis. Subclasses may override this routine to
1793 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001794 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001795 ParmVarDecl *Param) {
1796 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1797 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001798 }
1799
1800 /// \brief Build a new C++ zero-initialization expression.
1801 ///
1802 /// By default, performs semantic analysis to build the new expression.
1803 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001804 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1805 SourceLocation LParenLoc,
1806 SourceLocation RParenLoc) {
1807 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001808 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001809 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001810 }
Mike Stump11289f42009-09-09 15:08:12 +00001811
Douglas Gregora16548e2009-08-11 05:31:07 +00001812 /// \brief Build a new C++ "new" expression.
1813 ///
1814 /// By default, performs semantic analysis to build the new expression.
1815 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001816 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001817 bool UseGlobal,
1818 SourceLocation PlacementLParen,
1819 MultiExprArg PlacementArgs,
1820 SourceLocation PlacementRParen,
1821 SourceRange TypeIdParens,
1822 QualType AllocatedType,
1823 TypeSourceInfo *AllocatedTypeInfo,
1824 Expr *ArraySize,
1825 SourceLocation ConstructorLParen,
1826 MultiExprArg ConstructorArgs,
1827 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001828 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001829 PlacementLParen,
1830 move(PlacementArgs),
1831 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001832 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001833 AllocatedType,
1834 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001835 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001836 ConstructorLParen,
1837 move(ConstructorArgs),
1838 ConstructorRParen);
1839 }
Mike Stump11289f42009-09-09 15:08:12 +00001840
Douglas Gregora16548e2009-08-11 05:31:07 +00001841 /// \brief Build a new C++ "delete" expression.
1842 ///
1843 /// By default, performs semantic analysis to build the new expression.
1844 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001845 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001846 bool IsGlobalDelete,
1847 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001848 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001849 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001850 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001851 }
Mike Stump11289f42009-09-09 15:08:12 +00001852
Douglas Gregora16548e2009-08-11 05:31:07 +00001853 /// \brief Build a new unary type trait expression.
1854 ///
1855 /// By default, performs semantic analysis to build the new expression.
1856 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001857 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001858 SourceLocation StartLoc,
1859 TypeSourceInfo *T,
1860 SourceLocation RParenLoc) {
1861 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001862 }
1863
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001864 /// \brief Build a new binary type trait expression.
1865 ///
1866 /// By default, performs semantic analysis to build the new expression.
1867 /// Subclasses may override this routine to provide different behavior.
1868 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1869 SourceLocation StartLoc,
1870 TypeSourceInfo *LhsT,
1871 TypeSourceInfo *RhsT,
1872 SourceLocation RParenLoc) {
1873 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1874 }
1875
Mike Stump11289f42009-09-09 15:08:12 +00001876 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001877 /// expression.
1878 ///
1879 /// By default, performs semantic analysis to build the new expression.
1880 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001881 ExprResult RebuildDependentScopeDeclRefExpr(
1882 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001883 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001884 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001885 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001886 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00001887
1888 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001889 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001890 *TemplateArgs);
1891
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001892 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001893 }
1894
1895 /// \brief Build a new template-id 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 RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001900 LookupResult &R,
1901 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001902 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001903 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001904 }
1905
1906 /// \brief Build a new object-construction expression.
1907 ///
1908 /// By default, performs semantic analysis to build the new expression.
1909 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001910 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001911 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001912 CXXConstructorDecl *Constructor,
1913 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001914 MultiExprArg Args,
1915 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001916 CXXConstructExpr::ConstructionKind ConstructKind,
1917 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001918 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001919 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001920 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001921 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001922
Douglas Gregordb121ba2009-12-14 16:27:04 +00001923 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001924 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001925 RequiresZeroInit, ConstructKind,
1926 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 }
1928
1929 /// \brief Build a new object-construction expression.
1930 ///
1931 /// By default, performs semantic analysis to build the new expression.
1932 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001933 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1934 SourceLocation LParenLoc,
1935 MultiExprArg Args,
1936 SourceLocation RParenLoc) {
1937 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001938 LParenLoc,
1939 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 RParenLoc);
1941 }
1942
1943 /// \brief Build a new object-construction expression.
1944 ///
1945 /// By default, performs semantic analysis to build the new expression.
1946 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001947 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1948 SourceLocation LParenLoc,
1949 MultiExprArg Args,
1950 SourceLocation RParenLoc) {
1951 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 LParenLoc,
1953 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001954 RParenLoc);
1955 }
Mike Stump11289f42009-09-09 15:08:12 +00001956
Douglas Gregora16548e2009-08-11 05:31:07 +00001957 /// \brief Build a new member reference expression.
1958 ///
1959 /// By default, performs semantic analysis to build the new expression.
1960 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001961 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00001962 QualType BaseType,
1963 bool IsArrow,
1964 SourceLocation OperatorLoc,
1965 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00001966 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001967 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001968 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001969 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00001970 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001971
John McCallb268a282010-08-23 23:25:46 +00001972 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001973 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001974 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001975 MemberNameInfo,
1976 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001977 }
1978
John McCall10eae182009-11-30 22:42:35 +00001979 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001980 ///
1981 /// By default, performs semantic analysis to build the new expression.
1982 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001983 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001984 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001985 SourceLocation OperatorLoc,
1986 bool IsArrow,
Douglas Gregor0da1d432011-02-28 20:01:57 +00001987 NestedNameSpecifierLoc QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00001988 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001989 LookupResult &R,
1990 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001991 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00001992 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001993
John McCallb268a282010-08-23 23:25:46 +00001994 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001995 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001996 SS, FirstQualifierInScope,
1997 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001998 }
Mike Stump11289f42009-09-09 15:08:12 +00001999
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002000 /// \brief Build a new noexcept expression.
2001 ///
2002 /// By default, performs semantic analysis to build the new expression.
2003 /// Subclasses may override this routine to provide different behavior.
2004 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2005 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2006 }
2007
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002008 /// \brief Build a new expression to compute the length of a parameter pack.
2009 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2010 SourceLocation PackLoc,
2011 SourceLocation RParenLoc,
2012 unsigned Length) {
2013 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2014 OperatorLoc, Pack, PackLoc,
2015 RParenLoc, Length);
2016 }
2017
Douglas Gregora16548e2009-08-11 05:31:07 +00002018 /// \brief Build a new Objective-C @encode expression.
2019 ///
2020 /// By default, performs semantic analysis to build the new expression.
2021 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002022 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002023 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002024 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002025 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002026 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002027 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002028
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002029 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002030 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002031 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002032 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002033 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002034 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002035 MultiExprArg Args,
2036 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002037 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2038 ReceiverTypeInfo->getType(),
2039 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002040 Sel, Method, LBracLoc, SelectorLoc,
2041 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002042 }
2043
2044 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002045 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002046 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002047 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002048 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002049 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002050 MultiExprArg Args,
2051 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002052 return SemaRef.BuildInstanceMessage(Receiver,
2053 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002054 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002055 Sel, Method, LBracLoc, SelectorLoc,
2056 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002057 }
2058
Douglas Gregord51d90d2010-04-26 20:11:03 +00002059 /// \brief Build a new Objective-C ivar reference expression.
2060 ///
2061 /// By default, performs semantic analysis to build the new expression.
2062 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002063 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002064 SourceLocation IvarLoc,
2065 bool IsArrow, bool IsFreeIvar) {
2066 // FIXME: We lose track of the IsFreeIvar bit.
2067 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002068 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002069 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2070 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002071 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002072 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002073 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002074 false);
John Wiegley01296292011-04-08 18:41:53 +00002075 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002076 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002077
Douglas Gregord51d90d2010-04-26 20:11:03 +00002078 if (Result.get())
2079 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002080
John Wiegley01296292011-04-08 18:41:53 +00002081 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002082 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002083 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002084 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002085 /*TemplateArgs=*/0);
2086 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002087
2088 /// \brief Build a new Objective-C property reference expression.
2089 ///
2090 /// By default, performs semantic analysis to build the new expression.
2091 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002092 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002093 ObjCPropertyDecl *Property,
2094 SourceLocation PropertyLoc) {
2095 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002096 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002097 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2098 Sema::LookupMemberName);
2099 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002100 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002101 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002102 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002103 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002104 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002105
Douglas Gregor9faee212010-04-26 20:47:02 +00002106 if (Result.get())
2107 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002108
John Wiegley01296292011-04-08 18:41:53 +00002109 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002110 /*FIXME:*/PropertyLoc, IsArrow,
2111 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002112 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002113 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002114 /*TemplateArgs=*/0);
2115 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002116
John McCallb7bd14f2010-12-02 01:19:52 +00002117 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002118 ///
2119 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002120 /// Subclasses may override this routine to provide different behavior.
2121 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2122 ObjCMethodDecl *Getter,
2123 ObjCMethodDecl *Setter,
2124 SourceLocation PropertyLoc) {
2125 // Since these expressions can only be value-dependent, we do not
2126 // need to perform semantic analysis again.
2127 return Owned(
2128 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2129 VK_LValue, OK_ObjCProperty,
2130 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002131 }
2132
Douglas Gregord51d90d2010-04-26 20:11:03 +00002133 /// \brief Build a new Objective-C "isa" expression.
2134 ///
2135 /// By default, performs semantic analysis to build the new expression.
2136 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002137 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002138 bool IsArrow) {
2139 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002140 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002141 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2142 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002143 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002144 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002145 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002146 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002147 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002148
Douglas Gregord51d90d2010-04-26 20:11:03 +00002149 if (Result.get())
2150 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002151
John Wiegley01296292011-04-08 18:41:53 +00002152 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002153 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002154 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002155 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002156 /*TemplateArgs=*/0);
2157 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002158
Douglas Gregora16548e2009-08-11 05:31:07 +00002159 /// \brief Build a new shuffle vector expression.
2160 ///
2161 /// By default, performs semantic analysis to build the new expression.
2162 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002163 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002164 MultiExprArg SubExprs,
2165 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002166 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002167 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002168 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2169 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2170 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2171 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002172
Douglas Gregora16548e2009-08-11 05:31:07 +00002173 // Build a reference to the __builtin_shufflevector builtin
2174 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley01296292011-04-08 18:41:53 +00002175 ExprResult Callee
2176 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2177 VK_LValue, BuiltinLoc));
2178 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2179 if (Callee.isInvalid())
2180 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002181
2182 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002183 unsigned NumSubExprs = SubExprs.size();
2184 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley01296292011-04-08 18:41:53 +00002185 ExprResult TheCall = SemaRef.Owned(
2186 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregora16548e2009-08-11 05:31:07 +00002187 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002188 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002189 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley01296292011-04-08 18:41:53 +00002190 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002191
Douglas Gregora16548e2009-08-11 05:31:07 +00002192 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002193 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002194 }
John McCall31f82722010-11-12 08:19:04 +00002195
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002196 /// \brief Build a new template argument pack expansion.
2197 ///
2198 /// By default, performs semantic analysis to build a new pack expansion
2199 /// for a template argument. Subclasses may override this routine to provide
2200 /// different behavior.
2201 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002202 SourceLocation EllipsisLoc,
2203 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002204 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002205 case TemplateArgument::Expression: {
2206 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002207 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2208 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002209 if (Result.isInvalid())
2210 return TemplateArgumentLoc();
2211
2212 return TemplateArgumentLoc(Result.get(), Result.get());
2213 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002214
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002215 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002216 return TemplateArgumentLoc(TemplateArgument(
2217 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002218 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002219 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002220 Pattern.getTemplateNameLoc(),
2221 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002222
2223 case TemplateArgument::Null:
2224 case TemplateArgument::Integral:
2225 case TemplateArgument::Declaration:
2226 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002227 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002228 llvm_unreachable("Pack expansion pattern has no parameter packs");
2229
2230 case TemplateArgument::Type:
2231 if (TypeSourceInfo *Expansion
2232 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002233 EllipsisLoc,
2234 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002235 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2236 Expansion);
2237 break;
2238 }
2239
2240 return TemplateArgumentLoc();
2241 }
2242
Douglas Gregor968f23a2011-01-03 19:31:53 +00002243 /// \brief Build a new expression pack expansion.
2244 ///
2245 /// By default, performs semantic analysis to build a new pack expansion
2246 /// for an expression. Subclasses may override this routine to provide
2247 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002248 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2249 llvm::Optional<unsigned> NumExpansions) {
2250 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002251 }
2252
John McCall31f82722010-11-12 08:19:04 +00002253private:
Douglas Gregor14454802011-02-25 02:25:35 +00002254 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2255 QualType ObjectType,
2256 NamedDecl *FirstQualifierInScope,
2257 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002258
2259 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2260 QualType ObjectType,
2261 NamedDecl *FirstQualifierInScope,
2262 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002263};
Douglas Gregora16548e2009-08-11 05:31:07 +00002264
Douglas Gregorebe10102009-08-20 07:17:43 +00002265template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002266StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002267 if (!S)
2268 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002269
Douglas Gregorebe10102009-08-20 07:17:43 +00002270 switch (S->getStmtClass()) {
2271 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002272
Douglas Gregorebe10102009-08-20 07:17:43 +00002273 // Transform individual statement nodes
2274#define STMT(Node, Parent) \
2275 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002276#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002277#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002278#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002279
Douglas Gregorebe10102009-08-20 07:17:43 +00002280 // Transform expressions by calling TransformExpr.
2281#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002282#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002283#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002284#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002285 {
John McCalldadc5752010-08-24 06:29:42 +00002286 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002287 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002288 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002289
John McCallb268a282010-08-23 23:25:46 +00002290 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002291 }
Mike Stump11289f42009-09-09 15:08:12 +00002292 }
2293
John McCallc3007a22010-10-26 07:05:15 +00002294 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002295}
Mike Stump11289f42009-09-09 15:08:12 +00002296
2297
Douglas Gregore922c772009-08-04 22:27:00 +00002298template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002299ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002300 if (!E)
2301 return SemaRef.Owned(E);
2302
2303 switch (E->getStmtClass()) {
2304 case Stmt::NoStmtClass: break;
2305#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002306#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002307#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002308 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002309#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002310 }
2311
John McCallc3007a22010-10-26 07:05:15 +00002312 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002313}
2314
2315template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002316bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2317 unsigned NumInputs,
2318 bool IsCall,
2319 llvm::SmallVectorImpl<Expr *> &Outputs,
2320 bool *ArgChanged) {
2321 for (unsigned I = 0; I != NumInputs; ++I) {
2322 // If requested, drop call arguments that need to be dropped.
2323 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2324 if (ArgChanged)
2325 *ArgChanged = true;
2326
2327 break;
2328 }
2329
Douglas Gregor968f23a2011-01-03 19:31:53 +00002330 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2331 Expr *Pattern = Expansion->getPattern();
2332
2333 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2334 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2335 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2336
2337 // Determine whether the set of unexpanded parameter packs can and should
2338 // be expanded.
2339 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002340 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002341 llvm::Optional<unsigned> OrigNumExpansions
2342 = Expansion->getNumExpansions();
2343 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002344 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2345 Pattern->getSourceRange(),
2346 Unexpanded.data(),
2347 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002348 Expand, RetainExpansion,
2349 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002350 return true;
2351
2352 if (!Expand) {
2353 // The transform has determined that we should perform a simple
2354 // transformation on the pack expansion, producing another pack
2355 // expansion.
2356 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2357 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2358 if (OutPattern.isInvalid())
2359 return true;
2360
2361 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002362 Expansion->getEllipsisLoc(),
2363 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002364 if (Out.isInvalid())
2365 return true;
2366
2367 if (ArgChanged)
2368 *ArgChanged = true;
2369 Outputs.push_back(Out.get());
2370 continue;
2371 }
2372
2373 // The transform has determined that we should perform an elementwise
2374 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002375 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002376 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2377 ExprResult Out = getDerived().TransformExpr(Pattern);
2378 if (Out.isInvalid())
2379 return true;
2380
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002381 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002382 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2383 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002384 if (Out.isInvalid())
2385 return true;
2386 }
2387
Douglas Gregor968f23a2011-01-03 19:31:53 +00002388 if (ArgChanged)
2389 *ArgChanged = true;
2390 Outputs.push_back(Out.get());
2391 }
2392
2393 continue;
2394 }
2395
Douglas Gregora3efea12011-01-03 19:04:46 +00002396 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2397 if (Result.isInvalid())
2398 return true;
2399
2400 if (Result.get() != Inputs[I] && ArgChanged)
2401 *ArgChanged = true;
2402
2403 Outputs.push_back(Result.get());
2404 }
2405
2406 return false;
2407}
2408
2409template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002410NestedNameSpecifierLoc
2411TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2412 NestedNameSpecifierLoc NNS,
2413 QualType ObjectType,
2414 NamedDecl *FirstQualifierInScope) {
2415 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2416 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2417 Qualifier = Qualifier.getPrefix())
2418 Qualifiers.push_back(Qualifier);
2419
2420 CXXScopeSpec SS;
2421 while (!Qualifiers.empty()) {
2422 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2423 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2424
2425 switch (QNNS->getKind()) {
2426 case NestedNameSpecifier::Identifier:
2427 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2428 *QNNS->getAsIdentifier(),
2429 Q.getLocalBeginLoc(),
2430 Q.getLocalEndLoc(),
2431 ObjectType, false, SS,
2432 FirstQualifierInScope, false))
2433 return NestedNameSpecifierLoc();
2434
2435 break;
2436
2437 case NestedNameSpecifier::Namespace: {
2438 NamespaceDecl *NS
2439 = cast_or_null<NamespaceDecl>(
2440 getDerived().TransformDecl(
2441 Q.getLocalBeginLoc(),
2442 QNNS->getAsNamespace()));
2443 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2444 break;
2445 }
2446
2447 case NestedNameSpecifier::NamespaceAlias: {
2448 NamespaceAliasDecl *Alias
2449 = cast_or_null<NamespaceAliasDecl>(
2450 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2451 QNNS->getAsNamespaceAlias()));
2452 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2453 Q.getLocalEndLoc());
2454 break;
2455 }
2456
2457 case NestedNameSpecifier::Global:
2458 // There is no meaningful transformation that one could perform on the
2459 // global scope.
2460 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2461 break;
2462
2463 case NestedNameSpecifier::TypeSpecWithTemplate:
2464 case NestedNameSpecifier::TypeSpec: {
2465 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2466 FirstQualifierInScope, SS);
2467
2468 if (!TL)
2469 return NestedNameSpecifierLoc();
2470
2471 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2472 (SemaRef.getLangOptions().CPlusPlus0x &&
2473 TL.getType()->isEnumeralType())) {
2474 assert(!TL.getType().hasLocalQualifiers() &&
2475 "Can't get cv-qualifiers here");
2476 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2477 Q.getLocalEndLoc());
2478 break;
2479 }
2480
2481 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2482 << TL.getType() << SS.getRange();
2483 return NestedNameSpecifierLoc();
2484 }
Douglas Gregore16af532011-02-28 18:50:33 +00002485 }
Douglas Gregor14454802011-02-25 02:25:35 +00002486
Douglas Gregore16af532011-02-28 18:50:33 +00002487 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002488 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002489 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002490 }
2491
2492 // Don't rebuild the nested-name-specifier if we don't have to.
2493 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2494 !getDerived().AlwaysRebuild())
2495 return NNS;
2496
2497 // If we can re-use the source-location data from the original
2498 // nested-name-specifier, do so.
2499 if (SS.location_size() == NNS.getDataLength() &&
2500 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2501 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2502
2503 // Allocate new nested-name-specifier location information.
2504 return SS.getWithLocInContext(SemaRef.Context);
2505}
2506
2507template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002508DeclarationNameInfo
2509TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002510::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002511 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002512 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002513 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002514
2515 switch (Name.getNameKind()) {
2516 case DeclarationName::Identifier:
2517 case DeclarationName::ObjCZeroArgSelector:
2518 case DeclarationName::ObjCOneArgSelector:
2519 case DeclarationName::ObjCMultiArgSelector:
2520 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002521 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002522 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002523 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002524
Douglas Gregorf816bd72009-09-03 22:13:48 +00002525 case DeclarationName::CXXConstructorName:
2526 case DeclarationName::CXXDestructorName:
2527 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002528 TypeSourceInfo *NewTInfo;
2529 CanQualType NewCanTy;
2530 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002531 NewTInfo = getDerived().TransformType(OldTInfo);
2532 if (!NewTInfo)
2533 return DeclarationNameInfo();
2534 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002535 }
2536 else {
2537 NewTInfo = 0;
2538 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002539 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002540 if (NewT.isNull())
2541 return DeclarationNameInfo();
2542 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2543 }
Mike Stump11289f42009-09-09 15:08:12 +00002544
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002545 DeclarationName NewName
2546 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2547 NewCanTy);
2548 DeclarationNameInfo NewNameInfo(NameInfo);
2549 NewNameInfo.setName(NewName);
2550 NewNameInfo.setNamedTypeInfo(NewTInfo);
2551 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002552 }
Mike Stump11289f42009-09-09 15:08:12 +00002553 }
2554
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002555 assert(0 && "Unknown name kind.");
2556 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002557}
2558
2559template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002560TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00002561TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2562 TemplateName Name,
2563 SourceLocation NameLoc,
2564 QualType ObjectType,
2565 NamedDecl *FirstQualifierInScope) {
2566 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2567 TemplateDecl *Template = QTN->getTemplateDecl();
2568 assert(Template && "qualified template name must refer to a template");
2569
2570 TemplateDecl *TransTemplate
2571 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2572 Template));
2573 if (!TransTemplate)
2574 return TemplateName();
2575
2576 if (!getDerived().AlwaysRebuild() &&
2577 SS.getScopeRep() == QTN->getQualifier() &&
2578 TransTemplate == Template)
2579 return Name;
2580
2581 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2582 TransTemplate);
2583 }
2584
2585 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2586 if (SS.getScopeRep()) {
2587 // These apply to the scope specifier, not the template.
2588 ObjectType = QualType();
2589 FirstQualifierInScope = 0;
2590 }
2591
2592 if (!getDerived().AlwaysRebuild() &&
2593 SS.getScopeRep() == DTN->getQualifier() &&
2594 ObjectType.isNull())
2595 return Name;
2596
2597 if (DTN->isIdentifier()) {
2598 return getDerived().RebuildTemplateName(SS,
2599 *DTN->getIdentifier(),
2600 NameLoc,
2601 ObjectType,
2602 FirstQualifierInScope);
2603 }
2604
2605 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2606 ObjectType);
2607 }
2608
2609 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2610 TemplateDecl *TransTemplate
2611 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2612 Template));
2613 if (!TransTemplate)
2614 return TemplateName();
2615
2616 if (!getDerived().AlwaysRebuild() &&
2617 TransTemplate == Template)
2618 return Name;
2619
2620 return TemplateName(TransTemplate);
2621 }
2622
2623 if (SubstTemplateTemplateParmPackStorage *SubstPack
2624 = Name.getAsSubstTemplateTemplateParmPack()) {
2625 TemplateTemplateParmDecl *TransParam
2626 = cast_or_null<TemplateTemplateParmDecl>(
2627 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2628 if (!TransParam)
2629 return TemplateName();
2630
2631 if (!getDerived().AlwaysRebuild() &&
2632 TransParam == SubstPack->getParameterPack())
2633 return Name;
2634
2635 return getDerived().RebuildTemplateName(TransParam,
2636 SubstPack->getArgumentPack());
2637 }
2638
2639 // These should be getting filtered out before they reach the AST.
2640 llvm_unreachable("overloaded function decl survived to here");
2641 return TemplateName();
2642}
2643
2644template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002645void TreeTransform<Derived>::InventTemplateArgumentLoc(
2646 const TemplateArgument &Arg,
2647 TemplateArgumentLoc &Output) {
2648 SourceLocation Loc = getDerived().getBaseLocation();
2649 switch (Arg.getKind()) {
2650 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002651 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002652 break;
2653
2654 case TemplateArgument::Type:
2655 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002656 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002657
John McCall0ad16662009-10-29 08:12:44 +00002658 break;
2659
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002660 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00002661 case TemplateArgument::TemplateExpansion: {
2662 NestedNameSpecifierLocBuilder Builder;
2663 TemplateName Template = Arg.getAsTemplate();
2664 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2665 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2666 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2667 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2668
2669 if (Arg.getKind() == TemplateArgument::Template)
2670 Output = TemplateArgumentLoc(Arg,
2671 Builder.getWithLocInContext(SemaRef.Context),
2672 Loc);
2673 else
2674 Output = TemplateArgumentLoc(Arg,
2675 Builder.getWithLocInContext(SemaRef.Context),
2676 Loc, Loc);
2677
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002678 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00002679 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002680
John McCall0ad16662009-10-29 08:12:44 +00002681 case TemplateArgument::Expression:
2682 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2683 break;
2684
2685 case TemplateArgument::Declaration:
2686 case TemplateArgument::Integral:
2687 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002688 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002689 break;
2690 }
2691}
2692
2693template<typename Derived>
2694bool TreeTransform<Derived>::TransformTemplateArgument(
2695 const TemplateArgumentLoc &Input,
2696 TemplateArgumentLoc &Output) {
2697 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002698 switch (Arg.getKind()) {
2699 case TemplateArgument::Null:
2700 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002701 Output = Input;
2702 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002703
Douglas Gregore922c772009-08-04 22:27:00 +00002704 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002705 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002706 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002707 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002708
2709 DI = getDerived().TransformType(DI);
2710 if (!DI) return true;
2711
2712 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2713 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002714 }
Mike Stump11289f42009-09-09 15:08:12 +00002715
Douglas Gregore922c772009-08-04 22:27:00 +00002716 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002717 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002718 DeclarationName Name;
2719 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2720 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002721 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002722 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002723 if (!D) return true;
2724
John McCall0d07eb32009-10-29 18:45:58 +00002725 Expr *SourceExpr = Input.getSourceDeclExpression();
2726 if (SourceExpr) {
2727 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002728 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002729 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002730 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002731 }
2732
2733 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002734 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002735 }
Mike Stump11289f42009-09-09 15:08:12 +00002736
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002737 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00002738 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2739 if (QualifierLoc) {
2740 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2741 if (!QualifierLoc)
2742 return true;
2743 }
2744
Douglas Gregordf846d12011-03-02 18:46:51 +00002745 CXXScopeSpec SS;
2746 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002747 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00002748 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2749 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002750 if (Template.isNull())
2751 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002752
Douglas Gregor9d802122011-03-02 17:09:35 +00002753 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002754 Input.getTemplateNameLoc());
2755 return false;
2756 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002757
2758 case TemplateArgument::TemplateExpansion:
2759 llvm_unreachable("Caller should expand pack expansions");
2760
Douglas Gregore922c772009-08-04 22:27:00 +00002761 case TemplateArgument::Expression: {
2762 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002763 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002764 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002765
John McCall0ad16662009-10-29 08:12:44 +00002766 Expr *InputExpr = Input.getSourceExpression();
2767 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2768
John McCalldadc5752010-08-24 06:29:42 +00002769 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002770 = getDerived().TransformExpr(InputExpr);
2771 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002772 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002773 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002774 }
Mike Stump11289f42009-09-09 15:08:12 +00002775
Douglas Gregore922c772009-08-04 22:27:00 +00002776 case TemplateArgument::Pack: {
2777 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2778 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002779 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002780 AEnd = Arg.pack_end();
2781 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002782
John McCall0ad16662009-10-29 08:12:44 +00002783 // FIXME: preserve source information here when we start
2784 // caring about parameter packs.
2785
John McCall0d07eb32009-10-29 18:45:58 +00002786 TemplateArgumentLoc InputArg;
2787 TemplateArgumentLoc OutputArg;
2788 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2789 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002790 return true;
2791
John McCall0d07eb32009-10-29 18:45:58 +00002792 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002793 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002794
2795 TemplateArgument *TransformedArgsPtr
2796 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2797 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2798 TransformedArgsPtr);
2799 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2800 TransformedArgs.size()),
2801 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002802 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002803 }
2804 }
Mike Stump11289f42009-09-09 15:08:12 +00002805
Douglas Gregore922c772009-08-04 22:27:00 +00002806 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002807 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002808}
2809
Douglas Gregorfe921a72010-12-20 23:36:19 +00002810/// \brief Iterator adaptor that invents template argument location information
2811/// for each of the template arguments in its underlying iterator.
2812template<typename Derived, typename InputIterator>
2813class TemplateArgumentLocInventIterator {
2814 TreeTransform<Derived> &Self;
2815 InputIterator Iter;
2816
2817public:
2818 typedef TemplateArgumentLoc value_type;
2819 typedef TemplateArgumentLoc reference;
2820 typedef typename std::iterator_traits<InputIterator>::difference_type
2821 difference_type;
2822 typedef std::input_iterator_tag iterator_category;
2823
2824 class pointer {
2825 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002826
Douglas Gregorfe921a72010-12-20 23:36:19 +00002827 public:
2828 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2829
2830 const TemplateArgumentLoc *operator->() const { return &Arg; }
2831 };
2832
2833 TemplateArgumentLocInventIterator() { }
2834
2835 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2836 InputIterator Iter)
2837 : Self(Self), Iter(Iter) { }
2838
2839 TemplateArgumentLocInventIterator &operator++() {
2840 ++Iter;
2841 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002842 }
2843
Douglas Gregorfe921a72010-12-20 23:36:19 +00002844 TemplateArgumentLocInventIterator operator++(int) {
2845 TemplateArgumentLocInventIterator Old(*this);
2846 ++(*this);
2847 return Old;
2848 }
2849
2850 reference operator*() const {
2851 TemplateArgumentLoc Result;
2852 Self.InventTemplateArgumentLoc(*Iter, Result);
2853 return Result;
2854 }
2855
2856 pointer operator->() const { return pointer(**this); }
2857
2858 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2859 const TemplateArgumentLocInventIterator &Y) {
2860 return X.Iter == Y.Iter;
2861 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002862
Douglas Gregorfe921a72010-12-20 23:36:19 +00002863 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2864 const TemplateArgumentLocInventIterator &Y) {
2865 return X.Iter != Y.Iter;
2866 }
2867};
2868
Douglas Gregor42cafa82010-12-20 17:42:22 +00002869template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002870template<typename InputIterator>
2871bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2872 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002873 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002874 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002875 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002876 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002877
2878 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2879 // Unpack argument packs, which we translate them into separate
2880 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002881 // FIXME: We could do much better if we could guarantee that the
2882 // TemplateArgumentLocInfo for the pack expansion would be usable for
2883 // all of the template arguments in the argument pack.
2884 typedef TemplateArgumentLocInventIterator<Derived,
2885 TemplateArgument::pack_iterator>
2886 PackLocIterator;
2887 if (TransformTemplateArguments(PackLocIterator(*this,
2888 In.getArgument().pack_begin()),
2889 PackLocIterator(*this,
2890 In.getArgument().pack_end()),
2891 Outputs))
2892 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002893
2894 continue;
2895 }
2896
2897 if (In.getArgument().isPackExpansion()) {
2898 // We have a pack expansion, for which we will be substituting into
2899 // the pattern.
2900 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002901 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002902 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002903 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2904 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002905
2906 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2907 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2908 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2909
2910 // Determine whether the set of unexpanded parameter packs can and should
2911 // be expanded.
2912 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002913 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002914 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002915 if (getDerived().TryExpandParameterPacks(Ellipsis,
2916 Pattern.getSourceRange(),
2917 Unexpanded.data(),
2918 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002919 Expand,
2920 RetainExpansion,
2921 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002922 return true;
2923
2924 if (!Expand) {
2925 // The transform has determined that we should perform a simple
2926 // transformation on the pack expansion, producing another pack
2927 // expansion.
2928 TemplateArgumentLoc OutPattern;
2929 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2930 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2931 return true;
2932
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002933 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
2934 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002935 if (Out.getArgument().isNull())
2936 return true;
2937
2938 Outputs.addArgument(Out);
2939 continue;
2940 }
2941
2942 // The transform has determined that we should perform an elementwise
2943 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002944 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002945 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2946
2947 if (getDerived().TransformTemplateArgument(Pattern, Out))
2948 return true;
2949
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002950 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002951 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2952 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002953 if (Out.getArgument().isNull())
2954 return true;
2955 }
2956
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002957 Outputs.addArgument(Out);
2958 }
2959
Douglas Gregor48d24112011-01-10 20:53:55 +00002960 // If we're supposed to retain a pack expansion, do so by temporarily
2961 // forgetting the partially-substituted parameter pack.
2962 if (RetainExpansion) {
2963 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
2964
2965 if (getDerived().TransformTemplateArgument(Pattern, Out))
2966 return true;
2967
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002968 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2969 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00002970 if (Out.getArgument().isNull())
2971 return true;
2972
2973 Outputs.addArgument(Out);
2974 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002975
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002976 continue;
2977 }
2978
2979 // The simple case:
2980 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00002981 return true;
2982
2983 Outputs.addArgument(Out);
2984 }
2985
2986 return false;
2987
2988}
2989
Douglas Gregord6ff3322009-08-04 16:50:30 +00002990//===----------------------------------------------------------------------===//
2991// Type transformation
2992//===----------------------------------------------------------------------===//
2993
2994template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002995QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002996 if (getDerived().AlreadyTransformed(T))
2997 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002998
John McCall550e0c22009-10-21 00:40:46 +00002999 // Temporary workaround. All of these transformations should
3000 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003001 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3002 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003003
John McCall31f82722010-11-12 08:19:04 +00003004 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003005
John McCall550e0c22009-10-21 00:40:46 +00003006 if (!NewDI)
3007 return QualType();
3008
3009 return NewDI->getType();
3010}
3011
3012template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003013TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003014 if (getDerived().AlreadyTransformed(DI->getType()))
3015 return DI;
3016
3017 TypeLocBuilder TLB;
3018
3019 TypeLoc TL = DI->getTypeLoc();
3020 TLB.reserve(TL.getFullDataSize());
3021
John McCall31f82722010-11-12 08:19:04 +00003022 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003023 if (Result.isNull())
3024 return 0;
3025
John McCallbcd03502009-12-07 02:54:59 +00003026 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003027}
3028
3029template<typename Derived>
3030QualType
John McCall31f82722010-11-12 08:19:04 +00003031TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003032 switch (T.getTypeLocClass()) {
3033#define ABSTRACT_TYPELOC(CLASS, PARENT)
3034#define TYPELOC(CLASS, PARENT) \
3035 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003036 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003037#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003038 }
Mike Stump11289f42009-09-09 15:08:12 +00003039
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003040 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003041 return QualType();
3042}
3043
3044/// FIXME: By default, this routine adds type qualifiers only to types
3045/// that can have qualifiers, and silently suppresses those qualifiers
3046/// that are not permitted (e.g., qualifiers on reference or function
3047/// types). This is the right thing for template instantiation, but
3048/// probably not for other clients.
3049template<typename Derived>
3050QualType
3051TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003052 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003053 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003054
John McCall31f82722010-11-12 08:19:04 +00003055 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003056 if (Result.isNull())
3057 return QualType();
3058
3059 // Silently suppress qualifiers if the result type can't be qualified.
3060 // FIXME: this is the right thing for template instantiation, but
3061 // probably not for other clients.
3062 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003063 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003064
John McCallcb0f89a2010-06-05 06:41:15 +00003065 if (!Quals.empty()) {
3066 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3067 TLB.push<QualifiedTypeLoc>(Result);
3068 // No location information to preserve.
3069 }
John McCall550e0c22009-10-21 00:40:46 +00003070
3071 return Result;
3072}
3073
Douglas Gregor14454802011-02-25 02:25:35 +00003074template<typename Derived>
3075TypeLoc
3076TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3077 QualType ObjectType,
3078 NamedDecl *UnqualLookup,
3079 CXXScopeSpec &SS) {
Douglas Gregor14454802011-02-25 02:25:35 +00003080 QualType T = TL.getType();
3081 if (getDerived().AlreadyTransformed(T))
3082 return TL;
3083
3084 TypeLocBuilder TLB;
3085 QualType Result;
3086
3087 if (isa<TemplateSpecializationType>(T)) {
3088 TemplateSpecializationTypeLoc SpecTL
3089 = cast<TemplateSpecializationTypeLoc>(TL);
3090
3091 TemplateName Template =
Douglas Gregor9db53502011-03-02 18:07:45 +00003092 getDerived().TransformTemplateName(SS,
3093 SpecTL.getTypePtr()->getTemplateName(),
3094 SpecTL.getTemplateNameLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003095 ObjectType, UnqualLookup);
3096 if (Template.isNull())
3097 return TypeLoc();
3098
3099 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3100 Template);
3101 } else if (isa<DependentTemplateSpecializationType>(T)) {
3102 DependentTemplateSpecializationTypeLoc SpecTL
3103 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3104
Douglas Gregor5a064722011-02-28 17:23:35 +00003105 TemplateName Template
Douglas Gregor9db53502011-03-02 18:07:45 +00003106 = getDerived().RebuildTemplateName(SS,
Douglas Gregore16af532011-02-28 18:50:33 +00003107 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003108 SpecTL.getNameLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00003109 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003110 if (Template.isNull())
3111 return TypeLoc();
3112
Douglas Gregor14454802011-02-25 02:25:35 +00003113 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003114 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003115 Template,
3116 SS);
Douglas Gregor14454802011-02-25 02:25:35 +00003117 } else {
3118 // Nothing special needs to be done for these.
3119 Result = getDerived().TransformType(TLB, TL);
3120 }
3121
3122 if (Result.isNull())
3123 return TypeLoc();
3124
3125 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3126}
3127
Douglas Gregor579c15f2011-03-02 18:32:08 +00003128template<typename Derived>
3129TypeSourceInfo *
3130TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3131 QualType ObjectType,
3132 NamedDecl *UnqualLookup,
3133 CXXScopeSpec &SS) {
3134 // FIXME: Painfully copy-paste from the above!
3135
3136 QualType T = TSInfo->getType();
3137 if (getDerived().AlreadyTransformed(T))
3138 return TSInfo;
3139
3140 TypeLocBuilder TLB;
3141 QualType Result;
3142
3143 TypeLoc TL = TSInfo->getTypeLoc();
3144 if (isa<TemplateSpecializationType>(T)) {
3145 TemplateSpecializationTypeLoc SpecTL
3146 = cast<TemplateSpecializationTypeLoc>(TL);
3147
3148 TemplateName Template
3149 = getDerived().TransformTemplateName(SS,
3150 SpecTL.getTypePtr()->getTemplateName(),
3151 SpecTL.getTemplateNameLoc(),
3152 ObjectType, UnqualLookup);
3153 if (Template.isNull())
3154 return 0;
3155
3156 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3157 Template);
3158 } else if (isa<DependentTemplateSpecializationType>(T)) {
3159 DependentTemplateSpecializationTypeLoc SpecTL
3160 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3161
3162 TemplateName Template
3163 = getDerived().RebuildTemplateName(SS,
3164 *SpecTL.getTypePtr()->getIdentifier(),
3165 SpecTL.getNameLoc(),
3166 ObjectType, UnqualLookup);
3167 if (Template.isNull())
3168 return 0;
3169
3170 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3171 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003172 Template,
3173 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003174 } else {
3175 // Nothing special needs to be done for these.
3176 Result = getDerived().TransformType(TLB, TL);
3177 }
3178
3179 if (Result.isNull())
3180 return 0;
3181
3182 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3183}
3184
John McCall550e0c22009-10-21 00:40:46 +00003185template <class TyLoc> static inline
3186QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3187 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3188 NewT.setNameLoc(T.getNameLoc());
3189 return T.getType();
3190}
3191
John McCall550e0c22009-10-21 00:40:46 +00003192template<typename Derived>
3193QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003194 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003195 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3196 NewT.setBuiltinLoc(T.getBuiltinLoc());
3197 if (T.needsExtraLocalData())
3198 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3199 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003200}
Mike Stump11289f42009-09-09 15:08:12 +00003201
Douglas Gregord6ff3322009-08-04 16:50:30 +00003202template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003203QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003204 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003205 // FIXME: recurse?
3206 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003207}
Mike Stump11289f42009-09-09 15:08:12 +00003208
Douglas Gregord6ff3322009-08-04 16:50:30 +00003209template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003210QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003211 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003212 QualType PointeeType
3213 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003214 if (PointeeType.isNull())
3215 return QualType();
3216
3217 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003218 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003219 // A dependent pointer type 'T *' has is being transformed such
3220 // that an Objective-C class type is being replaced for 'T'. The
3221 // resulting pointer type is an ObjCObjectPointerType, not a
3222 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003223 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003224
John McCall8b07ec22010-05-15 11:32:37 +00003225 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3226 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003227 return Result;
3228 }
John McCall31f82722010-11-12 08:19:04 +00003229
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003230 if (getDerived().AlwaysRebuild() ||
3231 PointeeType != TL.getPointeeLoc().getType()) {
3232 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3233 if (Result.isNull())
3234 return QualType();
3235 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003236
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003237 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3238 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003239 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003240}
Mike Stump11289f42009-09-09 15:08:12 +00003241
3242template<typename Derived>
3243QualType
John McCall550e0c22009-10-21 00:40:46 +00003244TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003245 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003246 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003247 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3248 if (PointeeType.isNull())
3249 return QualType();
3250
3251 QualType Result = TL.getType();
3252 if (getDerived().AlwaysRebuild() ||
3253 PointeeType != TL.getPointeeLoc().getType()) {
3254 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003255 TL.getSigilLoc());
3256 if (Result.isNull())
3257 return QualType();
3258 }
3259
Douglas Gregor049211a2010-04-22 16:50:51 +00003260 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003261 NewT.setSigilLoc(TL.getSigilLoc());
3262 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003263}
3264
John McCall70dd5f62009-10-30 00:06:24 +00003265/// Transforms a reference type. Note that somewhat paradoxically we
3266/// don't care whether the type itself is an l-value type or an r-value
3267/// type; we only care if the type was *written* as an l-value type
3268/// or an r-value type.
3269template<typename Derived>
3270QualType
3271TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003272 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003273 const ReferenceType *T = TL.getTypePtr();
3274
3275 // Note that this works with the pointee-as-written.
3276 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3277 if (PointeeType.isNull())
3278 return QualType();
3279
3280 QualType Result = TL.getType();
3281 if (getDerived().AlwaysRebuild() ||
3282 PointeeType != T->getPointeeTypeAsWritten()) {
3283 Result = getDerived().RebuildReferenceType(PointeeType,
3284 T->isSpelledAsLValue(),
3285 TL.getSigilLoc());
3286 if (Result.isNull())
3287 return QualType();
3288 }
3289
3290 // r-value references can be rebuilt as l-value references.
3291 ReferenceTypeLoc NewTL;
3292 if (isa<LValueReferenceType>(Result))
3293 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3294 else
3295 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3296 NewTL.setSigilLoc(TL.getSigilLoc());
3297
3298 return Result;
3299}
3300
Mike Stump11289f42009-09-09 15:08:12 +00003301template<typename Derived>
3302QualType
John McCall550e0c22009-10-21 00:40:46 +00003303TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003304 LValueReferenceTypeLoc TL) {
3305 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003306}
3307
Mike Stump11289f42009-09-09 15:08:12 +00003308template<typename Derived>
3309QualType
John McCall550e0c22009-10-21 00:40:46 +00003310TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003311 RValueReferenceTypeLoc TL) {
3312 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003313}
Mike Stump11289f42009-09-09 15:08:12 +00003314
Douglas Gregord6ff3322009-08-04 16:50:30 +00003315template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003316QualType
John McCall550e0c22009-10-21 00:40:46 +00003317TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003318 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003319 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003320 if (PointeeType.isNull())
3321 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003322
Abramo Bagnara509357842011-03-05 14:42:21 +00003323 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3324 TypeSourceInfo* NewClsTInfo = 0;
3325 if (OldClsTInfo) {
3326 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3327 if (!NewClsTInfo)
3328 return QualType();
3329 }
3330
3331 const MemberPointerType *T = TL.getTypePtr();
3332 QualType OldClsType = QualType(T->getClass(), 0);
3333 QualType NewClsType;
3334 if (NewClsTInfo)
3335 NewClsType = NewClsTInfo->getType();
3336 else {
3337 NewClsType = getDerived().TransformType(OldClsType);
3338 if (NewClsType.isNull())
3339 return QualType();
3340 }
Mike Stump11289f42009-09-09 15:08:12 +00003341
John McCall550e0c22009-10-21 00:40:46 +00003342 QualType Result = TL.getType();
3343 if (getDerived().AlwaysRebuild() ||
3344 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003345 NewClsType != OldClsType) {
3346 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003347 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003348 if (Result.isNull())
3349 return QualType();
3350 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003351
John McCall550e0c22009-10-21 00:40:46 +00003352 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3353 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003354 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003355
3356 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003357}
3358
Mike Stump11289f42009-09-09 15:08:12 +00003359template<typename Derived>
3360QualType
John McCall550e0c22009-10-21 00:40:46 +00003361TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003362 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003363 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003364 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003365 if (ElementType.isNull())
3366 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003367
John McCall550e0c22009-10-21 00:40:46 +00003368 QualType Result = TL.getType();
3369 if (getDerived().AlwaysRebuild() ||
3370 ElementType != T->getElementType()) {
3371 Result = getDerived().RebuildConstantArrayType(ElementType,
3372 T->getSizeModifier(),
3373 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003374 T->getIndexTypeCVRQualifiers(),
3375 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003376 if (Result.isNull())
3377 return QualType();
3378 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003379
John McCall550e0c22009-10-21 00:40:46 +00003380 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3381 NewTL.setLBracketLoc(TL.getLBracketLoc());
3382 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003383
John McCall550e0c22009-10-21 00:40:46 +00003384 Expr *Size = TL.getSizeExpr();
3385 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003386 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003387 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3388 }
3389 NewTL.setSizeExpr(Size);
3390
3391 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003392}
Mike Stump11289f42009-09-09 15:08:12 +00003393
Douglas Gregord6ff3322009-08-04 16:50:30 +00003394template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003395QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003396 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003397 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003398 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003399 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003400 if (ElementType.isNull())
3401 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003402
John McCall550e0c22009-10-21 00:40:46 +00003403 QualType Result = TL.getType();
3404 if (getDerived().AlwaysRebuild() ||
3405 ElementType != T->getElementType()) {
3406 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003407 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003408 T->getIndexTypeCVRQualifiers(),
3409 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003410 if (Result.isNull())
3411 return QualType();
3412 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003413
John McCall550e0c22009-10-21 00:40:46 +00003414 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3415 NewTL.setLBracketLoc(TL.getLBracketLoc());
3416 NewTL.setRBracketLoc(TL.getRBracketLoc());
3417 NewTL.setSizeExpr(0);
3418
3419 return Result;
3420}
3421
3422template<typename Derived>
3423QualType
3424TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003425 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003426 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003427 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3428 if (ElementType.isNull())
3429 return QualType();
3430
3431 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003432 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003433
John McCalldadc5752010-08-24 06:29:42 +00003434 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003435 = getDerived().TransformExpr(T->getSizeExpr());
3436 if (SizeResult.isInvalid())
3437 return QualType();
3438
John McCallb268a282010-08-23 23:25:46 +00003439 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003440
3441 QualType Result = TL.getType();
3442 if (getDerived().AlwaysRebuild() ||
3443 ElementType != T->getElementType() ||
3444 Size != T->getSizeExpr()) {
3445 Result = getDerived().RebuildVariableArrayType(ElementType,
3446 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003447 Size,
John McCall550e0c22009-10-21 00:40:46 +00003448 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003449 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003450 if (Result.isNull())
3451 return QualType();
3452 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003453
John McCall550e0c22009-10-21 00:40:46 +00003454 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3455 NewTL.setLBracketLoc(TL.getLBracketLoc());
3456 NewTL.setRBracketLoc(TL.getRBracketLoc());
3457 NewTL.setSizeExpr(Size);
3458
3459 return Result;
3460}
3461
3462template<typename Derived>
3463QualType
3464TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003465 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003466 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003467 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3468 if (ElementType.isNull())
3469 return QualType();
3470
3471 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003472 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003473
John McCall33ddac02011-01-19 10:06:00 +00003474 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3475 Expr *origSize = TL.getSizeExpr();
3476 if (!origSize) origSize = T->getSizeExpr();
3477
3478 ExprResult sizeResult
3479 = getDerived().TransformExpr(origSize);
3480 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003481 return QualType();
3482
John McCall33ddac02011-01-19 10:06:00 +00003483 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003484
3485 QualType Result = TL.getType();
3486 if (getDerived().AlwaysRebuild() ||
3487 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003488 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003489 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3490 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003491 size,
John McCall550e0c22009-10-21 00:40:46 +00003492 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003493 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003494 if (Result.isNull())
3495 return QualType();
3496 }
John McCall550e0c22009-10-21 00:40:46 +00003497
3498 // We might have any sort of array type now, but fortunately they
3499 // all have the same location layout.
3500 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3501 NewTL.setLBracketLoc(TL.getLBracketLoc());
3502 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003503 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003504
3505 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003506}
Mike Stump11289f42009-09-09 15:08:12 +00003507
3508template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003509QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003510 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003511 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003512 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003513
3514 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003515 QualType ElementType = getDerived().TransformType(T->getElementType());
3516 if (ElementType.isNull())
3517 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003518
Douglas Gregore922c772009-08-04 22:27:00 +00003519 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003520 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003521
John McCalldadc5752010-08-24 06:29:42 +00003522 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003523 if (Size.isInvalid())
3524 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003525
John McCall550e0c22009-10-21 00:40:46 +00003526 QualType Result = TL.getType();
3527 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003528 ElementType != T->getElementType() ||
3529 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003530 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003531 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003532 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003533 if (Result.isNull())
3534 return QualType();
3535 }
John McCall550e0c22009-10-21 00:40:46 +00003536
3537 // Result might be dependent or not.
3538 if (isa<DependentSizedExtVectorType>(Result)) {
3539 DependentSizedExtVectorTypeLoc NewTL
3540 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3541 NewTL.setNameLoc(TL.getNameLoc());
3542 } else {
3543 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3544 NewTL.setNameLoc(TL.getNameLoc());
3545 }
3546
3547 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003548}
Mike Stump11289f42009-09-09 15:08:12 +00003549
3550template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003551QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003552 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003553 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003554 QualType ElementType = getDerived().TransformType(T->getElementType());
3555 if (ElementType.isNull())
3556 return QualType();
3557
John McCall550e0c22009-10-21 00:40:46 +00003558 QualType Result = TL.getType();
3559 if (getDerived().AlwaysRebuild() ||
3560 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003561 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003562 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003563 if (Result.isNull())
3564 return QualType();
3565 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003566
John McCall550e0c22009-10-21 00:40:46 +00003567 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3568 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003569
John McCall550e0c22009-10-21 00:40:46 +00003570 return Result;
3571}
3572
3573template<typename Derived>
3574QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003575 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003576 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003577 QualType ElementType = getDerived().TransformType(T->getElementType());
3578 if (ElementType.isNull())
3579 return QualType();
3580
3581 QualType Result = TL.getType();
3582 if (getDerived().AlwaysRebuild() ||
3583 ElementType != T->getElementType()) {
3584 Result = getDerived().RebuildExtVectorType(ElementType,
3585 T->getNumElements(),
3586 /*FIXME*/ SourceLocation());
3587 if (Result.isNull())
3588 return QualType();
3589 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003590
John McCall550e0c22009-10-21 00:40:46 +00003591 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3592 NewTL.setNameLoc(TL.getNameLoc());
3593
3594 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003595}
Mike Stump11289f42009-09-09 15:08:12 +00003596
3597template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003598ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003599TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3600 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003601 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003602 TypeSourceInfo *NewDI = 0;
3603
3604 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3605 // If we're substituting into a pack expansion type and we know the
3606 TypeLoc OldTL = OldDI->getTypeLoc();
3607 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3608
3609 TypeLocBuilder TLB;
3610 TypeLoc NewTL = OldDI->getTypeLoc();
3611 TLB.reserve(NewTL.getFullDataSize());
3612
3613 QualType Result = getDerived().TransformType(TLB,
3614 OldExpansionTL.getPatternLoc());
3615 if (Result.isNull())
3616 return 0;
3617
3618 Result = RebuildPackExpansionType(Result,
3619 OldExpansionTL.getPatternLoc().getSourceRange(),
3620 OldExpansionTL.getEllipsisLoc(),
3621 NumExpansions);
3622 if (Result.isNull())
3623 return 0;
3624
3625 PackExpansionTypeLoc NewExpansionTL
3626 = TLB.push<PackExpansionTypeLoc>(Result);
3627 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3628 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3629 } else
3630 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003631 if (!NewDI)
3632 return 0;
3633
3634 if (NewDI == OldDI)
3635 return OldParm;
3636 else
3637 return ParmVarDecl::Create(SemaRef.Context,
3638 OldParm->getDeclContext(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00003639 OldParm->getInnerLocStart(),
John McCall58f10c32010-03-11 09:03:00 +00003640 OldParm->getLocation(),
3641 OldParm->getIdentifier(),
3642 NewDI->getType(),
3643 NewDI,
3644 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003645 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003646 /* DefArg */ NULL);
3647}
3648
3649template<typename Derived>
3650bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003651 TransformFunctionTypeParams(SourceLocation Loc,
3652 ParmVarDecl **Params, unsigned NumParams,
3653 const QualType *ParamTypes,
3654 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3655 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3656 for (unsigned i = 0; i != NumParams; ++i) {
3657 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor715e4612011-01-14 22:40:04 +00003658 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003659 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00003660 if (OldParm->isParameterPack()) {
3661 // We have a function parameter pack that may need to be expanded.
3662 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003663
Douglas Gregor5499af42011-01-05 23:12:31 +00003664 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003665 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3666 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3667 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3668 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00003669 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3670
Douglas Gregor5499af42011-01-05 23:12:31 +00003671 // Determine whether we should expand the parameter packs.
3672 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003673 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003674 llvm::Optional<unsigned> OrigNumExpansions
3675 = ExpansionTL.getTypePtr()->getNumExpansions();
3676 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003677 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3678 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003679 Unexpanded.data(),
3680 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003681 ShouldExpand,
3682 RetainExpansion,
3683 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003684 return true;
3685 }
3686
3687 if (ShouldExpand) {
3688 // Expand the function parameter pack into multiple, separate
3689 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003690 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003691 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003692 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3693 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003694 = getDerived().TransformFunctionTypeParam(OldParm,
3695 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003696 if (!NewParm)
3697 return true;
3698
Douglas Gregordd472162011-01-07 00:20:55 +00003699 OutParamTypes.push_back(NewParm->getType());
3700 if (PVars)
3701 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003702 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003703
3704 // If we're supposed to retain a pack expansion, do so by temporarily
3705 // forgetting the partially-substituted parameter pack.
3706 if (RetainExpansion) {
3707 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3708 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003709 = getDerived().TransformFunctionTypeParam(OldParm,
3710 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003711 if (!NewParm)
3712 return true;
3713
3714 OutParamTypes.push_back(NewParm->getType());
3715 if (PVars)
3716 PVars->push_back(NewParm);
3717 }
3718
Douglas Gregor5499af42011-01-05 23:12:31 +00003719 // We're done with the pack expansion.
3720 continue;
3721 }
3722
3723 // We'll substitute the parameter now without expanding the pack
3724 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00003725 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3726 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3727 NumExpansions);
3728 } else {
3729 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3730 llvm::Optional<unsigned>());
Douglas Gregor5499af42011-01-05 23:12:31 +00003731 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00003732
John McCall58f10c32010-03-11 09:03:00 +00003733 if (!NewParm)
3734 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003735
Douglas Gregordd472162011-01-07 00:20:55 +00003736 OutParamTypes.push_back(NewParm->getType());
3737 if (PVars)
3738 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003739 continue;
3740 }
John McCall58f10c32010-03-11 09:03:00 +00003741
3742 // Deal with the possibility that we don't have a parameter
3743 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003744 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003745 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003746 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003747 QualType NewType;
Douglas Gregor5499af42011-01-05 23:12:31 +00003748 if (const PackExpansionType *Expansion
3749 = dyn_cast<PackExpansionType>(OldType)) {
3750 // We have a function parameter pack that may need to be expanded.
3751 QualType Pattern = Expansion->getPattern();
3752 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3753 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3754
3755 // Determine whether we should expand the parameter packs.
3756 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003757 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003758 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003759 Unexpanded.data(),
3760 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003761 ShouldExpand,
3762 RetainExpansion,
3763 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003764 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003765 }
3766
3767 if (ShouldExpand) {
3768 // Expand the function parameter pack into multiple, separate
3769 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003770 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003771 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3772 QualType NewType = getDerived().TransformType(Pattern);
3773 if (NewType.isNull())
3774 return true;
John McCall58f10c32010-03-11 09:03:00 +00003775
Douglas Gregordd472162011-01-07 00:20:55 +00003776 OutParamTypes.push_back(NewType);
3777 if (PVars)
3778 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003779 }
3780
3781 // We're done with the pack expansion.
3782 continue;
3783 }
3784
Douglas Gregor48d24112011-01-10 20:53:55 +00003785 // If we're supposed to retain a pack expansion, do so by temporarily
3786 // forgetting the partially-substituted parameter pack.
3787 if (RetainExpansion) {
3788 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3789 QualType NewType = getDerived().TransformType(Pattern);
3790 if (NewType.isNull())
3791 return true;
3792
3793 OutParamTypes.push_back(NewType);
3794 if (PVars)
3795 PVars->push_back(0);
3796 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003797
Douglas Gregor5499af42011-01-05 23:12:31 +00003798 // We'll substitute the parameter now without expanding the pack
3799 // expansion.
3800 OldType = Expansion->getPattern();
3801 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003802 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3803 NewType = getDerived().TransformType(OldType);
3804 } else {
3805 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00003806 }
3807
Douglas Gregor5499af42011-01-05 23:12:31 +00003808 if (NewType.isNull())
3809 return true;
3810
3811 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003812 NewType = getSema().Context.getPackExpansionType(NewType,
3813 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003814
Douglas Gregordd472162011-01-07 00:20:55 +00003815 OutParamTypes.push_back(NewType);
3816 if (PVars)
3817 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003818 }
3819
3820 return false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003821 }
John McCall58f10c32010-03-11 09:03:00 +00003822
3823template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003824QualType
John McCall550e0c22009-10-21 00:40:46 +00003825TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003826 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003827 // Transform the parameters and return type.
3828 //
3829 // We instantiate in source order, with the return type first followed by
3830 // the parameters, because users tend to expect this (even if they shouldn't
3831 // rely on it!).
3832 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003833 // When the function has a trailing return type, we instantiate the
3834 // parameters before the return type, since the return type can then refer
3835 // to the parameters themselves (via decltype, sizeof, etc.).
3836 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003837 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003838 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00003839 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003840
Douglas Gregor7fb25412010-10-01 18:44:50 +00003841 QualType ResultType;
3842
3843 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003844 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3845 TL.getParmArray(),
3846 TL.getNumArgs(),
3847 TL.getTypePtr()->arg_type_begin(),
3848 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003849 return QualType();
3850
3851 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3852 if (ResultType.isNull())
3853 return QualType();
3854 }
3855 else {
3856 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3857 if (ResultType.isNull())
3858 return QualType();
3859
Douglas Gregordd472162011-01-07 00:20:55 +00003860 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3861 TL.getParmArray(),
3862 TL.getNumArgs(),
3863 TL.getTypePtr()->arg_type_begin(),
3864 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003865 return QualType();
3866 }
3867
John McCall550e0c22009-10-21 00:40:46 +00003868 QualType Result = TL.getType();
3869 if (getDerived().AlwaysRebuild() ||
3870 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003871 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003872 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3873 Result = getDerived().RebuildFunctionProtoType(ResultType,
3874 ParamTypes.data(),
3875 ParamTypes.size(),
3876 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003877 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00003878 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003879 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003880 if (Result.isNull())
3881 return QualType();
3882 }
Mike Stump11289f42009-09-09 15:08:12 +00003883
John McCall550e0c22009-10-21 00:40:46 +00003884 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00003885 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
3886 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003887 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003888 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3889 NewTL.setArg(i, ParamDecls[i]);
3890
3891 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003892}
Mike Stump11289f42009-09-09 15:08:12 +00003893
Douglas Gregord6ff3322009-08-04 16:50:30 +00003894template<typename Derived>
3895QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003896 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003897 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003898 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003899 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3900 if (ResultType.isNull())
3901 return QualType();
3902
3903 QualType Result = TL.getType();
3904 if (getDerived().AlwaysRebuild() ||
3905 ResultType != T->getResultType())
3906 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3907
3908 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00003909 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
3910 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003911 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003912
3913 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003914}
Mike Stump11289f42009-09-09 15:08:12 +00003915
John McCallb96ec562009-12-04 22:46:56 +00003916template<typename Derived> QualType
3917TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003918 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003919 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003920 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003921 if (!D)
3922 return QualType();
3923
3924 QualType Result = TL.getType();
3925 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3926 Result = getDerived().RebuildUnresolvedUsingType(D);
3927 if (Result.isNull())
3928 return QualType();
3929 }
3930
3931 // We might get an arbitrary type spec type back. We should at
3932 // least always get a type spec type, though.
3933 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3934 NewTL.setNameLoc(TL.getNameLoc());
3935
3936 return Result;
3937}
3938
Douglas Gregord6ff3322009-08-04 16:50:30 +00003939template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003940QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003941 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003942 const TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003943 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003944 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3945 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003946 if (!Typedef)
3947 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003948
John McCall550e0c22009-10-21 00:40:46 +00003949 QualType Result = TL.getType();
3950 if (getDerived().AlwaysRebuild() ||
3951 Typedef != T->getDecl()) {
3952 Result = getDerived().RebuildTypedefType(Typedef);
3953 if (Result.isNull())
3954 return QualType();
3955 }
Mike Stump11289f42009-09-09 15:08:12 +00003956
John McCall550e0c22009-10-21 00:40:46 +00003957 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3958 NewTL.setNameLoc(TL.getNameLoc());
3959
3960 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003961}
Mike Stump11289f42009-09-09 15:08:12 +00003962
Douglas Gregord6ff3322009-08-04 16:50:30 +00003963template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003964QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003965 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003966 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003967 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003968
John McCalldadc5752010-08-24 06:29:42 +00003969 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003970 if (E.isInvalid())
3971 return QualType();
3972
John McCall550e0c22009-10-21 00:40:46 +00003973 QualType Result = TL.getType();
3974 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003975 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003976 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003977 if (Result.isNull())
3978 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003979 }
John McCall550e0c22009-10-21 00:40:46 +00003980 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003981
John McCall550e0c22009-10-21 00:40:46 +00003982 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003983 NewTL.setTypeofLoc(TL.getTypeofLoc());
3984 NewTL.setLParenLoc(TL.getLParenLoc());
3985 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003986
3987 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003988}
Mike Stump11289f42009-09-09 15:08:12 +00003989
3990template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003991QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003992 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003993 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3994 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3995 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003996 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003997
John McCall550e0c22009-10-21 00:40:46 +00003998 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003999 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4000 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004001 if (Result.isNull())
4002 return QualType();
4003 }
Mike Stump11289f42009-09-09 15:08:12 +00004004
John McCall550e0c22009-10-21 00:40:46 +00004005 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004006 NewTL.setTypeofLoc(TL.getTypeofLoc());
4007 NewTL.setLParenLoc(TL.getLParenLoc());
4008 NewTL.setRParenLoc(TL.getRParenLoc());
4009 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004010
4011 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004012}
Mike Stump11289f42009-09-09 15:08:12 +00004013
4014template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004015QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004016 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004017 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004018
Douglas Gregore922c772009-08-04 22:27:00 +00004019 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004020 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004021
John McCalldadc5752010-08-24 06:29:42 +00004022 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004023 if (E.isInvalid())
4024 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004025
John McCall550e0c22009-10-21 00:40:46 +00004026 QualType Result = TL.getType();
4027 if (getDerived().AlwaysRebuild() ||
4028 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004029 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004030 if (Result.isNull())
4031 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004032 }
John McCall550e0c22009-10-21 00:40:46 +00004033 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004034
John McCall550e0c22009-10-21 00:40:46 +00004035 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4036 NewTL.setNameLoc(TL.getNameLoc());
4037
4038 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004039}
4040
4041template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004042QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4043 AutoTypeLoc TL) {
4044 const AutoType *T = TL.getTypePtr();
4045 QualType OldDeduced = T->getDeducedType();
4046 QualType NewDeduced;
4047 if (!OldDeduced.isNull()) {
4048 NewDeduced = getDerived().TransformType(OldDeduced);
4049 if (NewDeduced.isNull())
4050 return QualType();
4051 }
4052
4053 QualType Result = TL.getType();
4054 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4055 Result = getDerived().RebuildAutoType(NewDeduced);
4056 if (Result.isNull())
4057 return QualType();
4058 }
4059
4060 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4061 NewTL.setNameLoc(TL.getNameLoc());
4062
4063 return Result;
4064}
4065
4066template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004067QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004068 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004069 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004070 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004071 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4072 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004073 if (!Record)
4074 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004075
John McCall550e0c22009-10-21 00:40:46 +00004076 QualType Result = TL.getType();
4077 if (getDerived().AlwaysRebuild() ||
4078 Record != T->getDecl()) {
4079 Result = getDerived().RebuildRecordType(Record);
4080 if (Result.isNull())
4081 return QualType();
4082 }
Mike Stump11289f42009-09-09 15:08:12 +00004083
John McCall550e0c22009-10-21 00:40:46 +00004084 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4085 NewTL.setNameLoc(TL.getNameLoc());
4086
4087 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004088}
Mike Stump11289f42009-09-09 15:08:12 +00004089
4090template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004091QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004092 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004093 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004094 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004095 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4096 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004097 if (!Enum)
4098 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004099
John McCall550e0c22009-10-21 00:40:46 +00004100 QualType Result = TL.getType();
4101 if (getDerived().AlwaysRebuild() ||
4102 Enum != T->getDecl()) {
4103 Result = getDerived().RebuildEnumType(Enum);
4104 if (Result.isNull())
4105 return QualType();
4106 }
Mike Stump11289f42009-09-09 15:08:12 +00004107
John McCall550e0c22009-10-21 00:40:46 +00004108 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4109 NewTL.setNameLoc(TL.getNameLoc());
4110
4111 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004112}
John McCallfcc33b02009-09-05 00:15:47 +00004113
John McCalle78aac42010-03-10 03:28:59 +00004114template<typename Derived>
4115QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4116 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004117 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004118 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4119 TL.getTypePtr()->getDecl());
4120 if (!D) return QualType();
4121
4122 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4123 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4124 return T;
4125}
4126
Douglas Gregord6ff3322009-08-04 16:50:30 +00004127template<typename Derived>
4128QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004129 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004130 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004131 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004132}
4133
Mike Stump11289f42009-09-09 15:08:12 +00004134template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004135QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004136 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004137 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004138 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4139
4140 // Substitute into the replacement type, which itself might involve something
4141 // that needs to be transformed. This only tends to occur with default
4142 // template arguments of template template parameters.
4143 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4144 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4145 if (Replacement.isNull())
4146 return QualType();
4147
4148 // Always canonicalize the replacement type.
4149 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4150 QualType Result
4151 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4152 Replacement);
4153
4154 // Propagate type-source information.
4155 SubstTemplateTypeParmTypeLoc NewTL
4156 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4157 NewTL.setNameLoc(TL.getNameLoc());
4158 return Result;
4159
John McCallcebee162009-10-18 09:09:24 +00004160}
4161
4162template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004163QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4164 TypeLocBuilder &TLB,
4165 SubstTemplateTypeParmPackTypeLoc TL) {
4166 return TransformTypeSpecType(TLB, TL);
4167}
4168
4169template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004170QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004171 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004172 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004173 const TemplateSpecializationType *T = TL.getTypePtr();
4174
Douglas Gregordf846d12011-03-02 18:46:51 +00004175 // The nested-name-specifier never matters in a TemplateSpecializationType,
4176 // because we can't have a dependent nested-name-specifier anyway.
4177 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004178 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004179 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4180 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004181 if (Template.isNull())
4182 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004183
John McCall31f82722010-11-12 08:19:04 +00004184 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4185}
4186
Douglas Gregorfe921a72010-12-20 23:36:19 +00004187namespace {
4188 /// \brief Simple iterator that traverses the template arguments in a
4189 /// container that provides a \c getArgLoc() member function.
4190 ///
4191 /// This iterator is intended to be used with the iterator form of
4192 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4193 template<typename ArgLocContainer>
4194 class TemplateArgumentLocContainerIterator {
4195 ArgLocContainer *Container;
4196 unsigned Index;
4197
4198 public:
4199 typedef TemplateArgumentLoc value_type;
4200 typedef TemplateArgumentLoc reference;
4201 typedef int difference_type;
4202 typedef std::input_iterator_tag iterator_category;
4203
4204 class pointer {
4205 TemplateArgumentLoc Arg;
4206
4207 public:
4208 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4209
4210 const TemplateArgumentLoc *operator->() const {
4211 return &Arg;
4212 }
4213 };
4214
4215
4216 TemplateArgumentLocContainerIterator() {}
4217
4218 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4219 unsigned Index)
4220 : Container(&Container), Index(Index) { }
4221
4222 TemplateArgumentLocContainerIterator &operator++() {
4223 ++Index;
4224 return *this;
4225 }
4226
4227 TemplateArgumentLocContainerIterator operator++(int) {
4228 TemplateArgumentLocContainerIterator Old(*this);
4229 ++(*this);
4230 return Old;
4231 }
4232
4233 TemplateArgumentLoc operator*() const {
4234 return Container->getArgLoc(Index);
4235 }
4236
4237 pointer operator->() const {
4238 return pointer(Container->getArgLoc(Index));
4239 }
4240
4241 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004242 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004243 return X.Container == Y.Container && X.Index == Y.Index;
4244 }
4245
4246 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004247 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004248 return !(X == Y);
4249 }
4250 };
4251}
4252
4253
John McCall31f82722010-11-12 08:19:04 +00004254template <typename Derived>
4255QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4256 TypeLocBuilder &TLB,
4257 TemplateSpecializationTypeLoc TL,
4258 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004259 TemplateArgumentListInfo NewTemplateArgs;
4260 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4261 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004262 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4263 ArgIterator;
4264 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4265 ArgIterator(TL, TL.getNumArgs()),
4266 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004267 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004268
John McCall0ad16662009-10-29 08:12:44 +00004269 // FIXME: maybe don't rebuild if all the template arguments are the same.
4270
4271 QualType Result =
4272 getDerived().RebuildTemplateSpecializationType(Template,
4273 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004274 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004275
4276 if (!Result.isNull()) {
4277 TemplateSpecializationTypeLoc NewTL
4278 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4279 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4280 NewTL.setLAngleLoc(TL.getLAngleLoc());
4281 NewTL.setRAngleLoc(TL.getRAngleLoc());
4282 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4283 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004284 }
Mike Stump11289f42009-09-09 15:08:12 +00004285
John McCall0ad16662009-10-29 08:12:44 +00004286 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004287}
Mike Stump11289f42009-09-09 15:08:12 +00004288
Douglas Gregor5a064722011-02-28 17:23:35 +00004289template <typename Derived>
4290QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4291 TypeLocBuilder &TLB,
4292 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004293 TemplateName Template,
4294 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004295 TemplateArgumentListInfo NewTemplateArgs;
4296 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4297 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4298 typedef TemplateArgumentLocContainerIterator<
4299 DependentTemplateSpecializationTypeLoc> ArgIterator;
4300 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4301 ArgIterator(TL, TL.getNumArgs()),
4302 NewTemplateArgs))
4303 return QualType();
4304
4305 // FIXME: maybe don't rebuild if all the template arguments are the same.
4306
4307 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4308 QualType Result
4309 = getSema().Context.getDependentTemplateSpecializationType(
4310 TL.getTypePtr()->getKeyword(),
4311 DTN->getQualifier(),
4312 DTN->getIdentifier(),
4313 NewTemplateArgs);
4314
4315 DependentTemplateSpecializationTypeLoc NewTL
4316 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4317 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004318
Douglas Gregora7a795b2011-03-01 20:11:18 +00004319 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004320 NewTL.setNameLoc(TL.getNameLoc());
4321 NewTL.setLAngleLoc(TL.getLAngleLoc());
4322 NewTL.setRAngleLoc(TL.getRAngleLoc());
4323 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4324 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4325 return Result;
4326 }
4327
4328 QualType Result
4329 = getDerived().RebuildTemplateSpecializationType(Template,
4330 TL.getNameLoc(),
4331 NewTemplateArgs);
4332
4333 if (!Result.isNull()) {
4334 /// FIXME: Wrap this in an elaborated-type-specifier?
4335 TemplateSpecializationTypeLoc NewTL
4336 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4337 NewTL.setTemplateNameLoc(TL.getNameLoc());
4338 NewTL.setLAngleLoc(TL.getLAngleLoc());
4339 NewTL.setRAngleLoc(TL.getRAngleLoc());
4340 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4341 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4342 }
4343
4344 return Result;
4345}
4346
Mike Stump11289f42009-09-09 15:08:12 +00004347template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004348QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004349TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004350 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004351 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004352
Douglas Gregor844cb502011-03-01 18:12:44 +00004353 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004354 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004355 if (TL.getQualifierLoc()) {
4356 QualifierLoc
4357 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4358 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004359 return QualType();
4360 }
Mike Stump11289f42009-09-09 15:08:12 +00004361
John McCall31f82722010-11-12 08:19:04 +00004362 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4363 if (NamedT.isNull())
4364 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004365
John McCall550e0c22009-10-21 00:40:46 +00004366 QualType Result = TL.getType();
4367 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004368 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004369 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004370 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004371 T->getKeyword(),
4372 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004373 if (Result.isNull())
4374 return QualType();
4375 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004376
Abramo Bagnara6150c882010-05-11 21:36:43 +00004377 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004378 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004379 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004380 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004381}
Mike Stump11289f42009-09-09 15:08:12 +00004382
4383template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004384QualType TreeTransform<Derived>::TransformAttributedType(
4385 TypeLocBuilder &TLB,
4386 AttributedTypeLoc TL) {
4387 const AttributedType *oldType = TL.getTypePtr();
4388 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4389 if (modifiedType.isNull())
4390 return QualType();
4391
4392 QualType result = TL.getType();
4393
4394 // FIXME: dependent operand expressions?
4395 if (getDerived().AlwaysRebuild() ||
4396 modifiedType != oldType->getModifiedType()) {
4397 // TODO: this is really lame; we should really be rebuilding the
4398 // equivalent type from first principles.
4399 QualType equivalentType
4400 = getDerived().TransformType(oldType->getEquivalentType());
4401 if (equivalentType.isNull())
4402 return QualType();
4403 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4404 modifiedType,
4405 equivalentType);
4406 }
4407
4408 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4409 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4410 if (TL.hasAttrOperand())
4411 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4412 if (TL.hasAttrExprOperand())
4413 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4414 else if (TL.hasAttrEnumOperand())
4415 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4416
4417 return result;
4418}
4419
4420template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004421QualType
4422TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4423 ParenTypeLoc TL) {
4424 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4425 if (Inner.isNull())
4426 return QualType();
4427
4428 QualType Result = TL.getType();
4429 if (getDerived().AlwaysRebuild() ||
4430 Inner != TL.getInnerLoc().getType()) {
4431 Result = getDerived().RebuildParenType(Inner);
4432 if (Result.isNull())
4433 return QualType();
4434 }
4435
4436 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4437 NewTL.setLParenLoc(TL.getLParenLoc());
4438 NewTL.setRParenLoc(TL.getRParenLoc());
4439 return Result;
4440}
4441
4442template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004443QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004444 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004445 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004446
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004447 NestedNameSpecifierLoc QualifierLoc
4448 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4449 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004450 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004451
John McCallc392f372010-06-11 00:33:02 +00004452 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004453 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004454 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004455 QualifierLoc,
4456 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004457 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004458 if (Result.isNull())
4459 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004460
Abramo Bagnarad7548482010-05-19 21:37:53 +00004461 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4462 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004463 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4464
Abramo Bagnarad7548482010-05-19 21:37:53 +00004465 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4466 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004467 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004468 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004469 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4470 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004471 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004472 NewTL.setNameLoc(TL.getNameLoc());
4473 }
John McCall550e0c22009-10-21 00:40:46 +00004474 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004475}
Mike Stump11289f42009-09-09 15:08:12 +00004476
Douglas Gregord6ff3322009-08-04 16:50:30 +00004477template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004478QualType TreeTransform<Derived>::
4479 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004480 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004481 NestedNameSpecifierLoc QualifierLoc;
4482 if (TL.getQualifierLoc()) {
4483 QualifierLoc
4484 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4485 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004486 return QualType();
4487 }
4488
John McCall31f82722010-11-12 08:19:04 +00004489 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004490 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004491}
4492
4493template<typename Derived>
4494QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00004495TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4496 DependentTemplateSpecializationTypeLoc TL,
4497 NestedNameSpecifierLoc QualifierLoc) {
4498 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4499
4500 TemplateArgumentListInfo NewTemplateArgs;
4501 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4502 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4503
4504 typedef TemplateArgumentLocContainerIterator<
4505 DependentTemplateSpecializationTypeLoc> ArgIterator;
4506 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4507 ArgIterator(TL, TL.getNumArgs()),
4508 NewTemplateArgs))
4509 return QualType();
4510
4511 QualType Result
4512 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4513 QualifierLoc,
4514 T->getIdentifier(),
4515 TL.getNameLoc(),
4516 NewTemplateArgs);
4517 if (Result.isNull())
4518 return QualType();
4519
4520 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4521 QualType NamedT = ElabT->getNamedType();
4522
4523 // Copy information relevant to the template specialization.
4524 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00004525 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004526 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004527 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4528 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004529 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004530 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004531
4532 // Copy information relevant to the elaborated type.
4533 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4534 NewTL.setKeywordLoc(TL.getKeywordLoc());
4535 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00004536 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4537 DependentTemplateSpecializationTypeLoc SpecTL
4538 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor11ddf132011-03-07 15:13:34 +00004539 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004540 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004541 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004542 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4543 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004544 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004545 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004546 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00004547 TemplateSpecializationTypeLoc SpecTL
4548 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004549 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004550 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4551 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004552 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004553 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004554 }
4555 return Result;
4556}
4557
4558template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004559QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4560 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004561 QualType Pattern
4562 = getDerived().TransformType(TLB, TL.getPatternLoc());
4563 if (Pattern.isNull())
4564 return QualType();
4565
4566 QualType Result = TL.getType();
4567 if (getDerived().AlwaysRebuild() ||
4568 Pattern != TL.getPatternLoc().getType()) {
4569 Result = getDerived().RebuildPackExpansionType(Pattern,
4570 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004571 TL.getEllipsisLoc(),
4572 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004573 if (Result.isNull())
4574 return QualType();
4575 }
4576
4577 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4578 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4579 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004580}
4581
4582template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004583QualType
4584TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004585 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004586 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004587 TLB.pushFullCopy(TL);
4588 return TL.getType();
4589}
4590
4591template<typename Derived>
4592QualType
4593TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004594 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004595 // ObjCObjectType is never dependent.
4596 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004597 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004598}
Mike Stump11289f42009-09-09 15:08:12 +00004599
4600template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004601QualType
4602TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004603 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004604 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004605 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004606 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004607}
4608
Douglas Gregord6ff3322009-08-04 16:50:30 +00004609//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004610// Statement transformation
4611//===----------------------------------------------------------------------===//
4612template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004613StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004614TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004615 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004616}
4617
4618template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004619StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004620TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4621 return getDerived().TransformCompoundStmt(S, false);
4622}
4623
4624template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004625StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004626TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004627 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004628 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004629 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004630 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004631 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4632 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004633 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004634 if (Result.isInvalid()) {
4635 // Immediately fail if this was a DeclStmt, since it's very
4636 // likely that this will cause problems for future statements.
4637 if (isa<DeclStmt>(*B))
4638 return StmtError();
4639
4640 // Otherwise, just keep processing substatements and fail later.
4641 SubStmtInvalid = true;
4642 continue;
4643 }
Mike Stump11289f42009-09-09 15:08:12 +00004644
Douglas Gregorebe10102009-08-20 07:17:43 +00004645 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4646 Statements.push_back(Result.takeAs<Stmt>());
4647 }
Mike Stump11289f42009-09-09 15:08:12 +00004648
John McCall1ababa62010-08-27 19:56:05 +00004649 if (SubStmtInvalid)
4650 return StmtError();
4651
Douglas Gregorebe10102009-08-20 07:17:43 +00004652 if (!getDerived().AlwaysRebuild() &&
4653 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004654 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004655
4656 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4657 move_arg(Statements),
4658 S->getRBracLoc(),
4659 IsStmtExpr);
4660}
Mike Stump11289f42009-09-09 15:08:12 +00004661
Douglas Gregorebe10102009-08-20 07:17:43 +00004662template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004663StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004664TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004665 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004666 {
4667 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004668 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004669
Eli Friedman06577382009-11-19 03:14:00 +00004670 // Transform the left-hand case value.
4671 LHS = getDerived().TransformExpr(S->getLHS());
4672 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004673 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004674
Eli Friedman06577382009-11-19 03:14:00 +00004675 // Transform the right-hand case value (for the GNU case-range extension).
4676 RHS = getDerived().TransformExpr(S->getRHS());
4677 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004678 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004679 }
Mike Stump11289f42009-09-09 15:08:12 +00004680
Douglas Gregorebe10102009-08-20 07:17:43 +00004681 // Build the case statement.
4682 // Case statements are always rebuilt so that they will attached to their
4683 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004684 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004685 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004686 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004687 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004688 S->getColonLoc());
4689 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004690 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004691
Douglas Gregorebe10102009-08-20 07:17:43 +00004692 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004693 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004694 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004695 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004696
Douglas Gregorebe10102009-08-20 07:17:43 +00004697 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004698 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004699}
4700
4701template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004702StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004703TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004704 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004705 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004706 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004707 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004708
Douglas Gregorebe10102009-08-20 07:17:43 +00004709 // Default statements are always rebuilt
4710 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004711 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004712}
Mike Stump11289f42009-09-09 15:08:12 +00004713
Douglas Gregorebe10102009-08-20 07:17:43 +00004714template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004715StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004716TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004717 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004718 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004719 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004720
Chris Lattnercab02a62011-02-17 20:34:02 +00004721 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4722 S->getDecl());
4723 if (!LD)
4724 return StmtError();
4725
4726
Douglas Gregorebe10102009-08-20 07:17:43 +00004727 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004728 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004729 cast<LabelDecl>(LD), SourceLocation(),
4730 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004731}
Mike Stump11289f42009-09-09 15:08:12 +00004732
Douglas Gregorebe10102009-08-20 07:17:43 +00004733template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004734StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004735TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004736 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004737 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004738 VarDecl *ConditionVar = 0;
4739 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004740 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004741 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004742 getDerived().TransformDefinition(
4743 S->getConditionVariable()->getLocation(),
4744 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004745 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004746 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004747 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004748 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004749
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004750 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004751 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004752
4753 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004754 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004755 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4756 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004757 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004758 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004759
John McCallb268a282010-08-23 23:25:46 +00004760 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004761 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004762 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004763
John McCallb268a282010-08-23 23:25:46 +00004764 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4765 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004766 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004767
Douglas Gregorebe10102009-08-20 07:17:43 +00004768 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004769 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004770 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004771 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004772
Douglas Gregorebe10102009-08-20 07:17:43 +00004773 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004774 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004775 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004776 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004777
Douglas Gregorebe10102009-08-20 07:17:43 +00004778 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004779 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004780 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004781 Then.get() == S->getThen() &&
4782 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004783 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004784
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004785 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004786 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004787 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004788}
4789
4790template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004791StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004792TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004793 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004794 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004795 VarDecl *ConditionVar = 0;
4796 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004797 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004798 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004799 getDerived().TransformDefinition(
4800 S->getConditionVariable()->getLocation(),
4801 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004802 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004803 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004804 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004805 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004806
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004807 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004808 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004809 }
Mike Stump11289f42009-09-09 15:08:12 +00004810
Douglas Gregorebe10102009-08-20 07:17:43 +00004811 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004812 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004813 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004814 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004815 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004816 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004817
Douglas Gregorebe10102009-08-20 07:17:43 +00004818 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004819 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004820 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004821 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004822
Douglas Gregorebe10102009-08-20 07:17:43 +00004823 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004824 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4825 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004826}
Mike Stump11289f42009-09-09 15:08:12 +00004827
Douglas Gregorebe10102009-08-20 07:17:43 +00004828template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004829StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004830TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004831 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004832 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004833 VarDecl *ConditionVar = 0;
4834 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004835 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004836 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004837 getDerived().TransformDefinition(
4838 S->getConditionVariable()->getLocation(),
4839 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004840 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004841 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004842 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004843 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004844
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004845 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004846 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004847
4848 if (S->getCond()) {
4849 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004850 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4851 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004852 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004853 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004854 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004855 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004856 }
Mike Stump11289f42009-09-09 15:08:12 +00004857
John McCallb268a282010-08-23 23:25:46 +00004858 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4859 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004860 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004861
Douglas Gregorebe10102009-08-20 07:17:43 +00004862 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004863 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004864 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004865 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004866
Douglas Gregorebe10102009-08-20 07:17:43 +00004867 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004868 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004869 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004870 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004871 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004872
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004873 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004874 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004875}
Mike Stump11289f42009-09-09 15:08:12 +00004876
Douglas Gregorebe10102009-08-20 07:17:43 +00004877template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004878StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004879TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004880 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004881 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004882 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004883 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004884
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004885 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004886 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004887 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004888 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004889
Douglas Gregorebe10102009-08-20 07:17:43 +00004890 if (!getDerived().AlwaysRebuild() &&
4891 Cond.get() == S->getCond() &&
4892 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004893 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004894
John McCallb268a282010-08-23 23:25:46 +00004895 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4896 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004897 S->getRParenLoc());
4898}
Mike Stump11289f42009-09-09 15:08:12 +00004899
Douglas Gregorebe10102009-08-20 07:17:43 +00004900template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004901StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004902TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004903 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004904 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004905 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004906 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004907
Douglas Gregorebe10102009-08-20 07:17:43 +00004908 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004909 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004910 VarDecl *ConditionVar = 0;
4911 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004912 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004913 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004914 getDerived().TransformDefinition(
4915 S->getConditionVariable()->getLocation(),
4916 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004917 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004918 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004919 } else {
4920 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004921
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004922 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004923 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004924
4925 if (S->getCond()) {
4926 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004927 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4928 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004929 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004930 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004931
John McCallb268a282010-08-23 23:25:46 +00004932 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004933 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004934 }
Mike Stump11289f42009-09-09 15:08:12 +00004935
John McCallb268a282010-08-23 23:25:46 +00004936 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4937 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004938 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004939
Douglas Gregorebe10102009-08-20 07:17:43 +00004940 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00004941 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00004942 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004943 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004944
John McCallb268a282010-08-23 23:25:46 +00004945 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4946 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004947 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004948
Douglas Gregorebe10102009-08-20 07:17:43 +00004949 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004950 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004951 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004952 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004953
Douglas Gregorebe10102009-08-20 07:17:43 +00004954 if (!getDerived().AlwaysRebuild() &&
4955 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00004956 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004957 Inc.get() == S->getInc() &&
4958 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004959 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004960
Douglas Gregorebe10102009-08-20 07:17:43 +00004961 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004962 Init.get(), FullCond, ConditionVar,
4963 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004964}
4965
4966template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004967StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004968TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00004969 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
4970 S->getLabel());
4971 if (!LD)
4972 return StmtError();
4973
Douglas Gregorebe10102009-08-20 07:17:43 +00004974 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00004975 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004976 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00004977}
4978
4979template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004980StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004981TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004982 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00004983 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004984 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004985
Douglas Gregorebe10102009-08-20 07:17:43 +00004986 if (!getDerived().AlwaysRebuild() &&
4987 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00004988 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004989
4990 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00004991 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004992}
4993
4994template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004995StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004996TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004997 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004998}
Mike Stump11289f42009-09-09 15:08:12 +00004999
Douglas Gregorebe10102009-08-20 07:17:43 +00005000template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005001StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005002TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005003 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005004}
Mike Stump11289f42009-09-09 15:08:12 +00005005
Douglas Gregorebe10102009-08-20 07:17:43 +00005006template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005007StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005008TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005009 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005010 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005011 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005012
Mike Stump11289f42009-09-09 15:08:12 +00005013 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005014 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005015 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005016}
Mike Stump11289f42009-09-09 15:08:12 +00005017
Douglas Gregorebe10102009-08-20 07:17:43 +00005018template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005019StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005020TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005021 bool DeclChanged = false;
5022 llvm::SmallVector<Decl *, 4> Decls;
5023 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5024 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005025 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5026 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005027 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005028 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005029
Douglas Gregorebe10102009-08-20 07:17:43 +00005030 if (Transformed != *D)
5031 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005032
Douglas Gregorebe10102009-08-20 07:17:43 +00005033 Decls.push_back(Transformed);
5034 }
Mike Stump11289f42009-09-09 15:08:12 +00005035
Douglas Gregorebe10102009-08-20 07:17:43 +00005036 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005037 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005038
5039 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005040 S->getStartLoc(), S->getEndLoc());
5041}
Mike Stump11289f42009-09-09 15:08:12 +00005042
Douglas Gregorebe10102009-08-20 07:17:43 +00005043template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005044StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005045TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005046
John McCall37ad5512010-08-23 06:44:23 +00005047 ASTOwningVector<Expr*> Constraints(getSema());
5048 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00005049 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005050
John McCalldadc5752010-08-24 06:29:42 +00005051 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005052 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005053
5054 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005055
Anders Carlssonaaeef072010-01-24 05:50:09 +00005056 // Go through the outputs.
5057 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005058 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005059
Anders Carlssonaaeef072010-01-24 05:50:09 +00005060 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005061 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005062
Anders Carlssonaaeef072010-01-24 05:50:09 +00005063 // Transform the output expr.
5064 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005065 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005066 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005067 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005068
Anders Carlssonaaeef072010-01-24 05:50:09 +00005069 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005070
John McCallb268a282010-08-23 23:25:46 +00005071 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005072 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005073
Anders Carlssonaaeef072010-01-24 05:50:09 +00005074 // Go through the inputs.
5075 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005076 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005077
Anders Carlssonaaeef072010-01-24 05:50:09 +00005078 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005079 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005080
Anders Carlssonaaeef072010-01-24 05:50:09 +00005081 // Transform the input expr.
5082 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005083 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005084 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005085 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005086
Anders Carlssonaaeef072010-01-24 05:50:09 +00005087 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005088
John McCallb268a282010-08-23 23:25:46 +00005089 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005090 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005091
Anders Carlssonaaeef072010-01-24 05:50:09 +00005092 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005093 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005094
5095 // Go through the clobbers.
5096 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005097 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005098
5099 // No need to transform the asm string literal.
5100 AsmString = SemaRef.Owned(S->getAsmString());
5101
5102 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5103 S->isSimple(),
5104 S->isVolatile(),
5105 S->getNumOutputs(),
5106 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005107 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005108 move_arg(Constraints),
5109 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005110 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005111 move_arg(Clobbers),
5112 S->getRParenLoc(),
5113 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005114}
5115
5116
5117template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005118StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005119TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005120 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005121 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005122 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005123 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005124
Douglas Gregor96c79492010-04-23 22:50:49 +00005125 // Transform the @catch statements (if present).
5126 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005127 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005128 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005129 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005130 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005131 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005132 if (Catch.get() != S->getCatchStmt(I))
5133 AnyCatchChanged = true;
5134 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005135 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005136
Douglas Gregor306de2f2010-04-22 23:59:56 +00005137 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005138 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005139 if (S->getFinallyStmt()) {
5140 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5141 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005142 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005143 }
5144
5145 // If nothing changed, just retain this statement.
5146 if (!getDerived().AlwaysRebuild() &&
5147 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005148 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005149 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005150 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005151
Douglas Gregor306de2f2010-04-22 23:59:56 +00005152 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005153 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5154 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005155}
Mike Stump11289f42009-09-09 15:08:12 +00005156
Douglas Gregorebe10102009-08-20 07:17:43 +00005157template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005158StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005159TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005160 // Transform the @catch parameter, if there is one.
5161 VarDecl *Var = 0;
5162 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5163 TypeSourceInfo *TSInfo = 0;
5164 if (FromVar->getTypeSourceInfo()) {
5165 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5166 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005167 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005168 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005169
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005170 QualType T;
5171 if (TSInfo)
5172 T = TSInfo->getType();
5173 else {
5174 T = getDerived().TransformType(FromVar->getType());
5175 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005176 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005177 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005178
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005179 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5180 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005181 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005182 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005183
John McCalldadc5752010-08-24 06:29:42 +00005184 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005185 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005186 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005187
5188 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005189 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005190 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005191}
Mike Stump11289f42009-09-09 15:08:12 +00005192
Douglas Gregorebe10102009-08-20 07:17:43 +00005193template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005194StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005195TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005196 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005197 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005198 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005199 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005200
Douglas Gregor306de2f2010-04-22 23:59:56 +00005201 // If nothing changed, just retain this statement.
5202 if (!getDerived().AlwaysRebuild() &&
5203 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005204 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005205
5206 // Build a new statement.
5207 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005208 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005209}
Mike Stump11289f42009-09-09 15:08:12 +00005210
Douglas Gregorebe10102009-08-20 07:17:43 +00005211template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005212StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005213TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005214 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005215 if (S->getThrowExpr()) {
5216 Operand = getDerived().TransformExpr(S->getThrowExpr());
5217 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005218 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005219 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005220
Douglas Gregor2900c162010-04-22 21:44:01 +00005221 if (!getDerived().AlwaysRebuild() &&
5222 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005223 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005224
John McCallb268a282010-08-23 23:25:46 +00005225 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005226}
Mike Stump11289f42009-09-09 15:08:12 +00005227
Douglas Gregorebe10102009-08-20 07:17:43 +00005228template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005229StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005230TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005231 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005232 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005233 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005234 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005235 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005236
Douglas Gregor6148de72010-04-22 22:01:21 +00005237 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005238 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005239 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005240 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005241
Douglas Gregor6148de72010-04-22 22:01:21 +00005242 // If nothing change, just retain the current statement.
5243 if (!getDerived().AlwaysRebuild() &&
5244 Object.get() == S->getSynchExpr() &&
5245 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005246 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005247
5248 // Build a new statement.
5249 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005250 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005251}
5252
5253template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005254StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005255TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005256 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005257 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005258 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005259 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005260 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005261
Douglas Gregorf68a5082010-04-22 23:10:45 +00005262 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005263 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005264 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005265 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005266
Douglas Gregorf68a5082010-04-22 23:10:45 +00005267 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005268 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005269 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005270 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005271
Douglas Gregorf68a5082010-04-22 23:10:45 +00005272 // If nothing changed, just retain this statement.
5273 if (!getDerived().AlwaysRebuild() &&
5274 Element.get() == S->getElement() &&
5275 Collection.get() == S->getCollection() &&
5276 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005277 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005278
Douglas Gregorf68a5082010-04-22 23:10:45 +00005279 // Build a new statement.
5280 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5281 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005282 Element.get(),
5283 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005284 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005285 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005286}
5287
5288
5289template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005290StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005291TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5292 // Transform the exception declaration, if any.
5293 VarDecl *Var = 0;
5294 if (S->getExceptionDecl()) {
5295 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005296 TypeSourceInfo *T = getDerived().TransformType(
5297 ExceptionDecl->getTypeSourceInfo());
5298 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005299 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005300
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005301 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaradff19302011-03-08 08:55:46 +00005302 ExceptionDecl->getInnerLocStart(),
5303 ExceptionDecl->getLocation(),
5304 ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00005305 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005306 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005307 }
Mike Stump11289f42009-09-09 15:08:12 +00005308
Douglas Gregorebe10102009-08-20 07:17:43 +00005309 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005310 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005311 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005312 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005313
Douglas Gregorebe10102009-08-20 07:17:43 +00005314 if (!getDerived().AlwaysRebuild() &&
5315 !Var &&
5316 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005317 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005318
5319 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5320 Var,
John McCallb268a282010-08-23 23:25:46 +00005321 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005322}
Mike Stump11289f42009-09-09 15:08:12 +00005323
Douglas Gregorebe10102009-08-20 07:17:43 +00005324template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005325StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005326TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5327 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005328 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005329 = getDerived().TransformCompoundStmt(S->getTryBlock());
5330 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005331 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005332
Douglas Gregorebe10102009-08-20 07:17:43 +00005333 // Transform the handlers.
5334 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005335 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005336 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005337 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005338 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5339 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005340 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005341
Douglas Gregorebe10102009-08-20 07:17:43 +00005342 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5343 Handlers.push_back(Handler.takeAs<Stmt>());
5344 }
Mike Stump11289f42009-09-09 15:08:12 +00005345
Douglas Gregorebe10102009-08-20 07:17:43 +00005346 if (!getDerived().AlwaysRebuild() &&
5347 TryBlock.get() == S->getTryBlock() &&
5348 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005349 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005350
John McCallb268a282010-08-23 23:25:46 +00005351 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005352 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005353}
Mike Stump11289f42009-09-09 15:08:12 +00005354
Douglas Gregorebe10102009-08-20 07:17:43 +00005355//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005356// Expression transformation
5357//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005358template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005359ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005360TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005361 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005362}
Mike Stump11289f42009-09-09 15:08:12 +00005363
5364template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005365ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005366TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005367 NestedNameSpecifierLoc QualifierLoc;
5368 if (E->getQualifierLoc()) {
5369 QualifierLoc
5370 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5371 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005372 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005373 }
John McCallce546572009-12-08 09:08:17 +00005374
5375 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005376 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5377 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005378 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005379 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005380
John McCall815039a2010-08-17 21:27:17 +00005381 DeclarationNameInfo NameInfo = E->getNameInfo();
5382 if (NameInfo.getName()) {
5383 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5384 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005385 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005386 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005387
5388 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005389 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005390 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005391 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005392 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005393
5394 // Mark it referenced in the new context regardless.
5395 // FIXME: this is a bit instantiation-specific.
5396 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5397
John McCallc3007a22010-10-26 07:05:15 +00005398 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005399 }
John McCallce546572009-12-08 09:08:17 +00005400
5401 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005402 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005403 TemplateArgs = &TransArgs;
5404 TransArgs.setLAngleLoc(E->getLAngleLoc());
5405 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005406 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5407 E->getNumTemplateArgs(),
5408 TransArgs))
5409 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005410 }
5411
Douglas Gregorea972d32011-02-28 21:54:11 +00005412 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5413 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005414}
Mike Stump11289f42009-09-09 15:08:12 +00005415
Douglas Gregora16548e2009-08-11 05:31:07 +00005416template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005417ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005418TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005419 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005420}
Mike Stump11289f42009-09-09 15:08:12 +00005421
Douglas Gregora16548e2009-08-11 05:31:07 +00005422template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005423ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005424TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005425 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005426}
Mike Stump11289f42009-09-09 15:08:12 +00005427
Douglas Gregora16548e2009-08-11 05:31:07 +00005428template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005429ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005430TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005431 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005432}
Mike Stump11289f42009-09-09 15:08:12 +00005433
Douglas Gregora16548e2009-08-11 05:31:07 +00005434template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005435ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005436TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005437 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005438}
Mike Stump11289f42009-09-09 15:08:12 +00005439
Douglas Gregora16548e2009-08-11 05:31:07 +00005440template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005441ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005442TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005443 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005444}
5445
5446template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005447ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005448TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005449 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005450 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005451 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005452
Douglas Gregora16548e2009-08-11 05:31:07 +00005453 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005454 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005455
John McCallb268a282010-08-23 23:25:46 +00005456 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005457 E->getRParen());
5458}
5459
Mike Stump11289f42009-09-09 15:08:12 +00005460template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005461ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005462TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005463 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005464 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005465 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005466
Douglas Gregora16548e2009-08-11 05:31:07 +00005467 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005468 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005469
Douglas Gregora16548e2009-08-11 05:31:07 +00005470 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5471 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005472 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005473}
Mike Stump11289f42009-09-09 15:08:12 +00005474
Douglas Gregora16548e2009-08-11 05:31:07 +00005475template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005476ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005477TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5478 // Transform the type.
5479 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5480 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005481 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005482
Douglas Gregor882211c2010-04-28 22:16:22 +00005483 // Transform all of the components into components similar to what the
5484 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005485 // FIXME: It would be slightly more efficient in the non-dependent case to
5486 // just map FieldDecls, rather than requiring the rebuilder to look for
5487 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005488 // template code that we don't care.
5489 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005490 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005491 typedef OffsetOfExpr::OffsetOfNode Node;
5492 llvm::SmallVector<Component, 4> Components;
5493 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5494 const Node &ON = E->getComponent(I);
5495 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005496 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00005497 Comp.LocStart = ON.getSourceRange().getBegin();
5498 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00005499 switch (ON.getKind()) {
5500 case Node::Array: {
5501 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005502 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005503 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005504 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005505
Douglas Gregor882211c2010-04-28 22:16:22 +00005506 ExprChanged = ExprChanged || Index.get() != FromIndex;
5507 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005508 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005509 break;
5510 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005511
Douglas Gregor882211c2010-04-28 22:16:22 +00005512 case Node::Field:
5513 case Node::Identifier:
5514 Comp.isBrackets = false;
5515 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005516 if (!Comp.U.IdentInfo)
5517 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005518
Douglas Gregor882211c2010-04-28 22:16:22 +00005519 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005520
Douglas Gregord1702062010-04-29 00:18:15 +00005521 case Node::Base:
5522 // Will be recomputed during the rebuild.
5523 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005524 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005525
Douglas Gregor882211c2010-04-28 22:16:22 +00005526 Components.push_back(Comp);
5527 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005528
Douglas Gregor882211c2010-04-28 22:16:22 +00005529 // If nothing changed, retain the existing expression.
5530 if (!getDerived().AlwaysRebuild() &&
5531 Type == E->getTypeSourceInfo() &&
5532 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005533 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005534
Douglas Gregor882211c2010-04-28 22:16:22 +00005535 // Build a new offsetof expression.
5536 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5537 Components.data(), Components.size(),
5538 E->getRParenLoc());
5539}
5540
5541template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005542ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005543TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5544 assert(getDerived().AlreadyTransformed(E->getType()) &&
5545 "opaque value expression requires transformation");
5546 return SemaRef.Owned(E);
5547}
5548
5549template<typename Derived>
5550ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00005551TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
5552 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005553 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005554 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005555
John McCallbcd03502009-12-07 02:54:59 +00005556 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005557 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005558 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005559
John McCall4c98fd82009-11-04 07:28:41 +00005560 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005561 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005562
Peter Collingbournee190dee2011-03-11 19:24:49 +00005563 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
5564 E->getKind(),
5565 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005566 }
Mike Stump11289f42009-09-09 15:08:12 +00005567
John McCalldadc5752010-08-24 06:29:42 +00005568 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005569 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005570 // C++0x [expr.sizeof]p1:
5571 // The operand is either an expression, which is an unevaluated operand
5572 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005573 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005574
Douglas Gregora16548e2009-08-11 05:31:07 +00005575 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5576 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005577 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005578
Douglas Gregora16548e2009-08-11 05:31:07 +00005579 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005580 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005581 }
Mike Stump11289f42009-09-09 15:08:12 +00005582
Peter Collingbournee190dee2011-03-11 19:24:49 +00005583 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
5584 E->getOperatorLoc(),
5585 E->getKind(),
5586 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005587}
Mike Stump11289f42009-09-09 15:08:12 +00005588
Douglas Gregora16548e2009-08-11 05:31:07 +00005589template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005590ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005591TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005592 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005593 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005594 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005595
John McCalldadc5752010-08-24 06:29:42 +00005596 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005597 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005598 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005599
5600
Douglas Gregora16548e2009-08-11 05:31:07 +00005601 if (!getDerived().AlwaysRebuild() &&
5602 LHS.get() == E->getLHS() &&
5603 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005604 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005605
John McCallb268a282010-08-23 23:25:46 +00005606 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005607 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005608 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005609 E->getRBracketLoc());
5610}
Mike Stump11289f42009-09-09 15:08:12 +00005611
5612template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005613ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005614TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005615 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005616 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005617 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005618 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005619
5620 // Transform arguments.
5621 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005622 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005623 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5624 &ArgChanged))
5625 return ExprError();
5626
Douglas Gregora16548e2009-08-11 05:31:07 +00005627 if (!getDerived().AlwaysRebuild() &&
5628 Callee.get() == E->getCallee() &&
5629 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005630 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005631
Douglas Gregora16548e2009-08-11 05:31:07 +00005632 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005633 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005634 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005635 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005636 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005637 E->getRParenLoc());
5638}
Mike Stump11289f42009-09-09 15:08:12 +00005639
5640template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005641ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005642TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005643 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005644 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005645 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005646
Douglas Gregorea972d32011-02-28 21:54:11 +00005647 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005648 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005649 QualifierLoc
5650 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5651
5652 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005653 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005654 }
Mike Stump11289f42009-09-09 15:08:12 +00005655
Eli Friedman2cfcef62009-12-04 06:40:45 +00005656 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005657 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5658 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005659 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005660 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005661
John McCall16df1e52010-03-30 21:47:33 +00005662 NamedDecl *FoundDecl = E->getFoundDecl();
5663 if (FoundDecl == E->getMemberDecl()) {
5664 FoundDecl = Member;
5665 } else {
5666 FoundDecl = cast_or_null<NamedDecl>(
5667 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5668 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005669 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005670 }
5671
Douglas Gregora16548e2009-08-11 05:31:07 +00005672 if (!getDerived().AlwaysRebuild() &&
5673 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005674 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005675 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005676 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005677 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005678
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005679 // Mark it referenced in the new context regardless.
5680 // FIXME: this is a bit instantiation-specific.
5681 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005682 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005683 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005684
John McCall6b51f282009-11-23 01:53:49 +00005685 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005686 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005687 TransArgs.setLAngleLoc(E->getLAngleLoc());
5688 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005689 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5690 E->getNumTemplateArgs(),
5691 TransArgs))
5692 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005693 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005694
Douglas Gregora16548e2009-08-11 05:31:07 +00005695 // FIXME: Bogus source location for the operator
5696 SourceLocation FakeOperatorLoc
5697 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5698
John McCall38836f02010-01-15 08:34:02 +00005699 // FIXME: to do this check properly, we will need to preserve the
5700 // first-qualifier-in-scope here, just in case we had a dependent
5701 // base (and therefore couldn't do the check) and a
5702 // nested-name-qualifier (and therefore could do the lookup).
5703 NamedDecl *FirstQualifierInScope = 0;
5704
John McCallb268a282010-08-23 23:25:46 +00005705 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005706 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00005707 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005708 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005709 Member,
John McCall16df1e52010-03-30 21:47:33 +00005710 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005711 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005712 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005713 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005714}
Mike Stump11289f42009-09-09 15:08:12 +00005715
Douglas Gregora16548e2009-08-11 05:31:07 +00005716template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005717ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005718TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005719 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005720 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005721 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005722
John McCalldadc5752010-08-24 06:29:42 +00005723 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005724 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005725 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005726
Douglas Gregora16548e2009-08-11 05:31:07 +00005727 if (!getDerived().AlwaysRebuild() &&
5728 LHS.get() == E->getLHS() &&
5729 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005730 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005731
Douglas Gregora16548e2009-08-11 05:31:07 +00005732 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005733 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005734}
5735
Mike Stump11289f42009-09-09 15:08:12 +00005736template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005737ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005738TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005739 CompoundAssignOperator *E) {
5740 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005741}
Mike Stump11289f42009-09-09 15:08:12 +00005742
Douglas Gregora16548e2009-08-11 05:31:07 +00005743template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00005744ExprResult TreeTransform<Derived>::
5745TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
5746 // Just rebuild the common and RHS expressions and see whether we
5747 // get any changes.
5748
5749 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
5750 if (commonExpr.isInvalid())
5751 return ExprError();
5752
5753 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
5754 if (rhs.isInvalid())
5755 return ExprError();
5756
5757 if (!getDerived().AlwaysRebuild() &&
5758 commonExpr.get() == e->getCommon() &&
5759 rhs.get() == e->getFalseExpr())
5760 return SemaRef.Owned(e);
5761
5762 return getDerived().RebuildConditionalOperator(commonExpr.take(),
5763 e->getQuestionLoc(),
5764 0,
5765 e->getColonLoc(),
5766 rhs.get());
5767}
5768
5769template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005770ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005771TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005772 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005773 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005774 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005775
John McCalldadc5752010-08-24 06:29:42 +00005776 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005777 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005778 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005779
John McCalldadc5752010-08-24 06:29:42 +00005780 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005781 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005782 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005783
Douglas Gregora16548e2009-08-11 05:31:07 +00005784 if (!getDerived().AlwaysRebuild() &&
5785 Cond.get() == E->getCond() &&
5786 LHS.get() == E->getLHS() &&
5787 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005788 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005789
John McCallb268a282010-08-23 23:25:46 +00005790 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005791 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005792 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005793 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005794 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005795}
Mike Stump11289f42009-09-09 15:08:12 +00005796
5797template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005798ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005799TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005800 // Implicit casts are eliminated during transformation, since they
5801 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005802 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005803}
Mike Stump11289f42009-09-09 15:08:12 +00005804
Douglas Gregora16548e2009-08-11 05:31:07 +00005805template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005806ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005807TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005808 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5809 if (!Type)
5810 return ExprError();
5811
John McCalldadc5752010-08-24 06:29:42 +00005812 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005813 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005814 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005815 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005816
Douglas Gregora16548e2009-08-11 05:31:07 +00005817 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005818 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005819 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005820 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005821
John McCall97513962010-01-15 18:39:57 +00005822 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005823 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005824 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005825 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005826}
Mike Stump11289f42009-09-09 15:08:12 +00005827
Douglas Gregora16548e2009-08-11 05:31:07 +00005828template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005829ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005830TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005831 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5832 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5833 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005834 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005835
John McCalldadc5752010-08-24 06:29:42 +00005836 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005837 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005838 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005839
Douglas Gregora16548e2009-08-11 05:31:07 +00005840 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005841 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005842 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005843 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005844
John McCall5d7aa7f2010-01-19 22:33:45 +00005845 // Note: the expression type doesn't necessarily match the
5846 // type-as-written, but that's okay, because it should always be
5847 // derivable from the initializer.
5848
John McCalle15bbff2010-01-18 19:35:47 +00005849 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005850 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005851 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005852}
Mike Stump11289f42009-09-09 15:08:12 +00005853
Douglas Gregora16548e2009-08-11 05:31:07 +00005854template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005855ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005856TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005857 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005858 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005859 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005860
Douglas Gregora16548e2009-08-11 05:31:07 +00005861 if (!getDerived().AlwaysRebuild() &&
5862 Base.get() == E->getBase())
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 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005866 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005867 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005868 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005869 E->getAccessorLoc(),
5870 E->getAccessor());
5871}
Mike Stump11289f42009-09-09 15:08:12 +00005872
Douglas Gregora16548e2009-08-11 05:31:07 +00005873template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005874ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005875TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005876 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005877
John McCall37ad5512010-08-23 06:44:23 +00005878 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005879 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5880 Inits, &InitChanged))
5881 return ExprError();
5882
Douglas Gregora16548e2009-08-11 05:31:07 +00005883 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005884 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005885
Douglas Gregora16548e2009-08-11 05:31:07 +00005886 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005887 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005888}
Mike Stump11289f42009-09-09 15:08:12 +00005889
Douglas Gregora16548e2009-08-11 05:31:07 +00005890template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005891ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005892TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005893 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005894
Douglas Gregorebe10102009-08-20 07:17:43 +00005895 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005896 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005897 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005898 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005899
Douglas Gregorebe10102009-08-20 07:17:43 +00005900 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005901 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005902 bool ExprChanged = false;
5903 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5904 DEnd = E->designators_end();
5905 D != DEnd; ++D) {
5906 if (D->isFieldDesignator()) {
5907 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5908 D->getDotLoc(),
5909 D->getFieldLoc()));
5910 continue;
5911 }
Mike Stump11289f42009-09-09 15:08:12 +00005912
Douglas Gregora16548e2009-08-11 05:31:07 +00005913 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005914 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005915 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005916 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005917
5918 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005919 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005920
Douglas Gregora16548e2009-08-11 05:31:07 +00005921 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5922 ArrayExprs.push_back(Index.release());
5923 continue;
5924 }
Mike Stump11289f42009-09-09 15:08:12 +00005925
Douglas Gregora16548e2009-08-11 05:31:07 +00005926 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00005927 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00005928 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5929 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005930 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005931
John McCalldadc5752010-08-24 06:29:42 +00005932 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005933 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005934 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005935
5936 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005937 End.get(),
5938 D->getLBracketLoc(),
5939 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005940
Douglas Gregora16548e2009-08-11 05:31:07 +00005941 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5942 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00005943
Douglas Gregora16548e2009-08-11 05:31:07 +00005944 ArrayExprs.push_back(Start.release());
5945 ArrayExprs.push_back(End.release());
5946 }
Mike Stump11289f42009-09-09 15:08:12 +00005947
Douglas Gregora16548e2009-08-11 05:31:07 +00005948 if (!getDerived().AlwaysRebuild() &&
5949 Init.get() == E->getInit() &&
5950 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005951 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005952
Douglas Gregora16548e2009-08-11 05:31:07 +00005953 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5954 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005955 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005956}
Mike Stump11289f42009-09-09 15:08:12 +00005957
Douglas Gregora16548e2009-08-11 05:31:07 +00005958template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005959ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005960TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005961 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00005962 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005963
Douglas Gregor3da3c062009-10-28 00:29:27 +00005964 // FIXME: Will we ever have proper type location here? Will we actually
5965 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00005966 QualType T = getDerived().TransformType(E->getType());
5967 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005968 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005969
Douglas Gregora16548e2009-08-11 05:31:07 +00005970 if (!getDerived().AlwaysRebuild() &&
5971 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005972 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005973
Douglas Gregora16548e2009-08-11 05:31:07 +00005974 return getDerived().RebuildImplicitValueInitExpr(T);
5975}
Mike Stump11289f42009-09-09 15:08:12 +00005976
Douglas Gregora16548e2009-08-11 05:31:07 +00005977template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005978ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005979TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00005980 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5981 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005982 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005983
John McCalldadc5752010-08-24 06:29:42 +00005984 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005985 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005986 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005987
Douglas Gregora16548e2009-08-11 05:31:07 +00005988 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00005989 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005990 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005991 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005992
John McCallb268a282010-08-23 23:25:46 +00005993 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00005994 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005995}
5996
5997template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005998ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005999TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006000 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006001 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006002 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6003 &ArgumentChanged))
6004 return ExprError();
6005
Douglas Gregora16548e2009-08-11 05:31:07 +00006006 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6007 move_arg(Inits),
6008 E->getRParenLoc());
6009}
Mike Stump11289f42009-09-09 15:08:12 +00006010
Douglas Gregora16548e2009-08-11 05:31:07 +00006011/// \brief Transform an address-of-label expression.
6012///
6013/// By default, the transformation of an address-of-label expression always
6014/// rebuilds the expression, so that the label identifier can be resolved to
6015/// the corresponding label statement by semantic analysis.
6016template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006017ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006018TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006019 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6020 E->getLabel());
6021 if (!LD)
6022 return ExprError();
6023
Douglas Gregora16548e2009-08-11 05:31:07 +00006024 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006025 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006026}
Mike Stump11289f42009-09-09 15:08:12 +00006027
6028template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006029ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006030TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006031 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006032 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6033 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006034 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006035
Douglas Gregora16548e2009-08-11 05:31:07 +00006036 if (!getDerived().AlwaysRebuild() &&
6037 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006038 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006039
6040 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006041 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006042 E->getRParenLoc());
6043}
Mike Stump11289f42009-09-09 15:08:12 +00006044
Douglas Gregora16548e2009-08-11 05:31:07 +00006045template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006046ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006047TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006048 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006049 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006050 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006051
John McCalldadc5752010-08-24 06:29:42 +00006052 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006053 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006054 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006055
John McCalldadc5752010-08-24 06:29:42 +00006056 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006057 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006058 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006059
Douglas Gregora16548e2009-08-11 05:31:07 +00006060 if (!getDerived().AlwaysRebuild() &&
6061 Cond.get() == E->getCond() &&
6062 LHS.get() == E->getLHS() &&
6063 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006064 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006065
Douglas Gregora16548e2009-08-11 05:31:07 +00006066 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006067 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006068 E->getRParenLoc());
6069}
Mike Stump11289f42009-09-09 15:08:12 +00006070
Douglas Gregora16548e2009-08-11 05:31:07 +00006071template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006072ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006073TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006074 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006075}
6076
6077template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006078ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006079TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006080 switch (E->getOperator()) {
6081 case OO_New:
6082 case OO_Delete:
6083 case OO_Array_New:
6084 case OO_Array_Delete:
6085 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006086 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006087
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006088 case OO_Call: {
6089 // This is a call to an object's operator().
6090 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6091
6092 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006093 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006094 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006095 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006096
6097 // FIXME: Poor location information
6098 SourceLocation FakeLParenLoc
6099 = SemaRef.PP.getLocForEndOfToken(
6100 static_cast<Expr *>(Object.get())->getLocEnd());
6101
6102 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006103 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006104 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6105 Args))
6106 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006107
John McCallb268a282010-08-23 23:25:46 +00006108 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006109 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006110 E->getLocEnd());
6111 }
6112
6113#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6114 case OO_##Name:
6115#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6116#include "clang/Basic/OperatorKinds.def"
6117 case OO_Subscript:
6118 // Handled below.
6119 break;
6120
6121 case OO_Conditional:
6122 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006123 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006124
6125 case OO_None:
6126 case NUM_OVERLOADED_OPERATORS:
6127 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006128 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006129 }
6130
John McCalldadc5752010-08-24 06:29:42 +00006131 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006132 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006133 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006134
John McCalldadc5752010-08-24 06:29:42 +00006135 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006136 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006137 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006138
John McCalldadc5752010-08-24 06:29:42 +00006139 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006140 if (E->getNumArgs() == 2) {
6141 Second = getDerived().TransformExpr(E->getArg(1));
6142 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006143 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006144 }
Mike Stump11289f42009-09-09 15:08:12 +00006145
Douglas Gregora16548e2009-08-11 05:31:07 +00006146 if (!getDerived().AlwaysRebuild() &&
6147 Callee.get() == E->getCallee() &&
6148 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006149 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006150 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006151
Douglas Gregora16548e2009-08-11 05:31:07 +00006152 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6153 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006154 Callee.get(),
6155 First.get(),
6156 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006157}
Mike Stump11289f42009-09-09 15:08:12 +00006158
Douglas Gregora16548e2009-08-11 05:31:07 +00006159template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006160ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006161TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6162 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006163}
Mike Stump11289f42009-09-09 15:08:12 +00006164
Douglas Gregora16548e2009-08-11 05:31:07 +00006165template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006166ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006167TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6168 // Transform the callee.
6169 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6170 if (Callee.isInvalid())
6171 return ExprError();
6172
6173 // Transform exec config.
6174 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6175 if (EC.isInvalid())
6176 return ExprError();
6177
6178 // Transform arguments.
6179 bool ArgChanged = false;
6180 ASTOwningVector<Expr*> Args(SemaRef);
6181 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6182 &ArgChanged))
6183 return ExprError();
6184
6185 if (!getDerived().AlwaysRebuild() &&
6186 Callee.get() == E->getCallee() &&
6187 !ArgChanged)
6188 return SemaRef.Owned(E);
6189
6190 // FIXME: Wrong source location information for the '('.
6191 SourceLocation FakeLParenLoc
6192 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6193 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6194 move_arg(Args),
6195 E->getRParenLoc(), EC.get());
6196}
6197
6198template<typename Derived>
6199ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006200TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006201 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6202 if (!Type)
6203 return ExprError();
6204
John McCalldadc5752010-08-24 06:29:42 +00006205 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006206 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006207 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006208 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006209
Douglas Gregora16548e2009-08-11 05:31:07 +00006210 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006211 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006212 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006213 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006214
Douglas Gregora16548e2009-08-11 05:31:07 +00006215 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006216 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006217 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6218 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6219 SourceLocation FakeRParenLoc
6220 = SemaRef.PP.getLocForEndOfToken(
6221 E->getSubExpr()->getSourceRange().getEnd());
6222 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006223 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006224 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006225 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006226 FakeRAngleLoc,
6227 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006228 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006229 FakeRParenLoc);
6230}
Mike Stump11289f42009-09-09 15:08:12 +00006231
Douglas Gregora16548e2009-08-11 05:31:07 +00006232template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006233ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006234TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6235 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006236}
Mike Stump11289f42009-09-09 15:08:12 +00006237
6238template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006239ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006240TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6241 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006242}
6243
Douglas Gregora16548e2009-08-11 05:31:07 +00006244template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006245ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006246TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006247 CXXReinterpretCastExpr *E) {
6248 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006249}
Mike Stump11289f42009-09-09 15:08:12 +00006250
Douglas Gregora16548e2009-08-11 05:31:07 +00006251template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006252ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006253TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6254 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006255}
Mike Stump11289f42009-09-09 15:08:12 +00006256
Douglas Gregora16548e2009-08-11 05:31:07 +00006257template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006258ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006259TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006260 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006261 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6262 if (!Type)
6263 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006264
John McCalldadc5752010-08-24 06:29:42 +00006265 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006266 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006267 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006268 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006269
Douglas Gregora16548e2009-08-11 05:31:07 +00006270 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006271 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006272 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006273 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006274
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006275 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006276 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006277 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006278 E->getRParenLoc());
6279}
Mike Stump11289f42009-09-09 15:08:12 +00006280
Douglas Gregora16548e2009-08-11 05:31:07 +00006281template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006282ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006283TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006284 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006285 TypeSourceInfo *TInfo
6286 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6287 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006288 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006289
Douglas Gregora16548e2009-08-11 05:31:07 +00006290 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006291 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006292 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006293
Douglas Gregor9da64192010-04-26 22:37:10 +00006294 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6295 E->getLocStart(),
6296 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006297 E->getLocEnd());
6298 }
Mike Stump11289f42009-09-09 15:08:12 +00006299
Douglas Gregora16548e2009-08-11 05:31:07 +00006300 // We don't know whether the expression is potentially evaluated until
6301 // after we perform semantic analysis, so the expression is potentially
6302 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006303 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006304 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006305
John McCalldadc5752010-08-24 06:29:42 +00006306 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006307 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006308 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006309
Douglas Gregora16548e2009-08-11 05:31:07 +00006310 if (!getDerived().AlwaysRebuild() &&
6311 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006312 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006313
Douglas Gregor9da64192010-04-26 22:37:10 +00006314 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6315 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006316 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006317 E->getLocEnd());
6318}
6319
6320template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006321ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006322TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6323 if (E->isTypeOperand()) {
6324 TypeSourceInfo *TInfo
6325 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6326 if (!TInfo)
6327 return ExprError();
6328
6329 if (!getDerived().AlwaysRebuild() &&
6330 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006331 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006332
Douglas Gregor69735112011-03-06 17:40:41 +00006333 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00006334 E->getLocStart(),
6335 TInfo,
6336 E->getLocEnd());
6337 }
6338
6339 // We don't know whether the expression is potentially evaluated until
6340 // after we perform semantic analysis, so the expression is potentially
6341 // potentially evaluated.
6342 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6343
6344 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6345 if (SubExpr.isInvalid())
6346 return ExprError();
6347
6348 if (!getDerived().AlwaysRebuild() &&
6349 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006350 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006351
6352 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6353 E->getLocStart(),
6354 SubExpr.get(),
6355 E->getLocEnd());
6356}
6357
6358template<typename Derived>
6359ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006360TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006361 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006362}
Mike Stump11289f42009-09-09 15:08:12 +00006363
Douglas Gregora16548e2009-08-11 05:31:07 +00006364template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006365ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006366TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006367 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006368 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006369}
Mike Stump11289f42009-09-09 15:08:12 +00006370
Douglas Gregora16548e2009-08-11 05:31:07 +00006371template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006372ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006373TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006374 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6375 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6376 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006377
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006378 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006379 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006380
Douglas Gregorb15af892010-01-07 23:12:05 +00006381 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
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>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006387 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006388 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006389 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006390
Douglas Gregora16548e2009-08-11 05:31:07 +00006391 if (!getDerived().AlwaysRebuild() &&
6392 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006393 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006394
John McCallb268a282010-08-23 23:25:46 +00006395 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006396}
Mike Stump11289f42009-09-09 15:08:12 +00006397
Douglas Gregora16548e2009-08-11 05:31:07 +00006398template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006399ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006400TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006401 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006402 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6403 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006404 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006405 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006406
Chandler Carruth794da4c2010-02-08 06:42:49 +00006407 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006408 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006409 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006410
Douglas Gregor033f6752009-12-23 23:03:06 +00006411 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006412}
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
Douglas Gregor2b88c112010-09-08 00:15:04 +00006416TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6417 CXXScalarValueInitExpr *E) {
6418 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6419 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006420 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006421
Douglas Gregora16548e2009-08-11 05:31:07 +00006422 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006423 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006424 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006425
Douglas Gregor2b88c112010-09-08 00:15:04 +00006426 return getDerived().RebuildCXXScalarValueInitExpr(T,
6427 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006428 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006429}
Mike Stump11289f42009-09-09 15:08:12 +00006430
Douglas Gregora16548e2009-08-11 05:31:07 +00006431template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006432ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006433TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006434 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006435 TypeSourceInfo *AllocTypeInfo
6436 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6437 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006438 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006439
Douglas Gregora16548e2009-08-11 05:31:07 +00006440 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006441 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006442 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006443 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006444
Douglas Gregora16548e2009-08-11 05:31:07 +00006445 // Transform the placement arguments (if any).
6446 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006447 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006448 if (getDerived().TransformExprs(E->getPlacementArgs(),
6449 E->getNumPlacementArgs(), true,
6450 PlacementArgs, &ArgumentChanged))
6451 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006452
Douglas Gregorebe10102009-08-20 07:17:43 +00006453 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006454 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006455 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6456 ConstructorArgs, &ArgumentChanged))
6457 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006458
Douglas Gregord2d9da02010-02-26 00:38:10 +00006459 // Transform constructor, new operator, and delete operator.
6460 CXXConstructorDecl *Constructor = 0;
6461 if (E->getConstructor()) {
6462 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006463 getDerived().TransformDecl(E->getLocStart(),
6464 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006465 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006466 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006467 }
6468
6469 FunctionDecl *OperatorNew = 0;
6470 if (E->getOperatorNew()) {
6471 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006472 getDerived().TransformDecl(E->getLocStart(),
6473 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006474 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006475 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006476 }
6477
6478 FunctionDecl *OperatorDelete = 0;
6479 if (E->getOperatorDelete()) {
6480 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006481 getDerived().TransformDecl(E->getLocStart(),
6482 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006483 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006484 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006485 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006486
Douglas Gregora16548e2009-08-11 05:31:07 +00006487 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006488 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006489 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006490 Constructor == E->getConstructor() &&
6491 OperatorNew == E->getOperatorNew() &&
6492 OperatorDelete == E->getOperatorDelete() &&
6493 !ArgumentChanged) {
6494 // Mark any declarations we need as referenced.
6495 // FIXME: instantiation-specific.
6496 if (Constructor)
6497 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6498 if (OperatorNew)
6499 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6500 if (OperatorDelete)
6501 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006502 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006503 }
Mike Stump11289f42009-09-09 15:08:12 +00006504
Douglas Gregor0744ef62010-09-07 21:49:58 +00006505 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006506 if (!ArraySize.get()) {
6507 // If no array size was specified, but the new expression was
6508 // instantiated with an array type (e.g., "new T" where T is
6509 // instantiated with "int[4]"), extract the outer bound from the
6510 // array type as our array size. We do this with constant and
6511 // dependently-sized array types.
6512 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6513 if (!ArrayT) {
6514 // Do nothing
6515 } else if (const ConstantArrayType *ConsArrayT
6516 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006517 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006518 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6519 ConsArrayT->getSize(),
6520 SemaRef.Context.getSizeType(),
6521 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006522 AllocType = ConsArrayT->getElementType();
6523 } else if (const DependentSizedArrayType *DepArrayT
6524 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6525 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006526 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006527 AllocType = DepArrayT->getElementType();
6528 }
6529 }
6530 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006531
Douglas Gregora16548e2009-08-11 05:31:07 +00006532 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6533 E->isGlobalNew(),
6534 /*FIXME:*/E->getLocStart(),
6535 move_arg(PlacementArgs),
6536 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006537 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006538 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006539 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006540 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006541 /*FIXME:*/E->getLocStart(),
6542 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006543 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006544}
Mike Stump11289f42009-09-09 15:08:12 +00006545
Douglas Gregora16548e2009-08-11 05:31:07 +00006546template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006547ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006548TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006549 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006550 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006551 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006552
Douglas Gregord2d9da02010-02-26 00:38:10 +00006553 // Transform the delete operator, if known.
6554 FunctionDecl *OperatorDelete = 0;
6555 if (E->getOperatorDelete()) {
6556 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006557 getDerived().TransformDecl(E->getLocStart(),
6558 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006559 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006560 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006561 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006562
Douglas Gregora16548e2009-08-11 05:31:07 +00006563 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006564 Operand.get() == E->getArgument() &&
6565 OperatorDelete == E->getOperatorDelete()) {
6566 // Mark any declarations we need as referenced.
6567 // FIXME: instantiation-specific.
6568 if (OperatorDelete)
6569 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006570
6571 if (!E->getArgument()->isTypeDependent()) {
6572 QualType Destroyed = SemaRef.Context.getBaseElementType(
6573 E->getDestroyedType());
6574 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6575 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6576 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6577 SemaRef.LookupDestructor(Record));
6578 }
6579 }
6580
John McCallc3007a22010-10-26 07:05:15 +00006581 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006582 }
Mike Stump11289f42009-09-09 15:08:12 +00006583
Douglas Gregora16548e2009-08-11 05:31:07 +00006584 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6585 E->isGlobalDelete(),
6586 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006587 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006588}
Mike Stump11289f42009-09-09 15:08:12 +00006589
Douglas Gregora16548e2009-08-11 05:31:07 +00006590template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006591ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006592TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006593 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006594 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006595 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006596 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006597
John McCallba7bf592010-08-24 05:47:05 +00006598 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006599 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006600 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006601 E->getOperatorLoc(),
6602 E->isArrow()? tok::arrow : tok::period,
6603 ObjectTypePtr,
6604 MayBePseudoDestructor);
6605 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006606 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006607
John McCallba7bf592010-08-24 05:47:05 +00006608 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00006609 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6610 if (QualifierLoc) {
6611 QualifierLoc
6612 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6613 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00006614 return ExprError();
6615 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00006616 CXXScopeSpec SS;
6617 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00006618
Douglas Gregor678f90d2010-02-25 01:56:36 +00006619 PseudoDestructorTypeStorage Destroyed;
6620 if (E->getDestroyedTypeInfo()) {
6621 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006622 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00006623 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00006624 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006625 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006626 Destroyed = DestroyedTypeInfo;
6627 } else if (ObjectType->isDependentType()) {
6628 // We aren't likely to be able to resolve the identifier down to a type
6629 // now anyway, so just retain the identifier.
6630 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6631 E->getDestroyedTypeLoc());
6632 } else {
6633 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00006634 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006635 *E->getDestroyedTypeIdentifier(),
6636 E->getDestroyedTypeLoc(),
6637 /*Scope=*/0,
6638 SS, ObjectTypePtr,
6639 false);
6640 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006641 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006642
Douglas Gregor678f90d2010-02-25 01:56:36 +00006643 Destroyed
6644 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6645 E->getDestroyedTypeLoc());
6646 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006647
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006648 TypeSourceInfo *ScopeTypeInfo = 0;
6649 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006650 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006651 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006652 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006653 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006654
John McCallb268a282010-08-23 23:25:46 +00006655 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006656 E->getOperatorLoc(),
6657 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006658 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006659 ScopeTypeInfo,
6660 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006661 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006662 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006663}
Mike Stump11289f42009-09-09 15:08:12 +00006664
Douglas Gregorad8a3362009-09-04 17:36:40 +00006665template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006666ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006667TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006668 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006669 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6670 Sema::LookupOrdinaryName);
6671
6672 // Transform all the decls.
6673 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6674 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006675 NamedDecl *InstD = static_cast<NamedDecl*>(
6676 getDerived().TransformDecl(Old->getNameLoc(),
6677 *I));
John McCall84d87672009-12-10 09:41:52 +00006678 if (!InstD) {
6679 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6680 // This can happen because of dependent hiding.
6681 if (isa<UsingShadowDecl>(*I))
6682 continue;
6683 else
John McCallfaf5fb42010-08-26 23:41:50 +00006684 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006685 }
John McCalle66edc12009-11-24 19:00:30 +00006686
6687 // Expand using declarations.
6688 if (isa<UsingDecl>(InstD)) {
6689 UsingDecl *UD = cast<UsingDecl>(InstD);
6690 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6691 E = UD->shadow_end(); I != E; ++I)
6692 R.addDecl(*I);
6693 continue;
6694 }
6695
6696 R.addDecl(InstD);
6697 }
6698
6699 // Resolve a kind, but don't do any further analysis. If it's
6700 // ambiguous, the callee needs to deal with it.
6701 R.resolveKind();
6702
6703 // Rebuild the nested-name qualifier, if present.
6704 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00006705 if (Old->getQualifierLoc()) {
6706 NestedNameSpecifierLoc QualifierLoc
6707 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
6708 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006709 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006710
Douglas Gregor0da1d432011-02-28 20:01:57 +00006711 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006712 }
6713
Douglas Gregor9262f472010-04-27 18:19:34 +00006714 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006715 CXXRecordDecl *NamingClass
6716 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6717 Old->getNameLoc(),
6718 Old->getNamingClass()));
6719 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006720 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006721
Douglas Gregorda7be082010-04-27 16:10:10 +00006722 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006723 }
6724
6725 // If we have no template arguments, it's a normal declaration name.
6726 if (!Old->hasExplicitTemplateArgs())
6727 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6728
6729 // If we have template arguments, rebuild them, then rebuild the
6730 // templateid expression.
6731 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006732 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6733 Old->getNumTemplateArgs(),
6734 TransArgs))
6735 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006736
6737 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6738 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006739}
Mike Stump11289f42009-09-09 15:08:12 +00006740
Douglas Gregora16548e2009-08-11 05:31:07 +00006741template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006742ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006743TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006744 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6745 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006746 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006747
Douglas Gregora16548e2009-08-11 05:31:07 +00006748 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006749 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006750 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006751
Mike Stump11289f42009-09-09 15:08:12 +00006752 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006753 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006754 T,
6755 E->getLocEnd());
6756}
Mike Stump11289f42009-09-09 15:08:12 +00006757
Douglas Gregora16548e2009-08-11 05:31:07 +00006758template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006759ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006760TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6761 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6762 if (!LhsT)
6763 return ExprError();
6764
6765 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6766 if (!RhsT)
6767 return ExprError();
6768
6769 if (!getDerived().AlwaysRebuild() &&
6770 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6771 return SemaRef.Owned(E);
6772
6773 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6774 E->getLocStart(),
6775 LhsT, RhsT,
6776 E->getLocEnd());
6777}
6778
6779template<typename Derived>
6780ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006781TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006782 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006783 NestedNameSpecifierLoc QualifierLoc
6784 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6785 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006786 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006787
John McCall31f82722010-11-12 08:19:04 +00006788 // TODO: If this is a conversion-function-id, verify that the
6789 // destination type name (if present) resolves the same way after
6790 // instantiation as it did in the local scope.
6791
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006792 DeclarationNameInfo NameInfo
6793 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6794 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006795 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006796
John McCalle66edc12009-11-24 19:00:30 +00006797 if (!E->hasExplicitTemplateArgs()) {
6798 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006799 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006800 // Note: it is sufficient to compare the Name component of NameInfo:
6801 // if name has not changed, DNLoc has not changed either.
6802 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006803 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006804
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006805 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006806 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006807 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006808 }
John McCall6b51f282009-11-23 01:53:49 +00006809
6810 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006811 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6812 E->getNumTemplateArgs(),
6813 TransArgs))
6814 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006815
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006816 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006817 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006818 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006819}
6820
6821template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006822ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006823TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006824 // CXXConstructExprs are always implicit, so when we have a
6825 // 1-argument construction we just transform that argument.
6826 if (E->getNumArgs() == 1 ||
6827 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6828 return getDerived().TransformExpr(E->getArg(0));
6829
Douglas Gregora16548e2009-08-11 05:31:07 +00006830 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6831
6832 QualType T = getDerived().TransformType(E->getType());
6833 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006834 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006835
6836 CXXConstructorDecl *Constructor
6837 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006838 getDerived().TransformDecl(E->getLocStart(),
6839 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006840 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006841 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006842
Douglas Gregora16548e2009-08-11 05:31:07 +00006843 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006844 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006845 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6846 &ArgumentChanged))
6847 return ExprError();
6848
Douglas Gregora16548e2009-08-11 05:31:07 +00006849 if (!getDerived().AlwaysRebuild() &&
6850 T == E->getType() &&
6851 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006852 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006853 // Mark the constructor as referenced.
6854 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006855 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006856 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006857 }
Mike Stump11289f42009-09-09 15:08:12 +00006858
Douglas Gregordb121ba2009-12-14 16:27:04 +00006859 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6860 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006861 move_arg(Args),
6862 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006863 E->getConstructionKind(),
6864 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006865}
Mike Stump11289f42009-09-09 15:08:12 +00006866
Douglas Gregora16548e2009-08-11 05:31:07 +00006867/// \brief Transform a C++ temporary-binding expression.
6868///
Douglas Gregor363b1512009-12-24 18:51:59 +00006869/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6870/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006871template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006872ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006873TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006874 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006875}
Mike Stump11289f42009-09-09 15:08:12 +00006876
John McCall5d413782010-12-06 08:20:24 +00006877/// \brief Transform a C++ expression that contains cleanups that should
6878/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006879///
John McCall5d413782010-12-06 08:20:24 +00006880/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006881/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006882template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006883ExprResult
John McCall5d413782010-12-06 08:20:24 +00006884TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006885 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006886}
Mike Stump11289f42009-09-09 15:08:12 +00006887
Douglas Gregora16548e2009-08-11 05:31:07 +00006888template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006889ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006890TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006891 CXXTemporaryObjectExpr *E) {
6892 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6893 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006894 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006895
Douglas Gregora16548e2009-08-11 05:31:07 +00006896 CXXConstructorDecl *Constructor
6897 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006898 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006899 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006900 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006901 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006902
Douglas Gregora16548e2009-08-11 05:31:07 +00006903 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006904 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006905 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00006906 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6907 &ArgumentChanged))
6908 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006909
Douglas Gregora16548e2009-08-11 05:31:07 +00006910 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006911 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006912 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006913 !ArgumentChanged) {
6914 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006915 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006916 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006917 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006918
6919 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6920 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006921 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006922 E->getLocEnd());
6923}
Mike Stump11289f42009-09-09 15:08:12 +00006924
Douglas Gregora16548e2009-08-11 05:31:07 +00006925template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006926ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006927TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006928 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00006929 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6930 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006931 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006932
Douglas Gregora16548e2009-08-11 05:31:07 +00006933 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006934 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006935 Args.reserve(E->arg_size());
6936 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6937 &ArgumentChanged))
6938 return ExprError();
6939
Douglas Gregora16548e2009-08-11 05:31:07 +00006940 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006941 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006942 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006943 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006944
Douglas Gregora16548e2009-08-11 05:31:07 +00006945 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00006946 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00006947 E->getLParenLoc(),
6948 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006949 E->getRParenLoc());
6950}
Mike Stump11289f42009-09-09 15:08:12 +00006951
Douglas Gregora16548e2009-08-11 05:31:07 +00006952template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006953ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006954TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006955 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006956 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006957 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006958 Expr *OldBase;
6959 QualType BaseType;
6960 QualType ObjectType;
6961 if (!E->isImplicitAccess()) {
6962 OldBase = E->getBase();
6963 Base = getDerived().TransformExpr(OldBase);
6964 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006965 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006966
John McCall2d74de92009-12-01 22:10:20 +00006967 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00006968 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00006969 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006970 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006971 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006972 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00006973 ObjectTy,
6974 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00006975 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006976 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006977
John McCallba7bf592010-08-24 05:47:05 +00006978 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00006979 BaseType = ((Expr*) Base.get())->getType();
6980 } else {
6981 OldBase = 0;
6982 BaseType = getDerived().TransformType(E->getBaseType());
6983 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6984 }
Mike Stump11289f42009-09-09 15:08:12 +00006985
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006986 // Transform the first part of the nested-name-specifier that qualifies
6987 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006988 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006989 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00006990 E->getFirstQualifierFoundInScope(),
6991 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00006992
Douglas Gregore16af532011-02-28 18:50:33 +00006993 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006994 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00006995 QualifierLoc
6996 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
6997 ObjectType,
6998 FirstQualifierInScope);
6999 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007000 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007001 }
Mike Stump11289f42009-09-09 15:08:12 +00007002
John McCall31f82722010-11-12 08:19:04 +00007003 // TODO: If this is a conversion-function-id, verify that the
7004 // destination type name (if present) resolves the same way after
7005 // instantiation as it did in the local scope.
7006
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007007 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007008 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007009 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007010 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007011
John McCall2d74de92009-12-01 22:10:20 +00007012 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007013 // This is a reference to a member without an explicitly-specified
7014 // template argument list. Optimize for this common case.
7015 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007016 Base.get() == OldBase &&
7017 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007018 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007019 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007020 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007021 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007022
John McCallb268a282010-08-23 23:25:46 +00007023 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007024 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007025 E->isArrow(),
7026 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007027 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007028 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007029 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007030 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007031 }
7032
John McCall6b51f282009-11-23 01:53:49 +00007033 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007034 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7035 E->getNumTemplateArgs(),
7036 TransArgs))
7037 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007038
John McCallb268a282010-08-23 23:25:46 +00007039 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007040 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007041 E->isArrow(),
7042 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007043 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007044 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007045 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007046 &TransArgs);
7047}
7048
7049template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007050ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007051TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007052 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007053 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007054 QualType BaseType;
7055 if (!Old->isImplicitAccess()) {
7056 Base = getDerived().TransformExpr(Old->getBase());
7057 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007058 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007059 BaseType = ((Expr*) Base.get())->getType();
7060 } else {
7061 BaseType = getDerived().TransformType(Old->getBaseType());
7062 }
John McCall10eae182009-11-30 22:42:35 +00007063
Douglas Gregor0da1d432011-02-28 20:01:57 +00007064 NestedNameSpecifierLoc QualifierLoc;
7065 if (Old->getQualifierLoc()) {
7066 QualifierLoc
7067 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7068 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007069 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007070 }
7071
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007072 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007073 Sema::LookupOrdinaryName);
7074
7075 // Transform all the decls.
7076 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7077 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007078 NamedDecl *InstD = static_cast<NamedDecl*>(
7079 getDerived().TransformDecl(Old->getMemberLoc(),
7080 *I));
John McCall84d87672009-12-10 09:41:52 +00007081 if (!InstD) {
7082 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7083 // This can happen because of dependent hiding.
7084 if (isa<UsingShadowDecl>(*I))
7085 continue;
7086 else
John McCallfaf5fb42010-08-26 23:41:50 +00007087 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00007088 }
John McCall10eae182009-11-30 22:42:35 +00007089
7090 // Expand using declarations.
7091 if (isa<UsingDecl>(InstD)) {
7092 UsingDecl *UD = cast<UsingDecl>(InstD);
7093 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7094 E = UD->shadow_end(); I != E; ++I)
7095 R.addDecl(*I);
7096 continue;
7097 }
7098
7099 R.addDecl(InstD);
7100 }
7101
7102 R.resolveKind();
7103
Douglas Gregor9262f472010-04-27 18:19:34 +00007104 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007105 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007106 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007107 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007108 Old->getMemberLoc(),
7109 Old->getNamingClass()));
7110 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007111 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007112
Douglas Gregorda7be082010-04-27 16:10:10 +00007113 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007114 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007115
John McCall10eae182009-11-30 22:42:35 +00007116 TemplateArgumentListInfo TransArgs;
7117 if (Old->hasExplicitTemplateArgs()) {
7118 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7119 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007120 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7121 Old->getNumTemplateArgs(),
7122 TransArgs))
7123 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007124 }
John McCall38836f02010-01-15 08:34:02 +00007125
7126 // FIXME: to do this check properly, we will need to preserve the
7127 // first-qualifier-in-scope here, just in case we had a dependent
7128 // base (and therefore couldn't do the check) and a
7129 // nested-name-qualifier (and therefore could do the lookup).
7130 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007131
John McCallb268a282010-08-23 23:25:46 +00007132 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007133 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007134 Old->getOperatorLoc(),
7135 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007136 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007137 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007138 R,
7139 (Old->hasExplicitTemplateArgs()
7140 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007141}
7142
7143template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007144ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007145TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7146 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7147 if (SubExpr.isInvalid())
7148 return ExprError();
7149
7150 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007151 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007152
7153 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7154}
7155
7156template<typename Derived>
7157ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007158TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007159 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7160 if (Pattern.isInvalid())
7161 return ExprError();
7162
7163 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7164 return SemaRef.Owned(E);
7165
Douglas Gregorb8840002011-01-14 21:20:45 +00007166 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7167 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007168}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007169
7170template<typename Derived>
7171ExprResult
7172TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7173 // If E is not value-dependent, then nothing will change when we transform it.
7174 // Note: This is an instantiation-centric view.
7175 if (!E->isValueDependent())
7176 return SemaRef.Owned(E);
7177
7178 // Note: None of the implementations of TryExpandParameterPacks can ever
7179 // produce a diagnostic when given only a single unexpanded parameter pack,
7180 // so
7181 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7182 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007183 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007184 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007185 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7186 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007187 ShouldExpand, RetainExpansion,
7188 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007189 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007190
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007191 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007192 return SemaRef.Owned(E);
7193
7194 // We now know the length of the parameter pack, so build a new expression
7195 // that stores that length.
7196 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7197 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007198 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007199}
7200
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007201template<typename Derived>
7202ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007203TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7204 SubstNonTypeTemplateParmPackExpr *E) {
7205 // Default behavior is to do nothing with this transformation.
7206 return SemaRef.Owned(E);
7207}
7208
7209template<typename Derived>
7210ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007211TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007212 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007213}
7214
Mike Stump11289f42009-09-09 15:08:12 +00007215template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007216ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007217TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007218 TypeSourceInfo *EncodedTypeInfo
7219 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7220 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007221 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007222
Douglas Gregora16548e2009-08-11 05:31:07 +00007223 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007224 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007225 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007226
7227 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007228 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007229 E->getRParenLoc());
7230}
Mike Stump11289f42009-09-09 15:08:12 +00007231
Douglas Gregora16548e2009-08-11 05:31:07 +00007232template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007233ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007234TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007235 // Transform arguments.
7236 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007237 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007238 Args.reserve(E->getNumArgs());
7239 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7240 &ArgChanged))
7241 return ExprError();
7242
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007243 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7244 // Class message: transform the receiver type.
7245 TypeSourceInfo *ReceiverTypeInfo
7246 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7247 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007248 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007249
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007250 // If nothing changed, just retain the existing message send.
7251 if (!getDerived().AlwaysRebuild() &&
7252 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007253 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007254
7255 // Build a new class message send.
7256 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7257 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007258 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007259 E->getMethodDecl(),
7260 E->getLeftLoc(),
7261 move_arg(Args),
7262 E->getRightLoc());
7263 }
7264
7265 // Instance message: transform the receiver
7266 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7267 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007268 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007269 = getDerived().TransformExpr(E->getInstanceReceiver());
7270 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007271 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007272
7273 // If nothing changed, just retain the existing message send.
7274 if (!getDerived().AlwaysRebuild() &&
7275 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007276 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007277
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007278 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007279 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007280 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007281 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007282 E->getMethodDecl(),
7283 E->getLeftLoc(),
7284 move_arg(Args),
7285 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007286}
7287
Mike Stump11289f42009-09-09 15:08:12 +00007288template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007289ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007290TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007291 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007292}
7293
Mike Stump11289f42009-09-09 15:08:12 +00007294template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007295ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007296TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007297 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007298}
7299
Mike Stump11289f42009-09-09 15:08:12 +00007300template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007301ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007302TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007303 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007304 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007305 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007306 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007307
7308 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007309
Douglas Gregord51d90d2010-04-26 20:11:03 +00007310 // If nothing changed, just retain the existing expression.
7311 if (!getDerived().AlwaysRebuild() &&
7312 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007313 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007314
John McCallb268a282010-08-23 23:25:46 +00007315 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007316 E->getLocation(),
7317 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007318}
7319
Mike Stump11289f42009-09-09 15:08:12 +00007320template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007321ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007322TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007323 // 'super' and types never change. Property never changes. Just
7324 // retain the existing expression.
7325 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007326 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007327
Douglas Gregor9faee212010-04-26 20:47:02 +00007328 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007329 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007330 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007331 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007332
Douglas Gregor9faee212010-04-26 20:47:02 +00007333 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007334
Douglas Gregor9faee212010-04-26 20:47:02 +00007335 // If nothing changed, just retain the existing expression.
7336 if (!getDerived().AlwaysRebuild() &&
7337 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007338 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007339
John McCallb7bd14f2010-12-02 01:19:52 +00007340 if (E->isExplicitProperty())
7341 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7342 E->getExplicitProperty(),
7343 E->getLocation());
7344
7345 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7346 E->getType(),
7347 E->getImplicitPropertyGetter(),
7348 E->getImplicitPropertySetter(),
7349 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007350}
7351
Mike Stump11289f42009-09-09 15:08:12 +00007352template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007353ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007354TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007355 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007356 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007357 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007358 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007359
Douglas Gregord51d90d2010-04-26 20:11:03 +00007360 // If nothing changed, just retain the existing expression.
7361 if (!getDerived().AlwaysRebuild() &&
7362 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007363 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007364
John McCallb268a282010-08-23 23:25:46 +00007365 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007366 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007367}
7368
Mike Stump11289f42009-09-09 15:08:12 +00007369template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007370ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007371TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007372 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007373 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007374 SubExprs.reserve(E->getNumSubExprs());
7375 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7376 SubExprs, &ArgumentChanged))
7377 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007378
Douglas Gregora16548e2009-08-11 05:31:07 +00007379 if (!getDerived().AlwaysRebuild() &&
7380 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007381 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007382
Douglas Gregora16548e2009-08-11 05:31:07 +00007383 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7384 move_arg(SubExprs),
7385 E->getRParenLoc());
7386}
7387
Mike Stump11289f42009-09-09 15:08:12 +00007388template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007389ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007390TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007391 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007392
John McCall490112f2011-02-04 18:33:18 +00007393 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7394 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7395
7396 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7397 llvm::SmallVector<ParmVarDecl*, 4> params;
7398 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007399
7400 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007401 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7402 oldBlock->param_begin(),
7403 oldBlock->param_size(),
7404 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007405 return true;
John McCall490112f2011-02-04 18:33:18 +00007406
7407 const FunctionType *exprFunctionType = E->getFunctionType();
7408 QualType exprResultType = exprFunctionType->getResultType();
7409 if (!exprResultType.isNull()) {
7410 if (!exprResultType->isDependentType())
7411 blockScope->ReturnType = exprResultType;
7412 else if (exprResultType != getSema().Context.DependentTy)
7413 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007414 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007415
7416 // If the return type has not been determined yet, leave it as a dependent
7417 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007418 if (blockScope->ReturnType.isNull())
7419 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007420
7421 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007422 if (blockScope->ReturnType->isObjCObjectType()) {
7423 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007424 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007425 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007426 return ExprError();
7427 }
John McCall3882ace2011-01-05 12:14:39 +00007428
John McCall490112f2011-02-04 18:33:18 +00007429 QualType functionType = getDerived().RebuildFunctionProtoType(
7430 blockScope->ReturnType,
7431 paramTypes.data(),
7432 paramTypes.size(),
7433 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007434 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007435 exprFunctionType->getExtInfo());
7436 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007437
7438 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007439 if (!params.empty())
7440 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007441
7442 // If the return type wasn't explicitly set, it will have been marked as a
7443 // dependent type (DependentTy); clear out the return type setting so
7444 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007445 if (blockScope->ReturnType == getSema().Context.DependentTy)
7446 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007447
John McCall3882ace2011-01-05 12:14:39 +00007448 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007449 StmtResult body = getDerived().TransformStmt(E->getBody());
7450 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007451 return ExprError();
7452
John McCall490112f2011-02-04 18:33:18 +00007453#ifndef NDEBUG
7454 // In builds with assertions, make sure that we captured everything we
7455 // captured before.
7456
7457 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7458
7459 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7460 e = oldBlock->capture_end(); i != e; ++i) {
John McCall351762c2011-02-07 10:33:21 +00007461 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007462
7463 // Ignore parameter packs.
7464 if (isa<ParmVarDecl>(oldCapture) &&
7465 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7466 continue;
7467
7468 VarDecl *newCapture =
7469 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7470 oldCapture));
John McCall351762c2011-02-07 10:33:21 +00007471 assert(blockScope->CaptureMap.count(newCapture));
John McCall490112f2011-02-04 18:33:18 +00007472 }
7473#endif
7474
7475 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7476 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007477}
7478
Mike Stump11289f42009-09-09 15:08:12 +00007479template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007480ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007481TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007482 ValueDecl *ND
7483 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7484 E->getDecl()));
7485 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007486 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007487
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007488 if (!getDerived().AlwaysRebuild() &&
7489 ND == E->getDecl()) {
7490 // Mark it referenced in the new context regardless.
7491 // FIXME: this is a bit instantiation-specific.
7492 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7493
John McCallc3007a22010-10-26 07:05:15 +00007494 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007495 }
7496
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007497 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00007498 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007499 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007500}
Mike Stump11289f42009-09-09 15:08:12 +00007501
Douglas Gregora16548e2009-08-11 05:31:07 +00007502//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007503// Type reconstruction
7504//===----------------------------------------------------------------------===//
7505
Mike Stump11289f42009-09-09 15:08:12 +00007506template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007507QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7508 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007509 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007510 getDerived().getBaseEntity());
7511}
7512
Mike Stump11289f42009-09-09 15:08:12 +00007513template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007514QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7515 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007516 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007517 getDerived().getBaseEntity());
7518}
7519
Mike Stump11289f42009-09-09 15:08:12 +00007520template<typename Derived>
7521QualType
John McCall70dd5f62009-10-30 00:06:24 +00007522TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7523 bool WrittenAsLValue,
7524 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007525 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007526 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007527}
7528
7529template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007530QualType
John McCall70dd5f62009-10-30 00:06:24 +00007531TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7532 QualType ClassType,
7533 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007534 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007535 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007536}
7537
7538template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007539QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007540TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7541 ArrayType::ArraySizeModifier SizeMod,
7542 const llvm::APInt *Size,
7543 Expr *SizeExpr,
7544 unsigned IndexTypeQuals,
7545 SourceRange BracketsRange) {
7546 if (SizeExpr || !Size)
7547 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7548 IndexTypeQuals, BracketsRange,
7549 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007550
7551 QualType Types[] = {
7552 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7553 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7554 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007555 };
7556 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7557 QualType SizeType;
7558 for (unsigned I = 0; I != NumTypes; ++I)
7559 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7560 SizeType = Types[I];
7561 break;
7562 }
Mike Stump11289f42009-09-09 15:08:12 +00007563
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007564 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7565 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007566 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007567 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007568 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007569}
Mike Stump11289f42009-09-09 15:08:12 +00007570
Douglas Gregord6ff3322009-08-04 16:50:30 +00007571template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007572QualType
7573TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007574 ArrayType::ArraySizeModifier SizeMod,
7575 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007576 unsigned IndexTypeQuals,
7577 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007578 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007579 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007580}
7581
7582template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007583QualType
Mike Stump11289f42009-09-09 15:08:12 +00007584TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007585 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007586 unsigned IndexTypeQuals,
7587 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007588 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007589 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007590}
Mike Stump11289f42009-09-09 15:08:12 +00007591
Douglas Gregord6ff3322009-08-04 16:50:30 +00007592template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007593QualType
7594TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007595 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007596 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007597 unsigned IndexTypeQuals,
7598 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007599 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007600 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007601 IndexTypeQuals, BracketsRange);
7602}
7603
7604template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007605QualType
7606TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007607 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007608 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007609 unsigned IndexTypeQuals,
7610 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007611 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007612 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007613 IndexTypeQuals, BracketsRange);
7614}
7615
7616template<typename Derived>
7617QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007618 unsigned NumElements,
7619 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007620 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007621 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007622}
Mike Stump11289f42009-09-09 15:08:12 +00007623
Douglas Gregord6ff3322009-08-04 16:50:30 +00007624template<typename Derived>
7625QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7626 unsigned NumElements,
7627 SourceLocation AttributeLoc) {
7628 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7629 NumElements, true);
7630 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007631 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7632 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007633 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007634}
Mike Stump11289f42009-09-09 15:08:12 +00007635
Douglas Gregord6ff3322009-08-04 16:50:30 +00007636template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007637QualType
7638TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007639 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007640 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007641 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007642}
Mike Stump11289f42009-09-09 15:08:12 +00007643
Douglas Gregord6ff3322009-08-04 16:50:30 +00007644template<typename Derived>
7645QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007646 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007647 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007648 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007649 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007650 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00007651 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007652 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007653 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007654 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007655 getDerived().getBaseEntity(),
7656 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007657}
Mike Stump11289f42009-09-09 15:08:12 +00007658
Douglas Gregord6ff3322009-08-04 16:50:30 +00007659template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007660QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7661 return SemaRef.Context.getFunctionNoProtoType(T);
7662}
7663
7664template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007665QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7666 assert(D && "no decl found");
7667 if (D->isInvalidDecl()) return QualType();
7668
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007669 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007670 TypeDecl *Ty;
7671 if (isa<UsingDecl>(D)) {
7672 UsingDecl *Using = cast<UsingDecl>(D);
7673 assert(Using->isTypeName() &&
7674 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7675
7676 // A valid resolved using typename decl points to exactly one type decl.
7677 assert(++Using->shadow_begin() == Using->shadow_end());
7678 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007679
John McCallb96ec562009-12-04 22:46:56 +00007680 } else {
7681 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7682 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7683 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7684 }
7685
7686 return SemaRef.Context.getTypeDeclType(Ty);
7687}
7688
7689template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007690QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7691 SourceLocation Loc) {
7692 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007693}
7694
7695template<typename Derived>
7696QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7697 return SemaRef.Context.getTypeOfType(Underlying);
7698}
7699
7700template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007701QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7702 SourceLocation Loc) {
7703 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007704}
7705
7706template<typename Derived>
7707QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007708 TemplateName Template,
7709 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00007710 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00007711 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007712}
Mike Stump11289f42009-09-09 15:08:12 +00007713
Douglas Gregor1135c352009-08-06 05:28:30 +00007714template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007715TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007716TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007717 bool TemplateKW,
7718 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00007719 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007720 Template);
7721}
7722
7723template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007724TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007725TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
7726 const IdentifierInfo &Name,
7727 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00007728 QualType ObjectType,
7729 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00007730 UnqualifiedId TemplateName;
7731 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00007732 Sema::TemplateTy Template;
7733 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00007734 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007735 SS,
Douglas Gregor9db53502011-03-02 18:07:45 +00007736 TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00007737 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007738 /*EnteringContext=*/false,
7739 Template);
John McCall31f82722010-11-12 08:19:04 +00007740 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007741}
Mike Stump11289f42009-09-09 15:08:12 +00007742
Douglas Gregora16548e2009-08-11 05:31:07 +00007743template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007744TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007745TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007746 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00007747 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007748 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00007749 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00007750 // FIXME: Bogus location information.
7751 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
7752 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007753 Sema::TemplateTy Template;
7754 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00007755 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007756 SS,
7757 Name,
John McCallba7bf592010-08-24 05:47:05 +00007758 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007759 /*EnteringContext=*/false,
7760 Template);
7761 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007762}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007763
Douglas Gregor71395fa2009-11-04 00:56:37 +00007764template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007765ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007766TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7767 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007768 Expr *OrigCallee,
7769 Expr *First,
7770 Expr *Second) {
7771 Expr *Callee = OrigCallee->IgnoreParenCasts();
7772 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007773
Douglas Gregora16548e2009-08-11 05:31:07 +00007774 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007775 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007776 if (!First->getType()->isOverloadableType() &&
7777 !Second->getType()->isOverloadableType())
7778 return getSema().CreateBuiltinArraySubscriptExpr(First,
7779 Callee->getLocStart(),
7780 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007781 } else if (Op == OO_Arrow) {
7782 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007783 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7784 } else if (Second == 0 || isPostIncDec) {
7785 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007786 // The argument is not of overloadable type, so try to create a
7787 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007788 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007789 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007790
John McCallb268a282010-08-23 23:25:46 +00007791 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007792 }
7793 } else {
John McCallb268a282010-08-23 23:25:46 +00007794 if (!First->getType()->isOverloadableType() &&
7795 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007796 // Neither of the arguments is an overloadable type, so try to
7797 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007798 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007799 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007800 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007801 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007802 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007803
Douglas Gregora16548e2009-08-11 05:31:07 +00007804 return move(Result);
7805 }
7806 }
Mike Stump11289f42009-09-09 15:08:12 +00007807
7808 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007809 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007810 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007811
John McCallb268a282010-08-23 23:25:46 +00007812 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007813 assert(ULE->requiresADL());
7814
7815 // FIXME: Do we have to check
7816 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007817 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007818 } else {
John McCallb268a282010-08-23 23:25:46 +00007819 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007820 }
Mike Stump11289f42009-09-09 15:08:12 +00007821
Douglas Gregora16548e2009-08-11 05:31:07 +00007822 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007823 Expr *Args[2] = { First, Second };
7824 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007825
Douglas Gregora16548e2009-08-11 05:31:07 +00007826 // Create the overloaded operator invocation for unary operators.
7827 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007828 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007829 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007830 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007831 }
Mike Stump11289f42009-09-09 15:08:12 +00007832
Sebastian Redladba46e2009-10-29 20:17:01 +00007833 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007834 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007835 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007836 First,
7837 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007838
Douglas Gregora16548e2009-08-11 05:31:07 +00007839 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007840 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007841 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007842 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7843 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007844 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007845
Mike Stump11289f42009-09-09 15:08:12 +00007846 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007847}
Mike Stump11289f42009-09-09 15:08:12 +00007848
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007849template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007850ExprResult
John McCallb268a282010-08-23 23:25:46 +00007851TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007852 SourceLocation OperatorLoc,
7853 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00007854 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007855 TypeSourceInfo *ScopeType,
7856 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007857 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007858 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00007859 QualType BaseType = Base->getType();
7860 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007861 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007862 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007863 !BaseType->getAs<PointerType>()->getPointeeType()
7864 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007865 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00007866 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007867 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007868 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007869 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007870 /*FIXME?*/true);
7871 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007872
Douglas Gregor678f90d2010-02-25 01:56:36 +00007873 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007874 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7875 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7876 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7877 NameInfo.setNamedTypeInfo(DestroyedType);
7878
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007879 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007880
John McCallb268a282010-08-23 23:25:46 +00007881 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007882 OperatorLoc, isArrow,
7883 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007884 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007885 /*TemplateArgs*/ 0);
7886}
7887
Douglas Gregord6ff3322009-08-04 16:50:30 +00007888} // end namespace clang
7889
7890#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H