blob: 835b2f875ed0a449c6296a2a669ba2415e3cb16a [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
Douglas Gregora16548e2009-08-11 05:31:07 +00001303 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001304 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001305 /// By default, performs semantic analysis to build the new expression.
1306 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001307 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001308 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001309 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001310 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001311 }
1312
Mike Stump11289f42009-09-09 15:08:12 +00001313 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001314 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001315 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001316 /// By default, performs semantic analysis to build the new expression.
1317 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001318 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001320 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001321 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001322 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001323 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001324
Douglas Gregora16548e2009-08-11 05:31:07 +00001325 return move(Result);
1326 }
Mike Stump11289f42009-09-09 15:08:12 +00001327
Douglas Gregora16548e2009-08-11 05:31:07 +00001328 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001329 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001330 /// By default, performs semantic analysis to build the new expression.
1331 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001332 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001334 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001335 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001336 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1337 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001338 RBracketLoc);
1339 }
1340
1341 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001342 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001343 /// By default, performs semantic analysis to build the new expression.
1344 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001345 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001346 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001347 SourceLocation RParenLoc,
1348 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001349 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001350 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001351 }
1352
1353 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001354 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 /// By default, performs semantic analysis to build the new expression.
1356 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001357 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001358 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001359 NestedNameSpecifierLoc QualifierLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001360 const DeclarationNameInfo &MemberNameInfo,
1361 ValueDecl *Member,
1362 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001363 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001364 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001365 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001366 // We have a reference to an unnamed field. This is always the
1367 // base of an anonymous struct/union member access, i.e. the
1368 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001369 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001370 assert(Member->getType()->isRecordType() &&
1371 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001372
Douglas Gregorea972d32011-02-28 21:54:11 +00001373 if (getSema().PerformObjectMemberConversion(Base,
1374 QualifierLoc.getNestedNameSpecifier(),
John McCall16df1e52010-03-30 21:47:33 +00001375 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001376 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001377
John McCall7decc9e2010-11-18 06:31:45 +00001378 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001379 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001380 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001381 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001382 cast<FieldDecl>(Member)->getType(),
1383 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001384 return getSema().Owned(ME);
1385 }
Mike Stump11289f42009-09-09 15:08:12 +00001386
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001387 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001388 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001389
John McCallb268a282010-08-23 23:25:46 +00001390 getSema().DefaultFunctionArrayConversion(Base);
1391 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001392
John McCall16df1e52010-03-30 21:47:33 +00001393 // FIXME: this involves duplicating earlier analysis in a lot of
1394 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001395 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001396 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001397 R.resolveKind();
1398
John McCallb268a282010-08-23 23:25:46 +00001399 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001400 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001401 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001402 }
Mike Stump11289f42009-09-09 15:08:12 +00001403
Douglas Gregora16548e2009-08-11 05:31:07 +00001404 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001405 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001406 /// By default, performs semantic analysis to build the new expression.
1407 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001408 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001409 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001410 Expr *LHS, Expr *RHS) {
1411 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001412 }
1413
1414 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001415 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001416 /// By default, performs semantic analysis to build the new expression.
1417 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001418 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001419 SourceLocation QuestionLoc,
1420 Expr *LHS,
1421 SourceLocation ColonLoc,
1422 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001423 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1424 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001425 }
1426
Douglas Gregora16548e2009-08-11 05:31:07 +00001427 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001428 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001429 /// By default, performs semantic analysis to build the new expression.
1430 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001431 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001432 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001433 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001434 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001435 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001436 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001437 }
Mike Stump11289f42009-09-09 15:08:12 +00001438
Douglas Gregora16548e2009-08-11 05:31:07 +00001439 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001440 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001441 /// By default, performs semantic analysis to build the new expression.
1442 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001443 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001444 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001445 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001446 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001447 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001448 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001449 }
Mike Stump11289f42009-09-09 15:08:12 +00001450
Douglas Gregora16548e2009-08-11 05:31:07 +00001451 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001452 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001453 /// By default, performs semantic analysis to build the new expression.
1454 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001455 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001456 SourceLocation OpLoc,
1457 SourceLocation AccessorLoc,
1458 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001459
John McCall10eae182009-11-30 22:42:35 +00001460 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001461 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001462 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001463 OpLoc, /*IsArrow*/ false,
1464 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001465 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001466 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001467 }
Mike Stump11289f42009-09-09 15:08:12 +00001468
Douglas Gregora16548e2009-08-11 05:31:07 +00001469 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001470 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001471 /// By default, performs semantic analysis to build the new expression.
1472 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001473 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001474 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001475 SourceLocation RBraceLoc,
1476 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001477 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001478 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1479 if (Result.isInvalid() || ResultTy->isDependentType())
1480 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001481
Douglas Gregord3d93062009-11-09 17:16:50 +00001482 // Patch in the result type we were given, which may have been computed
1483 // when the initial InitListExpr was built.
1484 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1485 ILE->setType(ResultTy);
1486 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001487 }
Mike Stump11289f42009-09-09 15:08:12 +00001488
Douglas Gregora16548e2009-08-11 05:31:07 +00001489 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001490 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001491 /// By default, performs semantic analysis to build the new expression.
1492 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001493 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001494 MultiExprArg ArrayExprs,
1495 SourceLocation EqualOrColonLoc,
1496 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001497 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001498 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001499 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001500 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001501 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001502 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001503
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 ArrayExprs.release();
1505 return move(Result);
1506 }
Mike Stump11289f42009-09-09 15:08:12 +00001507
Douglas Gregora16548e2009-08-11 05:31:07 +00001508 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001509 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001510 /// By default, builds the implicit value initialization without performing
1511 /// any semantic analysis. Subclasses may override this routine to provide
1512 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001513 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001514 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1515 }
Mike Stump11289f42009-09-09 15:08:12 +00001516
Douglas Gregora16548e2009-08-11 05:31:07 +00001517 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001518 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001519 /// By default, performs semantic analysis to build the new expression.
1520 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001521 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001522 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001523 SourceLocation RParenLoc) {
1524 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001525 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001526 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001527 }
1528
1529 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001530 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001531 /// By default, performs semantic analysis to build the new expression.
1532 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001533 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001534 MultiExprArg SubExprs,
1535 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001536 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001537 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001538 }
Mike Stump11289f42009-09-09 15:08:12 +00001539
Douglas Gregora16548e2009-08-11 05:31:07 +00001540 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001541 ///
1542 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 /// rather than attempting to map the label statement itself.
1544 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001545 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001546 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001547 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001548 }
Mike Stump11289f42009-09-09 15:08:12 +00001549
Douglas Gregora16548e2009-08-11 05:31:07 +00001550 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001551 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001552 /// By default, performs semantic analysis to build the new expression.
1553 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001554 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001555 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001556 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001557 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001558 }
Mike Stump11289f42009-09-09 15:08:12 +00001559
Douglas Gregora16548e2009-08-11 05:31:07 +00001560 /// \brief Build a new __builtin_choose_expr expression.
1561 ///
1562 /// By default, performs semantic analysis to build the new expression.
1563 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001564 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001565 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001566 SourceLocation RParenLoc) {
1567 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001568 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001569 RParenLoc);
1570 }
Mike Stump11289f42009-09-09 15:08:12 +00001571
Douglas Gregora16548e2009-08-11 05:31:07 +00001572 /// \brief Build a new overloaded operator call expression.
1573 ///
1574 /// By default, performs semantic analysis to build the new expression.
1575 /// The semantic analysis provides the behavior of template instantiation,
1576 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001577 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001578 /// argument-dependent lookup, etc. Subclasses may override this routine to
1579 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001580 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001581 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001582 Expr *Callee,
1583 Expr *First,
1584 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001585
1586 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001587 /// reinterpret_cast.
1588 ///
1589 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001590 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001591 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001592 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001593 Stmt::StmtClass Class,
1594 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001595 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001596 SourceLocation RAngleLoc,
1597 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001598 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001599 SourceLocation RParenLoc) {
1600 switch (Class) {
1601 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001602 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001603 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001604 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001605
1606 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001607 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001608 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001609 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001610
Douglas Gregora16548e2009-08-11 05:31:07 +00001611 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001612 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001613 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001614 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001615 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001616
Douglas Gregora16548e2009-08-11 05:31:07 +00001617 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001618 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001619 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001620 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001621
Douglas Gregora16548e2009-08-11 05:31:07 +00001622 default:
1623 assert(false && "Invalid C++ named cast");
1624 break;
1625 }
Mike Stump11289f42009-09-09 15:08:12 +00001626
John McCallfaf5fb42010-08-26 23:41:50 +00001627 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001628 }
Mike Stump11289f42009-09-09 15:08:12 +00001629
Douglas Gregora16548e2009-08-11 05:31:07 +00001630 /// \brief Build a new C++ static_cast expression.
1631 ///
1632 /// By default, performs semantic analysis to build the new expression.
1633 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001634 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001636 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001637 SourceLocation RAngleLoc,
1638 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001639 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001641 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001642 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001643 SourceRange(LAngleLoc, RAngleLoc),
1644 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001645 }
1646
1647 /// \brief Build a new C++ dynamic_cast expression.
1648 ///
1649 /// By default, performs semantic analysis to build the new expression.
1650 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001651 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001652 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001653 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001654 SourceLocation RAngleLoc,
1655 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001656 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001657 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001658 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001659 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001660 SourceRange(LAngleLoc, RAngleLoc),
1661 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001662 }
1663
1664 /// \brief Build a new C++ reinterpret_cast expression.
1665 ///
1666 /// By default, performs semantic analysis to build the new expression.
1667 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001668 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001669 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001670 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001671 SourceLocation RAngleLoc,
1672 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001673 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001674 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001675 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001676 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001677 SourceRange(LAngleLoc, RAngleLoc),
1678 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001679 }
1680
1681 /// \brief Build a new C++ const_cast expression.
1682 ///
1683 /// By default, performs semantic analysis to build the new expression.
1684 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001685 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001686 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001687 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001688 SourceLocation RAngleLoc,
1689 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001690 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001691 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001692 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001693 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001694 SourceRange(LAngleLoc, RAngleLoc),
1695 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001696 }
Mike Stump11289f42009-09-09 15:08:12 +00001697
Douglas Gregora16548e2009-08-11 05:31:07 +00001698 /// \brief Build a new C++ functional-style cast expression.
1699 ///
1700 /// By default, performs semantic analysis to build the new expression.
1701 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001702 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1703 SourceLocation LParenLoc,
1704 Expr *Sub,
1705 SourceLocation RParenLoc) {
1706 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001707 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001708 RParenLoc);
1709 }
Mike Stump11289f42009-09-09 15:08:12 +00001710
Douglas Gregora16548e2009-08-11 05:31:07 +00001711 /// \brief Build a new C++ typeid(type) expression.
1712 ///
1713 /// By default, performs semantic analysis to build the new expression.
1714 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001715 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001716 SourceLocation TypeidLoc,
1717 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001718 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001719 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001720 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001721 }
Mike Stump11289f42009-09-09 15:08:12 +00001722
Francois Pichet9f4f2072010-09-08 12:20:18 +00001723
Douglas Gregora16548e2009-08-11 05:31:07 +00001724 /// \brief Build a new C++ typeid(expr) expression.
1725 ///
1726 /// By default, performs semantic analysis to build the new expression.
1727 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001728 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001729 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001730 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001731 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001732 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001733 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001734 }
1735
Francois Pichet9f4f2072010-09-08 12:20:18 +00001736 /// \brief Build a new C++ __uuidof(type) expression.
1737 ///
1738 /// By default, performs semantic analysis to build the new expression.
1739 /// Subclasses may override this routine to provide different behavior.
1740 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1741 SourceLocation TypeidLoc,
1742 TypeSourceInfo *Operand,
1743 SourceLocation RParenLoc) {
1744 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1745 RParenLoc);
1746 }
1747
1748 /// \brief Build a new C++ __uuidof(expr) expression.
1749 ///
1750 /// By default, performs semantic analysis to build the new expression.
1751 /// Subclasses may override this routine to provide different behavior.
1752 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1753 SourceLocation TypeidLoc,
1754 Expr *Operand,
1755 SourceLocation RParenLoc) {
1756 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1757 RParenLoc);
1758 }
1759
Douglas Gregora16548e2009-08-11 05:31:07 +00001760 /// \brief Build a new C++ "this" expression.
1761 ///
1762 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001763 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001764 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001765 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001766 QualType ThisType,
1767 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001768 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001769 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1770 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001771 }
1772
1773 /// \brief Build a new C++ throw expression.
1774 ///
1775 /// By default, performs semantic analysis to build the new expression.
1776 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001777 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001778 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001779 }
1780
1781 /// \brief Build a new C++ default-argument expression.
1782 ///
1783 /// By default, builds a new default-argument expression, which does not
1784 /// require any semantic analysis. Subclasses may override this routine to
1785 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001786 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001787 ParmVarDecl *Param) {
1788 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1789 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001790 }
1791
1792 /// \brief Build a new C++ zero-initialization expression.
1793 ///
1794 /// By default, performs semantic analysis to build the new expression.
1795 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001796 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1797 SourceLocation LParenLoc,
1798 SourceLocation RParenLoc) {
1799 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001800 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001801 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001802 }
Mike Stump11289f42009-09-09 15:08:12 +00001803
Douglas Gregora16548e2009-08-11 05:31:07 +00001804 /// \brief Build a new C++ "new" expression.
1805 ///
1806 /// By default, performs semantic analysis to build the new expression.
1807 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001808 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001809 bool UseGlobal,
1810 SourceLocation PlacementLParen,
1811 MultiExprArg PlacementArgs,
1812 SourceLocation PlacementRParen,
1813 SourceRange TypeIdParens,
1814 QualType AllocatedType,
1815 TypeSourceInfo *AllocatedTypeInfo,
1816 Expr *ArraySize,
1817 SourceLocation ConstructorLParen,
1818 MultiExprArg ConstructorArgs,
1819 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001820 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001821 PlacementLParen,
1822 move(PlacementArgs),
1823 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001824 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001825 AllocatedType,
1826 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001827 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001828 ConstructorLParen,
1829 move(ConstructorArgs),
1830 ConstructorRParen);
1831 }
Mike Stump11289f42009-09-09 15:08:12 +00001832
Douglas Gregora16548e2009-08-11 05:31:07 +00001833 /// \brief Build a new C++ "delete" expression.
1834 ///
1835 /// By default, performs semantic analysis to build the new expression.
1836 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001837 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001838 bool IsGlobalDelete,
1839 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001840 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001841 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001842 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001843 }
Mike Stump11289f42009-09-09 15:08:12 +00001844
Douglas Gregora16548e2009-08-11 05:31:07 +00001845 /// \brief Build a new unary type trait expression.
1846 ///
1847 /// By default, performs semantic analysis to build the new expression.
1848 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001849 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001850 SourceLocation StartLoc,
1851 TypeSourceInfo *T,
1852 SourceLocation RParenLoc) {
1853 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001854 }
1855
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001856 /// \brief Build a new binary type trait expression.
1857 ///
1858 /// By default, performs semantic analysis to build the new expression.
1859 /// Subclasses may override this routine to provide different behavior.
1860 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1861 SourceLocation StartLoc,
1862 TypeSourceInfo *LhsT,
1863 TypeSourceInfo *RhsT,
1864 SourceLocation RParenLoc) {
1865 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1866 }
1867
Mike Stump11289f42009-09-09 15:08:12 +00001868 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001869 /// expression.
1870 ///
1871 /// By default, performs semantic analysis to build the new expression.
1872 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001873 ExprResult RebuildDependentScopeDeclRefExpr(
1874 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001875 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001876 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001877 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001878 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00001879
1880 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001881 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001882 *TemplateArgs);
1883
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001884 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001885 }
1886
1887 /// \brief Build a new template-id expression.
1888 ///
1889 /// By default, performs semantic analysis to build the new expression.
1890 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001891 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001892 LookupResult &R,
1893 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001894 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001895 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001896 }
1897
1898 /// \brief Build a new object-construction expression.
1899 ///
1900 /// By default, performs semantic analysis to build the new expression.
1901 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001902 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001903 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001904 CXXConstructorDecl *Constructor,
1905 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001906 MultiExprArg Args,
1907 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001908 CXXConstructExpr::ConstructionKind ConstructKind,
1909 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001910 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001911 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001912 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001913 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001914
Douglas Gregordb121ba2009-12-14 16:27:04 +00001915 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001916 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001917 RequiresZeroInit, ConstructKind,
1918 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001919 }
1920
1921 /// \brief Build a new object-construction expression.
1922 ///
1923 /// By default, performs semantic analysis to build the new expression.
1924 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001925 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1926 SourceLocation LParenLoc,
1927 MultiExprArg Args,
1928 SourceLocation RParenLoc) {
1929 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001930 LParenLoc,
1931 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001932 RParenLoc);
1933 }
1934
1935 /// \brief Build a new object-construction expression.
1936 ///
1937 /// By default, performs semantic analysis to build the new expression.
1938 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001939 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1940 SourceLocation LParenLoc,
1941 MultiExprArg Args,
1942 SourceLocation RParenLoc) {
1943 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001944 LParenLoc,
1945 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 RParenLoc);
1947 }
Mike Stump11289f42009-09-09 15:08:12 +00001948
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 /// \brief Build a new member reference expression.
1950 ///
1951 /// By default, performs semantic analysis to build the new expression.
1952 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001953 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00001954 QualType BaseType,
1955 bool IsArrow,
1956 SourceLocation OperatorLoc,
1957 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00001958 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001959 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001960 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001961 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00001962 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001963
John McCallb268a282010-08-23 23:25:46 +00001964 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001965 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001966 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001967 MemberNameInfo,
1968 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001969 }
1970
John McCall10eae182009-11-30 22:42:35 +00001971 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001972 ///
1973 /// By default, performs semantic analysis to build the new expression.
1974 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001975 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001976 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001977 SourceLocation OperatorLoc,
1978 bool IsArrow,
Douglas Gregor0da1d432011-02-28 20:01:57 +00001979 NestedNameSpecifierLoc QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00001980 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001981 LookupResult &R,
1982 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001983 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00001984 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001985
John McCallb268a282010-08-23 23:25:46 +00001986 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001987 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001988 SS, FirstQualifierInScope,
1989 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001990 }
Mike Stump11289f42009-09-09 15:08:12 +00001991
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001992 /// \brief Build a new noexcept expression.
1993 ///
1994 /// By default, performs semantic analysis to build the new expression.
1995 /// Subclasses may override this routine to provide different behavior.
1996 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1997 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1998 }
1999
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002000 /// \brief Build a new expression to compute the length of a parameter pack.
2001 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2002 SourceLocation PackLoc,
2003 SourceLocation RParenLoc,
2004 unsigned Length) {
2005 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2006 OperatorLoc, Pack, PackLoc,
2007 RParenLoc, Length);
2008 }
2009
Douglas Gregora16548e2009-08-11 05:31:07 +00002010 /// \brief Build a new Objective-C @encode expression.
2011 ///
2012 /// By default, performs semantic analysis to build the new expression.
2013 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002014 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002015 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002016 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002017 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002018 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002019 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002020
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002021 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002022 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002023 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002024 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002025 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002026 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002027 MultiExprArg Args,
2028 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002029 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2030 ReceiverTypeInfo->getType(),
2031 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002032 Sel, Method, LBracLoc, SelectorLoc,
2033 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002034 }
2035
2036 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002037 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002038 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002039 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002040 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002041 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002042 MultiExprArg Args,
2043 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002044 return SemaRef.BuildInstanceMessage(Receiver,
2045 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002046 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002047 Sel, Method, LBracLoc, SelectorLoc,
2048 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002049 }
2050
Douglas Gregord51d90d2010-04-26 20:11:03 +00002051 /// \brief Build a new Objective-C ivar reference expression.
2052 ///
2053 /// By default, performs semantic analysis to build the new expression.
2054 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002055 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002056 SourceLocation IvarLoc,
2057 bool IsArrow, bool IsFreeIvar) {
2058 // FIXME: We lose track of the IsFreeIvar bit.
2059 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002060 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002061 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2062 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002063 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002064 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002065 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002066 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002067 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002068 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002069
Douglas Gregord51d90d2010-04-26 20:11:03 +00002070 if (Result.get())
2071 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002072
John McCallb268a282010-08-23 23:25:46 +00002073 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002074 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002075 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002076 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002077 /*TemplateArgs=*/0);
2078 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002079
2080 /// \brief Build a new Objective-C property reference expression.
2081 ///
2082 /// By default, performs semantic analysis to build the new expression.
2083 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002084 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002085 ObjCPropertyDecl *Property,
2086 SourceLocation PropertyLoc) {
2087 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002088 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00002089 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2090 Sema::LookupMemberName);
2091 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002092 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002093 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002094 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00002095 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002096 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002097
Douglas Gregor9faee212010-04-26 20:47:02 +00002098 if (Result.get())
2099 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002100
John McCallb268a282010-08-23 23:25:46 +00002101 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002102 /*FIXME:*/PropertyLoc, IsArrow,
2103 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002104 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002105 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002106 /*TemplateArgs=*/0);
2107 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002108
John McCallb7bd14f2010-12-02 01:19:52 +00002109 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002110 ///
2111 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002112 /// Subclasses may override this routine to provide different behavior.
2113 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2114 ObjCMethodDecl *Getter,
2115 ObjCMethodDecl *Setter,
2116 SourceLocation PropertyLoc) {
2117 // Since these expressions can only be value-dependent, we do not
2118 // need to perform semantic analysis again.
2119 return Owned(
2120 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2121 VK_LValue, OK_ObjCProperty,
2122 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002123 }
2124
Douglas Gregord51d90d2010-04-26 20:11:03 +00002125 /// \brief Build a new Objective-C "isa" expression.
2126 ///
2127 /// By default, performs semantic analysis to build the new expression.
2128 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002129 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002130 bool IsArrow) {
2131 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002132 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002133 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2134 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002135 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002136 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002137 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002138 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002139 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002140
Douglas Gregord51d90d2010-04-26 20:11:03 +00002141 if (Result.get())
2142 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002143
John McCallb268a282010-08-23 23:25:46 +00002144 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002145 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002146 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002147 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002148 /*TemplateArgs=*/0);
2149 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002150
Douglas Gregora16548e2009-08-11 05:31:07 +00002151 /// \brief Build a new shuffle vector expression.
2152 ///
2153 /// By default, performs semantic analysis to build the new expression.
2154 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002155 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002156 MultiExprArg SubExprs,
2157 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002158 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002159 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002160 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2161 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2162 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2163 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002164
Douglas Gregora16548e2009-08-11 05:31:07 +00002165 // Build a reference to the __builtin_shufflevector builtin
2166 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00002167 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00002168 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00002169 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002170 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002171
2172 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002173 unsigned NumSubExprs = SubExprs.size();
2174 Expr **Subs = (Expr **)SubExprs.release();
2175 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2176 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002177 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002178 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002179 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002180 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002181
Douglas Gregora16548e2009-08-11 05:31:07 +00002182 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002183 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002185 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002186
Douglas Gregora16548e2009-08-11 05:31:07 +00002187 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002188 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002189 }
John McCall31f82722010-11-12 08:19:04 +00002190
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002191 /// \brief Build a new template argument pack expansion.
2192 ///
2193 /// By default, performs semantic analysis to build a new pack expansion
2194 /// for a template argument. Subclasses may override this routine to provide
2195 /// different behavior.
2196 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002197 SourceLocation EllipsisLoc,
2198 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002199 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002200 case TemplateArgument::Expression: {
2201 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002202 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2203 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002204 if (Result.isInvalid())
2205 return TemplateArgumentLoc();
2206
2207 return TemplateArgumentLoc(Result.get(), Result.get());
2208 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002209
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002210 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002211 return TemplateArgumentLoc(TemplateArgument(
2212 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002213 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002214 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002215 Pattern.getTemplateNameLoc(),
2216 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002217
2218 case TemplateArgument::Null:
2219 case TemplateArgument::Integral:
2220 case TemplateArgument::Declaration:
2221 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002222 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002223 llvm_unreachable("Pack expansion pattern has no parameter packs");
2224
2225 case TemplateArgument::Type:
2226 if (TypeSourceInfo *Expansion
2227 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002228 EllipsisLoc,
2229 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002230 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2231 Expansion);
2232 break;
2233 }
2234
2235 return TemplateArgumentLoc();
2236 }
2237
Douglas Gregor968f23a2011-01-03 19:31:53 +00002238 /// \brief Build a new expression pack expansion.
2239 ///
2240 /// By default, performs semantic analysis to build a new pack expansion
2241 /// for an expression. Subclasses may override this routine to provide
2242 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002243 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2244 llvm::Optional<unsigned> NumExpansions) {
2245 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002246 }
2247
John McCall31f82722010-11-12 08:19:04 +00002248private:
Douglas Gregor14454802011-02-25 02:25:35 +00002249 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2250 QualType ObjectType,
2251 NamedDecl *FirstQualifierInScope,
2252 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002253
2254 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2255 QualType ObjectType,
2256 NamedDecl *FirstQualifierInScope,
2257 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002258};
Douglas Gregora16548e2009-08-11 05:31:07 +00002259
Douglas Gregorebe10102009-08-20 07:17:43 +00002260template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002261StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002262 if (!S)
2263 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002264
Douglas Gregorebe10102009-08-20 07:17:43 +00002265 switch (S->getStmtClass()) {
2266 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002267
Douglas Gregorebe10102009-08-20 07:17:43 +00002268 // Transform individual statement nodes
2269#define STMT(Node, Parent) \
2270 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002271#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002272#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002273#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002274
Douglas Gregorebe10102009-08-20 07:17:43 +00002275 // Transform expressions by calling TransformExpr.
2276#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002277#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002278#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002279#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002280 {
John McCalldadc5752010-08-24 06:29:42 +00002281 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002282 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002283 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002284
John McCallb268a282010-08-23 23:25:46 +00002285 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002286 }
Mike Stump11289f42009-09-09 15:08:12 +00002287 }
2288
John McCallc3007a22010-10-26 07:05:15 +00002289 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002290}
Mike Stump11289f42009-09-09 15:08:12 +00002291
2292
Douglas Gregore922c772009-08-04 22:27:00 +00002293template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002294ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002295 if (!E)
2296 return SemaRef.Owned(E);
2297
2298 switch (E->getStmtClass()) {
2299 case Stmt::NoStmtClass: break;
2300#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002301#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002302#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002303 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002304#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002305 }
2306
John McCallc3007a22010-10-26 07:05:15 +00002307 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002308}
2309
2310template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002311bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2312 unsigned NumInputs,
2313 bool IsCall,
2314 llvm::SmallVectorImpl<Expr *> &Outputs,
2315 bool *ArgChanged) {
2316 for (unsigned I = 0; I != NumInputs; ++I) {
2317 // If requested, drop call arguments that need to be dropped.
2318 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2319 if (ArgChanged)
2320 *ArgChanged = true;
2321
2322 break;
2323 }
2324
Douglas Gregor968f23a2011-01-03 19:31:53 +00002325 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2326 Expr *Pattern = Expansion->getPattern();
2327
2328 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2329 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2330 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2331
2332 // Determine whether the set of unexpanded parameter packs can and should
2333 // be expanded.
2334 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002335 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002336 llvm::Optional<unsigned> OrigNumExpansions
2337 = Expansion->getNumExpansions();
2338 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002339 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2340 Pattern->getSourceRange(),
2341 Unexpanded.data(),
2342 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002343 Expand, RetainExpansion,
2344 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002345 return true;
2346
2347 if (!Expand) {
2348 // The transform has determined that we should perform a simple
2349 // transformation on the pack expansion, producing another pack
2350 // expansion.
2351 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2352 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2353 if (OutPattern.isInvalid())
2354 return true;
2355
2356 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002357 Expansion->getEllipsisLoc(),
2358 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002359 if (Out.isInvalid())
2360 return true;
2361
2362 if (ArgChanged)
2363 *ArgChanged = true;
2364 Outputs.push_back(Out.get());
2365 continue;
2366 }
2367
2368 // The transform has determined that we should perform an elementwise
2369 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002370 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002371 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2372 ExprResult Out = getDerived().TransformExpr(Pattern);
2373 if (Out.isInvalid())
2374 return true;
2375
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002376 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002377 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2378 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002379 if (Out.isInvalid())
2380 return true;
2381 }
2382
Douglas Gregor968f23a2011-01-03 19:31:53 +00002383 if (ArgChanged)
2384 *ArgChanged = true;
2385 Outputs.push_back(Out.get());
2386 }
2387
2388 continue;
2389 }
2390
Douglas Gregora3efea12011-01-03 19:04:46 +00002391 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2392 if (Result.isInvalid())
2393 return true;
2394
2395 if (Result.get() != Inputs[I] && ArgChanged)
2396 *ArgChanged = true;
2397
2398 Outputs.push_back(Result.get());
2399 }
2400
2401 return false;
2402}
2403
2404template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002405NestedNameSpecifierLoc
2406TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2407 NestedNameSpecifierLoc NNS,
2408 QualType ObjectType,
2409 NamedDecl *FirstQualifierInScope) {
2410 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2411 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2412 Qualifier = Qualifier.getPrefix())
2413 Qualifiers.push_back(Qualifier);
2414
2415 CXXScopeSpec SS;
2416 while (!Qualifiers.empty()) {
2417 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2418 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2419
2420 switch (QNNS->getKind()) {
2421 case NestedNameSpecifier::Identifier:
2422 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2423 *QNNS->getAsIdentifier(),
2424 Q.getLocalBeginLoc(),
2425 Q.getLocalEndLoc(),
2426 ObjectType, false, SS,
2427 FirstQualifierInScope, false))
2428 return NestedNameSpecifierLoc();
2429
2430 break;
2431
2432 case NestedNameSpecifier::Namespace: {
2433 NamespaceDecl *NS
2434 = cast_or_null<NamespaceDecl>(
2435 getDerived().TransformDecl(
2436 Q.getLocalBeginLoc(),
2437 QNNS->getAsNamespace()));
2438 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2439 break;
2440 }
2441
2442 case NestedNameSpecifier::NamespaceAlias: {
2443 NamespaceAliasDecl *Alias
2444 = cast_or_null<NamespaceAliasDecl>(
2445 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2446 QNNS->getAsNamespaceAlias()));
2447 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2448 Q.getLocalEndLoc());
2449 break;
2450 }
2451
2452 case NestedNameSpecifier::Global:
2453 // There is no meaningful transformation that one could perform on the
2454 // global scope.
2455 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2456 break;
2457
2458 case NestedNameSpecifier::TypeSpecWithTemplate:
2459 case NestedNameSpecifier::TypeSpec: {
2460 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2461 FirstQualifierInScope, SS);
2462
2463 if (!TL)
2464 return NestedNameSpecifierLoc();
2465
2466 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2467 (SemaRef.getLangOptions().CPlusPlus0x &&
2468 TL.getType()->isEnumeralType())) {
2469 assert(!TL.getType().hasLocalQualifiers() &&
2470 "Can't get cv-qualifiers here");
2471 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2472 Q.getLocalEndLoc());
2473 break;
2474 }
2475
2476 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2477 << TL.getType() << SS.getRange();
2478 return NestedNameSpecifierLoc();
2479 }
Douglas Gregore16af532011-02-28 18:50:33 +00002480 }
Douglas Gregor14454802011-02-25 02:25:35 +00002481
Douglas Gregore16af532011-02-28 18:50:33 +00002482 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002483 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002484 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002485 }
2486
2487 // Don't rebuild the nested-name-specifier if we don't have to.
2488 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2489 !getDerived().AlwaysRebuild())
2490 return NNS;
2491
2492 // If we can re-use the source-location data from the original
2493 // nested-name-specifier, do so.
2494 if (SS.location_size() == NNS.getDataLength() &&
2495 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2496 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2497
2498 // Allocate new nested-name-specifier location information.
2499 return SS.getWithLocInContext(SemaRef.Context);
2500}
2501
2502template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002503DeclarationNameInfo
2504TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002505::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002506 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002507 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002508 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002509
2510 switch (Name.getNameKind()) {
2511 case DeclarationName::Identifier:
2512 case DeclarationName::ObjCZeroArgSelector:
2513 case DeclarationName::ObjCOneArgSelector:
2514 case DeclarationName::ObjCMultiArgSelector:
2515 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002516 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002517 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002518 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002519
Douglas Gregorf816bd72009-09-03 22:13:48 +00002520 case DeclarationName::CXXConstructorName:
2521 case DeclarationName::CXXDestructorName:
2522 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002523 TypeSourceInfo *NewTInfo;
2524 CanQualType NewCanTy;
2525 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002526 NewTInfo = getDerived().TransformType(OldTInfo);
2527 if (!NewTInfo)
2528 return DeclarationNameInfo();
2529 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002530 }
2531 else {
2532 NewTInfo = 0;
2533 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002534 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002535 if (NewT.isNull())
2536 return DeclarationNameInfo();
2537 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2538 }
Mike Stump11289f42009-09-09 15:08:12 +00002539
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002540 DeclarationName NewName
2541 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2542 NewCanTy);
2543 DeclarationNameInfo NewNameInfo(NameInfo);
2544 NewNameInfo.setName(NewName);
2545 NewNameInfo.setNamedTypeInfo(NewTInfo);
2546 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002547 }
Mike Stump11289f42009-09-09 15:08:12 +00002548 }
2549
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002550 assert(0 && "Unknown name kind.");
2551 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002552}
2553
2554template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002555TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00002556TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2557 TemplateName Name,
2558 SourceLocation NameLoc,
2559 QualType ObjectType,
2560 NamedDecl *FirstQualifierInScope) {
2561 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2562 TemplateDecl *Template = QTN->getTemplateDecl();
2563 assert(Template && "qualified template name must refer to a template");
2564
2565 TemplateDecl *TransTemplate
2566 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2567 Template));
2568 if (!TransTemplate)
2569 return TemplateName();
2570
2571 if (!getDerived().AlwaysRebuild() &&
2572 SS.getScopeRep() == QTN->getQualifier() &&
2573 TransTemplate == Template)
2574 return Name;
2575
2576 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2577 TransTemplate);
2578 }
2579
2580 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2581 if (SS.getScopeRep()) {
2582 // These apply to the scope specifier, not the template.
2583 ObjectType = QualType();
2584 FirstQualifierInScope = 0;
2585 }
2586
2587 if (!getDerived().AlwaysRebuild() &&
2588 SS.getScopeRep() == DTN->getQualifier() &&
2589 ObjectType.isNull())
2590 return Name;
2591
2592 if (DTN->isIdentifier()) {
2593 return getDerived().RebuildTemplateName(SS,
2594 *DTN->getIdentifier(),
2595 NameLoc,
2596 ObjectType,
2597 FirstQualifierInScope);
2598 }
2599
2600 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2601 ObjectType);
2602 }
2603
2604 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2605 TemplateDecl *TransTemplate
2606 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2607 Template));
2608 if (!TransTemplate)
2609 return TemplateName();
2610
2611 if (!getDerived().AlwaysRebuild() &&
2612 TransTemplate == Template)
2613 return Name;
2614
2615 return TemplateName(TransTemplate);
2616 }
2617
2618 if (SubstTemplateTemplateParmPackStorage *SubstPack
2619 = Name.getAsSubstTemplateTemplateParmPack()) {
2620 TemplateTemplateParmDecl *TransParam
2621 = cast_or_null<TemplateTemplateParmDecl>(
2622 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2623 if (!TransParam)
2624 return TemplateName();
2625
2626 if (!getDerived().AlwaysRebuild() &&
2627 TransParam == SubstPack->getParameterPack())
2628 return Name;
2629
2630 return getDerived().RebuildTemplateName(TransParam,
2631 SubstPack->getArgumentPack());
2632 }
2633
2634 // These should be getting filtered out before they reach the AST.
2635 llvm_unreachable("overloaded function decl survived to here");
2636 return TemplateName();
2637}
2638
2639template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002640void TreeTransform<Derived>::InventTemplateArgumentLoc(
2641 const TemplateArgument &Arg,
2642 TemplateArgumentLoc &Output) {
2643 SourceLocation Loc = getDerived().getBaseLocation();
2644 switch (Arg.getKind()) {
2645 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002646 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002647 break;
2648
2649 case TemplateArgument::Type:
2650 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002651 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002652
John McCall0ad16662009-10-29 08:12:44 +00002653 break;
2654
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002655 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00002656 case TemplateArgument::TemplateExpansion: {
2657 NestedNameSpecifierLocBuilder Builder;
2658 TemplateName Template = Arg.getAsTemplate();
2659 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2660 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2661 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2662 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2663
2664 if (Arg.getKind() == TemplateArgument::Template)
2665 Output = TemplateArgumentLoc(Arg,
2666 Builder.getWithLocInContext(SemaRef.Context),
2667 Loc);
2668 else
2669 Output = TemplateArgumentLoc(Arg,
2670 Builder.getWithLocInContext(SemaRef.Context),
2671 Loc, Loc);
2672
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002673 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00002674 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002675
John McCall0ad16662009-10-29 08:12:44 +00002676 case TemplateArgument::Expression:
2677 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2678 break;
2679
2680 case TemplateArgument::Declaration:
2681 case TemplateArgument::Integral:
2682 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002683 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002684 break;
2685 }
2686}
2687
2688template<typename Derived>
2689bool TreeTransform<Derived>::TransformTemplateArgument(
2690 const TemplateArgumentLoc &Input,
2691 TemplateArgumentLoc &Output) {
2692 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002693 switch (Arg.getKind()) {
2694 case TemplateArgument::Null:
2695 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002696 Output = Input;
2697 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002698
Douglas Gregore922c772009-08-04 22:27:00 +00002699 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002700 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002701 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002702 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002703
2704 DI = getDerived().TransformType(DI);
2705 if (!DI) return true;
2706
2707 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2708 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002709 }
Mike Stump11289f42009-09-09 15:08:12 +00002710
Douglas Gregore922c772009-08-04 22:27:00 +00002711 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002712 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002713 DeclarationName Name;
2714 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2715 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002716 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002717 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002718 if (!D) return true;
2719
John McCall0d07eb32009-10-29 18:45:58 +00002720 Expr *SourceExpr = Input.getSourceDeclExpression();
2721 if (SourceExpr) {
2722 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002723 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002724 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002725 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002726 }
2727
2728 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002729 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002730 }
Mike Stump11289f42009-09-09 15:08:12 +00002731
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002732 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00002733 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2734 if (QualifierLoc) {
2735 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2736 if (!QualifierLoc)
2737 return true;
2738 }
2739
Douglas Gregordf846d12011-03-02 18:46:51 +00002740 CXXScopeSpec SS;
2741 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002742 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00002743 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2744 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002745 if (Template.isNull())
2746 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002747
Douglas Gregor9d802122011-03-02 17:09:35 +00002748 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002749 Input.getTemplateNameLoc());
2750 return false;
2751 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002752
2753 case TemplateArgument::TemplateExpansion:
2754 llvm_unreachable("Caller should expand pack expansions");
2755
Douglas Gregore922c772009-08-04 22:27:00 +00002756 case TemplateArgument::Expression: {
2757 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002758 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002759 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002760
John McCall0ad16662009-10-29 08:12:44 +00002761 Expr *InputExpr = Input.getSourceExpression();
2762 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2763
John McCalldadc5752010-08-24 06:29:42 +00002764 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002765 = getDerived().TransformExpr(InputExpr);
2766 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002767 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002768 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002769 }
Mike Stump11289f42009-09-09 15:08:12 +00002770
Douglas Gregore922c772009-08-04 22:27:00 +00002771 case TemplateArgument::Pack: {
2772 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2773 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002774 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002775 AEnd = Arg.pack_end();
2776 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002777
John McCall0ad16662009-10-29 08:12:44 +00002778 // FIXME: preserve source information here when we start
2779 // caring about parameter packs.
2780
John McCall0d07eb32009-10-29 18:45:58 +00002781 TemplateArgumentLoc InputArg;
2782 TemplateArgumentLoc OutputArg;
2783 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2784 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002785 return true;
2786
John McCall0d07eb32009-10-29 18:45:58 +00002787 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002788 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002789
2790 TemplateArgument *TransformedArgsPtr
2791 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2792 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2793 TransformedArgsPtr);
2794 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2795 TransformedArgs.size()),
2796 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002797 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002798 }
2799 }
Mike Stump11289f42009-09-09 15:08:12 +00002800
Douglas Gregore922c772009-08-04 22:27:00 +00002801 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002802 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002803}
2804
Douglas Gregorfe921a72010-12-20 23:36:19 +00002805/// \brief Iterator adaptor that invents template argument location information
2806/// for each of the template arguments in its underlying iterator.
2807template<typename Derived, typename InputIterator>
2808class TemplateArgumentLocInventIterator {
2809 TreeTransform<Derived> &Self;
2810 InputIterator Iter;
2811
2812public:
2813 typedef TemplateArgumentLoc value_type;
2814 typedef TemplateArgumentLoc reference;
2815 typedef typename std::iterator_traits<InputIterator>::difference_type
2816 difference_type;
2817 typedef std::input_iterator_tag iterator_category;
2818
2819 class pointer {
2820 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002821
Douglas Gregorfe921a72010-12-20 23:36:19 +00002822 public:
2823 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2824
2825 const TemplateArgumentLoc *operator->() const { return &Arg; }
2826 };
2827
2828 TemplateArgumentLocInventIterator() { }
2829
2830 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2831 InputIterator Iter)
2832 : Self(Self), Iter(Iter) { }
2833
2834 TemplateArgumentLocInventIterator &operator++() {
2835 ++Iter;
2836 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002837 }
2838
Douglas Gregorfe921a72010-12-20 23:36:19 +00002839 TemplateArgumentLocInventIterator operator++(int) {
2840 TemplateArgumentLocInventIterator Old(*this);
2841 ++(*this);
2842 return Old;
2843 }
2844
2845 reference operator*() const {
2846 TemplateArgumentLoc Result;
2847 Self.InventTemplateArgumentLoc(*Iter, Result);
2848 return Result;
2849 }
2850
2851 pointer operator->() const { return pointer(**this); }
2852
2853 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2854 const TemplateArgumentLocInventIterator &Y) {
2855 return X.Iter == Y.Iter;
2856 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002857
Douglas Gregorfe921a72010-12-20 23:36:19 +00002858 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2859 const TemplateArgumentLocInventIterator &Y) {
2860 return X.Iter != Y.Iter;
2861 }
2862};
2863
Douglas Gregor42cafa82010-12-20 17:42:22 +00002864template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002865template<typename InputIterator>
2866bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2867 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002868 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002869 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002870 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002871 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002872
2873 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2874 // Unpack argument packs, which we translate them into separate
2875 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002876 // FIXME: We could do much better if we could guarantee that the
2877 // TemplateArgumentLocInfo for the pack expansion would be usable for
2878 // all of the template arguments in the argument pack.
2879 typedef TemplateArgumentLocInventIterator<Derived,
2880 TemplateArgument::pack_iterator>
2881 PackLocIterator;
2882 if (TransformTemplateArguments(PackLocIterator(*this,
2883 In.getArgument().pack_begin()),
2884 PackLocIterator(*this,
2885 In.getArgument().pack_end()),
2886 Outputs))
2887 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002888
2889 continue;
2890 }
2891
2892 if (In.getArgument().isPackExpansion()) {
2893 // We have a pack expansion, for which we will be substituting into
2894 // the pattern.
2895 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002896 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002897 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002898 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2899 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002900
2901 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2902 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2903 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2904
2905 // Determine whether the set of unexpanded parameter packs can and should
2906 // be expanded.
2907 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002908 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002909 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002910 if (getDerived().TryExpandParameterPacks(Ellipsis,
2911 Pattern.getSourceRange(),
2912 Unexpanded.data(),
2913 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002914 Expand,
2915 RetainExpansion,
2916 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002917 return true;
2918
2919 if (!Expand) {
2920 // The transform has determined that we should perform a simple
2921 // transformation on the pack expansion, producing another pack
2922 // expansion.
2923 TemplateArgumentLoc OutPattern;
2924 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2925 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2926 return true;
2927
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002928 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
2929 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002930 if (Out.getArgument().isNull())
2931 return true;
2932
2933 Outputs.addArgument(Out);
2934 continue;
2935 }
2936
2937 // The transform has determined that we should perform an elementwise
2938 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002939 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002940 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2941
2942 if (getDerived().TransformTemplateArgument(Pattern, Out))
2943 return true;
2944
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002945 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002946 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2947 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002948 if (Out.getArgument().isNull())
2949 return true;
2950 }
2951
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002952 Outputs.addArgument(Out);
2953 }
2954
Douglas Gregor48d24112011-01-10 20:53:55 +00002955 // If we're supposed to retain a pack expansion, do so by temporarily
2956 // forgetting the partially-substituted parameter pack.
2957 if (RetainExpansion) {
2958 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
2959
2960 if (getDerived().TransformTemplateArgument(Pattern, Out))
2961 return true;
2962
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002963 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2964 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00002965 if (Out.getArgument().isNull())
2966 return true;
2967
2968 Outputs.addArgument(Out);
2969 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002970
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002971 continue;
2972 }
2973
2974 // The simple case:
2975 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00002976 return true;
2977
2978 Outputs.addArgument(Out);
2979 }
2980
2981 return false;
2982
2983}
2984
Douglas Gregord6ff3322009-08-04 16:50:30 +00002985//===----------------------------------------------------------------------===//
2986// Type transformation
2987//===----------------------------------------------------------------------===//
2988
2989template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002990QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002991 if (getDerived().AlreadyTransformed(T))
2992 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002993
John McCall550e0c22009-10-21 00:40:46 +00002994 // Temporary workaround. All of these transformations should
2995 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00002996 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
2997 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002998
John McCall31f82722010-11-12 08:19:04 +00002999 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003000
John McCall550e0c22009-10-21 00:40:46 +00003001 if (!NewDI)
3002 return QualType();
3003
3004 return NewDI->getType();
3005}
3006
3007template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003008TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003009 if (getDerived().AlreadyTransformed(DI->getType()))
3010 return DI;
3011
3012 TypeLocBuilder TLB;
3013
3014 TypeLoc TL = DI->getTypeLoc();
3015 TLB.reserve(TL.getFullDataSize());
3016
John McCall31f82722010-11-12 08:19:04 +00003017 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003018 if (Result.isNull())
3019 return 0;
3020
John McCallbcd03502009-12-07 02:54:59 +00003021 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003022}
3023
3024template<typename Derived>
3025QualType
John McCall31f82722010-11-12 08:19:04 +00003026TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003027 switch (T.getTypeLocClass()) {
3028#define ABSTRACT_TYPELOC(CLASS, PARENT)
3029#define TYPELOC(CLASS, PARENT) \
3030 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003031 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003032#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003033 }
Mike Stump11289f42009-09-09 15:08:12 +00003034
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003035 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003036 return QualType();
3037}
3038
3039/// FIXME: By default, this routine adds type qualifiers only to types
3040/// that can have qualifiers, and silently suppresses those qualifiers
3041/// that are not permitted (e.g., qualifiers on reference or function
3042/// types). This is the right thing for template instantiation, but
3043/// probably not for other clients.
3044template<typename Derived>
3045QualType
3046TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003047 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003048 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003049
John McCall31f82722010-11-12 08:19:04 +00003050 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003051 if (Result.isNull())
3052 return QualType();
3053
3054 // Silently suppress qualifiers if the result type can't be qualified.
3055 // FIXME: this is the right thing for template instantiation, but
3056 // probably not for other clients.
3057 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003058 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003059
John McCallcb0f89a2010-06-05 06:41:15 +00003060 if (!Quals.empty()) {
3061 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3062 TLB.push<QualifiedTypeLoc>(Result);
3063 // No location information to preserve.
3064 }
John McCall550e0c22009-10-21 00:40:46 +00003065
3066 return Result;
3067}
3068
Douglas Gregor14454802011-02-25 02:25:35 +00003069template<typename Derived>
3070TypeLoc
3071TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3072 QualType ObjectType,
3073 NamedDecl *UnqualLookup,
3074 CXXScopeSpec &SS) {
Douglas Gregor14454802011-02-25 02:25:35 +00003075 QualType T = TL.getType();
3076 if (getDerived().AlreadyTransformed(T))
3077 return TL;
3078
3079 TypeLocBuilder TLB;
3080 QualType Result;
3081
3082 if (isa<TemplateSpecializationType>(T)) {
3083 TemplateSpecializationTypeLoc SpecTL
3084 = cast<TemplateSpecializationTypeLoc>(TL);
3085
3086 TemplateName Template =
Douglas Gregor9db53502011-03-02 18:07:45 +00003087 getDerived().TransformTemplateName(SS,
3088 SpecTL.getTypePtr()->getTemplateName(),
3089 SpecTL.getTemplateNameLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003090 ObjectType, UnqualLookup);
3091 if (Template.isNull())
3092 return TypeLoc();
3093
3094 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3095 Template);
3096 } else if (isa<DependentTemplateSpecializationType>(T)) {
3097 DependentTemplateSpecializationTypeLoc SpecTL
3098 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3099
Douglas Gregor5a064722011-02-28 17:23:35 +00003100 TemplateName Template
Douglas Gregor9db53502011-03-02 18:07:45 +00003101 = getDerived().RebuildTemplateName(SS,
Douglas Gregore16af532011-02-28 18:50:33 +00003102 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003103 SpecTL.getNameLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00003104 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003105 if (Template.isNull())
3106 return TypeLoc();
3107
Douglas Gregor14454802011-02-25 02:25:35 +00003108 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003109 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003110 Template,
3111 SS);
Douglas Gregor14454802011-02-25 02:25:35 +00003112 } else {
3113 // Nothing special needs to be done for these.
3114 Result = getDerived().TransformType(TLB, TL);
3115 }
3116
3117 if (Result.isNull())
3118 return TypeLoc();
3119
3120 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3121}
3122
Douglas Gregor579c15f2011-03-02 18:32:08 +00003123template<typename Derived>
3124TypeSourceInfo *
3125TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3126 QualType ObjectType,
3127 NamedDecl *UnqualLookup,
3128 CXXScopeSpec &SS) {
3129 // FIXME: Painfully copy-paste from the above!
3130
3131 QualType T = TSInfo->getType();
3132 if (getDerived().AlreadyTransformed(T))
3133 return TSInfo;
3134
3135 TypeLocBuilder TLB;
3136 QualType Result;
3137
3138 TypeLoc TL = TSInfo->getTypeLoc();
3139 if (isa<TemplateSpecializationType>(T)) {
3140 TemplateSpecializationTypeLoc SpecTL
3141 = cast<TemplateSpecializationTypeLoc>(TL);
3142
3143 TemplateName Template
3144 = getDerived().TransformTemplateName(SS,
3145 SpecTL.getTypePtr()->getTemplateName(),
3146 SpecTL.getTemplateNameLoc(),
3147 ObjectType, UnqualLookup);
3148 if (Template.isNull())
3149 return 0;
3150
3151 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3152 Template);
3153 } else if (isa<DependentTemplateSpecializationType>(T)) {
3154 DependentTemplateSpecializationTypeLoc SpecTL
3155 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3156
3157 TemplateName Template
3158 = getDerived().RebuildTemplateName(SS,
3159 *SpecTL.getTypePtr()->getIdentifier(),
3160 SpecTL.getNameLoc(),
3161 ObjectType, UnqualLookup);
3162 if (Template.isNull())
3163 return 0;
3164
3165 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3166 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003167 Template,
3168 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003169 } else {
3170 // Nothing special needs to be done for these.
3171 Result = getDerived().TransformType(TLB, TL);
3172 }
3173
3174 if (Result.isNull())
3175 return 0;
3176
3177 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3178}
3179
John McCall550e0c22009-10-21 00:40:46 +00003180template <class TyLoc> static inline
3181QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3182 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3183 NewT.setNameLoc(T.getNameLoc());
3184 return T.getType();
3185}
3186
John McCall550e0c22009-10-21 00:40:46 +00003187template<typename Derived>
3188QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003189 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003190 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3191 NewT.setBuiltinLoc(T.getBuiltinLoc());
3192 if (T.needsExtraLocalData())
3193 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3194 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003195}
Mike Stump11289f42009-09-09 15:08:12 +00003196
Douglas Gregord6ff3322009-08-04 16:50:30 +00003197template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003198QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003199 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003200 // FIXME: recurse?
3201 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003202}
Mike Stump11289f42009-09-09 15:08:12 +00003203
Douglas Gregord6ff3322009-08-04 16:50:30 +00003204template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003205QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003206 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003207 QualType PointeeType
3208 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003209 if (PointeeType.isNull())
3210 return QualType();
3211
3212 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003213 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003214 // A dependent pointer type 'T *' has is being transformed such
3215 // that an Objective-C class type is being replaced for 'T'. The
3216 // resulting pointer type is an ObjCObjectPointerType, not a
3217 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003218 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003219
John McCall8b07ec22010-05-15 11:32:37 +00003220 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3221 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003222 return Result;
3223 }
John McCall31f82722010-11-12 08:19:04 +00003224
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003225 if (getDerived().AlwaysRebuild() ||
3226 PointeeType != TL.getPointeeLoc().getType()) {
3227 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3228 if (Result.isNull())
3229 return QualType();
3230 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003231
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003232 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3233 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003234 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003235}
Mike Stump11289f42009-09-09 15:08:12 +00003236
3237template<typename Derived>
3238QualType
John McCall550e0c22009-10-21 00:40:46 +00003239TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003240 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003241 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003242 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3243 if (PointeeType.isNull())
3244 return QualType();
3245
3246 QualType Result = TL.getType();
3247 if (getDerived().AlwaysRebuild() ||
3248 PointeeType != TL.getPointeeLoc().getType()) {
3249 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003250 TL.getSigilLoc());
3251 if (Result.isNull())
3252 return QualType();
3253 }
3254
Douglas Gregor049211a2010-04-22 16:50:51 +00003255 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003256 NewT.setSigilLoc(TL.getSigilLoc());
3257 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003258}
3259
John McCall70dd5f62009-10-30 00:06:24 +00003260/// Transforms a reference type. Note that somewhat paradoxically we
3261/// don't care whether the type itself is an l-value type or an r-value
3262/// type; we only care if the type was *written* as an l-value type
3263/// or an r-value type.
3264template<typename Derived>
3265QualType
3266TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003267 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003268 const ReferenceType *T = TL.getTypePtr();
3269
3270 // Note that this works with the pointee-as-written.
3271 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3272 if (PointeeType.isNull())
3273 return QualType();
3274
3275 QualType Result = TL.getType();
3276 if (getDerived().AlwaysRebuild() ||
3277 PointeeType != T->getPointeeTypeAsWritten()) {
3278 Result = getDerived().RebuildReferenceType(PointeeType,
3279 T->isSpelledAsLValue(),
3280 TL.getSigilLoc());
3281 if (Result.isNull())
3282 return QualType();
3283 }
3284
3285 // r-value references can be rebuilt as l-value references.
3286 ReferenceTypeLoc NewTL;
3287 if (isa<LValueReferenceType>(Result))
3288 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3289 else
3290 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3291 NewTL.setSigilLoc(TL.getSigilLoc());
3292
3293 return Result;
3294}
3295
Mike Stump11289f42009-09-09 15:08:12 +00003296template<typename Derived>
3297QualType
John McCall550e0c22009-10-21 00:40:46 +00003298TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003299 LValueReferenceTypeLoc TL) {
3300 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003301}
3302
Mike Stump11289f42009-09-09 15:08:12 +00003303template<typename Derived>
3304QualType
John McCall550e0c22009-10-21 00:40:46 +00003305TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003306 RValueReferenceTypeLoc TL) {
3307 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003308}
Mike Stump11289f42009-09-09 15:08:12 +00003309
Douglas Gregord6ff3322009-08-04 16:50:30 +00003310template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003311QualType
John McCall550e0c22009-10-21 00:40:46 +00003312TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003313 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003314 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003315 if (PointeeType.isNull())
3316 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003317
Abramo Bagnara509357842011-03-05 14:42:21 +00003318 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3319 TypeSourceInfo* NewClsTInfo = 0;
3320 if (OldClsTInfo) {
3321 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3322 if (!NewClsTInfo)
3323 return QualType();
3324 }
3325
3326 const MemberPointerType *T = TL.getTypePtr();
3327 QualType OldClsType = QualType(T->getClass(), 0);
3328 QualType NewClsType;
3329 if (NewClsTInfo)
3330 NewClsType = NewClsTInfo->getType();
3331 else {
3332 NewClsType = getDerived().TransformType(OldClsType);
3333 if (NewClsType.isNull())
3334 return QualType();
3335 }
Mike Stump11289f42009-09-09 15:08:12 +00003336
John McCall550e0c22009-10-21 00:40:46 +00003337 QualType Result = TL.getType();
3338 if (getDerived().AlwaysRebuild() ||
3339 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003340 NewClsType != OldClsType) {
3341 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003342 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003343 if (Result.isNull())
3344 return QualType();
3345 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003346
John McCall550e0c22009-10-21 00:40:46 +00003347 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3348 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003349 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003350
3351 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003352}
3353
Mike Stump11289f42009-09-09 15:08:12 +00003354template<typename Derived>
3355QualType
John McCall550e0c22009-10-21 00:40:46 +00003356TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003357 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003358 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003359 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003360 if (ElementType.isNull())
3361 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003362
John McCall550e0c22009-10-21 00:40:46 +00003363 QualType Result = TL.getType();
3364 if (getDerived().AlwaysRebuild() ||
3365 ElementType != T->getElementType()) {
3366 Result = getDerived().RebuildConstantArrayType(ElementType,
3367 T->getSizeModifier(),
3368 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003369 T->getIndexTypeCVRQualifiers(),
3370 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003371 if (Result.isNull())
3372 return QualType();
3373 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003374
John McCall550e0c22009-10-21 00:40:46 +00003375 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3376 NewTL.setLBracketLoc(TL.getLBracketLoc());
3377 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003378
John McCall550e0c22009-10-21 00:40:46 +00003379 Expr *Size = TL.getSizeExpr();
3380 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003381 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003382 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3383 }
3384 NewTL.setSizeExpr(Size);
3385
3386 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003387}
Mike Stump11289f42009-09-09 15:08:12 +00003388
Douglas Gregord6ff3322009-08-04 16:50:30 +00003389template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003390QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003391 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003392 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003393 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003394 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003395 if (ElementType.isNull())
3396 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003397
John McCall550e0c22009-10-21 00:40:46 +00003398 QualType Result = TL.getType();
3399 if (getDerived().AlwaysRebuild() ||
3400 ElementType != T->getElementType()) {
3401 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003402 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003403 T->getIndexTypeCVRQualifiers(),
3404 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003405 if (Result.isNull())
3406 return QualType();
3407 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003408
John McCall550e0c22009-10-21 00:40:46 +00003409 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3410 NewTL.setLBracketLoc(TL.getLBracketLoc());
3411 NewTL.setRBracketLoc(TL.getRBracketLoc());
3412 NewTL.setSizeExpr(0);
3413
3414 return Result;
3415}
3416
3417template<typename Derived>
3418QualType
3419TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003420 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003421 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003422 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3423 if (ElementType.isNull())
3424 return QualType();
3425
3426 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003427 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003428
John McCalldadc5752010-08-24 06:29:42 +00003429 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003430 = getDerived().TransformExpr(T->getSizeExpr());
3431 if (SizeResult.isInvalid())
3432 return QualType();
3433
John McCallb268a282010-08-23 23:25:46 +00003434 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003435
3436 QualType Result = TL.getType();
3437 if (getDerived().AlwaysRebuild() ||
3438 ElementType != T->getElementType() ||
3439 Size != T->getSizeExpr()) {
3440 Result = getDerived().RebuildVariableArrayType(ElementType,
3441 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003442 Size,
John McCall550e0c22009-10-21 00:40:46 +00003443 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003444 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003445 if (Result.isNull())
3446 return QualType();
3447 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003448
John McCall550e0c22009-10-21 00:40:46 +00003449 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3450 NewTL.setLBracketLoc(TL.getLBracketLoc());
3451 NewTL.setRBracketLoc(TL.getRBracketLoc());
3452 NewTL.setSizeExpr(Size);
3453
3454 return Result;
3455}
3456
3457template<typename Derived>
3458QualType
3459TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003460 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003461 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003462 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3463 if (ElementType.isNull())
3464 return QualType();
3465
3466 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003467 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003468
John McCall33ddac02011-01-19 10:06:00 +00003469 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3470 Expr *origSize = TL.getSizeExpr();
3471 if (!origSize) origSize = T->getSizeExpr();
3472
3473 ExprResult sizeResult
3474 = getDerived().TransformExpr(origSize);
3475 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003476 return QualType();
3477
John McCall33ddac02011-01-19 10:06:00 +00003478 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003479
3480 QualType Result = TL.getType();
3481 if (getDerived().AlwaysRebuild() ||
3482 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003483 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003484 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3485 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003486 size,
John McCall550e0c22009-10-21 00:40:46 +00003487 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003488 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003489 if (Result.isNull())
3490 return QualType();
3491 }
John McCall550e0c22009-10-21 00:40:46 +00003492
3493 // We might have any sort of array type now, but fortunately they
3494 // all have the same location layout.
3495 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3496 NewTL.setLBracketLoc(TL.getLBracketLoc());
3497 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003498 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003499
3500 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003501}
Mike Stump11289f42009-09-09 15:08:12 +00003502
3503template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003504QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003505 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003506 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003507 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003508
3509 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003510 QualType ElementType = getDerived().TransformType(T->getElementType());
3511 if (ElementType.isNull())
3512 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003513
Douglas Gregore922c772009-08-04 22:27:00 +00003514 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003515 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003516
John McCalldadc5752010-08-24 06:29:42 +00003517 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003518 if (Size.isInvalid())
3519 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003520
John McCall550e0c22009-10-21 00:40:46 +00003521 QualType Result = TL.getType();
3522 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003523 ElementType != T->getElementType() ||
3524 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003525 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003526 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003527 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003528 if (Result.isNull())
3529 return QualType();
3530 }
John McCall550e0c22009-10-21 00:40:46 +00003531
3532 // Result might be dependent or not.
3533 if (isa<DependentSizedExtVectorType>(Result)) {
3534 DependentSizedExtVectorTypeLoc NewTL
3535 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3536 NewTL.setNameLoc(TL.getNameLoc());
3537 } else {
3538 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3539 NewTL.setNameLoc(TL.getNameLoc());
3540 }
3541
3542 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003543}
Mike Stump11289f42009-09-09 15:08:12 +00003544
3545template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003546QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003547 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003548 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003549 QualType ElementType = getDerived().TransformType(T->getElementType());
3550 if (ElementType.isNull())
3551 return QualType();
3552
John McCall550e0c22009-10-21 00:40:46 +00003553 QualType Result = TL.getType();
3554 if (getDerived().AlwaysRebuild() ||
3555 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003556 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003557 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003558 if (Result.isNull())
3559 return QualType();
3560 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003561
John McCall550e0c22009-10-21 00:40:46 +00003562 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3563 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003564
John McCall550e0c22009-10-21 00:40:46 +00003565 return Result;
3566}
3567
3568template<typename Derived>
3569QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003570 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003571 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003572 QualType ElementType = getDerived().TransformType(T->getElementType());
3573 if (ElementType.isNull())
3574 return QualType();
3575
3576 QualType Result = TL.getType();
3577 if (getDerived().AlwaysRebuild() ||
3578 ElementType != T->getElementType()) {
3579 Result = getDerived().RebuildExtVectorType(ElementType,
3580 T->getNumElements(),
3581 /*FIXME*/ SourceLocation());
3582 if (Result.isNull())
3583 return QualType();
3584 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003585
John McCall550e0c22009-10-21 00:40:46 +00003586 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3587 NewTL.setNameLoc(TL.getNameLoc());
3588
3589 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003590}
Mike Stump11289f42009-09-09 15:08:12 +00003591
3592template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003593ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003594TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3595 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003596 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003597 TypeSourceInfo *NewDI = 0;
3598
3599 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3600 // If we're substituting into a pack expansion type and we know the
3601 TypeLoc OldTL = OldDI->getTypeLoc();
3602 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3603
3604 TypeLocBuilder TLB;
3605 TypeLoc NewTL = OldDI->getTypeLoc();
3606 TLB.reserve(NewTL.getFullDataSize());
3607
3608 QualType Result = getDerived().TransformType(TLB,
3609 OldExpansionTL.getPatternLoc());
3610 if (Result.isNull())
3611 return 0;
3612
3613 Result = RebuildPackExpansionType(Result,
3614 OldExpansionTL.getPatternLoc().getSourceRange(),
3615 OldExpansionTL.getEllipsisLoc(),
3616 NumExpansions);
3617 if (Result.isNull())
3618 return 0;
3619
3620 PackExpansionTypeLoc NewExpansionTL
3621 = TLB.push<PackExpansionTypeLoc>(Result);
3622 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3623 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3624 } else
3625 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003626 if (!NewDI)
3627 return 0;
3628
3629 if (NewDI == OldDI)
3630 return OldParm;
3631 else
3632 return ParmVarDecl::Create(SemaRef.Context,
3633 OldParm->getDeclContext(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00003634 OldParm->getInnerLocStart(),
John McCall58f10c32010-03-11 09:03:00 +00003635 OldParm->getLocation(),
3636 OldParm->getIdentifier(),
3637 NewDI->getType(),
3638 NewDI,
3639 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003640 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003641 /* DefArg */ NULL);
3642}
3643
3644template<typename Derived>
3645bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003646 TransformFunctionTypeParams(SourceLocation Loc,
3647 ParmVarDecl **Params, unsigned NumParams,
3648 const QualType *ParamTypes,
3649 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3650 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3651 for (unsigned i = 0; i != NumParams; ++i) {
3652 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor715e4612011-01-14 22:40:04 +00003653 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003654 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00003655 if (OldParm->isParameterPack()) {
3656 // We have a function parameter pack that may need to be expanded.
3657 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003658
Douglas Gregor5499af42011-01-05 23:12:31 +00003659 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003660 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3661 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3662 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3663 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00003664 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3665
Douglas Gregor5499af42011-01-05 23:12:31 +00003666 // Determine whether we should expand the parameter packs.
3667 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003668 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003669 llvm::Optional<unsigned> OrigNumExpansions
3670 = ExpansionTL.getTypePtr()->getNumExpansions();
3671 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003672 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3673 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003674 Unexpanded.data(),
3675 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003676 ShouldExpand,
3677 RetainExpansion,
3678 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003679 return true;
3680 }
3681
3682 if (ShouldExpand) {
3683 // Expand the function parameter pack into multiple, separate
3684 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003685 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003686 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003687 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3688 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003689 = getDerived().TransformFunctionTypeParam(OldParm,
3690 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003691 if (!NewParm)
3692 return true;
3693
Douglas Gregordd472162011-01-07 00:20:55 +00003694 OutParamTypes.push_back(NewParm->getType());
3695 if (PVars)
3696 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003697 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003698
3699 // If we're supposed to retain a pack expansion, do so by temporarily
3700 // forgetting the partially-substituted parameter pack.
3701 if (RetainExpansion) {
3702 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3703 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003704 = getDerived().TransformFunctionTypeParam(OldParm,
3705 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003706 if (!NewParm)
3707 return true;
3708
3709 OutParamTypes.push_back(NewParm->getType());
3710 if (PVars)
3711 PVars->push_back(NewParm);
3712 }
3713
Douglas Gregor5499af42011-01-05 23:12:31 +00003714 // We're done with the pack expansion.
3715 continue;
3716 }
3717
3718 // We'll substitute the parameter now without expanding the pack
3719 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00003720 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3721 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3722 NumExpansions);
3723 } else {
3724 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3725 llvm::Optional<unsigned>());
Douglas Gregor5499af42011-01-05 23:12:31 +00003726 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00003727
John McCall58f10c32010-03-11 09:03:00 +00003728 if (!NewParm)
3729 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003730
Douglas Gregordd472162011-01-07 00:20:55 +00003731 OutParamTypes.push_back(NewParm->getType());
3732 if (PVars)
3733 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003734 continue;
3735 }
John McCall58f10c32010-03-11 09:03:00 +00003736
3737 // Deal with the possibility that we don't have a parameter
3738 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003739 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003740 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003741 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003742 QualType NewType;
Douglas Gregor5499af42011-01-05 23:12:31 +00003743 if (const PackExpansionType *Expansion
3744 = dyn_cast<PackExpansionType>(OldType)) {
3745 // We have a function parameter pack that may need to be expanded.
3746 QualType Pattern = Expansion->getPattern();
3747 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3748 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3749
3750 // Determine whether we should expand the parameter packs.
3751 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003752 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003753 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003754 Unexpanded.data(),
3755 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003756 ShouldExpand,
3757 RetainExpansion,
3758 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003759 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003760 }
3761
3762 if (ShouldExpand) {
3763 // Expand the function parameter pack into multiple, separate
3764 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003765 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003766 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3767 QualType NewType = getDerived().TransformType(Pattern);
3768 if (NewType.isNull())
3769 return true;
John McCall58f10c32010-03-11 09:03:00 +00003770
Douglas Gregordd472162011-01-07 00:20:55 +00003771 OutParamTypes.push_back(NewType);
3772 if (PVars)
3773 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003774 }
3775
3776 // We're done with the pack expansion.
3777 continue;
3778 }
3779
Douglas Gregor48d24112011-01-10 20:53:55 +00003780 // If we're supposed to retain a pack expansion, do so by temporarily
3781 // forgetting the partially-substituted parameter pack.
3782 if (RetainExpansion) {
3783 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3784 QualType NewType = getDerived().TransformType(Pattern);
3785 if (NewType.isNull())
3786 return true;
3787
3788 OutParamTypes.push_back(NewType);
3789 if (PVars)
3790 PVars->push_back(0);
3791 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003792
Douglas Gregor5499af42011-01-05 23:12:31 +00003793 // We'll substitute the parameter now without expanding the pack
3794 // expansion.
3795 OldType = Expansion->getPattern();
3796 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003797 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3798 NewType = getDerived().TransformType(OldType);
3799 } else {
3800 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00003801 }
3802
Douglas Gregor5499af42011-01-05 23:12:31 +00003803 if (NewType.isNull())
3804 return true;
3805
3806 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003807 NewType = getSema().Context.getPackExpansionType(NewType,
3808 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003809
Douglas Gregordd472162011-01-07 00:20:55 +00003810 OutParamTypes.push_back(NewType);
3811 if (PVars)
3812 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003813 }
3814
3815 return false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003816 }
John McCall58f10c32010-03-11 09:03:00 +00003817
3818template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003819QualType
John McCall550e0c22009-10-21 00:40:46 +00003820TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003821 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003822 // Transform the parameters and return type.
3823 //
3824 // We instantiate in source order, with the return type first followed by
3825 // the parameters, because users tend to expect this (even if they shouldn't
3826 // rely on it!).
3827 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003828 // When the function has a trailing return type, we instantiate the
3829 // parameters before the return type, since the return type can then refer
3830 // to the parameters themselves (via decltype, sizeof, etc.).
3831 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003832 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003833 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00003834 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003835
Douglas Gregor7fb25412010-10-01 18:44:50 +00003836 QualType ResultType;
3837
3838 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003839 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3840 TL.getParmArray(),
3841 TL.getNumArgs(),
3842 TL.getTypePtr()->arg_type_begin(),
3843 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003844 return QualType();
3845
3846 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3847 if (ResultType.isNull())
3848 return QualType();
3849 }
3850 else {
3851 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3852 if (ResultType.isNull())
3853 return QualType();
3854
Douglas Gregordd472162011-01-07 00:20:55 +00003855 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3856 TL.getParmArray(),
3857 TL.getNumArgs(),
3858 TL.getTypePtr()->arg_type_begin(),
3859 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003860 return QualType();
3861 }
3862
John McCall550e0c22009-10-21 00:40:46 +00003863 QualType Result = TL.getType();
3864 if (getDerived().AlwaysRebuild() ||
3865 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003866 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003867 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3868 Result = getDerived().RebuildFunctionProtoType(ResultType,
3869 ParamTypes.data(),
3870 ParamTypes.size(),
3871 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003872 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00003873 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003874 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003875 if (Result.isNull())
3876 return QualType();
3877 }
Mike Stump11289f42009-09-09 15:08:12 +00003878
John McCall550e0c22009-10-21 00:40:46 +00003879 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3880 NewTL.setLParenLoc(TL.getLParenLoc());
3881 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003882 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003883 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3884 NewTL.setArg(i, ParamDecls[i]);
3885
3886 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003887}
Mike Stump11289f42009-09-09 15:08:12 +00003888
Douglas Gregord6ff3322009-08-04 16:50:30 +00003889template<typename Derived>
3890QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003891 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003892 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003893 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003894 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3895 if (ResultType.isNull())
3896 return QualType();
3897
3898 QualType Result = TL.getType();
3899 if (getDerived().AlwaysRebuild() ||
3900 ResultType != T->getResultType())
3901 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3902
3903 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3904 NewTL.setLParenLoc(TL.getLParenLoc());
3905 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003906 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003907
3908 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003909}
Mike Stump11289f42009-09-09 15:08:12 +00003910
John McCallb96ec562009-12-04 22:46:56 +00003911template<typename Derived> QualType
3912TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003913 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003914 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003915 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003916 if (!D)
3917 return QualType();
3918
3919 QualType Result = TL.getType();
3920 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3921 Result = getDerived().RebuildUnresolvedUsingType(D);
3922 if (Result.isNull())
3923 return QualType();
3924 }
3925
3926 // We might get an arbitrary type spec type back. We should at
3927 // least always get a type spec type, though.
3928 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3929 NewTL.setNameLoc(TL.getNameLoc());
3930
3931 return Result;
3932}
3933
Douglas Gregord6ff3322009-08-04 16:50:30 +00003934template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003935QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003936 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003937 const TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003938 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003939 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3940 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003941 if (!Typedef)
3942 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003943
John McCall550e0c22009-10-21 00:40:46 +00003944 QualType Result = TL.getType();
3945 if (getDerived().AlwaysRebuild() ||
3946 Typedef != T->getDecl()) {
3947 Result = getDerived().RebuildTypedefType(Typedef);
3948 if (Result.isNull())
3949 return QualType();
3950 }
Mike Stump11289f42009-09-09 15:08:12 +00003951
John McCall550e0c22009-10-21 00:40:46 +00003952 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3953 NewTL.setNameLoc(TL.getNameLoc());
3954
3955 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003956}
Mike Stump11289f42009-09-09 15:08:12 +00003957
Douglas Gregord6ff3322009-08-04 16:50:30 +00003958template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003959QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003960 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003961 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003962 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003963
John McCalldadc5752010-08-24 06:29:42 +00003964 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003965 if (E.isInvalid())
3966 return QualType();
3967
John McCall550e0c22009-10-21 00:40:46 +00003968 QualType Result = TL.getType();
3969 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003970 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003971 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003972 if (Result.isNull())
3973 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003974 }
John McCall550e0c22009-10-21 00:40:46 +00003975 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003976
John McCall550e0c22009-10-21 00:40:46 +00003977 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003978 NewTL.setTypeofLoc(TL.getTypeofLoc());
3979 NewTL.setLParenLoc(TL.getLParenLoc());
3980 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003981
3982 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003983}
Mike Stump11289f42009-09-09 15:08:12 +00003984
3985template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003986QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003987 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003988 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3989 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3990 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003991 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003992
John McCall550e0c22009-10-21 00:40:46 +00003993 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003994 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3995 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003996 if (Result.isNull())
3997 return QualType();
3998 }
Mike Stump11289f42009-09-09 15:08:12 +00003999
John McCall550e0c22009-10-21 00:40:46 +00004000 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004001 NewTL.setTypeofLoc(TL.getTypeofLoc());
4002 NewTL.setLParenLoc(TL.getLParenLoc());
4003 NewTL.setRParenLoc(TL.getRParenLoc());
4004 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004005
4006 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004007}
Mike Stump11289f42009-09-09 15:08:12 +00004008
4009template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004010QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004011 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004012 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004013
Douglas Gregore922c772009-08-04 22:27:00 +00004014 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004015 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004016
John McCalldadc5752010-08-24 06:29:42 +00004017 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004018 if (E.isInvalid())
4019 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004020
John McCall550e0c22009-10-21 00:40:46 +00004021 QualType Result = TL.getType();
4022 if (getDerived().AlwaysRebuild() ||
4023 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004024 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004025 if (Result.isNull())
4026 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004027 }
John McCall550e0c22009-10-21 00:40:46 +00004028 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004029
John McCall550e0c22009-10-21 00:40:46 +00004030 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4031 NewTL.setNameLoc(TL.getNameLoc());
4032
4033 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004034}
4035
4036template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004037QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4038 AutoTypeLoc TL) {
4039 const AutoType *T = TL.getTypePtr();
4040 QualType OldDeduced = T->getDeducedType();
4041 QualType NewDeduced;
4042 if (!OldDeduced.isNull()) {
4043 NewDeduced = getDerived().TransformType(OldDeduced);
4044 if (NewDeduced.isNull())
4045 return QualType();
4046 }
4047
4048 QualType Result = TL.getType();
4049 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4050 Result = getDerived().RebuildAutoType(NewDeduced);
4051 if (Result.isNull())
4052 return QualType();
4053 }
4054
4055 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4056 NewTL.setNameLoc(TL.getNameLoc());
4057
4058 return Result;
4059}
4060
4061template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004062QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004063 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004064 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004065 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004066 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4067 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004068 if (!Record)
4069 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004070
John McCall550e0c22009-10-21 00:40:46 +00004071 QualType Result = TL.getType();
4072 if (getDerived().AlwaysRebuild() ||
4073 Record != T->getDecl()) {
4074 Result = getDerived().RebuildRecordType(Record);
4075 if (Result.isNull())
4076 return QualType();
4077 }
Mike Stump11289f42009-09-09 15:08:12 +00004078
John McCall550e0c22009-10-21 00:40:46 +00004079 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4080 NewTL.setNameLoc(TL.getNameLoc());
4081
4082 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004083}
Mike Stump11289f42009-09-09 15:08:12 +00004084
4085template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004086QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004087 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004088 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004089 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004090 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4091 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004092 if (!Enum)
4093 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004094
John McCall550e0c22009-10-21 00:40:46 +00004095 QualType Result = TL.getType();
4096 if (getDerived().AlwaysRebuild() ||
4097 Enum != T->getDecl()) {
4098 Result = getDerived().RebuildEnumType(Enum);
4099 if (Result.isNull())
4100 return QualType();
4101 }
Mike Stump11289f42009-09-09 15:08:12 +00004102
John McCall550e0c22009-10-21 00:40:46 +00004103 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4104 NewTL.setNameLoc(TL.getNameLoc());
4105
4106 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004107}
John McCallfcc33b02009-09-05 00:15:47 +00004108
John McCalle78aac42010-03-10 03:28:59 +00004109template<typename Derived>
4110QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4111 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004112 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004113 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4114 TL.getTypePtr()->getDecl());
4115 if (!D) return QualType();
4116
4117 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4118 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4119 return T;
4120}
4121
Douglas Gregord6ff3322009-08-04 16:50:30 +00004122template<typename Derived>
4123QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004124 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004125 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004126 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004127}
4128
Mike Stump11289f42009-09-09 15:08:12 +00004129template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004130QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004131 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004132 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004133 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4134
4135 // Substitute into the replacement type, which itself might involve something
4136 // that needs to be transformed. This only tends to occur with default
4137 // template arguments of template template parameters.
4138 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4139 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4140 if (Replacement.isNull())
4141 return QualType();
4142
4143 // Always canonicalize the replacement type.
4144 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4145 QualType Result
4146 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4147 Replacement);
4148
4149 // Propagate type-source information.
4150 SubstTemplateTypeParmTypeLoc NewTL
4151 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4152 NewTL.setNameLoc(TL.getNameLoc());
4153 return Result;
4154
John McCallcebee162009-10-18 09:09:24 +00004155}
4156
4157template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004158QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4159 TypeLocBuilder &TLB,
4160 SubstTemplateTypeParmPackTypeLoc TL) {
4161 return TransformTypeSpecType(TLB, TL);
4162}
4163
4164template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004165QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004166 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004167 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004168 const TemplateSpecializationType *T = TL.getTypePtr();
4169
Douglas Gregordf846d12011-03-02 18:46:51 +00004170 // The nested-name-specifier never matters in a TemplateSpecializationType,
4171 // because we can't have a dependent nested-name-specifier anyway.
4172 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004173 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004174 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4175 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004176 if (Template.isNull())
4177 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004178
John McCall31f82722010-11-12 08:19:04 +00004179 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4180}
4181
Douglas Gregorfe921a72010-12-20 23:36:19 +00004182namespace {
4183 /// \brief Simple iterator that traverses the template arguments in a
4184 /// container that provides a \c getArgLoc() member function.
4185 ///
4186 /// This iterator is intended to be used with the iterator form of
4187 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4188 template<typename ArgLocContainer>
4189 class TemplateArgumentLocContainerIterator {
4190 ArgLocContainer *Container;
4191 unsigned Index;
4192
4193 public:
4194 typedef TemplateArgumentLoc value_type;
4195 typedef TemplateArgumentLoc reference;
4196 typedef int difference_type;
4197 typedef std::input_iterator_tag iterator_category;
4198
4199 class pointer {
4200 TemplateArgumentLoc Arg;
4201
4202 public:
4203 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4204
4205 const TemplateArgumentLoc *operator->() const {
4206 return &Arg;
4207 }
4208 };
4209
4210
4211 TemplateArgumentLocContainerIterator() {}
4212
4213 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4214 unsigned Index)
4215 : Container(&Container), Index(Index) { }
4216
4217 TemplateArgumentLocContainerIterator &operator++() {
4218 ++Index;
4219 return *this;
4220 }
4221
4222 TemplateArgumentLocContainerIterator operator++(int) {
4223 TemplateArgumentLocContainerIterator Old(*this);
4224 ++(*this);
4225 return Old;
4226 }
4227
4228 TemplateArgumentLoc operator*() const {
4229 return Container->getArgLoc(Index);
4230 }
4231
4232 pointer operator->() const {
4233 return pointer(Container->getArgLoc(Index));
4234 }
4235
4236 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004237 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004238 return X.Container == Y.Container && X.Index == Y.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 == Y);
4244 }
4245 };
4246}
4247
4248
John McCall31f82722010-11-12 08:19:04 +00004249template <typename Derived>
4250QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4251 TypeLocBuilder &TLB,
4252 TemplateSpecializationTypeLoc TL,
4253 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004254 TemplateArgumentListInfo NewTemplateArgs;
4255 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4256 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004257 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4258 ArgIterator;
4259 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4260 ArgIterator(TL, TL.getNumArgs()),
4261 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004262 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004263
John McCall0ad16662009-10-29 08:12:44 +00004264 // FIXME: maybe don't rebuild if all the template arguments are the same.
4265
4266 QualType Result =
4267 getDerived().RebuildTemplateSpecializationType(Template,
4268 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004269 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004270
4271 if (!Result.isNull()) {
4272 TemplateSpecializationTypeLoc NewTL
4273 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4274 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4275 NewTL.setLAngleLoc(TL.getLAngleLoc());
4276 NewTL.setRAngleLoc(TL.getRAngleLoc());
4277 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4278 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004279 }
Mike Stump11289f42009-09-09 15:08:12 +00004280
John McCall0ad16662009-10-29 08:12:44 +00004281 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004282}
Mike Stump11289f42009-09-09 15:08:12 +00004283
Douglas Gregor5a064722011-02-28 17:23:35 +00004284template <typename Derived>
4285QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4286 TypeLocBuilder &TLB,
4287 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004288 TemplateName Template,
4289 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004290 TemplateArgumentListInfo NewTemplateArgs;
4291 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4292 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4293 typedef TemplateArgumentLocContainerIterator<
4294 DependentTemplateSpecializationTypeLoc> ArgIterator;
4295 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4296 ArgIterator(TL, TL.getNumArgs()),
4297 NewTemplateArgs))
4298 return QualType();
4299
4300 // FIXME: maybe don't rebuild if all the template arguments are the same.
4301
4302 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4303 QualType Result
4304 = getSema().Context.getDependentTemplateSpecializationType(
4305 TL.getTypePtr()->getKeyword(),
4306 DTN->getQualifier(),
4307 DTN->getIdentifier(),
4308 NewTemplateArgs);
4309
4310 DependentTemplateSpecializationTypeLoc NewTL
4311 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4312 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004313
Douglas Gregora7a795b2011-03-01 20:11:18 +00004314 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004315 NewTL.setNameLoc(TL.getNameLoc());
4316 NewTL.setLAngleLoc(TL.getLAngleLoc());
4317 NewTL.setRAngleLoc(TL.getRAngleLoc());
4318 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4319 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4320 return Result;
4321 }
4322
4323 QualType Result
4324 = getDerived().RebuildTemplateSpecializationType(Template,
4325 TL.getNameLoc(),
4326 NewTemplateArgs);
4327
4328 if (!Result.isNull()) {
4329 /// FIXME: Wrap this in an elaborated-type-specifier?
4330 TemplateSpecializationTypeLoc NewTL
4331 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4332 NewTL.setTemplateNameLoc(TL.getNameLoc());
4333 NewTL.setLAngleLoc(TL.getLAngleLoc());
4334 NewTL.setRAngleLoc(TL.getRAngleLoc());
4335 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4336 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4337 }
4338
4339 return Result;
4340}
4341
Mike Stump11289f42009-09-09 15:08:12 +00004342template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004343QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004344TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004345 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004346 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004347
Douglas Gregor844cb502011-03-01 18:12:44 +00004348 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004349 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004350 if (TL.getQualifierLoc()) {
4351 QualifierLoc
4352 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4353 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004354 return QualType();
4355 }
Mike Stump11289f42009-09-09 15:08:12 +00004356
John McCall31f82722010-11-12 08:19:04 +00004357 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4358 if (NamedT.isNull())
4359 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004360
John McCall550e0c22009-10-21 00:40:46 +00004361 QualType Result = TL.getType();
4362 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004363 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004364 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004365 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004366 T->getKeyword(),
4367 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004368 if (Result.isNull())
4369 return QualType();
4370 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004371
Abramo Bagnara6150c882010-05-11 21:36:43 +00004372 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004373 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004374 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004375 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004376}
Mike Stump11289f42009-09-09 15:08:12 +00004377
4378template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004379QualType TreeTransform<Derived>::TransformAttributedType(
4380 TypeLocBuilder &TLB,
4381 AttributedTypeLoc TL) {
4382 const AttributedType *oldType = TL.getTypePtr();
4383 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4384 if (modifiedType.isNull())
4385 return QualType();
4386
4387 QualType result = TL.getType();
4388
4389 // FIXME: dependent operand expressions?
4390 if (getDerived().AlwaysRebuild() ||
4391 modifiedType != oldType->getModifiedType()) {
4392 // TODO: this is really lame; we should really be rebuilding the
4393 // equivalent type from first principles.
4394 QualType equivalentType
4395 = getDerived().TransformType(oldType->getEquivalentType());
4396 if (equivalentType.isNull())
4397 return QualType();
4398 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4399 modifiedType,
4400 equivalentType);
4401 }
4402
4403 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4404 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4405 if (TL.hasAttrOperand())
4406 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4407 if (TL.hasAttrExprOperand())
4408 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4409 else if (TL.hasAttrEnumOperand())
4410 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4411
4412 return result;
4413}
4414
4415template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004416QualType
4417TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4418 ParenTypeLoc TL) {
4419 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4420 if (Inner.isNull())
4421 return QualType();
4422
4423 QualType Result = TL.getType();
4424 if (getDerived().AlwaysRebuild() ||
4425 Inner != TL.getInnerLoc().getType()) {
4426 Result = getDerived().RebuildParenType(Inner);
4427 if (Result.isNull())
4428 return QualType();
4429 }
4430
4431 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4432 NewTL.setLParenLoc(TL.getLParenLoc());
4433 NewTL.setRParenLoc(TL.getRParenLoc());
4434 return Result;
4435}
4436
4437template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004438QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004439 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004440 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004441
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004442 NestedNameSpecifierLoc QualifierLoc
4443 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4444 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004445 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004446
John McCallc392f372010-06-11 00:33:02 +00004447 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004448 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004449 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004450 QualifierLoc,
4451 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004452 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004453 if (Result.isNull())
4454 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004455
Abramo Bagnarad7548482010-05-19 21:37:53 +00004456 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4457 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004458 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4459
Abramo Bagnarad7548482010-05-19 21:37:53 +00004460 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4461 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004462 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004463 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004464 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4465 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004466 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004467 NewTL.setNameLoc(TL.getNameLoc());
4468 }
John McCall550e0c22009-10-21 00:40:46 +00004469 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004470}
Mike Stump11289f42009-09-09 15:08:12 +00004471
Douglas Gregord6ff3322009-08-04 16:50:30 +00004472template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004473QualType TreeTransform<Derived>::
4474 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004475 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004476 NestedNameSpecifierLoc QualifierLoc;
4477 if (TL.getQualifierLoc()) {
4478 QualifierLoc
4479 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4480 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004481 return QualType();
4482 }
4483
John McCall31f82722010-11-12 08:19:04 +00004484 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004485 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004486}
4487
4488template<typename Derived>
4489QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00004490TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4491 DependentTemplateSpecializationTypeLoc TL,
4492 NestedNameSpecifierLoc QualifierLoc) {
4493 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4494
4495 TemplateArgumentListInfo NewTemplateArgs;
4496 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4497 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4498
4499 typedef TemplateArgumentLocContainerIterator<
4500 DependentTemplateSpecializationTypeLoc> ArgIterator;
4501 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4502 ArgIterator(TL, TL.getNumArgs()),
4503 NewTemplateArgs))
4504 return QualType();
4505
4506 QualType Result
4507 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4508 QualifierLoc,
4509 T->getIdentifier(),
4510 TL.getNameLoc(),
4511 NewTemplateArgs);
4512 if (Result.isNull())
4513 return QualType();
4514
4515 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4516 QualType NamedT = ElabT->getNamedType();
4517
4518 // Copy information relevant to the template specialization.
4519 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00004520 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Douglas Gregora7a795b2011-03-01 20:11:18 +00004521 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4522 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004523 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004524 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004525
4526 // Copy information relevant to the elaborated type.
4527 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4528 NewTL.setKeywordLoc(TL.getKeywordLoc());
4529 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00004530 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4531 DependentTemplateSpecializationTypeLoc SpecTL
4532 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor11ddf132011-03-07 15:13:34 +00004533 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004534 SpecTL.setQualifierLoc(QualifierLoc);
4535 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4536 SpecTL.setRAngleLoc(TL.getRAngleLoc());
4537 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004538 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004539 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004540 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00004541 TemplateSpecializationTypeLoc SpecTL
4542 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4543 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4544 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004545 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004546 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004547 }
4548 return Result;
4549}
4550
4551template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004552QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4553 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004554 QualType Pattern
4555 = getDerived().TransformType(TLB, TL.getPatternLoc());
4556 if (Pattern.isNull())
4557 return QualType();
4558
4559 QualType Result = TL.getType();
4560 if (getDerived().AlwaysRebuild() ||
4561 Pattern != TL.getPatternLoc().getType()) {
4562 Result = getDerived().RebuildPackExpansionType(Pattern,
4563 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004564 TL.getEllipsisLoc(),
4565 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004566 if (Result.isNull())
4567 return QualType();
4568 }
4569
4570 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4571 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4572 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004573}
4574
4575template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004576QualType
4577TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004578 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004579 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004580 TLB.pushFullCopy(TL);
4581 return TL.getType();
4582}
4583
4584template<typename Derived>
4585QualType
4586TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004587 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004588 // ObjCObjectType is never dependent.
4589 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004590 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004591}
Mike Stump11289f42009-09-09 15:08:12 +00004592
4593template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004594QualType
4595TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004596 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004597 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004598 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004599 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004600}
4601
Douglas Gregord6ff3322009-08-04 16:50:30 +00004602//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004603// Statement transformation
4604//===----------------------------------------------------------------------===//
4605template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004606StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004607TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004608 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004609}
4610
4611template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004612StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004613TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4614 return getDerived().TransformCompoundStmt(S, false);
4615}
4616
4617template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004618StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004619TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004620 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004621 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004622 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004623 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004624 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4625 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004626 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004627 if (Result.isInvalid()) {
4628 // Immediately fail if this was a DeclStmt, since it's very
4629 // likely that this will cause problems for future statements.
4630 if (isa<DeclStmt>(*B))
4631 return StmtError();
4632
4633 // Otherwise, just keep processing substatements and fail later.
4634 SubStmtInvalid = true;
4635 continue;
4636 }
Mike Stump11289f42009-09-09 15:08:12 +00004637
Douglas Gregorebe10102009-08-20 07:17:43 +00004638 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4639 Statements.push_back(Result.takeAs<Stmt>());
4640 }
Mike Stump11289f42009-09-09 15:08:12 +00004641
John McCall1ababa62010-08-27 19:56:05 +00004642 if (SubStmtInvalid)
4643 return StmtError();
4644
Douglas Gregorebe10102009-08-20 07:17:43 +00004645 if (!getDerived().AlwaysRebuild() &&
4646 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004647 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004648
4649 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4650 move_arg(Statements),
4651 S->getRBracLoc(),
4652 IsStmtExpr);
4653}
Mike Stump11289f42009-09-09 15:08:12 +00004654
Douglas Gregorebe10102009-08-20 07:17:43 +00004655template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004656StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004657TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004658 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004659 {
4660 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004661 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004662
Eli Friedman06577382009-11-19 03:14:00 +00004663 // Transform the left-hand case value.
4664 LHS = getDerived().TransformExpr(S->getLHS());
4665 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004666 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004667
Eli Friedman06577382009-11-19 03:14:00 +00004668 // Transform the right-hand case value (for the GNU case-range extension).
4669 RHS = getDerived().TransformExpr(S->getRHS());
4670 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004671 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004672 }
Mike Stump11289f42009-09-09 15:08:12 +00004673
Douglas Gregorebe10102009-08-20 07:17:43 +00004674 // Build the case statement.
4675 // Case statements are always rebuilt so that they will attached to their
4676 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004677 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004678 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004679 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004680 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004681 S->getColonLoc());
4682 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004683 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004684
Douglas Gregorebe10102009-08-20 07:17:43 +00004685 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004686 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004687 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004688 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004689
Douglas Gregorebe10102009-08-20 07:17:43 +00004690 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004691 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004692}
4693
4694template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004695StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004696TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004697 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004698 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004699 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004700 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004701
Douglas Gregorebe10102009-08-20 07:17:43 +00004702 // Default statements are always rebuilt
4703 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004704 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004705}
Mike Stump11289f42009-09-09 15:08:12 +00004706
Douglas Gregorebe10102009-08-20 07:17:43 +00004707template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004708StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004709TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004710 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004711 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004712 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004713
Chris Lattnercab02a62011-02-17 20:34:02 +00004714 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4715 S->getDecl());
4716 if (!LD)
4717 return StmtError();
4718
4719
Douglas Gregorebe10102009-08-20 07:17:43 +00004720 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004721 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004722 cast<LabelDecl>(LD), SourceLocation(),
4723 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004724}
Mike Stump11289f42009-09-09 15:08:12 +00004725
Douglas Gregorebe10102009-08-20 07:17:43 +00004726template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004727StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004728TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004729 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004730 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004731 VarDecl *ConditionVar = 0;
4732 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004733 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004734 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004735 getDerived().TransformDefinition(
4736 S->getConditionVariable()->getLocation(),
4737 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004738 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004739 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004740 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004741 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004742
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004743 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004744 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004745
4746 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004747 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004748 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4749 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004750 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004751 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004752
John McCallb268a282010-08-23 23:25:46 +00004753 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004754 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004755 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004756
John McCallb268a282010-08-23 23:25:46 +00004757 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4758 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004759 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004760
Douglas Gregorebe10102009-08-20 07:17:43 +00004761 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004762 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004763 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004764 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004765
Douglas Gregorebe10102009-08-20 07:17:43 +00004766 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004767 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004768 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004769 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004770
Douglas Gregorebe10102009-08-20 07:17:43 +00004771 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004772 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004773 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004774 Then.get() == S->getThen() &&
4775 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004776 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004777
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004778 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004779 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004780 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004781}
4782
4783template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004784StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004785TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004786 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004787 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004788 VarDecl *ConditionVar = 0;
4789 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004790 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004791 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004792 getDerived().TransformDefinition(
4793 S->getConditionVariable()->getLocation(),
4794 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004795 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004796 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004797 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004798 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004799
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004800 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004801 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004802 }
Mike Stump11289f42009-09-09 15:08:12 +00004803
Douglas Gregorebe10102009-08-20 07:17:43 +00004804 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004805 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004806 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004807 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004808 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004809 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004810
Douglas Gregorebe10102009-08-20 07:17:43 +00004811 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004812 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004813 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004814 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004815
Douglas Gregorebe10102009-08-20 07:17:43 +00004816 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004817 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4818 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004819}
Mike Stump11289f42009-09-09 15:08:12 +00004820
Douglas Gregorebe10102009-08-20 07:17:43 +00004821template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004822StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004823TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004824 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004825 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004826 VarDecl *ConditionVar = 0;
4827 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004828 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004829 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004830 getDerived().TransformDefinition(
4831 S->getConditionVariable()->getLocation(),
4832 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004833 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004834 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004835 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004836 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004837
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004838 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004839 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004840
4841 if (S->getCond()) {
4842 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004843 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4844 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004845 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004846 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004847 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004848 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004849 }
Mike Stump11289f42009-09-09 15:08:12 +00004850
John McCallb268a282010-08-23 23:25:46 +00004851 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4852 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004853 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004854
Douglas Gregorebe10102009-08-20 07:17:43 +00004855 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004856 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004857 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004858 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004859
Douglas Gregorebe10102009-08-20 07:17:43 +00004860 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004861 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004862 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004863 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004864 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004865
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004866 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004867 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004868}
Mike Stump11289f42009-09-09 15:08:12 +00004869
Douglas Gregorebe10102009-08-20 07:17:43 +00004870template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004871StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004872TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004873 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004874 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004875 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004876 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004877
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004878 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004879 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004880 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004881 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004882
Douglas Gregorebe10102009-08-20 07:17:43 +00004883 if (!getDerived().AlwaysRebuild() &&
4884 Cond.get() == S->getCond() &&
4885 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004886 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004887
John McCallb268a282010-08-23 23:25:46 +00004888 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4889 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004890 S->getRParenLoc());
4891}
Mike Stump11289f42009-09-09 15:08:12 +00004892
Douglas Gregorebe10102009-08-20 07:17:43 +00004893template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004894StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004895TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004896 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004897 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004898 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004899 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004900
Douglas Gregorebe10102009-08-20 07:17:43 +00004901 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004902 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004903 VarDecl *ConditionVar = 0;
4904 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004905 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004906 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004907 getDerived().TransformDefinition(
4908 S->getConditionVariable()->getLocation(),
4909 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004910 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004911 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004912 } else {
4913 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004914
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004915 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004916 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004917
4918 if (S->getCond()) {
4919 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004920 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4921 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004922 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004923 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004924
John McCallb268a282010-08-23 23:25:46 +00004925 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004926 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004927 }
Mike Stump11289f42009-09-09 15:08:12 +00004928
John McCallb268a282010-08-23 23:25:46 +00004929 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4930 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004931 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004932
Douglas Gregorebe10102009-08-20 07:17:43 +00004933 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00004934 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00004935 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004936 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004937
John McCallb268a282010-08-23 23:25:46 +00004938 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4939 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004940 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004941
Douglas Gregorebe10102009-08-20 07:17:43 +00004942 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004943 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004944 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004945 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004946
Douglas Gregorebe10102009-08-20 07:17:43 +00004947 if (!getDerived().AlwaysRebuild() &&
4948 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00004949 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004950 Inc.get() == S->getInc() &&
4951 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004952 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004953
Douglas Gregorebe10102009-08-20 07:17:43 +00004954 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004955 Init.get(), FullCond, ConditionVar,
4956 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004957}
4958
4959template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004960StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004961TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00004962 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
4963 S->getLabel());
4964 if (!LD)
4965 return StmtError();
4966
Douglas Gregorebe10102009-08-20 07:17:43 +00004967 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00004968 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004969 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00004970}
4971
4972template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004973StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004974TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004975 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00004976 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004977 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004978
Douglas Gregorebe10102009-08-20 07:17:43 +00004979 if (!getDerived().AlwaysRebuild() &&
4980 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00004981 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004982
4983 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00004984 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004985}
4986
4987template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004988StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004989TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004990 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004991}
Mike Stump11289f42009-09-09 15:08:12 +00004992
Douglas Gregorebe10102009-08-20 07:17:43 +00004993template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004994StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004995TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004996 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004997}
Mike Stump11289f42009-09-09 15:08:12 +00004998
Douglas Gregorebe10102009-08-20 07:17:43 +00004999template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005000StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005001TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005002 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005003 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005004 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005005
Mike Stump11289f42009-09-09 15:08:12 +00005006 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005007 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005008 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005009}
Mike Stump11289f42009-09-09 15:08:12 +00005010
Douglas Gregorebe10102009-08-20 07:17:43 +00005011template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005012StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005013TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005014 bool DeclChanged = false;
5015 llvm::SmallVector<Decl *, 4> Decls;
5016 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5017 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005018 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5019 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005020 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005021 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005022
Douglas Gregorebe10102009-08-20 07:17:43 +00005023 if (Transformed != *D)
5024 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005025
Douglas Gregorebe10102009-08-20 07:17:43 +00005026 Decls.push_back(Transformed);
5027 }
Mike Stump11289f42009-09-09 15:08:12 +00005028
Douglas Gregorebe10102009-08-20 07:17:43 +00005029 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005030 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005031
5032 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005033 S->getStartLoc(), S->getEndLoc());
5034}
Mike Stump11289f42009-09-09 15:08:12 +00005035
Douglas Gregorebe10102009-08-20 07:17:43 +00005036template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005037StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005038TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005039
John McCall37ad5512010-08-23 06:44:23 +00005040 ASTOwningVector<Expr*> Constraints(getSema());
5041 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00005042 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005043
John McCalldadc5752010-08-24 06:29:42 +00005044 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005045 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005046
5047 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005048
Anders Carlssonaaeef072010-01-24 05:50:09 +00005049 // Go through the outputs.
5050 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005051 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005052
Anders Carlssonaaeef072010-01-24 05:50:09 +00005053 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005054 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005055
Anders Carlssonaaeef072010-01-24 05:50:09 +00005056 // Transform the output expr.
5057 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005058 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005059 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005060 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005061
Anders Carlssonaaeef072010-01-24 05:50:09 +00005062 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005063
John McCallb268a282010-08-23 23:25:46 +00005064 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005065 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005066
Anders Carlssonaaeef072010-01-24 05:50:09 +00005067 // Go through the inputs.
5068 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005069 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005070
Anders Carlssonaaeef072010-01-24 05:50:09 +00005071 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005072 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005073
Anders Carlssonaaeef072010-01-24 05:50:09 +00005074 // Transform the input expr.
5075 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005076 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005077 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005078 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005079
Anders Carlssonaaeef072010-01-24 05:50:09 +00005080 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005081
John McCallb268a282010-08-23 23:25:46 +00005082 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005083 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005084
Anders Carlssonaaeef072010-01-24 05:50:09 +00005085 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005086 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005087
5088 // Go through the clobbers.
5089 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005090 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005091
5092 // No need to transform the asm string literal.
5093 AsmString = SemaRef.Owned(S->getAsmString());
5094
5095 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5096 S->isSimple(),
5097 S->isVolatile(),
5098 S->getNumOutputs(),
5099 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005100 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005101 move_arg(Constraints),
5102 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005103 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005104 move_arg(Clobbers),
5105 S->getRParenLoc(),
5106 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005107}
5108
5109
5110template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005111StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005112TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005113 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005114 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005115 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005116 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005117
Douglas Gregor96c79492010-04-23 22:50:49 +00005118 // Transform the @catch statements (if present).
5119 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005120 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005121 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005122 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005123 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005124 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005125 if (Catch.get() != S->getCatchStmt(I))
5126 AnyCatchChanged = true;
5127 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005128 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005129
Douglas Gregor306de2f2010-04-22 23:59:56 +00005130 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005131 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005132 if (S->getFinallyStmt()) {
5133 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5134 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005135 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005136 }
5137
5138 // If nothing changed, just retain this statement.
5139 if (!getDerived().AlwaysRebuild() &&
5140 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005141 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005142 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005143 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005144
Douglas Gregor306de2f2010-04-22 23:59:56 +00005145 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005146 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5147 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005148}
Mike Stump11289f42009-09-09 15:08:12 +00005149
Douglas Gregorebe10102009-08-20 07:17:43 +00005150template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005151StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005152TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005153 // Transform the @catch parameter, if there is one.
5154 VarDecl *Var = 0;
5155 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5156 TypeSourceInfo *TSInfo = 0;
5157 if (FromVar->getTypeSourceInfo()) {
5158 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5159 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005160 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005161 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005162
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005163 QualType T;
5164 if (TSInfo)
5165 T = TSInfo->getType();
5166 else {
5167 T = getDerived().TransformType(FromVar->getType());
5168 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005169 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005170 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005171
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005172 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5173 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005174 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005175 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005176
John McCalldadc5752010-08-24 06:29:42 +00005177 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005178 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005179 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005180
5181 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005182 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005183 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005184}
Mike Stump11289f42009-09-09 15:08:12 +00005185
Douglas Gregorebe10102009-08-20 07:17:43 +00005186template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005187StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005188TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005189 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005190 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005191 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005192 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005193
Douglas Gregor306de2f2010-04-22 23:59:56 +00005194 // If nothing changed, just retain this statement.
5195 if (!getDerived().AlwaysRebuild() &&
5196 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005197 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005198
5199 // Build a new statement.
5200 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005201 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005202}
Mike Stump11289f42009-09-09 15:08:12 +00005203
Douglas Gregorebe10102009-08-20 07:17:43 +00005204template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005205StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005206TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005207 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005208 if (S->getThrowExpr()) {
5209 Operand = getDerived().TransformExpr(S->getThrowExpr());
5210 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005211 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005212 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005213
Douglas Gregor2900c162010-04-22 21:44:01 +00005214 if (!getDerived().AlwaysRebuild() &&
5215 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005216 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005217
John McCallb268a282010-08-23 23:25:46 +00005218 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005219}
Mike Stump11289f42009-09-09 15:08:12 +00005220
Douglas Gregorebe10102009-08-20 07:17:43 +00005221template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005222StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005223TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005224 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005225 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005226 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005227 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005228 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005229
Douglas Gregor6148de72010-04-22 22:01:21 +00005230 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005231 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005232 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005233 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005234
Douglas Gregor6148de72010-04-22 22:01:21 +00005235 // If nothing change, just retain the current statement.
5236 if (!getDerived().AlwaysRebuild() &&
5237 Object.get() == S->getSynchExpr() &&
5238 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005239 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005240
5241 // Build a new statement.
5242 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005243 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005244}
5245
5246template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005247StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005248TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005249 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005250 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005251 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005252 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005253 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005254
Douglas Gregorf68a5082010-04-22 23:10:45 +00005255 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005256 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005257 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005258 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005259
Douglas Gregorf68a5082010-04-22 23:10:45 +00005260 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005261 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005262 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005263 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005264
Douglas Gregorf68a5082010-04-22 23:10:45 +00005265 // If nothing changed, just retain this statement.
5266 if (!getDerived().AlwaysRebuild() &&
5267 Element.get() == S->getElement() &&
5268 Collection.get() == S->getCollection() &&
5269 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005270 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005271
Douglas Gregorf68a5082010-04-22 23:10:45 +00005272 // Build a new statement.
5273 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5274 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005275 Element.get(),
5276 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005277 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005278 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005279}
5280
5281
5282template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005283StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005284TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5285 // Transform the exception declaration, if any.
5286 VarDecl *Var = 0;
5287 if (S->getExceptionDecl()) {
5288 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005289 TypeSourceInfo *T = getDerived().TransformType(
5290 ExceptionDecl->getTypeSourceInfo());
5291 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005292 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005293
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005294 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaradff19302011-03-08 08:55:46 +00005295 ExceptionDecl->getInnerLocStart(),
5296 ExceptionDecl->getLocation(),
5297 ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00005298 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005299 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005300 }
Mike Stump11289f42009-09-09 15:08:12 +00005301
Douglas Gregorebe10102009-08-20 07:17:43 +00005302 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005303 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005304 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005305 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005306
Douglas Gregorebe10102009-08-20 07:17:43 +00005307 if (!getDerived().AlwaysRebuild() &&
5308 !Var &&
5309 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005310 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005311
5312 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5313 Var,
John McCallb268a282010-08-23 23:25:46 +00005314 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005315}
Mike Stump11289f42009-09-09 15:08:12 +00005316
Douglas Gregorebe10102009-08-20 07:17:43 +00005317template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005318StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005319TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5320 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005321 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005322 = getDerived().TransformCompoundStmt(S->getTryBlock());
5323 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005324 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005325
Douglas Gregorebe10102009-08-20 07:17:43 +00005326 // Transform the handlers.
5327 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005328 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005329 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005330 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005331 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5332 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005333 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005334
Douglas Gregorebe10102009-08-20 07:17:43 +00005335 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5336 Handlers.push_back(Handler.takeAs<Stmt>());
5337 }
Mike Stump11289f42009-09-09 15:08:12 +00005338
Douglas Gregorebe10102009-08-20 07:17:43 +00005339 if (!getDerived().AlwaysRebuild() &&
5340 TryBlock.get() == S->getTryBlock() &&
5341 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005342 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005343
John McCallb268a282010-08-23 23:25:46 +00005344 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005345 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005346}
Mike Stump11289f42009-09-09 15:08:12 +00005347
Douglas Gregorebe10102009-08-20 07:17:43 +00005348//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005349// Expression transformation
5350//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005351template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005352ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005353TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005354 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005355}
Mike Stump11289f42009-09-09 15:08:12 +00005356
5357template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005358ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005359TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005360 NestedNameSpecifierLoc QualifierLoc;
5361 if (E->getQualifierLoc()) {
5362 QualifierLoc
5363 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5364 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005365 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005366 }
John McCallce546572009-12-08 09:08:17 +00005367
5368 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005369 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5370 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005371 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005372 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005373
John McCall815039a2010-08-17 21:27:17 +00005374 DeclarationNameInfo NameInfo = E->getNameInfo();
5375 if (NameInfo.getName()) {
5376 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5377 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005378 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005379 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005380
5381 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005382 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005383 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005384 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005385 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005386
5387 // Mark it referenced in the new context regardless.
5388 // FIXME: this is a bit instantiation-specific.
5389 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5390
John McCallc3007a22010-10-26 07:05:15 +00005391 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005392 }
John McCallce546572009-12-08 09:08:17 +00005393
5394 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005395 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005396 TemplateArgs = &TransArgs;
5397 TransArgs.setLAngleLoc(E->getLAngleLoc());
5398 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005399 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5400 E->getNumTemplateArgs(),
5401 TransArgs))
5402 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005403 }
5404
Douglas Gregorea972d32011-02-28 21:54:11 +00005405 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5406 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005407}
Mike Stump11289f42009-09-09 15:08:12 +00005408
Douglas Gregora16548e2009-08-11 05:31:07 +00005409template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005410ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005411TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005412 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005413}
Mike Stump11289f42009-09-09 15:08:12 +00005414
Douglas Gregora16548e2009-08-11 05:31:07 +00005415template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005416ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005417TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005418 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005419}
Mike Stump11289f42009-09-09 15:08:12 +00005420
Douglas Gregora16548e2009-08-11 05:31:07 +00005421template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005422ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005423TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005424 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005425}
Mike Stump11289f42009-09-09 15:08:12 +00005426
Douglas Gregora16548e2009-08-11 05:31:07 +00005427template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005428ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005429TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005430 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005431}
Mike Stump11289f42009-09-09 15:08:12 +00005432
Douglas Gregora16548e2009-08-11 05:31:07 +00005433template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005434ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005435TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005436 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005437}
5438
5439template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005440ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005441TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005442 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005443 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005444 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005445
Douglas Gregora16548e2009-08-11 05:31:07 +00005446 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005447 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005448
John McCallb268a282010-08-23 23:25:46 +00005449 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005450 E->getRParen());
5451}
5452
Mike Stump11289f42009-09-09 15:08:12 +00005453template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005454ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005455TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005456 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005457 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005458 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005459
Douglas Gregora16548e2009-08-11 05:31:07 +00005460 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005461 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005462
Douglas Gregora16548e2009-08-11 05:31:07 +00005463 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5464 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005465 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005466}
Mike Stump11289f42009-09-09 15:08:12 +00005467
Douglas Gregora16548e2009-08-11 05:31:07 +00005468template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005469ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005470TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5471 // Transform the type.
5472 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5473 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005474 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005475
Douglas Gregor882211c2010-04-28 22:16:22 +00005476 // Transform all of the components into components similar to what the
5477 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005478 // FIXME: It would be slightly more efficient in the non-dependent case to
5479 // just map FieldDecls, rather than requiring the rebuilder to look for
5480 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005481 // template code that we don't care.
5482 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005483 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005484 typedef OffsetOfExpr::OffsetOfNode Node;
5485 llvm::SmallVector<Component, 4> Components;
5486 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5487 const Node &ON = E->getComponent(I);
5488 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005489 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00005490 Comp.LocStart = ON.getRange().getBegin();
5491 Comp.LocEnd = ON.getRange().getEnd();
5492 switch (ON.getKind()) {
5493 case Node::Array: {
5494 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005495 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005496 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005497 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005498
Douglas Gregor882211c2010-04-28 22:16:22 +00005499 ExprChanged = ExprChanged || Index.get() != FromIndex;
5500 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005501 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005502 break;
5503 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005504
Douglas Gregor882211c2010-04-28 22:16:22 +00005505 case Node::Field:
5506 case Node::Identifier:
5507 Comp.isBrackets = false;
5508 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005509 if (!Comp.U.IdentInfo)
5510 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005511
Douglas Gregor882211c2010-04-28 22:16:22 +00005512 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005513
Douglas Gregord1702062010-04-29 00:18:15 +00005514 case Node::Base:
5515 // Will be recomputed during the rebuild.
5516 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005517 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005518
Douglas Gregor882211c2010-04-28 22:16:22 +00005519 Components.push_back(Comp);
5520 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005521
Douglas Gregor882211c2010-04-28 22:16:22 +00005522 // If nothing changed, retain the existing expression.
5523 if (!getDerived().AlwaysRebuild() &&
5524 Type == E->getTypeSourceInfo() &&
5525 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005526 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005527
Douglas Gregor882211c2010-04-28 22:16:22 +00005528 // Build a new offsetof expression.
5529 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5530 Components.data(), Components.size(),
5531 E->getRParenLoc());
5532}
5533
5534template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005535ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005536TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5537 assert(getDerived().AlreadyTransformed(E->getType()) &&
5538 "opaque value expression requires transformation");
5539 return SemaRef.Owned(E);
5540}
5541
5542template<typename Derived>
5543ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005544TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005545 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005546 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005547
John McCallbcd03502009-12-07 02:54:59 +00005548 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005549 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005550 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005551
John McCall4c98fd82009-11-04 07:28:41 +00005552 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005553 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005554
John McCall4c98fd82009-11-04 07:28:41 +00005555 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005556 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005557 E->getSourceRange());
5558 }
Mike Stump11289f42009-09-09 15:08:12 +00005559
John McCalldadc5752010-08-24 06:29:42 +00005560 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005561 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005562 // C++0x [expr.sizeof]p1:
5563 // The operand is either an expression, which is an unevaluated operand
5564 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005565 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005566
Douglas Gregora16548e2009-08-11 05:31:07 +00005567 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5568 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005569 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005570
Douglas Gregora16548e2009-08-11 05:31:07 +00005571 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005572 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005573 }
Mike Stump11289f42009-09-09 15:08:12 +00005574
John McCallb268a282010-08-23 23:25:46 +00005575 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005576 E->isSizeOf(),
5577 E->getSourceRange());
5578}
Mike Stump11289f42009-09-09 15:08:12 +00005579
Douglas Gregora16548e2009-08-11 05:31:07 +00005580template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005581ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005582TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005583 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005584 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005585 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005586
John McCalldadc5752010-08-24 06:29:42 +00005587 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005588 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005589 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005590
5591
Douglas Gregora16548e2009-08-11 05:31:07 +00005592 if (!getDerived().AlwaysRebuild() &&
5593 LHS.get() == E->getLHS() &&
5594 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005595 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005596
John McCallb268a282010-08-23 23:25:46 +00005597 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005598 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005599 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005600 E->getRBracketLoc());
5601}
Mike Stump11289f42009-09-09 15:08:12 +00005602
5603template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005604ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005605TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005606 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005607 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005608 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005609 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005610
5611 // Transform arguments.
5612 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005613 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005614 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5615 &ArgChanged))
5616 return ExprError();
5617
Douglas Gregora16548e2009-08-11 05:31:07 +00005618 if (!getDerived().AlwaysRebuild() &&
5619 Callee.get() == E->getCallee() &&
5620 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005621 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005622
Douglas Gregora16548e2009-08-11 05:31:07 +00005623 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005624 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005625 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005626 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005627 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005628 E->getRParenLoc());
5629}
Mike Stump11289f42009-09-09 15:08:12 +00005630
5631template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005632ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005633TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005634 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005635 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005636 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005637
Douglas Gregorea972d32011-02-28 21:54:11 +00005638 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005639 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005640 QualifierLoc
5641 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5642
5643 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005644 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005645 }
Mike Stump11289f42009-09-09 15:08:12 +00005646
Eli Friedman2cfcef62009-12-04 06:40:45 +00005647 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005648 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5649 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005650 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005651 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005652
John McCall16df1e52010-03-30 21:47:33 +00005653 NamedDecl *FoundDecl = E->getFoundDecl();
5654 if (FoundDecl == E->getMemberDecl()) {
5655 FoundDecl = Member;
5656 } else {
5657 FoundDecl = cast_or_null<NamedDecl>(
5658 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5659 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005660 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005661 }
5662
Douglas Gregora16548e2009-08-11 05:31:07 +00005663 if (!getDerived().AlwaysRebuild() &&
5664 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005665 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005666 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005667 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005668 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005669
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005670 // Mark it referenced in the new context regardless.
5671 // FIXME: this is a bit instantiation-specific.
5672 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005673 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005674 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005675
John McCall6b51f282009-11-23 01:53:49 +00005676 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005677 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005678 TransArgs.setLAngleLoc(E->getLAngleLoc());
5679 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005680 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5681 E->getNumTemplateArgs(),
5682 TransArgs))
5683 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005684 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005685
Douglas Gregora16548e2009-08-11 05:31:07 +00005686 // FIXME: Bogus source location for the operator
5687 SourceLocation FakeOperatorLoc
5688 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5689
John McCall38836f02010-01-15 08:34:02 +00005690 // FIXME: to do this check properly, we will need to preserve the
5691 // first-qualifier-in-scope here, just in case we had a dependent
5692 // base (and therefore couldn't do the check) and a
5693 // nested-name-qualifier (and therefore could do the lookup).
5694 NamedDecl *FirstQualifierInScope = 0;
5695
John McCallb268a282010-08-23 23:25:46 +00005696 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005697 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00005698 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005699 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005700 Member,
John McCall16df1e52010-03-30 21:47:33 +00005701 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005702 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005703 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005704 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005705}
Mike Stump11289f42009-09-09 15:08:12 +00005706
Douglas Gregora16548e2009-08-11 05:31:07 +00005707template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005708ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005709TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005710 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005711 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005712 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005713
John McCalldadc5752010-08-24 06:29:42 +00005714 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005715 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005716 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005717
Douglas Gregora16548e2009-08-11 05:31:07 +00005718 if (!getDerived().AlwaysRebuild() &&
5719 LHS.get() == E->getLHS() &&
5720 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005721 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005722
Douglas Gregora16548e2009-08-11 05:31:07 +00005723 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005724 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005725}
5726
Mike Stump11289f42009-09-09 15:08:12 +00005727template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005728ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005729TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005730 CompoundAssignOperator *E) {
5731 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005732}
Mike Stump11289f42009-09-09 15:08:12 +00005733
Douglas Gregora16548e2009-08-11 05:31:07 +00005734template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00005735ExprResult TreeTransform<Derived>::
5736TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
5737 // Just rebuild the common and RHS expressions and see whether we
5738 // get any changes.
5739
5740 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
5741 if (commonExpr.isInvalid())
5742 return ExprError();
5743
5744 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
5745 if (rhs.isInvalid())
5746 return ExprError();
5747
5748 if (!getDerived().AlwaysRebuild() &&
5749 commonExpr.get() == e->getCommon() &&
5750 rhs.get() == e->getFalseExpr())
5751 return SemaRef.Owned(e);
5752
5753 return getDerived().RebuildConditionalOperator(commonExpr.take(),
5754 e->getQuestionLoc(),
5755 0,
5756 e->getColonLoc(),
5757 rhs.get());
5758}
5759
5760template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005761ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005762TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005763 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005764 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005765 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005766
John McCalldadc5752010-08-24 06:29:42 +00005767 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005768 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005769 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005770
John McCalldadc5752010-08-24 06:29:42 +00005771 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005772 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005773 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005774
Douglas Gregora16548e2009-08-11 05:31:07 +00005775 if (!getDerived().AlwaysRebuild() &&
5776 Cond.get() == E->getCond() &&
5777 LHS.get() == E->getLHS() &&
5778 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005779 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005780
John McCallb268a282010-08-23 23:25:46 +00005781 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005782 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005783 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005784 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005785 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005786}
Mike Stump11289f42009-09-09 15:08:12 +00005787
5788template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005789ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005790TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005791 // Implicit casts are eliminated during transformation, since they
5792 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005793 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005794}
Mike Stump11289f42009-09-09 15:08:12 +00005795
Douglas Gregora16548e2009-08-11 05:31:07 +00005796template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005797ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005798TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005799 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5800 if (!Type)
5801 return ExprError();
5802
John McCalldadc5752010-08-24 06:29:42 +00005803 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005804 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005805 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005806 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005807
Douglas Gregora16548e2009-08-11 05:31:07 +00005808 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005809 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005810 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005811 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005812
John McCall97513962010-01-15 18:39:57 +00005813 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005814 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005815 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005816 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005817}
Mike Stump11289f42009-09-09 15:08:12 +00005818
Douglas Gregora16548e2009-08-11 05:31:07 +00005819template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005820ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005821TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005822 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5823 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5824 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005825 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005826
John McCalldadc5752010-08-24 06:29:42 +00005827 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005828 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005829 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005830
Douglas Gregora16548e2009-08-11 05:31:07 +00005831 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005832 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005833 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005834 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005835
John McCall5d7aa7f2010-01-19 22:33:45 +00005836 // Note: the expression type doesn't necessarily match the
5837 // type-as-written, but that's okay, because it should always be
5838 // derivable from the initializer.
5839
John McCalle15bbff2010-01-18 19:35:47 +00005840 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005841 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005842 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005843}
Mike Stump11289f42009-09-09 15:08:12 +00005844
Douglas Gregora16548e2009-08-11 05:31:07 +00005845template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005846ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005847TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005848 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005849 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005850 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005851
Douglas Gregora16548e2009-08-11 05:31:07 +00005852 if (!getDerived().AlwaysRebuild() &&
5853 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00005854 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005855
Douglas Gregora16548e2009-08-11 05:31:07 +00005856 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005857 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005858 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005859 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005860 E->getAccessorLoc(),
5861 E->getAccessor());
5862}
Mike Stump11289f42009-09-09 15:08:12 +00005863
Douglas Gregora16548e2009-08-11 05:31:07 +00005864template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005865ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005866TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005867 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005868
John McCall37ad5512010-08-23 06:44:23 +00005869 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005870 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5871 Inits, &InitChanged))
5872 return ExprError();
5873
Douglas Gregora16548e2009-08-11 05:31:07 +00005874 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005875 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005876
Douglas Gregora16548e2009-08-11 05:31:07 +00005877 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005878 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005879}
Mike Stump11289f42009-09-09 15:08:12 +00005880
Douglas Gregora16548e2009-08-11 05:31:07 +00005881template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005882ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005883TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005884 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005885
Douglas Gregorebe10102009-08-20 07:17:43 +00005886 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005887 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005888 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005889 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005890
Douglas Gregorebe10102009-08-20 07:17:43 +00005891 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005892 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005893 bool ExprChanged = false;
5894 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5895 DEnd = E->designators_end();
5896 D != DEnd; ++D) {
5897 if (D->isFieldDesignator()) {
5898 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5899 D->getDotLoc(),
5900 D->getFieldLoc()));
5901 continue;
5902 }
Mike Stump11289f42009-09-09 15:08:12 +00005903
Douglas Gregora16548e2009-08-11 05:31:07 +00005904 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005905 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005906 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005907 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005908
5909 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005910 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005911
Douglas Gregora16548e2009-08-11 05:31:07 +00005912 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5913 ArrayExprs.push_back(Index.release());
5914 continue;
5915 }
Mike Stump11289f42009-09-09 15:08:12 +00005916
Douglas Gregora16548e2009-08-11 05:31:07 +00005917 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00005918 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00005919 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5920 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005921 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005922
John McCalldadc5752010-08-24 06:29:42 +00005923 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005924 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005925 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005926
5927 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005928 End.get(),
5929 D->getLBracketLoc(),
5930 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005931
Douglas Gregora16548e2009-08-11 05:31:07 +00005932 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5933 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00005934
Douglas Gregora16548e2009-08-11 05:31:07 +00005935 ArrayExprs.push_back(Start.release());
5936 ArrayExprs.push_back(End.release());
5937 }
Mike Stump11289f42009-09-09 15:08:12 +00005938
Douglas Gregora16548e2009-08-11 05:31:07 +00005939 if (!getDerived().AlwaysRebuild() &&
5940 Init.get() == E->getInit() &&
5941 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005942 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005943
Douglas Gregora16548e2009-08-11 05:31:07 +00005944 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5945 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005946 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005947}
Mike Stump11289f42009-09-09 15:08:12 +00005948
Douglas Gregora16548e2009-08-11 05:31:07 +00005949template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005950ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005951TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005952 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00005953 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005954
Douglas Gregor3da3c062009-10-28 00:29:27 +00005955 // FIXME: Will we ever have proper type location here? Will we actually
5956 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00005957 QualType T = getDerived().TransformType(E->getType());
5958 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005959 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005960
Douglas Gregora16548e2009-08-11 05:31:07 +00005961 if (!getDerived().AlwaysRebuild() &&
5962 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005963 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005964
Douglas Gregora16548e2009-08-11 05:31:07 +00005965 return getDerived().RebuildImplicitValueInitExpr(T);
5966}
Mike Stump11289f42009-09-09 15:08:12 +00005967
Douglas Gregora16548e2009-08-11 05:31:07 +00005968template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005969ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005970TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00005971 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5972 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005973 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005974
John McCalldadc5752010-08-24 06:29:42 +00005975 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005976 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005977 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005978
Douglas Gregora16548e2009-08-11 05:31:07 +00005979 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00005980 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005981 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005982 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005983
John McCallb268a282010-08-23 23:25:46 +00005984 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00005985 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005986}
5987
5988template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005989ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005990TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005991 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005992 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005993 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5994 &ArgumentChanged))
5995 return ExprError();
5996
Douglas Gregora16548e2009-08-11 05:31:07 +00005997 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5998 move_arg(Inits),
5999 E->getRParenLoc());
6000}
Mike Stump11289f42009-09-09 15:08:12 +00006001
Douglas Gregora16548e2009-08-11 05:31:07 +00006002/// \brief Transform an address-of-label expression.
6003///
6004/// By default, the transformation of an address-of-label expression always
6005/// rebuilds the expression, so that the label identifier can be resolved to
6006/// the corresponding label statement by semantic analysis.
6007template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006008ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006009TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006010 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6011 E->getLabel());
6012 if (!LD)
6013 return ExprError();
6014
Douglas Gregora16548e2009-08-11 05:31:07 +00006015 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006016 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006017}
Mike Stump11289f42009-09-09 15:08:12 +00006018
6019template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006020ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006021TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006022 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006023 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6024 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006025 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006026
Douglas Gregora16548e2009-08-11 05:31:07 +00006027 if (!getDerived().AlwaysRebuild() &&
6028 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006029 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006030
6031 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006032 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006033 E->getRParenLoc());
6034}
Mike Stump11289f42009-09-09 15:08:12 +00006035
Douglas Gregora16548e2009-08-11 05:31:07 +00006036template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006037ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006038TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006039 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006040 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006041 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006042
John McCalldadc5752010-08-24 06:29:42 +00006043 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006044 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006045 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006046
John McCalldadc5752010-08-24 06:29:42 +00006047 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006048 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006049 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006050
Douglas Gregora16548e2009-08-11 05:31:07 +00006051 if (!getDerived().AlwaysRebuild() &&
6052 Cond.get() == E->getCond() &&
6053 LHS.get() == E->getLHS() &&
6054 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006055 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006056
Douglas Gregora16548e2009-08-11 05:31:07 +00006057 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006058 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006059 E->getRParenLoc());
6060}
Mike Stump11289f42009-09-09 15:08:12 +00006061
Douglas Gregora16548e2009-08-11 05:31:07 +00006062template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006063ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006064TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006065 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006066}
6067
6068template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006069ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006070TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006071 switch (E->getOperator()) {
6072 case OO_New:
6073 case OO_Delete:
6074 case OO_Array_New:
6075 case OO_Array_Delete:
6076 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006077 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006078
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006079 case OO_Call: {
6080 // This is a call to an object's operator().
6081 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6082
6083 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006084 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006085 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006086 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006087
6088 // FIXME: Poor location information
6089 SourceLocation FakeLParenLoc
6090 = SemaRef.PP.getLocForEndOfToken(
6091 static_cast<Expr *>(Object.get())->getLocEnd());
6092
6093 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006094 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006095 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6096 Args))
6097 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006098
John McCallb268a282010-08-23 23:25:46 +00006099 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006100 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006101 E->getLocEnd());
6102 }
6103
6104#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6105 case OO_##Name:
6106#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6107#include "clang/Basic/OperatorKinds.def"
6108 case OO_Subscript:
6109 // Handled below.
6110 break;
6111
6112 case OO_Conditional:
6113 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006114 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006115
6116 case OO_None:
6117 case NUM_OVERLOADED_OPERATORS:
6118 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006119 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006120 }
6121
John McCalldadc5752010-08-24 06:29:42 +00006122 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006123 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006124 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006125
John McCalldadc5752010-08-24 06:29:42 +00006126 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006127 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006128 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006129
John McCalldadc5752010-08-24 06:29:42 +00006130 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006131 if (E->getNumArgs() == 2) {
6132 Second = getDerived().TransformExpr(E->getArg(1));
6133 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006134 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006135 }
Mike Stump11289f42009-09-09 15:08:12 +00006136
Douglas Gregora16548e2009-08-11 05:31:07 +00006137 if (!getDerived().AlwaysRebuild() &&
6138 Callee.get() == E->getCallee() &&
6139 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006140 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006141 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006142
Douglas Gregora16548e2009-08-11 05:31:07 +00006143 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6144 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006145 Callee.get(),
6146 First.get(),
6147 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006148}
Mike Stump11289f42009-09-09 15:08:12 +00006149
Douglas Gregora16548e2009-08-11 05:31:07 +00006150template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006151ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006152TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6153 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006154}
Mike Stump11289f42009-09-09 15:08:12 +00006155
Douglas Gregora16548e2009-08-11 05:31:07 +00006156template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006157ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006158TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6159 // Transform the callee.
6160 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6161 if (Callee.isInvalid())
6162 return ExprError();
6163
6164 // Transform exec config.
6165 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6166 if (EC.isInvalid())
6167 return ExprError();
6168
6169 // Transform arguments.
6170 bool ArgChanged = false;
6171 ASTOwningVector<Expr*> Args(SemaRef);
6172 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6173 &ArgChanged))
6174 return ExprError();
6175
6176 if (!getDerived().AlwaysRebuild() &&
6177 Callee.get() == E->getCallee() &&
6178 !ArgChanged)
6179 return SemaRef.Owned(E);
6180
6181 // FIXME: Wrong source location information for the '('.
6182 SourceLocation FakeLParenLoc
6183 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6184 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6185 move_arg(Args),
6186 E->getRParenLoc(), EC.get());
6187}
6188
6189template<typename Derived>
6190ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006191TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006192 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6193 if (!Type)
6194 return ExprError();
6195
John McCalldadc5752010-08-24 06:29:42 +00006196 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006197 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006198 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006199 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006200
Douglas Gregora16548e2009-08-11 05:31:07 +00006201 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006202 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006203 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006204 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006205
Douglas Gregora16548e2009-08-11 05:31:07 +00006206 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006207 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006208 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6209 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6210 SourceLocation FakeRParenLoc
6211 = SemaRef.PP.getLocForEndOfToken(
6212 E->getSubExpr()->getSourceRange().getEnd());
6213 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006214 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006215 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006216 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006217 FakeRAngleLoc,
6218 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006219 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006220 FakeRParenLoc);
6221}
Mike Stump11289f42009-09-09 15:08:12 +00006222
Douglas Gregora16548e2009-08-11 05:31:07 +00006223template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006224ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006225TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6226 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006227}
Mike Stump11289f42009-09-09 15:08:12 +00006228
6229template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006230ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006231TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6232 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006233}
6234
Douglas Gregora16548e2009-08-11 05:31:07 +00006235template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006236ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006237TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006238 CXXReinterpretCastExpr *E) {
6239 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006240}
Mike Stump11289f42009-09-09 15:08:12 +00006241
Douglas Gregora16548e2009-08-11 05:31:07 +00006242template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006243ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006244TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6245 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006246}
Mike Stump11289f42009-09-09 15:08:12 +00006247
Douglas Gregora16548e2009-08-11 05:31:07 +00006248template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006249ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006250TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006251 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006252 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6253 if (!Type)
6254 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006255
John McCalldadc5752010-08-24 06:29:42 +00006256 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006257 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006258 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006259 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006260
Douglas Gregora16548e2009-08-11 05:31:07 +00006261 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006262 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006263 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006264 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006265
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006266 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006267 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006268 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006269 E->getRParenLoc());
6270}
Mike Stump11289f42009-09-09 15:08:12 +00006271
Douglas Gregora16548e2009-08-11 05:31:07 +00006272template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006273ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006274TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006275 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006276 TypeSourceInfo *TInfo
6277 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6278 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006279 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006280
Douglas Gregora16548e2009-08-11 05:31:07 +00006281 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006282 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006283 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006284
Douglas Gregor9da64192010-04-26 22:37:10 +00006285 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6286 E->getLocStart(),
6287 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006288 E->getLocEnd());
6289 }
Mike Stump11289f42009-09-09 15:08:12 +00006290
Douglas Gregora16548e2009-08-11 05:31:07 +00006291 // We don't know whether the expression is potentially evaluated until
6292 // after we perform semantic analysis, so the expression is potentially
6293 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006294 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006295 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006296
John McCalldadc5752010-08-24 06:29:42 +00006297 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006298 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006299 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006300
Douglas Gregora16548e2009-08-11 05:31:07 +00006301 if (!getDerived().AlwaysRebuild() &&
6302 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006303 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006304
Douglas Gregor9da64192010-04-26 22:37:10 +00006305 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6306 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006307 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006308 E->getLocEnd());
6309}
6310
6311template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006312ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006313TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6314 if (E->isTypeOperand()) {
6315 TypeSourceInfo *TInfo
6316 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6317 if (!TInfo)
6318 return ExprError();
6319
6320 if (!getDerived().AlwaysRebuild() &&
6321 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006322 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006323
Douglas Gregor69735112011-03-06 17:40:41 +00006324 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00006325 E->getLocStart(),
6326 TInfo,
6327 E->getLocEnd());
6328 }
6329
6330 // We don't know whether the expression is potentially evaluated until
6331 // after we perform semantic analysis, so the expression is potentially
6332 // potentially evaluated.
6333 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6334
6335 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6336 if (SubExpr.isInvalid())
6337 return ExprError();
6338
6339 if (!getDerived().AlwaysRebuild() &&
6340 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006341 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006342
6343 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6344 E->getLocStart(),
6345 SubExpr.get(),
6346 E->getLocEnd());
6347}
6348
6349template<typename Derived>
6350ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006351TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006352 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006353}
Mike Stump11289f42009-09-09 15:08:12 +00006354
Douglas Gregora16548e2009-08-11 05:31:07 +00006355template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006356ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006357TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006358 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006359 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006360}
Mike Stump11289f42009-09-09 15:08:12 +00006361
Douglas Gregora16548e2009-08-11 05:31:07 +00006362template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006363ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006364TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006365 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6366 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6367 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006368
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006369 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006370 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006371
Douglas Gregorb15af892010-01-07 23:12:05 +00006372 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006373}
Mike Stump11289f42009-09-09 15:08:12 +00006374
Douglas Gregora16548e2009-08-11 05:31:07 +00006375template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006376ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006377TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006378 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006379 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006380 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006381
Douglas Gregora16548e2009-08-11 05:31:07 +00006382 if (!getDerived().AlwaysRebuild() &&
6383 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006384 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006385
John McCallb268a282010-08-23 23:25:46 +00006386 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006387}
Mike Stump11289f42009-09-09 15:08:12 +00006388
Douglas Gregora16548e2009-08-11 05:31:07 +00006389template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006390ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006391TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006392 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006393 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6394 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006395 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006396 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006397
Chandler Carruth794da4c2010-02-08 06:42:49 +00006398 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006399 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006400 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006401
Douglas Gregor033f6752009-12-23 23:03:06 +00006402 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006403}
Mike Stump11289f42009-09-09 15:08:12 +00006404
Douglas Gregora16548e2009-08-11 05:31:07 +00006405template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006406ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006407TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6408 CXXScalarValueInitExpr *E) {
6409 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6410 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006411 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006412
Douglas Gregora16548e2009-08-11 05:31:07 +00006413 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006414 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006415 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006416
Douglas Gregor2b88c112010-09-08 00:15:04 +00006417 return getDerived().RebuildCXXScalarValueInitExpr(T,
6418 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006419 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006420}
Mike Stump11289f42009-09-09 15:08:12 +00006421
Douglas Gregora16548e2009-08-11 05:31:07 +00006422template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006423ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006424TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006425 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006426 TypeSourceInfo *AllocTypeInfo
6427 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6428 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006429 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006430
Douglas Gregora16548e2009-08-11 05:31:07 +00006431 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006432 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006433 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006434 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006435
Douglas Gregora16548e2009-08-11 05:31:07 +00006436 // Transform the placement arguments (if any).
6437 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006438 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006439 if (getDerived().TransformExprs(E->getPlacementArgs(),
6440 E->getNumPlacementArgs(), true,
6441 PlacementArgs, &ArgumentChanged))
6442 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006443
Douglas Gregorebe10102009-08-20 07:17:43 +00006444 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006445 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006446 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6447 ConstructorArgs, &ArgumentChanged))
6448 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006449
Douglas Gregord2d9da02010-02-26 00:38:10 +00006450 // Transform constructor, new operator, and delete operator.
6451 CXXConstructorDecl *Constructor = 0;
6452 if (E->getConstructor()) {
6453 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006454 getDerived().TransformDecl(E->getLocStart(),
6455 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006456 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006457 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006458 }
6459
6460 FunctionDecl *OperatorNew = 0;
6461 if (E->getOperatorNew()) {
6462 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006463 getDerived().TransformDecl(E->getLocStart(),
6464 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006465 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006466 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006467 }
6468
6469 FunctionDecl *OperatorDelete = 0;
6470 if (E->getOperatorDelete()) {
6471 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006472 getDerived().TransformDecl(E->getLocStart(),
6473 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006474 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006475 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006476 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006477
Douglas Gregora16548e2009-08-11 05:31:07 +00006478 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006479 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006480 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006481 Constructor == E->getConstructor() &&
6482 OperatorNew == E->getOperatorNew() &&
6483 OperatorDelete == E->getOperatorDelete() &&
6484 !ArgumentChanged) {
6485 // Mark any declarations we need as referenced.
6486 // FIXME: instantiation-specific.
6487 if (Constructor)
6488 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6489 if (OperatorNew)
6490 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6491 if (OperatorDelete)
6492 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006493 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006494 }
Mike Stump11289f42009-09-09 15:08:12 +00006495
Douglas Gregor0744ef62010-09-07 21:49:58 +00006496 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006497 if (!ArraySize.get()) {
6498 // If no array size was specified, but the new expression was
6499 // instantiated with an array type (e.g., "new T" where T is
6500 // instantiated with "int[4]"), extract the outer bound from the
6501 // array type as our array size. We do this with constant and
6502 // dependently-sized array types.
6503 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6504 if (!ArrayT) {
6505 // Do nothing
6506 } else if (const ConstantArrayType *ConsArrayT
6507 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006508 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006509 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6510 ConsArrayT->getSize(),
6511 SemaRef.Context.getSizeType(),
6512 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006513 AllocType = ConsArrayT->getElementType();
6514 } else if (const DependentSizedArrayType *DepArrayT
6515 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6516 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006517 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006518 AllocType = DepArrayT->getElementType();
6519 }
6520 }
6521 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006522
Douglas Gregora16548e2009-08-11 05:31:07 +00006523 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6524 E->isGlobalNew(),
6525 /*FIXME:*/E->getLocStart(),
6526 move_arg(PlacementArgs),
6527 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006528 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006529 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006530 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006531 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006532 /*FIXME:*/E->getLocStart(),
6533 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006534 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006535}
Mike Stump11289f42009-09-09 15:08:12 +00006536
Douglas Gregora16548e2009-08-11 05:31:07 +00006537template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006538ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006539TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006540 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006541 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006542 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006543
Douglas Gregord2d9da02010-02-26 00:38:10 +00006544 // Transform the delete operator, if known.
6545 FunctionDecl *OperatorDelete = 0;
6546 if (E->getOperatorDelete()) {
6547 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006548 getDerived().TransformDecl(E->getLocStart(),
6549 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006550 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006551 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006552 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006553
Douglas Gregora16548e2009-08-11 05:31:07 +00006554 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006555 Operand.get() == E->getArgument() &&
6556 OperatorDelete == E->getOperatorDelete()) {
6557 // Mark any declarations we need as referenced.
6558 // FIXME: instantiation-specific.
6559 if (OperatorDelete)
6560 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006561
6562 if (!E->getArgument()->isTypeDependent()) {
6563 QualType Destroyed = SemaRef.Context.getBaseElementType(
6564 E->getDestroyedType());
6565 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6566 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6567 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6568 SemaRef.LookupDestructor(Record));
6569 }
6570 }
6571
John McCallc3007a22010-10-26 07:05:15 +00006572 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006573 }
Mike Stump11289f42009-09-09 15:08:12 +00006574
Douglas Gregora16548e2009-08-11 05:31:07 +00006575 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6576 E->isGlobalDelete(),
6577 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006578 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006579}
Mike Stump11289f42009-09-09 15:08:12 +00006580
Douglas Gregora16548e2009-08-11 05:31:07 +00006581template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006582ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006583TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006584 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006585 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006586 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006587 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006588
John McCallba7bf592010-08-24 05:47:05 +00006589 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006590 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006591 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006592 E->getOperatorLoc(),
6593 E->isArrow()? tok::arrow : tok::period,
6594 ObjectTypePtr,
6595 MayBePseudoDestructor);
6596 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006597 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006598
John McCallba7bf592010-08-24 05:47:05 +00006599 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00006600 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6601 if (QualifierLoc) {
6602 QualifierLoc
6603 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6604 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00006605 return ExprError();
6606 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00006607 CXXScopeSpec SS;
6608 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00006609
Douglas Gregor678f90d2010-02-25 01:56:36 +00006610 PseudoDestructorTypeStorage Destroyed;
6611 if (E->getDestroyedTypeInfo()) {
6612 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006613 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00006614 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00006615 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006616 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006617 Destroyed = DestroyedTypeInfo;
6618 } else if (ObjectType->isDependentType()) {
6619 // We aren't likely to be able to resolve the identifier down to a type
6620 // now anyway, so just retain the identifier.
6621 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6622 E->getDestroyedTypeLoc());
6623 } else {
6624 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00006625 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006626 *E->getDestroyedTypeIdentifier(),
6627 E->getDestroyedTypeLoc(),
6628 /*Scope=*/0,
6629 SS, ObjectTypePtr,
6630 false);
6631 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006632 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006633
Douglas Gregor678f90d2010-02-25 01:56:36 +00006634 Destroyed
6635 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6636 E->getDestroyedTypeLoc());
6637 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006638
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006639 TypeSourceInfo *ScopeTypeInfo = 0;
6640 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006641 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006642 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006643 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006644 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006645
John McCallb268a282010-08-23 23:25:46 +00006646 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006647 E->getOperatorLoc(),
6648 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006649 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006650 ScopeTypeInfo,
6651 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006652 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006653 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006654}
Mike Stump11289f42009-09-09 15:08:12 +00006655
Douglas Gregorad8a3362009-09-04 17:36:40 +00006656template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006657ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006658TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006659 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006660 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6661 Sema::LookupOrdinaryName);
6662
6663 // Transform all the decls.
6664 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6665 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006666 NamedDecl *InstD = static_cast<NamedDecl*>(
6667 getDerived().TransformDecl(Old->getNameLoc(),
6668 *I));
John McCall84d87672009-12-10 09:41:52 +00006669 if (!InstD) {
6670 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6671 // This can happen because of dependent hiding.
6672 if (isa<UsingShadowDecl>(*I))
6673 continue;
6674 else
John McCallfaf5fb42010-08-26 23:41:50 +00006675 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006676 }
John McCalle66edc12009-11-24 19:00:30 +00006677
6678 // Expand using declarations.
6679 if (isa<UsingDecl>(InstD)) {
6680 UsingDecl *UD = cast<UsingDecl>(InstD);
6681 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6682 E = UD->shadow_end(); I != E; ++I)
6683 R.addDecl(*I);
6684 continue;
6685 }
6686
6687 R.addDecl(InstD);
6688 }
6689
6690 // Resolve a kind, but don't do any further analysis. If it's
6691 // ambiguous, the callee needs to deal with it.
6692 R.resolveKind();
6693
6694 // Rebuild the nested-name qualifier, if present.
6695 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00006696 if (Old->getQualifierLoc()) {
6697 NestedNameSpecifierLoc QualifierLoc
6698 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
6699 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006700 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006701
Douglas Gregor0da1d432011-02-28 20:01:57 +00006702 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006703 }
6704
Douglas Gregor9262f472010-04-27 18:19:34 +00006705 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006706 CXXRecordDecl *NamingClass
6707 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6708 Old->getNameLoc(),
6709 Old->getNamingClass()));
6710 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006711 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006712
Douglas Gregorda7be082010-04-27 16:10:10 +00006713 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006714 }
6715
6716 // If we have no template arguments, it's a normal declaration name.
6717 if (!Old->hasExplicitTemplateArgs())
6718 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6719
6720 // If we have template arguments, rebuild them, then rebuild the
6721 // templateid expression.
6722 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006723 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6724 Old->getNumTemplateArgs(),
6725 TransArgs))
6726 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006727
6728 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6729 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006730}
Mike Stump11289f42009-09-09 15:08:12 +00006731
Douglas Gregora16548e2009-08-11 05:31:07 +00006732template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006733ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006734TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006735 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6736 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006737 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006738
Douglas Gregora16548e2009-08-11 05:31:07 +00006739 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006740 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006741 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006742
Mike Stump11289f42009-09-09 15:08:12 +00006743 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006744 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006745 T,
6746 E->getLocEnd());
6747}
Mike Stump11289f42009-09-09 15:08:12 +00006748
Douglas Gregora16548e2009-08-11 05:31:07 +00006749template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006750ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006751TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6752 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6753 if (!LhsT)
6754 return ExprError();
6755
6756 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6757 if (!RhsT)
6758 return ExprError();
6759
6760 if (!getDerived().AlwaysRebuild() &&
6761 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6762 return SemaRef.Owned(E);
6763
6764 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6765 E->getLocStart(),
6766 LhsT, RhsT,
6767 E->getLocEnd());
6768}
6769
6770template<typename Derived>
6771ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006772TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006773 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006774 NestedNameSpecifierLoc QualifierLoc
6775 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6776 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006777 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006778
John McCall31f82722010-11-12 08:19:04 +00006779 // TODO: If this is a conversion-function-id, verify that the
6780 // destination type name (if present) resolves the same way after
6781 // instantiation as it did in the local scope.
6782
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006783 DeclarationNameInfo NameInfo
6784 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6785 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006786 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006787
John McCalle66edc12009-11-24 19:00:30 +00006788 if (!E->hasExplicitTemplateArgs()) {
6789 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006790 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006791 // Note: it is sufficient to compare the Name component of NameInfo:
6792 // if name has not changed, DNLoc has not changed either.
6793 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006794 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006795
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006796 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006797 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006798 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006799 }
John McCall6b51f282009-11-23 01:53:49 +00006800
6801 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006802 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6803 E->getNumTemplateArgs(),
6804 TransArgs))
6805 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006806
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006807 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006808 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006809 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006810}
6811
6812template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006813ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006814TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006815 // CXXConstructExprs are always implicit, so when we have a
6816 // 1-argument construction we just transform that argument.
6817 if (E->getNumArgs() == 1 ||
6818 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6819 return getDerived().TransformExpr(E->getArg(0));
6820
Douglas Gregora16548e2009-08-11 05:31:07 +00006821 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6822
6823 QualType T = getDerived().TransformType(E->getType());
6824 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006825 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006826
6827 CXXConstructorDecl *Constructor
6828 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006829 getDerived().TransformDecl(E->getLocStart(),
6830 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006831 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006832 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006833
Douglas Gregora16548e2009-08-11 05:31:07 +00006834 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006835 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006836 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6837 &ArgumentChanged))
6838 return ExprError();
6839
Douglas Gregora16548e2009-08-11 05:31:07 +00006840 if (!getDerived().AlwaysRebuild() &&
6841 T == E->getType() &&
6842 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006843 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006844 // Mark the constructor as referenced.
6845 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006846 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006847 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006848 }
Mike Stump11289f42009-09-09 15:08:12 +00006849
Douglas Gregordb121ba2009-12-14 16:27:04 +00006850 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6851 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006852 move_arg(Args),
6853 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006854 E->getConstructionKind(),
6855 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006856}
Mike Stump11289f42009-09-09 15:08:12 +00006857
Douglas Gregora16548e2009-08-11 05:31:07 +00006858/// \brief Transform a C++ temporary-binding expression.
6859///
Douglas Gregor363b1512009-12-24 18:51:59 +00006860/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6861/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006862template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006863ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006864TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006865 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006866}
Mike Stump11289f42009-09-09 15:08:12 +00006867
John McCall5d413782010-12-06 08:20:24 +00006868/// \brief Transform a C++ expression that contains cleanups that should
6869/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006870///
John McCall5d413782010-12-06 08:20:24 +00006871/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006872/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006873template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006874ExprResult
John McCall5d413782010-12-06 08:20:24 +00006875TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006876 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006877}
Mike Stump11289f42009-09-09 15:08:12 +00006878
Douglas Gregora16548e2009-08-11 05:31:07 +00006879template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006880ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006881TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006882 CXXTemporaryObjectExpr *E) {
6883 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6884 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006885 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006886
Douglas Gregora16548e2009-08-11 05:31:07 +00006887 CXXConstructorDecl *Constructor
6888 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006889 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006890 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006891 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006892 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006893
Douglas Gregora16548e2009-08-11 05:31:07 +00006894 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006895 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006896 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00006897 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6898 &ArgumentChanged))
6899 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006900
Douglas Gregora16548e2009-08-11 05:31:07 +00006901 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006902 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006903 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006904 !ArgumentChanged) {
6905 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006906 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006907 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006908 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006909
6910 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6911 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006912 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006913 E->getLocEnd());
6914}
Mike Stump11289f42009-09-09 15:08:12 +00006915
Douglas Gregora16548e2009-08-11 05:31:07 +00006916template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006917ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006918TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006919 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00006920 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6921 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006922 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006923
Douglas Gregora16548e2009-08-11 05:31:07 +00006924 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006925 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006926 Args.reserve(E->arg_size());
6927 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6928 &ArgumentChanged))
6929 return ExprError();
6930
Douglas Gregora16548e2009-08-11 05:31:07 +00006931 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006932 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006933 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006934 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006935
Douglas Gregora16548e2009-08-11 05:31:07 +00006936 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00006937 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00006938 E->getLParenLoc(),
6939 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006940 E->getRParenLoc());
6941}
Mike Stump11289f42009-09-09 15:08:12 +00006942
Douglas Gregora16548e2009-08-11 05:31:07 +00006943template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006944ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006945TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006946 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006947 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006948 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006949 Expr *OldBase;
6950 QualType BaseType;
6951 QualType ObjectType;
6952 if (!E->isImplicitAccess()) {
6953 OldBase = E->getBase();
6954 Base = getDerived().TransformExpr(OldBase);
6955 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006956 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006957
John McCall2d74de92009-12-01 22:10:20 +00006958 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00006959 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00006960 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006961 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006962 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006963 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00006964 ObjectTy,
6965 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00006966 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006967 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006968
John McCallba7bf592010-08-24 05:47:05 +00006969 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00006970 BaseType = ((Expr*) Base.get())->getType();
6971 } else {
6972 OldBase = 0;
6973 BaseType = getDerived().TransformType(E->getBaseType());
6974 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6975 }
Mike Stump11289f42009-09-09 15:08:12 +00006976
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006977 // Transform the first part of the nested-name-specifier that qualifies
6978 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006979 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006980 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00006981 E->getFirstQualifierFoundInScope(),
6982 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00006983
Douglas Gregore16af532011-02-28 18:50:33 +00006984 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006985 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00006986 QualifierLoc
6987 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
6988 ObjectType,
6989 FirstQualifierInScope);
6990 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006991 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006992 }
Mike Stump11289f42009-09-09 15:08:12 +00006993
John McCall31f82722010-11-12 08:19:04 +00006994 // TODO: If this is a conversion-function-id, verify that the
6995 // destination type name (if present) resolves the same way after
6996 // instantiation as it did in the local scope.
6997
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006998 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00006999 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007000 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007001 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007002
John McCall2d74de92009-12-01 22:10:20 +00007003 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007004 // This is a reference to a member without an explicitly-specified
7005 // template argument list. Optimize for this common case.
7006 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007007 Base.get() == OldBase &&
7008 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007009 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007010 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007011 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007012 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007013
John McCallb268a282010-08-23 23:25:46 +00007014 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007015 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007016 E->isArrow(),
7017 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007018 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007019 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007020 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007021 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007022 }
7023
John McCall6b51f282009-11-23 01:53:49 +00007024 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007025 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7026 E->getNumTemplateArgs(),
7027 TransArgs))
7028 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007029
John McCallb268a282010-08-23 23:25:46 +00007030 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007031 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007032 E->isArrow(),
7033 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007034 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007035 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007036 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007037 &TransArgs);
7038}
7039
7040template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007041ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007042TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007043 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007044 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007045 QualType BaseType;
7046 if (!Old->isImplicitAccess()) {
7047 Base = getDerived().TransformExpr(Old->getBase());
7048 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007049 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007050 BaseType = ((Expr*) Base.get())->getType();
7051 } else {
7052 BaseType = getDerived().TransformType(Old->getBaseType());
7053 }
John McCall10eae182009-11-30 22:42:35 +00007054
Douglas Gregor0da1d432011-02-28 20:01:57 +00007055 NestedNameSpecifierLoc QualifierLoc;
7056 if (Old->getQualifierLoc()) {
7057 QualifierLoc
7058 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7059 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007060 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007061 }
7062
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007063 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007064 Sema::LookupOrdinaryName);
7065
7066 // Transform all the decls.
7067 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7068 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007069 NamedDecl *InstD = static_cast<NamedDecl*>(
7070 getDerived().TransformDecl(Old->getMemberLoc(),
7071 *I));
John McCall84d87672009-12-10 09:41:52 +00007072 if (!InstD) {
7073 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7074 // This can happen because of dependent hiding.
7075 if (isa<UsingShadowDecl>(*I))
7076 continue;
7077 else
John McCallfaf5fb42010-08-26 23:41:50 +00007078 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00007079 }
John McCall10eae182009-11-30 22:42:35 +00007080
7081 // Expand using declarations.
7082 if (isa<UsingDecl>(InstD)) {
7083 UsingDecl *UD = cast<UsingDecl>(InstD);
7084 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7085 E = UD->shadow_end(); I != E; ++I)
7086 R.addDecl(*I);
7087 continue;
7088 }
7089
7090 R.addDecl(InstD);
7091 }
7092
7093 R.resolveKind();
7094
Douglas Gregor9262f472010-04-27 18:19:34 +00007095 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007096 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007097 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007098 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007099 Old->getMemberLoc(),
7100 Old->getNamingClass()));
7101 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007102 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007103
Douglas Gregorda7be082010-04-27 16:10:10 +00007104 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007105 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007106
John McCall10eae182009-11-30 22:42:35 +00007107 TemplateArgumentListInfo TransArgs;
7108 if (Old->hasExplicitTemplateArgs()) {
7109 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7110 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007111 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7112 Old->getNumTemplateArgs(),
7113 TransArgs))
7114 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007115 }
John McCall38836f02010-01-15 08:34:02 +00007116
7117 // FIXME: to do this check properly, we will need to preserve the
7118 // first-qualifier-in-scope here, just in case we had a dependent
7119 // base (and therefore couldn't do the check) and a
7120 // nested-name-qualifier (and therefore could do the lookup).
7121 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007122
John McCallb268a282010-08-23 23:25:46 +00007123 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007124 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007125 Old->getOperatorLoc(),
7126 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007127 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007128 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007129 R,
7130 (Old->hasExplicitTemplateArgs()
7131 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007132}
7133
7134template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007135ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007136TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7137 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7138 if (SubExpr.isInvalid())
7139 return ExprError();
7140
7141 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007142 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007143
7144 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7145}
7146
7147template<typename Derived>
7148ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007149TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007150 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7151 if (Pattern.isInvalid())
7152 return ExprError();
7153
7154 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7155 return SemaRef.Owned(E);
7156
Douglas Gregorb8840002011-01-14 21:20:45 +00007157 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7158 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007159}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007160
7161template<typename Derived>
7162ExprResult
7163TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7164 // If E is not value-dependent, then nothing will change when we transform it.
7165 // Note: This is an instantiation-centric view.
7166 if (!E->isValueDependent())
7167 return SemaRef.Owned(E);
7168
7169 // Note: None of the implementations of TryExpandParameterPacks can ever
7170 // produce a diagnostic when given only a single unexpanded parameter pack,
7171 // so
7172 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7173 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007174 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007175 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007176 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7177 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007178 ShouldExpand, RetainExpansion,
7179 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007180 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007181
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007182 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007183 return SemaRef.Owned(E);
7184
7185 // We now know the length of the parameter pack, so build a new expression
7186 // that stores that length.
7187 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7188 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007189 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007190}
7191
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007192template<typename Derived>
7193ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007194TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7195 SubstNonTypeTemplateParmPackExpr *E) {
7196 // Default behavior is to do nothing with this transformation.
7197 return SemaRef.Owned(E);
7198}
7199
7200template<typename Derived>
7201ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007202TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007203 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007204}
7205
Mike Stump11289f42009-09-09 15:08:12 +00007206template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007207ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007208TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007209 TypeSourceInfo *EncodedTypeInfo
7210 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7211 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007212 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007213
Douglas Gregora16548e2009-08-11 05:31:07 +00007214 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007215 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007216 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007217
7218 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007219 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007220 E->getRParenLoc());
7221}
Mike Stump11289f42009-09-09 15:08:12 +00007222
Douglas Gregora16548e2009-08-11 05:31:07 +00007223template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007224ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007225TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007226 // Transform arguments.
7227 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007228 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007229 Args.reserve(E->getNumArgs());
7230 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7231 &ArgChanged))
7232 return ExprError();
7233
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007234 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7235 // Class message: transform the receiver type.
7236 TypeSourceInfo *ReceiverTypeInfo
7237 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7238 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007239 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007240
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007241 // If nothing changed, just retain the existing message send.
7242 if (!getDerived().AlwaysRebuild() &&
7243 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007244 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007245
7246 // Build a new class message send.
7247 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7248 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007249 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007250 E->getMethodDecl(),
7251 E->getLeftLoc(),
7252 move_arg(Args),
7253 E->getRightLoc());
7254 }
7255
7256 // Instance message: transform the receiver
7257 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7258 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007259 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007260 = getDerived().TransformExpr(E->getInstanceReceiver());
7261 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007262 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007263
7264 // If nothing changed, just retain the existing message send.
7265 if (!getDerived().AlwaysRebuild() &&
7266 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007267 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007268
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007269 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007270 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007271 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007272 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007273 E->getMethodDecl(),
7274 E->getLeftLoc(),
7275 move_arg(Args),
7276 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007277}
7278
Mike Stump11289f42009-09-09 15:08:12 +00007279template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007280ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007281TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007282 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007283}
7284
Mike Stump11289f42009-09-09 15:08:12 +00007285template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007286ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007287TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007288 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007289}
7290
Mike Stump11289f42009-09-09 15:08:12 +00007291template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007292ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007293TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007294 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007295 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007296 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007297 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007298
7299 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007300
Douglas Gregord51d90d2010-04-26 20:11:03 +00007301 // If nothing changed, just retain the existing expression.
7302 if (!getDerived().AlwaysRebuild() &&
7303 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007304 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007305
John McCallb268a282010-08-23 23:25:46 +00007306 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007307 E->getLocation(),
7308 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007309}
7310
Mike Stump11289f42009-09-09 15:08:12 +00007311template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007312ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007313TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007314 // 'super' and types never change. Property never changes. Just
7315 // retain the existing expression.
7316 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007317 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007318
Douglas Gregor9faee212010-04-26 20:47:02 +00007319 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007320 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007321 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007322 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007323
Douglas Gregor9faee212010-04-26 20:47:02 +00007324 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007325
Douglas Gregor9faee212010-04-26 20:47:02 +00007326 // If nothing changed, just retain the existing expression.
7327 if (!getDerived().AlwaysRebuild() &&
7328 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007329 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007330
John McCallb7bd14f2010-12-02 01:19:52 +00007331 if (E->isExplicitProperty())
7332 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7333 E->getExplicitProperty(),
7334 E->getLocation());
7335
7336 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7337 E->getType(),
7338 E->getImplicitPropertyGetter(),
7339 E->getImplicitPropertySetter(),
7340 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007341}
7342
Mike Stump11289f42009-09-09 15:08:12 +00007343template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007344ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007345TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007346 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007347 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007348 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007349 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007350
Douglas Gregord51d90d2010-04-26 20:11:03 +00007351 // If nothing changed, just retain the existing expression.
7352 if (!getDerived().AlwaysRebuild() &&
7353 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007354 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007355
John McCallb268a282010-08-23 23:25:46 +00007356 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007357 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007358}
7359
Mike Stump11289f42009-09-09 15:08:12 +00007360template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007361ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007362TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007363 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007364 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007365 SubExprs.reserve(E->getNumSubExprs());
7366 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7367 SubExprs, &ArgumentChanged))
7368 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007369
Douglas Gregora16548e2009-08-11 05:31:07 +00007370 if (!getDerived().AlwaysRebuild() &&
7371 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007372 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007373
Douglas Gregora16548e2009-08-11 05:31:07 +00007374 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7375 move_arg(SubExprs),
7376 E->getRParenLoc());
7377}
7378
Mike Stump11289f42009-09-09 15:08:12 +00007379template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007380ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007381TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007382 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007383
John McCall490112f2011-02-04 18:33:18 +00007384 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7385 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7386
7387 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7388 llvm::SmallVector<ParmVarDecl*, 4> params;
7389 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007390
7391 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007392 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7393 oldBlock->param_begin(),
7394 oldBlock->param_size(),
7395 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007396 return true;
John McCall490112f2011-02-04 18:33:18 +00007397
7398 const FunctionType *exprFunctionType = E->getFunctionType();
7399 QualType exprResultType = exprFunctionType->getResultType();
7400 if (!exprResultType.isNull()) {
7401 if (!exprResultType->isDependentType())
7402 blockScope->ReturnType = exprResultType;
7403 else if (exprResultType != getSema().Context.DependentTy)
7404 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007405 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007406
7407 // If the return type has not been determined yet, leave it as a dependent
7408 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007409 if (blockScope->ReturnType.isNull())
7410 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007411
7412 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007413 if (blockScope->ReturnType->isObjCObjectType()) {
7414 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007415 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007416 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007417 return ExprError();
7418 }
John McCall3882ace2011-01-05 12:14:39 +00007419
John McCall490112f2011-02-04 18:33:18 +00007420 QualType functionType = getDerived().RebuildFunctionProtoType(
7421 blockScope->ReturnType,
7422 paramTypes.data(),
7423 paramTypes.size(),
7424 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007425 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007426 exprFunctionType->getExtInfo());
7427 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007428
7429 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007430 if (!params.empty())
7431 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007432
7433 // If the return type wasn't explicitly set, it will have been marked as a
7434 // dependent type (DependentTy); clear out the return type setting so
7435 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007436 if (blockScope->ReturnType == getSema().Context.DependentTy)
7437 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007438
John McCall3882ace2011-01-05 12:14:39 +00007439 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007440 StmtResult body = getDerived().TransformStmt(E->getBody());
7441 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007442 return ExprError();
7443
John McCall490112f2011-02-04 18:33:18 +00007444#ifndef NDEBUG
7445 // In builds with assertions, make sure that we captured everything we
7446 // captured before.
7447
7448 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7449
7450 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7451 e = oldBlock->capture_end(); i != e; ++i) {
John McCall351762c2011-02-07 10:33:21 +00007452 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007453
7454 // Ignore parameter packs.
7455 if (isa<ParmVarDecl>(oldCapture) &&
7456 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7457 continue;
7458
7459 VarDecl *newCapture =
7460 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7461 oldCapture));
John McCall351762c2011-02-07 10:33:21 +00007462 assert(blockScope->CaptureMap.count(newCapture));
John McCall490112f2011-02-04 18:33:18 +00007463 }
7464#endif
7465
7466 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7467 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007468}
7469
Mike Stump11289f42009-09-09 15:08:12 +00007470template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007471ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007472TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007473 ValueDecl *ND
7474 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7475 E->getDecl()));
7476 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007477 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007478
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007479 if (!getDerived().AlwaysRebuild() &&
7480 ND == E->getDecl()) {
7481 // Mark it referenced in the new context regardless.
7482 // FIXME: this is a bit instantiation-specific.
7483 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7484
John McCallc3007a22010-10-26 07:05:15 +00007485 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007486 }
7487
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007488 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00007489 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007490 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007491}
Mike Stump11289f42009-09-09 15:08:12 +00007492
Douglas Gregora16548e2009-08-11 05:31:07 +00007493//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007494// Type reconstruction
7495//===----------------------------------------------------------------------===//
7496
Mike Stump11289f42009-09-09 15:08:12 +00007497template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007498QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7499 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007500 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007501 getDerived().getBaseEntity());
7502}
7503
Mike Stump11289f42009-09-09 15:08:12 +00007504template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007505QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7506 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007507 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007508 getDerived().getBaseEntity());
7509}
7510
Mike Stump11289f42009-09-09 15:08:12 +00007511template<typename Derived>
7512QualType
John McCall70dd5f62009-10-30 00:06:24 +00007513TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7514 bool WrittenAsLValue,
7515 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007516 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007517 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007518}
7519
7520template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007521QualType
John McCall70dd5f62009-10-30 00:06:24 +00007522TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7523 QualType ClassType,
7524 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007525 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
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
Douglas Gregord6ff3322009-08-04 16:50:30 +00007531TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7532 ArrayType::ArraySizeModifier SizeMod,
7533 const llvm::APInt *Size,
7534 Expr *SizeExpr,
7535 unsigned IndexTypeQuals,
7536 SourceRange BracketsRange) {
7537 if (SizeExpr || !Size)
7538 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7539 IndexTypeQuals, BracketsRange,
7540 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007541
7542 QualType Types[] = {
7543 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7544 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7545 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007546 };
7547 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7548 QualType SizeType;
7549 for (unsigned I = 0; I != NumTypes; ++I)
7550 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7551 SizeType = Types[I];
7552 break;
7553 }
Mike Stump11289f42009-09-09 15:08:12 +00007554
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007555 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7556 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007557 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007558 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007559 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007560}
Mike Stump11289f42009-09-09 15:08:12 +00007561
Douglas Gregord6ff3322009-08-04 16:50:30 +00007562template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007563QualType
7564TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007565 ArrayType::ArraySizeModifier SizeMod,
7566 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007567 unsigned IndexTypeQuals,
7568 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007569 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007570 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007571}
7572
7573template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007574QualType
Mike Stump11289f42009-09-09 15:08:12 +00007575TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007576 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007577 unsigned IndexTypeQuals,
7578 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007579 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007580 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007581}
Mike Stump11289f42009-09-09 15:08:12 +00007582
Douglas Gregord6ff3322009-08-04 16:50:30 +00007583template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007584QualType
7585TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007586 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007587 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007588 unsigned IndexTypeQuals,
7589 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007590 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007591 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007592 IndexTypeQuals, BracketsRange);
7593}
7594
7595template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007596QualType
7597TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007598 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007599 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007600 unsigned IndexTypeQuals,
7601 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007602 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007603 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007604 IndexTypeQuals, BracketsRange);
7605}
7606
7607template<typename Derived>
7608QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007609 unsigned NumElements,
7610 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007611 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007612 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007613}
Mike Stump11289f42009-09-09 15:08:12 +00007614
Douglas Gregord6ff3322009-08-04 16:50:30 +00007615template<typename Derived>
7616QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7617 unsigned NumElements,
7618 SourceLocation AttributeLoc) {
7619 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7620 NumElements, true);
7621 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007622 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7623 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007624 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007625}
Mike Stump11289f42009-09-09 15:08:12 +00007626
Douglas Gregord6ff3322009-08-04 16:50:30 +00007627template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007628QualType
7629TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007630 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007631 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007632 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007633}
Mike Stump11289f42009-09-09 15:08:12 +00007634
Douglas Gregord6ff3322009-08-04 16:50:30 +00007635template<typename Derived>
7636QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007637 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007638 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007639 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007640 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007641 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00007642 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007643 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007644 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007645 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007646 getDerived().getBaseEntity(),
7647 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007648}
Mike Stump11289f42009-09-09 15:08:12 +00007649
Douglas Gregord6ff3322009-08-04 16:50:30 +00007650template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007651QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7652 return SemaRef.Context.getFunctionNoProtoType(T);
7653}
7654
7655template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007656QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7657 assert(D && "no decl found");
7658 if (D->isInvalidDecl()) return QualType();
7659
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007660 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007661 TypeDecl *Ty;
7662 if (isa<UsingDecl>(D)) {
7663 UsingDecl *Using = cast<UsingDecl>(D);
7664 assert(Using->isTypeName() &&
7665 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7666
7667 // A valid resolved using typename decl points to exactly one type decl.
7668 assert(++Using->shadow_begin() == Using->shadow_end());
7669 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007670
John McCallb96ec562009-12-04 22:46:56 +00007671 } else {
7672 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7673 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7674 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7675 }
7676
7677 return SemaRef.Context.getTypeDeclType(Ty);
7678}
7679
7680template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007681QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7682 SourceLocation Loc) {
7683 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007684}
7685
7686template<typename Derived>
7687QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7688 return SemaRef.Context.getTypeOfType(Underlying);
7689}
7690
7691template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007692QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7693 SourceLocation Loc) {
7694 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007695}
7696
7697template<typename Derived>
7698QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007699 TemplateName Template,
7700 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00007701 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00007702 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007703}
Mike Stump11289f42009-09-09 15:08:12 +00007704
Douglas Gregor1135c352009-08-06 05:28:30 +00007705template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007706TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007707TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007708 bool TemplateKW,
7709 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00007710 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007711 Template);
7712}
7713
7714template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007715TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007716TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
7717 const IdentifierInfo &Name,
7718 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00007719 QualType ObjectType,
7720 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00007721 UnqualifiedId TemplateName;
7722 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00007723 Sema::TemplateTy Template;
7724 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00007725 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007726 SS,
Douglas Gregor9db53502011-03-02 18:07:45 +00007727 TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00007728 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007729 /*EnteringContext=*/false,
7730 Template);
John McCall31f82722010-11-12 08:19:04 +00007731 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007732}
Mike Stump11289f42009-09-09 15:08:12 +00007733
Douglas Gregora16548e2009-08-11 05:31:07 +00007734template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007735TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007736TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007737 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00007738 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007739 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00007740 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00007741 // FIXME: Bogus location information.
7742 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
7743 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007744 Sema::TemplateTy Template;
7745 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00007746 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007747 SS,
7748 Name,
John McCallba7bf592010-08-24 05:47:05 +00007749 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007750 /*EnteringContext=*/false,
7751 Template);
7752 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007753}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007754
Douglas Gregor71395fa2009-11-04 00:56:37 +00007755template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007756ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007757TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7758 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007759 Expr *OrigCallee,
7760 Expr *First,
7761 Expr *Second) {
7762 Expr *Callee = OrigCallee->IgnoreParenCasts();
7763 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007764
Douglas Gregora16548e2009-08-11 05:31:07 +00007765 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007766 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007767 if (!First->getType()->isOverloadableType() &&
7768 !Second->getType()->isOverloadableType())
7769 return getSema().CreateBuiltinArraySubscriptExpr(First,
7770 Callee->getLocStart(),
7771 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007772 } else if (Op == OO_Arrow) {
7773 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007774 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7775 } else if (Second == 0 || isPostIncDec) {
7776 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007777 // The argument is not of overloadable type, so try to create a
7778 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007779 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007780 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007781
John McCallb268a282010-08-23 23:25:46 +00007782 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007783 }
7784 } else {
John McCallb268a282010-08-23 23:25:46 +00007785 if (!First->getType()->isOverloadableType() &&
7786 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007787 // Neither of the arguments is an overloadable type, so try to
7788 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007789 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007790 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007791 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007792 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007793 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007794
Douglas Gregora16548e2009-08-11 05:31:07 +00007795 return move(Result);
7796 }
7797 }
Mike Stump11289f42009-09-09 15:08:12 +00007798
7799 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007800 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007801 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007802
John McCallb268a282010-08-23 23:25:46 +00007803 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007804 assert(ULE->requiresADL());
7805
7806 // FIXME: Do we have to check
7807 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007808 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007809 } else {
John McCallb268a282010-08-23 23:25:46 +00007810 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007811 }
Mike Stump11289f42009-09-09 15:08:12 +00007812
Douglas Gregora16548e2009-08-11 05:31:07 +00007813 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007814 Expr *Args[2] = { First, Second };
7815 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007816
Douglas Gregora16548e2009-08-11 05:31:07 +00007817 // Create the overloaded operator invocation for unary operators.
7818 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007819 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007820 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007821 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007822 }
Mike Stump11289f42009-09-09 15:08:12 +00007823
Sebastian Redladba46e2009-10-29 20:17:01 +00007824 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007825 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007826 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007827 First,
7828 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007829
Douglas Gregora16548e2009-08-11 05:31:07 +00007830 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007831 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007832 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007833 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7834 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007835 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007836
Mike Stump11289f42009-09-09 15:08:12 +00007837 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007838}
Mike Stump11289f42009-09-09 15:08:12 +00007839
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007840template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007841ExprResult
John McCallb268a282010-08-23 23:25:46 +00007842TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007843 SourceLocation OperatorLoc,
7844 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00007845 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007846 TypeSourceInfo *ScopeType,
7847 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007848 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007849 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00007850 QualType BaseType = Base->getType();
7851 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007852 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007853 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007854 !BaseType->getAs<PointerType>()->getPointeeType()
7855 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007856 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00007857 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007858 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007859 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007860 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007861 /*FIXME?*/true);
7862 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007863
Douglas Gregor678f90d2010-02-25 01:56:36 +00007864 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007865 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7866 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7867 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7868 NameInfo.setNamedTypeInfo(DestroyedType);
7869
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007870 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007871
John McCallb268a282010-08-23 23:25:46 +00007872 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007873 OperatorLoc, isArrow,
7874 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007875 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007876 /*TemplateArgs*/ 0);
7877}
7878
Douglas Gregord6ff3322009-08-04 16:50:30 +00007879} // end namespace clang
7880
7881#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H