blob: 1a5a98a23e650ef22c5b4747bea79b2359b052a4 [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) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001133 return getSema().BuildObjCExceptionDecl(TInfo, T,
1134 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001135 ExceptionDecl->getLocation());
1136 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001137
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001138 /// \brief Build a new Objective-C @catch statement.
1139 ///
1140 /// By default, performs semantic analysis to build the new statement.
1141 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001142 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001143 SourceLocation RParenLoc,
1144 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001145 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001146 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001147 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001148 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001149
Douglas Gregor306de2f2010-04-22 23:59:56 +00001150 /// \brief Build a new Objective-C @finally statement.
1151 ///
1152 /// By default, performs semantic analysis to build the new statement.
1153 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001154 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001155 Stmt *Body) {
1156 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001157 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001158
Douglas Gregor6148de72010-04-22 22:01:21 +00001159 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001160 ///
1161 /// By default, performs semantic analysis to build the new statement.
1162 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001163 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001164 Expr *Operand) {
1165 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001166 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001167
Douglas Gregor6148de72010-04-22 22:01:21 +00001168 /// \brief Build a new Objective-C @synchronized statement.
1169 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001170 /// By default, performs semantic analysis to build the new statement.
1171 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001172 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001173 Expr *Object,
1174 Stmt *Body) {
1175 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1176 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001177 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001178
1179 /// \brief Build a new Objective-C fast enumeration statement.
1180 ///
1181 /// By default, performs semantic analysis to build the new statement.
1182 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001183 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001184 SourceLocation LParenLoc,
1185 Stmt *Element,
1186 Expr *Collection,
1187 SourceLocation RParenLoc,
1188 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001189 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001190 Element,
1191 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001192 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001193 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001194 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001195
Douglas Gregorebe10102009-08-20 07:17:43 +00001196 /// \brief Build a new C++ exception declaration.
1197 ///
1198 /// By default, performs semantic analysis to build the new decaration.
1199 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001200 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001201 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +00001202 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001203 SourceLocation Loc) {
1204 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001205 }
1206
1207 /// \brief Build a new C++ catch statement.
1208 ///
1209 /// By default, performs semantic analysis to build the new statement.
1210 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001211 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001212 VarDecl *ExceptionDecl,
1213 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001214 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1215 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001216 }
Mike Stump11289f42009-09-09 15:08:12 +00001217
Douglas Gregorebe10102009-08-20 07:17:43 +00001218 /// \brief Build a new C++ try statement.
1219 ///
1220 /// By default, performs semantic analysis to build the new statement.
1221 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001222 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001223 Stmt *TryBlock,
1224 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001225 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001226 }
Mike Stump11289f42009-09-09 15:08:12 +00001227
Douglas Gregora16548e2009-08-11 05:31:07 +00001228 /// \brief Build a new expression that references a declaration.
1229 ///
1230 /// By default, performs semantic analysis to build the new expression.
1231 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001232 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001233 LookupResult &R,
1234 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001235 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1236 }
1237
1238
1239 /// \brief Build a new expression that references a declaration.
1240 ///
1241 /// By default, performs semantic analysis to build the new expression.
1242 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001243 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001244 ValueDecl *VD,
1245 const DeclarationNameInfo &NameInfo,
1246 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001247 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001248 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001249
1250 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001251
1252 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001253 }
Mike Stump11289f42009-09-09 15:08:12 +00001254
Douglas Gregora16548e2009-08-11 05:31:07 +00001255 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001256 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001257 /// By default, performs semantic analysis to build the new expression.
1258 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001259 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001260 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001261 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001262 }
1263
Douglas Gregorad8a3362009-09-04 17:36:40 +00001264 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001265 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001266 /// By default, performs semantic analysis to build the new expression.
1267 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001268 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001269 SourceLocation OperatorLoc,
1270 bool isArrow,
1271 CXXScopeSpec &SS,
1272 TypeSourceInfo *ScopeType,
1273 SourceLocation CCLoc,
1274 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001275 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001276
Douglas Gregora16548e2009-08-11 05:31:07 +00001277 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001278 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001279 /// By default, performs semantic analysis to build the new expression.
1280 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001281 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001282 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001283 Expr *SubExpr) {
1284 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001285 }
Mike Stump11289f42009-09-09 15:08:12 +00001286
Douglas Gregor882211c2010-04-28 22:16:22 +00001287 /// \brief Build a new builtin offsetof expression.
1288 ///
1289 /// By default, performs semantic analysis to build the new expression.
1290 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001291 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001292 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001293 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001294 unsigned NumComponents,
1295 SourceLocation RParenLoc) {
1296 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1297 NumComponents, RParenLoc);
1298 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001299
Douglas Gregora16548e2009-08-11 05:31:07 +00001300 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001301 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001302 /// By default, performs semantic analysis to build the new expression.
1303 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001304 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001305 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001306 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001307 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001308 }
1309
Mike Stump11289f42009-09-09 15:08:12 +00001310 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001311 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001312 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001313 /// By default, performs semantic analysis to build the new expression.
1314 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001315 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001316 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001317 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001318 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001320 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001321
Douglas Gregora16548e2009-08-11 05:31:07 +00001322 return move(Result);
1323 }
Mike Stump11289f42009-09-09 15:08:12 +00001324
Douglas Gregora16548e2009-08-11 05:31:07 +00001325 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001326 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001327 /// By default, performs semantic analysis to build the new expression.
1328 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001329 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001330 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001331 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001333 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1334 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001335 RBracketLoc);
1336 }
1337
1338 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001339 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001340 /// By default, performs semantic analysis to build the new expression.
1341 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001342 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001343 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001344 SourceLocation RParenLoc,
1345 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001346 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001347 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001348 }
1349
1350 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001351 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001352 /// By default, performs semantic analysis to build the new expression.
1353 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001354 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001355 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001356 NestedNameSpecifierLoc QualifierLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001357 const DeclarationNameInfo &MemberNameInfo,
1358 ValueDecl *Member,
1359 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001360 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001361 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001362 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001363 // We have a reference to an unnamed field. This is always the
1364 // base of an anonymous struct/union member access, i.e. the
1365 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001366 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001367 assert(Member->getType()->isRecordType() &&
1368 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001369
Douglas Gregorea972d32011-02-28 21:54:11 +00001370 if (getSema().PerformObjectMemberConversion(Base,
1371 QualifierLoc.getNestedNameSpecifier(),
John McCall16df1e52010-03-30 21:47:33 +00001372 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001373 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001374
John McCall7decc9e2010-11-18 06:31:45 +00001375 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001376 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001377 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001378 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001379 cast<FieldDecl>(Member)->getType(),
1380 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001381 return getSema().Owned(ME);
1382 }
Mike Stump11289f42009-09-09 15:08:12 +00001383
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001384 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001385 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001386
John McCallb268a282010-08-23 23:25:46 +00001387 getSema().DefaultFunctionArrayConversion(Base);
1388 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001389
John McCall16df1e52010-03-30 21:47:33 +00001390 // FIXME: this involves duplicating earlier analysis in a lot of
1391 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001392 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001393 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001394 R.resolveKind();
1395
John McCallb268a282010-08-23 23:25:46 +00001396 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001397 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001398 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001399 }
Mike Stump11289f42009-09-09 15:08:12 +00001400
Douglas Gregora16548e2009-08-11 05:31:07 +00001401 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001402 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001403 /// By default, performs semantic analysis to build the new expression.
1404 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001405 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001406 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001407 Expr *LHS, Expr *RHS) {
1408 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 }
1410
1411 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001412 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001413 /// By default, performs semantic analysis to build the new expression.
1414 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001415 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001416 SourceLocation QuestionLoc,
1417 Expr *LHS,
1418 SourceLocation ColonLoc,
1419 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001420 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1421 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001422 }
1423
Douglas Gregora16548e2009-08-11 05:31:07 +00001424 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001425 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001426 /// By default, performs semantic analysis to build the new expression.
1427 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001428 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001429 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001430 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001431 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001432 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001433 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001434 }
Mike Stump11289f42009-09-09 15:08:12 +00001435
Douglas Gregora16548e2009-08-11 05:31:07 +00001436 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001437 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001438 /// By default, performs semantic analysis to build the new expression.
1439 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001440 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001441 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001442 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001443 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001444 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001445 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001446 }
Mike Stump11289f42009-09-09 15:08:12 +00001447
Douglas Gregora16548e2009-08-11 05:31:07 +00001448 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001449 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001450 /// By default, performs semantic analysis to build the new expression.
1451 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001452 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001453 SourceLocation OpLoc,
1454 SourceLocation AccessorLoc,
1455 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001456
John McCall10eae182009-11-30 22:42:35 +00001457 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001458 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001459 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001460 OpLoc, /*IsArrow*/ false,
1461 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001462 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001463 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001464 }
Mike Stump11289f42009-09-09 15:08:12 +00001465
Douglas Gregora16548e2009-08-11 05:31:07 +00001466 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001467 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001468 /// By default, performs semantic analysis to build the new expression.
1469 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001470 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001471 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001472 SourceLocation RBraceLoc,
1473 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001474 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001475 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1476 if (Result.isInvalid() || ResultTy->isDependentType())
1477 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001478
Douglas Gregord3d93062009-11-09 17:16:50 +00001479 // Patch in the result type we were given, which may have been computed
1480 // when the initial InitListExpr was built.
1481 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1482 ILE->setType(ResultTy);
1483 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001484 }
Mike Stump11289f42009-09-09 15:08:12 +00001485
Douglas Gregora16548e2009-08-11 05:31:07 +00001486 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001487 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001488 /// By default, performs semantic analysis to build the new expression.
1489 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001490 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001491 MultiExprArg ArrayExprs,
1492 SourceLocation EqualOrColonLoc,
1493 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001494 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001495 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001496 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001497 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001498 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001499 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001500
Douglas Gregora16548e2009-08-11 05:31:07 +00001501 ArrayExprs.release();
1502 return move(Result);
1503 }
Mike Stump11289f42009-09-09 15:08:12 +00001504
Douglas Gregora16548e2009-08-11 05:31:07 +00001505 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001506 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001507 /// By default, builds the implicit value initialization without performing
1508 /// any semantic analysis. Subclasses may override this routine to provide
1509 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001510 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1512 }
Mike Stump11289f42009-09-09 15:08:12 +00001513
Douglas Gregora16548e2009-08-11 05:31:07 +00001514 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001515 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001516 /// By default, performs semantic analysis to build the new expression.
1517 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001518 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001519 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001520 SourceLocation RParenLoc) {
1521 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001522 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001523 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001524 }
1525
1526 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001527 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001528 /// By default, performs semantic analysis to build the new expression.
1529 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001530 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001531 MultiExprArg SubExprs,
1532 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001533 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001534 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001535 }
Mike Stump11289f42009-09-09 15:08:12 +00001536
Douglas Gregora16548e2009-08-11 05:31:07 +00001537 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001538 ///
1539 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001540 /// rather than attempting to map the label statement itself.
1541 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001542 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001543 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001544 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001545 }
Mike Stump11289f42009-09-09 15:08:12 +00001546
Douglas Gregora16548e2009-08-11 05:31:07 +00001547 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001548 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001549 /// By default, performs semantic analysis to build the new expression.
1550 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001551 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001552 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001553 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001554 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001555 }
Mike Stump11289f42009-09-09 15:08:12 +00001556
Douglas Gregora16548e2009-08-11 05:31:07 +00001557 /// \brief Build a new __builtin_choose_expr expression.
1558 ///
1559 /// By default, performs semantic analysis to build the new expression.
1560 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001561 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001562 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001563 SourceLocation RParenLoc) {
1564 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001565 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001566 RParenLoc);
1567 }
Mike Stump11289f42009-09-09 15:08:12 +00001568
Douglas Gregora16548e2009-08-11 05:31:07 +00001569 /// \brief Build a new overloaded operator call expression.
1570 ///
1571 /// By default, performs semantic analysis to build the new expression.
1572 /// The semantic analysis provides the behavior of template instantiation,
1573 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001574 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001575 /// argument-dependent lookup, etc. Subclasses may override this routine to
1576 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001577 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001578 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001579 Expr *Callee,
1580 Expr *First,
1581 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001582
1583 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001584 /// reinterpret_cast.
1585 ///
1586 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001587 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001588 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001589 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001590 Stmt::StmtClass Class,
1591 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001592 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001593 SourceLocation RAngleLoc,
1594 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001595 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001596 SourceLocation RParenLoc) {
1597 switch (Class) {
1598 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001599 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001600 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001601 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001602
1603 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001604 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001605 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001606 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001607
Douglas Gregora16548e2009-08-11 05:31:07 +00001608 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001609 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001610 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001611 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001612 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001613
Douglas Gregora16548e2009-08-11 05:31:07 +00001614 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001615 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001616 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001617 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001618
Douglas Gregora16548e2009-08-11 05:31:07 +00001619 default:
1620 assert(false && "Invalid C++ named cast");
1621 break;
1622 }
Mike Stump11289f42009-09-09 15:08:12 +00001623
John McCallfaf5fb42010-08-26 23:41:50 +00001624 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001625 }
Mike Stump11289f42009-09-09 15:08:12 +00001626
Douglas Gregora16548e2009-08-11 05:31:07 +00001627 /// \brief Build a new C++ static_cast expression.
1628 ///
1629 /// By default, performs semantic analysis to build the new expression.
1630 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001631 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001633 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001634 SourceLocation RAngleLoc,
1635 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001636 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001637 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001638 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001639 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001640 SourceRange(LAngleLoc, RAngleLoc),
1641 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001642 }
1643
1644 /// \brief Build a new C++ dynamic_cast expression.
1645 ///
1646 /// By default, performs semantic analysis to build the new expression.
1647 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001648 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001649 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001650 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001651 SourceLocation RAngleLoc,
1652 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001653 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001654 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001655 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001656 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001657 SourceRange(LAngleLoc, RAngleLoc),
1658 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001659 }
1660
1661 /// \brief Build a new C++ reinterpret_cast expression.
1662 ///
1663 /// By default, performs semantic analysis to build the new expression.
1664 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001665 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001666 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001667 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001668 SourceLocation RAngleLoc,
1669 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001670 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001671 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001672 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001673 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001674 SourceRange(LAngleLoc, RAngleLoc),
1675 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001676 }
1677
1678 /// \brief Build a new C++ const_cast expression.
1679 ///
1680 /// By default, performs semantic analysis to build the new expression.
1681 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001682 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001683 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001684 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001685 SourceLocation RAngleLoc,
1686 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001687 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001688 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001689 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001690 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001691 SourceRange(LAngleLoc, RAngleLoc),
1692 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001693 }
Mike Stump11289f42009-09-09 15:08:12 +00001694
Douglas Gregora16548e2009-08-11 05:31:07 +00001695 /// \brief Build a new C++ functional-style cast expression.
1696 ///
1697 /// By default, performs semantic analysis to build the new expression.
1698 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001699 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1700 SourceLocation LParenLoc,
1701 Expr *Sub,
1702 SourceLocation RParenLoc) {
1703 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001704 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001705 RParenLoc);
1706 }
Mike Stump11289f42009-09-09 15:08:12 +00001707
Douglas Gregora16548e2009-08-11 05:31:07 +00001708 /// \brief Build a new C++ typeid(type) expression.
1709 ///
1710 /// By default, performs semantic analysis to build the new expression.
1711 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001712 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001713 SourceLocation TypeidLoc,
1714 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001715 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001716 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001717 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001718 }
Mike Stump11289f42009-09-09 15:08:12 +00001719
Francois Pichet9f4f2072010-09-08 12:20:18 +00001720
Douglas Gregora16548e2009-08-11 05:31:07 +00001721 /// \brief Build a new C++ typeid(expr) expression.
1722 ///
1723 /// By default, performs semantic analysis to build the new expression.
1724 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001725 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001726 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001727 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001728 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001729 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001730 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001731 }
1732
Francois Pichet9f4f2072010-09-08 12:20:18 +00001733 /// \brief Build a new C++ __uuidof(type) expression.
1734 ///
1735 /// By default, performs semantic analysis to build the new expression.
1736 /// Subclasses may override this routine to provide different behavior.
1737 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1738 SourceLocation TypeidLoc,
1739 TypeSourceInfo *Operand,
1740 SourceLocation RParenLoc) {
1741 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1742 RParenLoc);
1743 }
1744
1745 /// \brief Build a new C++ __uuidof(expr) expression.
1746 ///
1747 /// By default, performs semantic analysis to build the new expression.
1748 /// Subclasses may override this routine to provide different behavior.
1749 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1750 SourceLocation TypeidLoc,
1751 Expr *Operand,
1752 SourceLocation RParenLoc) {
1753 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1754 RParenLoc);
1755 }
1756
Douglas Gregora16548e2009-08-11 05:31:07 +00001757 /// \brief Build a new C++ "this" expression.
1758 ///
1759 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001760 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001761 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001762 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001763 QualType ThisType,
1764 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001765 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001766 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1767 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001768 }
1769
1770 /// \brief Build a new C++ throw expression.
1771 ///
1772 /// By default, performs semantic analysis to build the new expression.
1773 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001774 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001775 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001776 }
1777
1778 /// \brief Build a new C++ default-argument expression.
1779 ///
1780 /// By default, builds a new default-argument expression, which does not
1781 /// require any semantic analysis. Subclasses may override this routine to
1782 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001783 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001784 ParmVarDecl *Param) {
1785 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1786 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001787 }
1788
1789 /// \brief Build a new C++ zero-initialization expression.
1790 ///
1791 /// By default, performs semantic analysis to build the new expression.
1792 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001793 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1794 SourceLocation LParenLoc,
1795 SourceLocation RParenLoc) {
1796 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001797 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001798 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001799 }
Mike Stump11289f42009-09-09 15:08:12 +00001800
Douglas Gregora16548e2009-08-11 05:31:07 +00001801 /// \brief Build a new C++ "new" expression.
1802 ///
1803 /// By default, performs semantic analysis to build the new expression.
1804 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001805 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001806 bool UseGlobal,
1807 SourceLocation PlacementLParen,
1808 MultiExprArg PlacementArgs,
1809 SourceLocation PlacementRParen,
1810 SourceRange TypeIdParens,
1811 QualType AllocatedType,
1812 TypeSourceInfo *AllocatedTypeInfo,
1813 Expr *ArraySize,
1814 SourceLocation ConstructorLParen,
1815 MultiExprArg ConstructorArgs,
1816 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001817 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001818 PlacementLParen,
1819 move(PlacementArgs),
1820 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001821 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001822 AllocatedType,
1823 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001824 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001825 ConstructorLParen,
1826 move(ConstructorArgs),
1827 ConstructorRParen);
1828 }
Mike Stump11289f42009-09-09 15:08:12 +00001829
Douglas Gregora16548e2009-08-11 05:31:07 +00001830 /// \brief Build a new C++ "delete" expression.
1831 ///
1832 /// By default, performs semantic analysis to build the new expression.
1833 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001834 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001835 bool IsGlobalDelete,
1836 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001837 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001838 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001839 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001840 }
Mike Stump11289f42009-09-09 15:08:12 +00001841
Douglas Gregora16548e2009-08-11 05:31:07 +00001842 /// \brief Build a new unary type trait expression.
1843 ///
1844 /// By default, performs semantic analysis to build the new expression.
1845 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001846 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001847 SourceLocation StartLoc,
1848 TypeSourceInfo *T,
1849 SourceLocation RParenLoc) {
1850 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001851 }
1852
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001853 /// \brief Build a new binary type trait expression.
1854 ///
1855 /// By default, performs semantic analysis to build the new expression.
1856 /// Subclasses may override this routine to provide different behavior.
1857 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1858 SourceLocation StartLoc,
1859 TypeSourceInfo *LhsT,
1860 TypeSourceInfo *RhsT,
1861 SourceLocation RParenLoc) {
1862 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1863 }
1864
Mike Stump11289f42009-09-09 15:08:12 +00001865 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001866 /// expression.
1867 ///
1868 /// By default, performs semantic analysis to build the new expression.
1869 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001870 ExprResult RebuildDependentScopeDeclRefExpr(
1871 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001872 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001873 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001874 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001875 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00001876
1877 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001878 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001879 *TemplateArgs);
1880
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001881 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001882 }
1883
1884 /// \brief Build a new template-id expression.
1885 ///
1886 /// By default, performs semantic analysis to build the new expression.
1887 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001888 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001889 LookupResult &R,
1890 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001891 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001892 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001893 }
1894
1895 /// \brief Build a new object-construction expression.
1896 ///
1897 /// By default, performs semantic analysis to build the new expression.
1898 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001899 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001900 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001901 CXXConstructorDecl *Constructor,
1902 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001903 MultiExprArg Args,
1904 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001905 CXXConstructExpr::ConstructionKind ConstructKind,
1906 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001907 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001908 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001909 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001910 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001911
Douglas Gregordb121ba2009-12-14 16:27:04 +00001912 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001913 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001914 RequiresZeroInit, ConstructKind,
1915 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001916 }
1917
1918 /// \brief Build a new object-construction expression.
1919 ///
1920 /// By default, performs semantic analysis to build the new expression.
1921 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001922 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1923 SourceLocation LParenLoc,
1924 MultiExprArg Args,
1925 SourceLocation RParenLoc) {
1926 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 LParenLoc,
1928 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001929 RParenLoc);
1930 }
1931
1932 /// \brief Build a new object-construction expression.
1933 ///
1934 /// By default, performs semantic analysis to build the new expression.
1935 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001936 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1937 SourceLocation LParenLoc,
1938 MultiExprArg Args,
1939 SourceLocation RParenLoc) {
1940 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 LParenLoc,
1942 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 RParenLoc);
1944 }
Mike Stump11289f42009-09-09 15:08:12 +00001945
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 /// \brief Build a new member reference expression.
1947 ///
1948 /// By default, performs semantic analysis to build the new expression.
1949 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001950 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00001951 QualType BaseType,
1952 bool IsArrow,
1953 SourceLocation OperatorLoc,
1954 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00001955 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001956 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001957 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001958 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00001959 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001960
John McCallb268a282010-08-23 23:25:46 +00001961 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001962 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001963 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001964 MemberNameInfo,
1965 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001966 }
1967
John McCall10eae182009-11-30 22:42:35 +00001968 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001969 ///
1970 /// By default, performs semantic analysis to build the new expression.
1971 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001972 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001973 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001974 SourceLocation OperatorLoc,
1975 bool IsArrow,
Douglas Gregor0da1d432011-02-28 20:01:57 +00001976 NestedNameSpecifierLoc QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00001977 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001978 LookupResult &R,
1979 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001980 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00001981 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001982
John McCallb268a282010-08-23 23:25:46 +00001983 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001984 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001985 SS, FirstQualifierInScope,
1986 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001987 }
Mike Stump11289f42009-09-09 15:08:12 +00001988
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001989 /// \brief Build a new noexcept expression.
1990 ///
1991 /// By default, performs semantic analysis to build the new expression.
1992 /// Subclasses may override this routine to provide different behavior.
1993 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1994 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1995 }
1996
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001997 /// \brief Build a new expression to compute the length of a parameter pack.
1998 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
1999 SourceLocation PackLoc,
2000 SourceLocation RParenLoc,
2001 unsigned Length) {
2002 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2003 OperatorLoc, Pack, PackLoc,
2004 RParenLoc, Length);
2005 }
2006
Douglas Gregora16548e2009-08-11 05:31:07 +00002007 /// \brief Build a new Objective-C @encode expression.
2008 ///
2009 /// By default, performs semantic analysis to build the new expression.
2010 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002011 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002012 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002013 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002014 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002015 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002016 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002017
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002018 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002019 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002020 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002021 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002022 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002023 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002024 MultiExprArg Args,
2025 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002026 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2027 ReceiverTypeInfo->getType(),
2028 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002029 Sel, Method, LBracLoc, SelectorLoc,
2030 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002031 }
2032
2033 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002034 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002035 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002036 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002037 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002038 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002039 MultiExprArg Args,
2040 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002041 return SemaRef.BuildInstanceMessage(Receiver,
2042 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002043 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002044 Sel, Method, LBracLoc, SelectorLoc,
2045 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002046 }
2047
Douglas Gregord51d90d2010-04-26 20:11:03 +00002048 /// \brief Build a new Objective-C ivar reference expression.
2049 ///
2050 /// By default, performs semantic analysis to build the new expression.
2051 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002052 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002053 SourceLocation IvarLoc,
2054 bool IsArrow, bool IsFreeIvar) {
2055 // FIXME: We lose track of the IsFreeIvar bit.
2056 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002057 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002058 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2059 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002060 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002061 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002062 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002063 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002064 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002065 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002066
Douglas Gregord51d90d2010-04-26 20:11:03 +00002067 if (Result.get())
2068 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002069
John McCallb268a282010-08-23 23:25:46 +00002070 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002071 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002072 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002073 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002074 /*TemplateArgs=*/0);
2075 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002076
2077 /// \brief Build a new Objective-C property reference expression.
2078 ///
2079 /// By default, performs semantic analysis to build the new expression.
2080 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002081 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002082 ObjCPropertyDecl *Property,
2083 SourceLocation PropertyLoc) {
2084 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002085 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00002086 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2087 Sema::LookupMemberName);
2088 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002089 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002090 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002091 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00002092 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002093 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002094
Douglas Gregor9faee212010-04-26 20:47:02 +00002095 if (Result.get())
2096 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002097
John McCallb268a282010-08-23 23:25:46 +00002098 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002099 /*FIXME:*/PropertyLoc, IsArrow,
2100 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002101 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002102 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002103 /*TemplateArgs=*/0);
2104 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002105
John McCallb7bd14f2010-12-02 01:19:52 +00002106 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002107 ///
2108 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002109 /// Subclasses may override this routine to provide different behavior.
2110 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2111 ObjCMethodDecl *Getter,
2112 ObjCMethodDecl *Setter,
2113 SourceLocation PropertyLoc) {
2114 // Since these expressions can only be value-dependent, we do not
2115 // need to perform semantic analysis again.
2116 return Owned(
2117 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2118 VK_LValue, OK_ObjCProperty,
2119 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002120 }
2121
Douglas Gregord51d90d2010-04-26 20:11:03 +00002122 /// \brief Build a new Objective-C "isa" expression.
2123 ///
2124 /// By default, performs semantic analysis to build the new expression.
2125 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002126 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002127 bool IsArrow) {
2128 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002129 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002130 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2131 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002132 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002133 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002134 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002135 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002136 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002137
Douglas Gregord51d90d2010-04-26 20:11:03 +00002138 if (Result.get())
2139 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002140
John McCallb268a282010-08-23 23:25:46 +00002141 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002142 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002143 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002144 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002145 /*TemplateArgs=*/0);
2146 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002147
Douglas Gregora16548e2009-08-11 05:31:07 +00002148 /// \brief Build a new shuffle vector expression.
2149 ///
2150 /// By default, performs semantic analysis to build the new expression.
2151 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002152 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002153 MultiExprArg SubExprs,
2154 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002155 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002156 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002157 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2158 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2159 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2160 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002161
Douglas Gregora16548e2009-08-11 05:31:07 +00002162 // Build a reference to the __builtin_shufflevector builtin
2163 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00002164 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00002165 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00002166 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002167 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002168
2169 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002170 unsigned NumSubExprs = SubExprs.size();
2171 Expr **Subs = (Expr **)SubExprs.release();
2172 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2173 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002174 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002175 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002176 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002177 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002178
Douglas Gregora16548e2009-08-11 05:31:07 +00002179 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002180 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002181 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002182 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002183
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002185 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002186 }
John McCall31f82722010-11-12 08:19:04 +00002187
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002188 /// \brief Build a new template argument pack expansion.
2189 ///
2190 /// By default, performs semantic analysis to build a new pack expansion
2191 /// for a template argument. Subclasses may override this routine to provide
2192 /// different behavior.
2193 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002194 SourceLocation EllipsisLoc,
2195 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002196 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002197 case TemplateArgument::Expression: {
2198 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002199 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2200 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002201 if (Result.isInvalid())
2202 return TemplateArgumentLoc();
2203
2204 return TemplateArgumentLoc(Result.get(), Result.get());
2205 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002206
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002207 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002208 return TemplateArgumentLoc(TemplateArgument(
2209 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002210 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002211 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002212 Pattern.getTemplateNameLoc(),
2213 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002214
2215 case TemplateArgument::Null:
2216 case TemplateArgument::Integral:
2217 case TemplateArgument::Declaration:
2218 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002219 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002220 llvm_unreachable("Pack expansion pattern has no parameter packs");
2221
2222 case TemplateArgument::Type:
2223 if (TypeSourceInfo *Expansion
2224 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002225 EllipsisLoc,
2226 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002227 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2228 Expansion);
2229 break;
2230 }
2231
2232 return TemplateArgumentLoc();
2233 }
2234
Douglas Gregor968f23a2011-01-03 19:31:53 +00002235 /// \brief Build a new expression pack expansion.
2236 ///
2237 /// By default, performs semantic analysis to build a new pack expansion
2238 /// for an expression. Subclasses may override this routine to provide
2239 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002240 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2241 llvm::Optional<unsigned> NumExpansions) {
2242 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002243 }
2244
John McCall31f82722010-11-12 08:19:04 +00002245private:
Douglas Gregor14454802011-02-25 02:25:35 +00002246 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2247 QualType ObjectType,
2248 NamedDecl *FirstQualifierInScope,
2249 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002250
2251 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2252 QualType ObjectType,
2253 NamedDecl *FirstQualifierInScope,
2254 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002255};
Douglas Gregora16548e2009-08-11 05:31:07 +00002256
Douglas Gregorebe10102009-08-20 07:17:43 +00002257template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002258StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002259 if (!S)
2260 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002261
Douglas Gregorebe10102009-08-20 07:17:43 +00002262 switch (S->getStmtClass()) {
2263 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002264
Douglas Gregorebe10102009-08-20 07:17:43 +00002265 // Transform individual statement nodes
2266#define STMT(Node, Parent) \
2267 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002268#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002269#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002270#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002271
Douglas Gregorebe10102009-08-20 07:17:43 +00002272 // Transform expressions by calling TransformExpr.
2273#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002274#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002275#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002276#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002277 {
John McCalldadc5752010-08-24 06:29:42 +00002278 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002279 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002280 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002281
John McCallb268a282010-08-23 23:25:46 +00002282 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002283 }
Mike Stump11289f42009-09-09 15:08:12 +00002284 }
2285
John McCallc3007a22010-10-26 07:05:15 +00002286 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002287}
Mike Stump11289f42009-09-09 15:08:12 +00002288
2289
Douglas Gregore922c772009-08-04 22:27:00 +00002290template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002291ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002292 if (!E)
2293 return SemaRef.Owned(E);
2294
2295 switch (E->getStmtClass()) {
2296 case Stmt::NoStmtClass: break;
2297#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002298#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002299#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002300 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002301#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002302 }
2303
John McCallc3007a22010-10-26 07:05:15 +00002304 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002305}
2306
2307template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002308bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2309 unsigned NumInputs,
2310 bool IsCall,
2311 llvm::SmallVectorImpl<Expr *> &Outputs,
2312 bool *ArgChanged) {
2313 for (unsigned I = 0; I != NumInputs; ++I) {
2314 // If requested, drop call arguments that need to be dropped.
2315 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2316 if (ArgChanged)
2317 *ArgChanged = true;
2318
2319 break;
2320 }
2321
Douglas Gregor968f23a2011-01-03 19:31:53 +00002322 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2323 Expr *Pattern = Expansion->getPattern();
2324
2325 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2326 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2327 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2328
2329 // Determine whether the set of unexpanded parameter packs can and should
2330 // be expanded.
2331 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002332 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002333 llvm::Optional<unsigned> OrigNumExpansions
2334 = Expansion->getNumExpansions();
2335 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002336 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2337 Pattern->getSourceRange(),
2338 Unexpanded.data(),
2339 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002340 Expand, RetainExpansion,
2341 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002342 return true;
2343
2344 if (!Expand) {
2345 // The transform has determined that we should perform a simple
2346 // transformation on the pack expansion, producing another pack
2347 // expansion.
2348 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2349 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2350 if (OutPattern.isInvalid())
2351 return true;
2352
2353 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002354 Expansion->getEllipsisLoc(),
2355 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002356 if (Out.isInvalid())
2357 return true;
2358
2359 if (ArgChanged)
2360 *ArgChanged = true;
2361 Outputs.push_back(Out.get());
2362 continue;
2363 }
2364
2365 // The transform has determined that we should perform an elementwise
2366 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002367 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002368 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2369 ExprResult Out = getDerived().TransformExpr(Pattern);
2370 if (Out.isInvalid())
2371 return true;
2372
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002373 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002374 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2375 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002376 if (Out.isInvalid())
2377 return true;
2378 }
2379
Douglas Gregor968f23a2011-01-03 19:31:53 +00002380 if (ArgChanged)
2381 *ArgChanged = true;
2382 Outputs.push_back(Out.get());
2383 }
2384
2385 continue;
2386 }
2387
Douglas Gregora3efea12011-01-03 19:04:46 +00002388 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2389 if (Result.isInvalid())
2390 return true;
2391
2392 if (Result.get() != Inputs[I] && ArgChanged)
2393 *ArgChanged = true;
2394
2395 Outputs.push_back(Result.get());
2396 }
2397
2398 return false;
2399}
2400
2401template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002402NestedNameSpecifierLoc
2403TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2404 NestedNameSpecifierLoc NNS,
2405 QualType ObjectType,
2406 NamedDecl *FirstQualifierInScope) {
2407 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2408 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2409 Qualifier = Qualifier.getPrefix())
2410 Qualifiers.push_back(Qualifier);
2411
2412 CXXScopeSpec SS;
2413 while (!Qualifiers.empty()) {
2414 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2415 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2416
2417 switch (QNNS->getKind()) {
2418 case NestedNameSpecifier::Identifier:
2419 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2420 *QNNS->getAsIdentifier(),
2421 Q.getLocalBeginLoc(),
2422 Q.getLocalEndLoc(),
2423 ObjectType, false, SS,
2424 FirstQualifierInScope, false))
2425 return NestedNameSpecifierLoc();
2426
2427 break;
2428
2429 case NestedNameSpecifier::Namespace: {
2430 NamespaceDecl *NS
2431 = cast_or_null<NamespaceDecl>(
2432 getDerived().TransformDecl(
2433 Q.getLocalBeginLoc(),
2434 QNNS->getAsNamespace()));
2435 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2436 break;
2437 }
2438
2439 case NestedNameSpecifier::NamespaceAlias: {
2440 NamespaceAliasDecl *Alias
2441 = cast_or_null<NamespaceAliasDecl>(
2442 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2443 QNNS->getAsNamespaceAlias()));
2444 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2445 Q.getLocalEndLoc());
2446 break;
2447 }
2448
2449 case NestedNameSpecifier::Global:
2450 // There is no meaningful transformation that one could perform on the
2451 // global scope.
2452 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2453 break;
2454
2455 case NestedNameSpecifier::TypeSpecWithTemplate:
2456 case NestedNameSpecifier::TypeSpec: {
2457 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2458 FirstQualifierInScope, SS);
2459
2460 if (!TL)
2461 return NestedNameSpecifierLoc();
2462
2463 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2464 (SemaRef.getLangOptions().CPlusPlus0x &&
2465 TL.getType()->isEnumeralType())) {
2466 assert(!TL.getType().hasLocalQualifiers() &&
2467 "Can't get cv-qualifiers here");
2468 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2469 Q.getLocalEndLoc());
2470 break;
2471 }
2472
2473 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2474 << TL.getType() << SS.getRange();
2475 return NestedNameSpecifierLoc();
2476 }
Douglas Gregore16af532011-02-28 18:50:33 +00002477 }
Douglas Gregor14454802011-02-25 02:25:35 +00002478
Douglas Gregore16af532011-02-28 18:50:33 +00002479 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002480 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002481 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002482 }
2483
2484 // Don't rebuild the nested-name-specifier if we don't have to.
2485 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2486 !getDerived().AlwaysRebuild())
2487 return NNS;
2488
2489 // If we can re-use the source-location data from the original
2490 // nested-name-specifier, do so.
2491 if (SS.location_size() == NNS.getDataLength() &&
2492 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2493 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2494
2495 // Allocate new nested-name-specifier location information.
2496 return SS.getWithLocInContext(SemaRef.Context);
2497}
2498
2499template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002500DeclarationNameInfo
2501TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002502::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002503 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002504 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002505 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002506
2507 switch (Name.getNameKind()) {
2508 case DeclarationName::Identifier:
2509 case DeclarationName::ObjCZeroArgSelector:
2510 case DeclarationName::ObjCOneArgSelector:
2511 case DeclarationName::ObjCMultiArgSelector:
2512 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002513 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002514 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002515 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002516
Douglas Gregorf816bd72009-09-03 22:13:48 +00002517 case DeclarationName::CXXConstructorName:
2518 case DeclarationName::CXXDestructorName:
2519 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002520 TypeSourceInfo *NewTInfo;
2521 CanQualType NewCanTy;
2522 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002523 NewTInfo = getDerived().TransformType(OldTInfo);
2524 if (!NewTInfo)
2525 return DeclarationNameInfo();
2526 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002527 }
2528 else {
2529 NewTInfo = 0;
2530 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002531 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002532 if (NewT.isNull())
2533 return DeclarationNameInfo();
2534 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2535 }
Mike Stump11289f42009-09-09 15:08:12 +00002536
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002537 DeclarationName NewName
2538 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2539 NewCanTy);
2540 DeclarationNameInfo NewNameInfo(NameInfo);
2541 NewNameInfo.setName(NewName);
2542 NewNameInfo.setNamedTypeInfo(NewTInfo);
2543 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002544 }
Mike Stump11289f42009-09-09 15:08:12 +00002545 }
2546
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002547 assert(0 && "Unknown name kind.");
2548 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002549}
2550
2551template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002552TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00002553TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2554 TemplateName Name,
2555 SourceLocation NameLoc,
2556 QualType ObjectType,
2557 NamedDecl *FirstQualifierInScope) {
2558 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2559 TemplateDecl *Template = QTN->getTemplateDecl();
2560 assert(Template && "qualified template name must refer to a template");
2561
2562 TemplateDecl *TransTemplate
2563 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2564 Template));
2565 if (!TransTemplate)
2566 return TemplateName();
2567
2568 if (!getDerived().AlwaysRebuild() &&
2569 SS.getScopeRep() == QTN->getQualifier() &&
2570 TransTemplate == Template)
2571 return Name;
2572
2573 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2574 TransTemplate);
2575 }
2576
2577 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2578 if (SS.getScopeRep()) {
2579 // These apply to the scope specifier, not the template.
2580 ObjectType = QualType();
2581 FirstQualifierInScope = 0;
2582 }
2583
2584 if (!getDerived().AlwaysRebuild() &&
2585 SS.getScopeRep() == DTN->getQualifier() &&
2586 ObjectType.isNull())
2587 return Name;
2588
2589 if (DTN->isIdentifier()) {
2590 return getDerived().RebuildTemplateName(SS,
2591 *DTN->getIdentifier(),
2592 NameLoc,
2593 ObjectType,
2594 FirstQualifierInScope);
2595 }
2596
2597 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2598 ObjectType);
2599 }
2600
2601 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2602 TemplateDecl *TransTemplate
2603 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2604 Template));
2605 if (!TransTemplate)
2606 return TemplateName();
2607
2608 if (!getDerived().AlwaysRebuild() &&
2609 TransTemplate == Template)
2610 return Name;
2611
2612 return TemplateName(TransTemplate);
2613 }
2614
2615 if (SubstTemplateTemplateParmPackStorage *SubstPack
2616 = Name.getAsSubstTemplateTemplateParmPack()) {
2617 TemplateTemplateParmDecl *TransParam
2618 = cast_or_null<TemplateTemplateParmDecl>(
2619 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2620 if (!TransParam)
2621 return TemplateName();
2622
2623 if (!getDerived().AlwaysRebuild() &&
2624 TransParam == SubstPack->getParameterPack())
2625 return Name;
2626
2627 return getDerived().RebuildTemplateName(TransParam,
2628 SubstPack->getArgumentPack());
2629 }
2630
2631 // These should be getting filtered out before they reach the AST.
2632 llvm_unreachable("overloaded function decl survived to here");
2633 return TemplateName();
2634}
2635
2636template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002637void TreeTransform<Derived>::InventTemplateArgumentLoc(
2638 const TemplateArgument &Arg,
2639 TemplateArgumentLoc &Output) {
2640 SourceLocation Loc = getDerived().getBaseLocation();
2641 switch (Arg.getKind()) {
2642 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002643 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002644 break;
2645
2646 case TemplateArgument::Type:
2647 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002648 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002649
John McCall0ad16662009-10-29 08:12:44 +00002650 break;
2651
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002652 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00002653 case TemplateArgument::TemplateExpansion: {
2654 NestedNameSpecifierLocBuilder Builder;
2655 TemplateName Template = Arg.getAsTemplate();
2656 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2657 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2658 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2659 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2660
2661 if (Arg.getKind() == TemplateArgument::Template)
2662 Output = TemplateArgumentLoc(Arg,
2663 Builder.getWithLocInContext(SemaRef.Context),
2664 Loc);
2665 else
2666 Output = TemplateArgumentLoc(Arg,
2667 Builder.getWithLocInContext(SemaRef.Context),
2668 Loc, Loc);
2669
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002670 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00002671 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002672
John McCall0ad16662009-10-29 08:12:44 +00002673 case TemplateArgument::Expression:
2674 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2675 break;
2676
2677 case TemplateArgument::Declaration:
2678 case TemplateArgument::Integral:
2679 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002680 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002681 break;
2682 }
2683}
2684
2685template<typename Derived>
2686bool TreeTransform<Derived>::TransformTemplateArgument(
2687 const TemplateArgumentLoc &Input,
2688 TemplateArgumentLoc &Output) {
2689 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002690 switch (Arg.getKind()) {
2691 case TemplateArgument::Null:
2692 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002693 Output = Input;
2694 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002695
Douglas Gregore922c772009-08-04 22:27:00 +00002696 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002697 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002698 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002699 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002700
2701 DI = getDerived().TransformType(DI);
2702 if (!DI) return true;
2703
2704 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2705 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002706 }
Mike Stump11289f42009-09-09 15:08:12 +00002707
Douglas Gregore922c772009-08-04 22:27:00 +00002708 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002709 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002710 DeclarationName Name;
2711 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2712 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002713 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002714 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002715 if (!D) return true;
2716
John McCall0d07eb32009-10-29 18:45:58 +00002717 Expr *SourceExpr = Input.getSourceDeclExpression();
2718 if (SourceExpr) {
2719 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002720 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002721 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002722 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002723 }
2724
2725 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002726 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002727 }
Mike Stump11289f42009-09-09 15:08:12 +00002728
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002729 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00002730 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2731 if (QualifierLoc) {
2732 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2733 if (!QualifierLoc)
2734 return true;
2735 }
2736
Douglas Gregordf846d12011-03-02 18:46:51 +00002737 CXXScopeSpec SS;
2738 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002739 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00002740 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2741 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002742 if (Template.isNull())
2743 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002744
Douglas Gregor9d802122011-03-02 17:09:35 +00002745 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002746 Input.getTemplateNameLoc());
2747 return false;
2748 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002749
2750 case TemplateArgument::TemplateExpansion:
2751 llvm_unreachable("Caller should expand pack expansions");
2752
Douglas Gregore922c772009-08-04 22:27:00 +00002753 case TemplateArgument::Expression: {
2754 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002755 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002756 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002757
John McCall0ad16662009-10-29 08:12:44 +00002758 Expr *InputExpr = Input.getSourceExpression();
2759 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2760
John McCalldadc5752010-08-24 06:29:42 +00002761 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002762 = getDerived().TransformExpr(InputExpr);
2763 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002764 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002765 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002766 }
Mike Stump11289f42009-09-09 15:08:12 +00002767
Douglas Gregore922c772009-08-04 22:27:00 +00002768 case TemplateArgument::Pack: {
2769 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2770 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002771 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002772 AEnd = Arg.pack_end();
2773 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002774
John McCall0ad16662009-10-29 08:12:44 +00002775 // FIXME: preserve source information here when we start
2776 // caring about parameter packs.
2777
John McCall0d07eb32009-10-29 18:45:58 +00002778 TemplateArgumentLoc InputArg;
2779 TemplateArgumentLoc OutputArg;
2780 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2781 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002782 return true;
2783
John McCall0d07eb32009-10-29 18:45:58 +00002784 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002785 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002786
2787 TemplateArgument *TransformedArgsPtr
2788 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2789 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2790 TransformedArgsPtr);
2791 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2792 TransformedArgs.size()),
2793 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002794 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002795 }
2796 }
Mike Stump11289f42009-09-09 15:08:12 +00002797
Douglas Gregore922c772009-08-04 22:27:00 +00002798 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002799 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002800}
2801
Douglas Gregorfe921a72010-12-20 23:36:19 +00002802/// \brief Iterator adaptor that invents template argument location information
2803/// for each of the template arguments in its underlying iterator.
2804template<typename Derived, typename InputIterator>
2805class TemplateArgumentLocInventIterator {
2806 TreeTransform<Derived> &Self;
2807 InputIterator Iter;
2808
2809public:
2810 typedef TemplateArgumentLoc value_type;
2811 typedef TemplateArgumentLoc reference;
2812 typedef typename std::iterator_traits<InputIterator>::difference_type
2813 difference_type;
2814 typedef std::input_iterator_tag iterator_category;
2815
2816 class pointer {
2817 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002818
Douglas Gregorfe921a72010-12-20 23:36:19 +00002819 public:
2820 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2821
2822 const TemplateArgumentLoc *operator->() const { return &Arg; }
2823 };
2824
2825 TemplateArgumentLocInventIterator() { }
2826
2827 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2828 InputIterator Iter)
2829 : Self(Self), Iter(Iter) { }
2830
2831 TemplateArgumentLocInventIterator &operator++() {
2832 ++Iter;
2833 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002834 }
2835
Douglas Gregorfe921a72010-12-20 23:36:19 +00002836 TemplateArgumentLocInventIterator operator++(int) {
2837 TemplateArgumentLocInventIterator Old(*this);
2838 ++(*this);
2839 return Old;
2840 }
2841
2842 reference operator*() const {
2843 TemplateArgumentLoc Result;
2844 Self.InventTemplateArgumentLoc(*Iter, Result);
2845 return Result;
2846 }
2847
2848 pointer operator->() const { return pointer(**this); }
2849
2850 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2851 const TemplateArgumentLocInventIterator &Y) {
2852 return X.Iter == Y.Iter;
2853 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002854
Douglas Gregorfe921a72010-12-20 23:36:19 +00002855 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2856 const TemplateArgumentLocInventIterator &Y) {
2857 return X.Iter != Y.Iter;
2858 }
2859};
2860
Douglas Gregor42cafa82010-12-20 17:42:22 +00002861template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002862template<typename InputIterator>
2863bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2864 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002865 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002866 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002867 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002868 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002869
2870 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2871 // Unpack argument packs, which we translate them into separate
2872 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002873 // FIXME: We could do much better if we could guarantee that the
2874 // TemplateArgumentLocInfo for the pack expansion would be usable for
2875 // all of the template arguments in the argument pack.
2876 typedef TemplateArgumentLocInventIterator<Derived,
2877 TemplateArgument::pack_iterator>
2878 PackLocIterator;
2879 if (TransformTemplateArguments(PackLocIterator(*this,
2880 In.getArgument().pack_begin()),
2881 PackLocIterator(*this,
2882 In.getArgument().pack_end()),
2883 Outputs))
2884 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002885
2886 continue;
2887 }
2888
2889 if (In.getArgument().isPackExpansion()) {
2890 // We have a pack expansion, for which we will be substituting into
2891 // the pattern.
2892 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002893 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002894 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002895 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2896 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002897
2898 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2899 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2900 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2901
2902 // Determine whether the set of unexpanded parameter packs can and should
2903 // be expanded.
2904 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002905 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002906 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002907 if (getDerived().TryExpandParameterPacks(Ellipsis,
2908 Pattern.getSourceRange(),
2909 Unexpanded.data(),
2910 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002911 Expand,
2912 RetainExpansion,
2913 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002914 return true;
2915
2916 if (!Expand) {
2917 // The transform has determined that we should perform a simple
2918 // transformation on the pack expansion, producing another pack
2919 // expansion.
2920 TemplateArgumentLoc OutPattern;
2921 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2922 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2923 return true;
2924
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002925 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
2926 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002927 if (Out.getArgument().isNull())
2928 return true;
2929
2930 Outputs.addArgument(Out);
2931 continue;
2932 }
2933
2934 // The transform has determined that we should perform an elementwise
2935 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002936 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002937 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2938
2939 if (getDerived().TransformTemplateArgument(Pattern, Out))
2940 return true;
2941
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002942 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002943 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2944 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002945 if (Out.getArgument().isNull())
2946 return true;
2947 }
2948
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002949 Outputs.addArgument(Out);
2950 }
2951
Douglas Gregor48d24112011-01-10 20:53:55 +00002952 // If we're supposed to retain a pack expansion, do so by temporarily
2953 // forgetting the partially-substituted parameter pack.
2954 if (RetainExpansion) {
2955 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
2956
2957 if (getDerived().TransformTemplateArgument(Pattern, Out))
2958 return true;
2959
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002960 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2961 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00002962 if (Out.getArgument().isNull())
2963 return true;
2964
2965 Outputs.addArgument(Out);
2966 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002967
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002968 continue;
2969 }
2970
2971 // The simple case:
2972 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00002973 return true;
2974
2975 Outputs.addArgument(Out);
2976 }
2977
2978 return false;
2979
2980}
2981
Douglas Gregord6ff3322009-08-04 16:50:30 +00002982//===----------------------------------------------------------------------===//
2983// Type transformation
2984//===----------------------------------------------------------------------===//
2985
2986template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002987QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002988 if (getDerived().AlreadyTransformed(T))
2989 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002990
John McCall550e0c22009-10-21 00:40:46 +00002991 // Temporary workaround. All of these transformations should
2992 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00002993 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
2994 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002995
John McCall31f82722010-11-12 08:19:04 +00002996 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002997
John McCall550e0c22009-10-21 00:40:46 +00002998 if (!NewDI)
2999 return QualType();
3000
3001 return NewDI->getType();
3002}
3003
3004template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003005TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003006 if (getDerived().AlreadyTransformed(DI->getType()))
3007 return DI;
3008
3009 TypeLocBuilder TLB;
3010
3011 TypeLoc TL = DI->getTypeLoc();
3012 TLB.reserve(TL.getFullDataSize());
3013
John McCall31f82722010-11-12 08:19:04 +00003014 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003015 if (Result.isNull())
3016 return 0;
3017
John McCallbcd03502009-12-07 02:54:59 +00003018 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003019}
3020
3021template<typename Derived>
3022QualType
John McCall31f82722010-11-12 08:19:04 +00003023TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003024 switch (T.getTypeLocClass()) {
3025#define ABSTRACT_TYPELOC(CLASS, PARENT)
3026#define TYPELOC(CLASS, PARENT) \
3027 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003028 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003029#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003030 }
Mike Stump11289f42009-09-09 15:08:12 +00003031
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003032 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003033 return QualType();
3034}
3035
3036/// FIXME: By default, this routine adds type qualifiers only to types
3037/// that can have qualifiers, and silently suppresses those qualifiers
3038/// that are not permitted (e.g., qualifiers on reference or function
3039/// types). This is the right thing for template instantiation, but
3040/// probably not for other clients.
3041template<typename Derived>
3042QualType
3043TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003044 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003045 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003046
John McCall31f82722010-11-12 08:19:04 +00003047 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003048 if (Result.isNull())
3049 return QualType();
3050
3051 // Silently suppress qualifiers if the result type can't be qualified.
3052 // FIXME: this is the right thing for template instantiation, but
3053 // probably not for other clients.
3054 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003055 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003056
John McCallcb0f89a2010-06-05 06:41:15 +00003057 if (!Quals.empty()) {
3058 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3059 TLB.push<QualifiedTypeLoc>(Result);
3060 // No location information to preserve.
3061 }
John McCall550e0c22009-10-21 00:40:46 +00003062
3063 return Result;
3064}
3065
Douglas Gregor14454802011-02-25 02:25:35 +00003066template<typename Derived>
3067TypeLoc
3068TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3069 QualType ObjectType,
3070 NamedDecl *UnqualLookup,
3071 CXXScopeSpec &SS) {
Douglas Gregor14454802011-02-25 02:25:35 +00003072 QualType T = TL.getType();
3073 if (getDerived().AlreadyTransformed(T))
3074 return TL;
3075
3076 TypeLocBuilder TLB;
3077 QualType Result;
3078
3079 if (isa<TemplateSpecializationType>(T)) {
3080 TemplateSpecializationTypeLoc SpecTL
3081 = cast<TemplateSpecializationTypeLoc>(TL);
3082
3083 TemplateName Template =
Douglas Gregor9db53502011-03-02 18:07:45 +00003084 getDerived().TransformTemplateName(SS,
3085 SpecTL.getTypePtr()->getTemplateName(),
3086 SpecTL.getTemplateNameLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003087 ObjectType, UnqualLookup);
3088 if (Template.isNull())
3089 return TypeLoc();
3090
3091 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3092 Template);
3093 } else if (isa<DependentTemplateSpecializationType>(T)) {
3094 DependentTemplateSpecializationTypeLoc SpecTL
3095 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3096
Douglas Gregor5a064722011-02-28 17:23:35 +00003097 TemplateName Template
Douglas Gregor9db53502011-03-02 18:07:45 +00003098 = getDerived().RebuildTemplateName(SS,
Douglas Gregore16af532011-02-28 18:50:33 +00003099 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003100 SpecTL.getNameLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00003101 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003102 if (Template.isNull())
3103 return TypeLoc();
3104
Douglas Gregor14454802011-02-25 02:25:35 +00003105 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003106 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003107 Template,
3108 SS);
Douglas Gregor14454802011-02-25 02:25:35 +00003109 } else {
3110 // Nothing special needs to be done for these.
3111 Result = getDerived().TransformType(TLB, TL);
3112 }
3113
3114 if (Result.isNull())
3115 return TypeLoc();
3116
3117 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3118}
3119
Douglas Gregor579c15f2011-03-02 18:32:08 +00003120template<typename Derived>
3121TypeSourceInfo *
3122TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3123 QualType ObjectType,
3124 NamedDecl *UnqualLookup,
3125 CXXScopeSpec &SS) {
3126 // FIXME: Painfully copy-paste from the above!
3127
3128 QualType T = TSInfo->getType();
3129 if (getDerived().AlreadyTransformed(T))
3130 return TSInfo;
3131
3132 TypeLocBuilder TLB;
3133 QualType Result;
3134
3135 TypeLoc TL = TSInfo->getTypeLoc();
3136 if (isa<TemplateSpecializationType>(T)) {
3137 TemplateSpecializationTypeLoc SpecTL
3138 = cast<TemplateSpecializationTypeLoc>(TL);
3139
3140 TemplateName Template
3141 = getDerived().TransformTemplateName(SS,
3142 SpecTL.getTypePtr()->getTemplateName(),
3143 SpecTL.getTemplateNameLoc(),
3144 ObjectType, UnqualLookup);
3145 if (Template.isNull())
3146 return 0;
3147
3148 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3149 Template);
3150 } else if (isa<DependentTemplateSpecializationType>(T)) {
3151 DependentTemplateSpecializationTypeLoc SpecTL
3152 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3153
3154 TemplateName Template
3155 = getDerived().RebuildTemplateName(SS,
3156 *SpecTL.getTypePtr()->getIdentifier(),
3157 SpecTL.getNameLoc(),
3158 ObjectType, UnqualLookup);
3159 if (Template.isNull())
3160 return 0;
3161
3162 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3163 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003164 Template,
3165 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003166 } else {
3167 // Nothing special needs to be done for these.
3168 Result = getDerived().TransformType(TLB, TL);
3169 }
3170
3171 if (Result.isNull())
3172 return 0;
3173
3174 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3175}
3176
John McCall550e0c22009-10-21 00:40:46 +00003177template <class TyLoc> static inline
3178QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3179 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3180 NewT.setNameLoc(T.getNameLoc());
3181 return T.getType();
3182}
3183
John McCall550e0c22009-10-21 00:40:46 +00003184template<typename Derived>
3185QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003186 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003187 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3188 NewT.setBuiltinLoc(T.getBuiltinLoc());
3189 if (T.needsExtraLocalData())
3190 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3191 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003192}
Mike Stump11289f42009-09-09 15:08:12 +00003193
Douglas Gregord6ff3322009-08-04 16:50:30 +00003194template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003195QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003196 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003197 // FIXME: recurse?
3198 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003199}
Mike Stump11289f42009-09-09 15:08:12 +00003200
Douglas Gregord6ff3322009-08-04 16:50:30 +00003201template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003202QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003203 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003204 QualType PointeeType
3205 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003206 if (PointeeType.isNull())
3207 return QualType();
3208
3209 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003210 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003211 // A dependent pointer type 'T *' has is being transformed such
3212 // that an Objective-C class type is being replaced for 'T'. The
3213 // resulting pointer type is an ObjCObjectPointerType, not a
3214 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003215 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003216
John McCall8b07ec22010-05-15 11:32:37 +00003217 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3218 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003219 return Result;
3220 }
John McCall31f82722010-11-12 08:19:04 +00003221
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003222 if (getDerived().AlwaysRebuild() ||
3223 PointeeType != TL.getPointeeLoc().getType()) {
3224 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3225 if (Result.isNull())
3226 return QualType();
3227 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003228
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003229 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3230 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003231 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003232}
Mike Stump11289f42009-09-09 15:08:12 +00003233
3234template<typename Derived>
3235QualType
John McCall550e0c22009-10-21 00:40:46 +00003236TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003237 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003238 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003239 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3240 if (PointeeType.isNull())
3241 return QualType();
3242
3243 QualType Result = TL.getType();
3244 if (getDerived().AlwaysRebuild() ||
3245 PointeeType != TL.getPointeeLoc().getType()) {
3246 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003247 TL.getSigilLoc());
3248 if (Result.isNull())
3249 return QualType();
3250 }
3251
Douglas Gregor049211a2010-04-22 16:50:51 +00003252 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003253 NewT.setSigilLoc(TL.getSigilLoc());
3254 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003255}
3256
John McCall70dd5f62009-10-30 00:06:24 +00003257/// Transforms a reference type. Note that somewhat paradoxically we
3258/// don't care whether the type itself is an l-value type or an r-value
3259/// type; we only care if the type was *written* as an l-value type
3260/// or an r-value type.
3261template<typename Derived>
3262QualType
3263TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003264 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003265 const ReferenceType *T = TL.getTypePtr();
3266
3267 // Note that this works with the pointee-as-written.
3268 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3269 if (PointeeType.isNull())
3270 return QualType();
3271
3272 QualType Result = TL.getType();
3273 if (getDerived().AlwaysRebuild() ||
3274 PointeeType != T->getPointeeTypeAsWritten()) {
3275 Result = getDerived().RebuildReferenceType(PointeeType,
3276 T->isSpelledAsLValue(),
3277 TL.getSigilLoc());
3278 if (Result.isNull())
3279 return QualType();
3280 }
3281
3282 // r-value references can be rebuilt as l-value references.
3283 ReferenceTypeLoc NewTL;
3284 if (isa<LValueReferenceType>(Result))
3285 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3286 else
3287 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3288 NewTL.setSigilLoc(TL.getSigilLoc());
3289
3290 return Result;
3291}
3292
Mike Stump11289f42009-09-09 15:08:12 +00003293template<typename Derived>
3294QualType
John McCall550e0c22009-10-21 00:40:46 +00003295TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003296 LValueReferenceTypeLoc TL) {
3297 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003298}
3299
Mike Stump11289f42009-09-09 15:08:12 +00003300template<typename Derived>
3301QualType
John McCall550e0c22009-10-21 00:40:46 +00003302TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003303 RValueReferenceTypeLoc TL) {
3304 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003305}
Mike Stump11289f42009-09-09 15:08:12 +00003306
Douglas Gregord6ff3322009-08-04 16:50:30 +00003307template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003308QualType
John McCall550e0c22009-10-21 00:40:46 +00003309TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003310 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003311 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003312 if (PointeeType.isNull())
3313 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003314
Abramo Bagnara509357842011-03-05 14:42:21 +00003315 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3316 TypeSourceInfo* NewClsTInfo = 0;
3317 if (OldClsTInfo) {
3318 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3319 if (!NewClsTInfo)
3320 return QualType();
3321 }
3322
3323 const MemberPointerType *T = TL.getTypePtr();
3324 QualType OldClsType = QualType(T->getClass(), 0);
3325 QualType NewClsType;
3326 if (NewClsTInfo)
3327 NewClsType = NewClsTInfo->getType();
3328 else {
3329 NewClsType = getDerived().TransformType(OldClsType);
3330 if (NewClsType.isNull())
3331 return QualType();
3332 }
Mike Stump11289f42009-09-09 15:08:12 +00003333
John McCall550e0c22009-10-21 00:40:46 +00003334 QualType Result = TL.getType();
3335 if (getDerived().AlwaysRebuild() ||
3336 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003337 NewClsType != OldClsType) {
3338 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003339 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003340 if (Result.isNull())
3341 return QualType();
3342 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003343
John McCall550e0c22009-10-21 00:40:46 +00003344 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3345 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003346 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003347
3348 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003349}
3350
Mike Stump11289f42009-09-09 15:08:12 +00003351template<typename Derived>
3352QualType
John McCall550e0c22009-10-21 00:40:46 +00003353TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003354 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003355 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003356 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003357 if (ElementType.isNull())
3358 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003359
John McCall550e0c22009-10-21 00:40:46 +00003360 QualType Result = TL.getType();
3361 if (getDerived().AlwaysRebuild() ||
3362 ElementType != T->getElementType()) {
3363 Result = getDerived().RebuildConstantArrayType(ElementType,
3364 T->getSizeModifier(),
3365 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003366 T->getIndexTypeCVRQualifiers(),
3367 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003368 if (Result.isNull())
3369 return QualType();
3370 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003371
John McCall550e0c22009-10-21 00:40:46 +00003372 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3373 NewTL.setLBracketLoc(TL.getLBracketLoc());
3374 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003375
John McCall550e0c22009-10-21 00:40:46 +00003376 Expr *Size = TL.getSizeExpr();
3377 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003378 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003379 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3380 }
3381 NewTL.setSizeExpr(Size);
3382
3383 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003384}
Mike Stump11289f42009-09-09 15:08:12 +00003385
Douglas Gregord6ff3322009-08-04 16:50:30 +00003386template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003387QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003388 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003389 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003390 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003391 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003392 if (ElementType.isNull())
3393 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003394
John McCall550e0c22009-10-21 00:40:46 +00003395 QualType Result = TL.getType();
3396 if (getDerived().AlwaysRebuild() ||
3397 ElementType != T->getElementType()) {
3398 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003399 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003400 T->getIndexTypeCVRQualifiers(),
3401 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003402 if (Result.isNull())
3403 return QualType();
3404 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003405
John McCall550e0c22009-10-21 00:40:46 +00003406 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3407 NewTL.setLBracketLoc(TL.getLBracketLoc());
3408 NewTL.setRBracketLoc(TL.getRBracketLoc());
3409 NewTL.setSizeExpr(0);
3410
3411 return Result;
3412}
3413
3414template<typename Derived>
3415QualType
3416TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003417 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003418 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003419 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3420 if (ElementType.isNull())
3421 return QualType();
3422
3423 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003424 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003425
John McCalldadc5752010-08-24 06:29:42 +00003426 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003427 = getDerived().TransformExpr(T->getSizeExpr());
3428 if (SizeResult.isInvalid())
3429 return QualType();
3430
John McCallb268a282010-08-23 23:25:46 +00003431 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003432
3433 QualType Result = TL.getType();
3434 if (getDerived().AlwaysRebuild() ||
3435 ElementType != T->getElementType() ||
3436 Size != T->getSizeExpr()) {
3437 Result = getDerived().RebuildVariableArrayType(ElementType,
3438 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003439 Size,
John McCall550e0c22009-10-21 00:40:46 +00003440 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003441 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003442 if (Result.isNull())
3443 return QualType();
3444 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003445
John McCall550e0c22009-10-21 00:40:46 +00003446 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3447 NewTL.setLBracketLoc(TL.getLBracketLoc());
3448 NewTL.setRBracketLoc(TL.getRBracketLoc());
3449 NewTL.setSizeExpr(Size);
3450
3451 return Result;
3452}
3453
3454template<typename Derived>
3455QualType
3456TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003457 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003458 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003459 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3460 if (ElementType.isNull())
3461 return QualType();
3462
3463 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003464 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003465
John McCall33ddac02011-01-19 10:06:00 +00003466 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3467 Expr *origSize = TL.getSizeExpr();
3468 if (!origSize) origSize = T->getSizeExpr();
3469
3470 ExprResult sizeResult
3471 = getDerived().TransformExpr(origSize);
3472 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003473 return QualType();
3474
John McCall33ddac02011-01-19 10:06:00 +00003475 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003476
3477 QualType Result = TL.getType();
3478 if (getDerived().AlwaysRebuild() ||
3479 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003480 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003481 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3482 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003483 size,
John McCall550e0c22009-10-21 00:40:46 +00003484 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003485 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003486 if (Result.isNull())
3487 return QualType();
3488 }
John McCall550e0c22009-10-21 00:40:46 +00003489
3490 // We might have any sort of array type now, but fortunately they
3491 // all have the same location layout.
3492 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3493 NewTL.setLBracketLoc(TL.getLBracketLoc());
3494 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003495 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003496
3497 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003498}
Mike Stump11289f42009-09-09 15:08:12 +00003499
3500template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003501QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003502 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003503 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003504 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003505
3506 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003507 QualType ElementType = getDerived().TransformType(T->getElementType());
3508 if (ElementType.isNull())
3509 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003510
Douglas Gregore922c772009-08-04 22:27:00 +00003511 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003512 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003513
John McCalldadc5752010-08-24 06:29:42 +00003514 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003515 if (Size.isInvalid())
3516 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003517
John McCall550e0c22009-10-21 00:40:46 +00003518 QualType Result = TL.getType();
3519 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003520 ElementType != T->getElementType() ||
3521 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003522 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003523 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003524 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003525 if (Result.isNull())
3526 return QualType();
3527 }
John McCall550e0c22009-10-21 00:40:46 +00003528
3529 // Result might be dependent or not.
3530 if (isa<DependentSizedExtVectorType>(Result)) {
3531 DependentSizedExtVectorTypeLoc NewTL
3532 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3533 NewTL.setNameLoc(TL.getNameLoc());
3534 } else {
3535 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3536 NewTL.setNameLoc(TL.getNameLoc());
3537 }
3538
3539 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003540}
Mike Stump11289f42009-09-09 15:08:12 +00003541
3542template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003543QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003544 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003545 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003546 QualType ElementType = getDerived().TransformType(T->getElementType());
3547 if (ElementType.isNull())
3548 return QualType();
3549
John McCall550e0c22009-10-21 00:40:46 +00003550 QualType Result = TL.getType();
3551 if (getDerived().AlwaysRebuild() ||
3552 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003553 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003554 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003555 if (Result.isNull())
3556 return QualType();
3557 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003558
John McCall550e0c22009-10-21 00:40:46 +00003559 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3560 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003561
John McCall550e0c22009-10-21 00:40:46 +00003562 return Result;
3563}
3564
3565template<typename Derived>
3566QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003567 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003568 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003569 QualType ElementType = getDerived().TransformType(T->getElementType());
3570 if (ElementType.isNull())
3571 return QualType();
3572
3573 QualType Result = TL.getType();
3574 if (getDerived().AlwaysRebuild() ||
3575 ElementType != T->getElementType()) {
3576 Result = getDerived().RebuildExtVectorType(ElementType,
3577 T->getNumElements(),
3578 /*FIXME*/ SourceLocation());
3579 if (Result.isNull())
3580 return QualType();
3581 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003582
John McCall550e0c22009-10-21 00:40:46 +00003583 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3584 NewTL.setNameLoc(TL.getNameLoc());
3585
3586 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003587}
Mike Stump11289f42009-09-09 15:08:12 +00003588
3589template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003590ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003591TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3592 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003593 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003594 TypeSourceInfo *NewDI = 0;
3595
3596 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3597 // If we're substituting into a pack expansion type and we know the
3598 TypeLoc OldTL = OldDI->getTypeLoc();
3599 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3600
3601 TypeLocBuilder TLB;
3602 TypeLoc NewTL = OldDI->getTypeLoc();
3603 TLB.reserve(NewTL.getFullDataSize());
3604
3605 QualType Result = getDerived().TransformType(TLB,
3606 OldExpansionTL.getPatternLoc());
3607 if (Result.isNull())
3608 return 0;
3609
3610 Result = RebuildPackExpansionType(Result,
3611 OldExpansionTL.getPatternLoc().getSourceRange(),
3612 OldExpansionTL.getEllipsisLoc(),
3613 NumExpansions);
3614 if (Result.isNull())
3615 return 0;
3616
3617 PackExpansionTypeLoc NewExpansionTL
3618 = TLB.push<PackExpansionTypeLoc>(Result);
3619 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3620 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3621 } else
3622 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003623 if (!NewDI)
3624 return 0;
3625
3626 if (NewDI == OldDI)
3627 return OldParm;
3628 else
3629 return ParmVarDecl::Create(SemaRef.Context,
3630 OldParm->getDeclContext(),
3631 OldParm->getLocation(),
3632 OldParm->getIdentifier(),
3633 NewDI->getType(),
3634 NewDI,
3635 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003636 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003637 /* DefArg */ NULL);
3638}
3639
3640template<typename Derived>
3641bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003642 TransformFunctionTypeParams(SourceLocation Loc,
3643 ParmVarDecl **Params, unsigned NumParams,
3644 const QualType *ParamTypes,
3645 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3646 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3647 for (unsigned i = 0; i != NumParams; ++i) {
3648 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor715e4612011-01-14 22:40:04 +00003649 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003650 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00003651 if (OldParm->isParameterPack()) {
3652 // We have a function parameter pack that may need to be expanded.
3653 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003654
Douglas Gregor5499af42011-01-05 23:12:31 +00003655 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003656 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3657 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3658 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3659 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00003660 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3661
Douglas Gregor5499af42011-01-05 23:12:31 +00003662 // Determine whether we should expand the parameter packs.
3663 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003664 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003665 llvm::Optional<unsigned> OrigNumExpansions
3666 = ExpansionTL.getTypePtr()->getNumExpansions();
3667 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003668 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3669 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003670 Unexpanded.data(),
3671 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003672 ShouldExpand,
3673 RetainExpansion,
3674 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003675 return true;
3676 }
3677
3678 if (ShouldExpand) {
3679 // Expand the function parameter pack into multiple, separate
3680 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003681 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003682 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003683 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3684 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003685 = getDerived().TransformFunctionTypeParam(OldParm,
3686 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003687 if (!NewParm)
3688 return true;
3689
Douglas Gregordd472162011-01-07 00:20:55 +00003690 OutParamTypes.push_back(NewParm->getType());
3691 if (PVars)
3692 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003693 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003694
3695 // If we're supposed to retain a pack expansion, do so by temporarily
3696 // forgetting the partially-substituted parameter pack.
3697 if (RetainExpansion) {
3698 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3699 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003700 = getDerived().TransformFunctionTypeParam(OldParm,
3701 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003702 if (!NewParm)
3703 return true;
3704
3705 OutParamTypes.push_back(NewParm->getType());
3706 if (PVars)
3707 PVars->push_back(NewParm);
3708 }
3709
Douglas Gregor5499af42011-01-05 23:12:31 +00003710 // We're done with the pack expansion.
3711 continue;
3712 }
3713
3714 // We'll substitute the parameter now without expanding the pack
3715 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00003716 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3717 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3718 NumExpansions);
3719 } else {
3720 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3721 llvm::Optional<unsigned>());
Douglas Gregor5499af42011-01-05 23:12:31 +00003722 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00003723
John McCall58f10c32010-03-11 09:03:00 +00003724 if (!NewParm)
3725 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003726
Douglas Gregordd472162011-01-07 00:20:55 +00003727 OutParamTypes.push_back(NewParm->getType());
3728 if (PVars)
3729 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003730 continue;
3731 }
John McCall58f10c32010-03-11 09:03:00 +00003732
3733 // Deal with the possibility that we don't have a parameter
3734 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003735 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003736 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003737 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003738 QualType NewType;
Douglas Gregor5499af42011-01-05 23:12:31 +00003739 if (const PackExpansionType *Expansion
3740 = dyn_cast<PackExpansionType>(OldType)) {
3741 // We have a function parameter pack that may need to be expanded.
3742 QualType Pattern = Expansion->getPattern();
3743 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3744 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3745
3746 // Determine whether we should expand the parameter packs.
3747 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003748 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003749 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003750 Unexpanded.data(),
3751 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003752 ShouldExpand,
3753 RetainExpansion,
3754 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003755 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003756 }
3757
3758 if (ShouldExpand) {
3759 // Expand the function parameter pack into multiple, separate
3760 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003761 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003762 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3763 QualType NewType = getDerived().TransformType(Pattern);
3764 if (NewType.isNull())
3765 return true;
John McCall58f10c32010-03-11 09:03:00 +00003766
Douglas Gregordd472162011-01-07 00:20:55 +00003767 OutParamTypes.push_back(NewType);
3768 if (PVars)
3769 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003770 }
3771
3772 // We're done with the pack expansion.
3773 continue;
3774 }
3775
Douglas Gregor48d24112011-01-10 20:53:55 +00003776 // If we're supposed to retain a pack expansion, do so by temporarily
3777 // forgetting the partially-substituted parameter pack.
3778 if (RetainExpansion) {
3779 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3780 QualType NewType = getDerived().TransformType(Pattern);
3781 if (NewType.isNull())
3782 return true;
3783
3784 OutParamTypes.push_back(NewType);
3785 if (PVars)
3786 PVars->push_back(0);
3787 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003788
Douglas Gregor5499af42011-01-05 23:12:31 +00003789 // We'll substitute the parameter now without expanding the pack
3790 // expansion.
3791 OldType = Expansion->getPattern();
3792 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003793 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3794 NewType = getDerived().TransformType(OldType);
3795 } else {
3796 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00003797 }
3798
Douglas Gregor5499af42011-01-05 23:12:31 +00003799 if (NewType.isNull())
3800 return true;
3801
3802 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003803 NewType = getSema().Context.getPackExpansionType(NewType,
3804 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003805
Douglas Gregordd472162011-01-07 00:20:55 +00003806 OutParamTypes.push_back(NewType);
3807 if (PVars)
3808 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003809 }
3810
3811 return false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003812 }
John McCall58f10c32010-03-11 09:03:00 +00003813
3814template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003815QualType
John McCall550e0c22009-10-21 00:40:46 +00003816TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003817 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003818 // Transform the parameters and return type.
3819 //
3820 // We instantiate in source order, with the return type first followed by
3821 // the parameters, because users tend to expect this (even if they shouldn't
3822 // rely on it!).
3823 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003824 // When the function has a trailing return type, we instantiate the
3825 // parameters before the return type, since the return type can then refer
3826 // to the parameters themselves (via decltype, sizeof, etc.).
3827 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003828 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003829 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00003830 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003831
Douglas Gregor7fb25412010-10-01 18:44:50 +00003832 QualType ResultType;
3833
3834 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003835 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3836 TL.getParmArray(),
3837 TL.getNumArgs(),
3838 TL.getTypePtr()->arg_type_begin(),
3839 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003840 return QualType();
3841
3842 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3843 if (ResultType.isNull())
3844 return QualType();
3845 }
3846 else {
3847 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3848 if (ResultType.isNull())
3849 return QualType();
3850
Douglas Gregordd472162011-01-07 00:20:55 +00003851 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3852 TL.getParmArray(),
3853 TL.getNumArgs(),
3854 TL.getTypePtr()->arg_type_begin(),
3855 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003856 return QualType();
3857 }
3858
John McCall550e0c22009-10-21 00:40:46 +00003859 QualType Result = TL.getType();
3860 if (getDerived().AlwaysRebuild() ||
3861 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003862 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003863 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3864 Result = getDerived().RebuildFunctionProtoType(ResultType,
3865 ParamTypes.data(),
3866 ParamTypes.size(),
3867 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003868 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00003869 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003870 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003871 if (Result.isNull())
3872 return QualType();
3873 }
Mike Stump11289f42009-09-09 15:08:12 +00003874
John McCall550e0c22009-10-21 00:40:46 +00003875 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3876 NewTL.setLParenLoc(TL.getLParenLoc());
3877 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003878 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003879 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3880 NewTL.setArg(i, ParamDecls[i]);
3881
3882 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003883}
Mike Stump11289f42009-09-09 15:08:12 +00003884
Douglas Gregord6ff3322009-08-04 16:50:30 +00003885template<typename Derived>
3886QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003887 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003888 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003889 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003890 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3891 if (ResultType.isNull())
3892 return QualType();
3893
3894 QualType Result = TL.getType();
3895 if (getDerived().AlwaysRebuild() ||
3896 ResultType != T->getResultType())
3897 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3898
3899 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3900 NewTL.setLParenLoc(TL.getLParenLoc());
3901 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003902 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003903
3904 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003905}
Mike Stump11289f42009-09-09 15:08:12 +00003906
John McCallb96ec562009-12-04 22:46:56 +00003907template<typename Derived> QualType
3908TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003909 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003910 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003911 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003912 if (!D)
3913 return QualType();
3914
3915 QualType Result = TL.getType();
3916 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3917 Result = getDerived().RebuildUnresolvedUsingType(D);
3918 if (Result.isNull())
3919 return QualType();
3920 }
3921
3922 // We might get an arbitrary type spec type back. We should at
3923 // least always get a type spec type, though.
3924 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3925 NewTL.setNameLoc(TL.getNameLoc());
3926
3927 return Result;
3928}
3929
Douglas Gregord6ff3322009-08-04 16:50:30 +00003930template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003931QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003932 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003933 const TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003934 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003935 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3936 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003937 if (!Typedef)
3938 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003939
John McCall550e0c22009-10-21 00:40:46 +00003940 QualType Result = TL.getType();
3941 if (getDerived().AlwaysRebuild() ||
3942 Typedef != T->getDecl()) {
3943 Result = getDerived().RebuildTypedefType(Typedef);
3944 if (Result.isNull())
3945 return QualType();
3946 }
Mike Stump11289f42009-09-09 15:08:12 +00003947
John McCall550e0c22009-10-21 00:40:46 +00003948 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3949 NewTL.setNameLoc(TL.getNameLoc());
3950
3951 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003952}
Mike Stump11289f42009-09-09 15:08:12 +00003953
Douglas Gregord6ff3322009-08-04 16:50:30 +00003954template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003955QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003956 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003957 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003958 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003959
John McCalldadc5752010-08-24 06:29:42 +00003960 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003961 if (E.isInvalid())
3962 return QualType();
3963
John McCall550e0c22009-10-21 00:40:46 +00003964 QualType Result = TL.getType();
3965 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003966 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003967 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003968 if (Result.isNull())
3969 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003970 }
John McCall550e0c22009-10-21 00:40:46 +00003971 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003972
John McCall550e0c22009-10-21 00:40:46 +00003973 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003974 NewTL.setTypeofLoc(TL.getTypeofLoc());
3975 NewTL.setLParenLoc(TL.getLParenLoc());
3976 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003977
3978 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003979}
Mike Stump11289f42009-09-09 15:08:12 +00003980
3981template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003982QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003983 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003984 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3985 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3986 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003987 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003988
John McCall550e0c22009-10-21 00:40:46 +00003989 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003990 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3991 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003992 if (Result.isNull())
3993 return QualType();
3994 }
Mike Stump11289f42009-09-09 15:08:12 +00003995
John McCall550e0c22009-10-21 00:40:46 +00003996 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003997 NewTL.setTypeofLoc(TL.getTypeofLoc());
3998 NewTL.setLParenLoc(TL.getLParenLoc());
3999 NewTL.setRParenLoc(TL.getRParenLoc());
4000 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004001
4002 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004003}
Mike Stump11289f42009-09-09 15:08:12 +00004004
4005template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004006QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004007 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004008 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004009
Douglas Gregore922c772009-08-04 22:27:00 +00004010 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004011 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004012
John McCalldadc5752010-08-24 06:29:42 +00004013 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004014 if (E.isInvalid())
4015 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004016
John McCall550e0c22009-10-21 00:40:46 +00004017 QualType Result = TL.getType();
4018 if (getDerived().AlwaysRebuild() ||
4019 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004020 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004021 if (Result.isNull())
4022 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004023 }
John McCall550e0c22009-10-21 00:40:46 +00004024 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004025
John McCall550e0c22009-10-21 00:40:46 +00004026 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4027 NewTL.setNameLoc(TL.getNameLoc());
4028
4029 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004030}
4031
4032template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004033QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4034 AutoTypeLoc TL) {
4035 const AutoType *T = TL.getTypePtr();
4036 QualType OldDeduced = T->getDeducedType();
4037 QualType NewDeduced;
4038 if (!OldDeduced.isNull()) {
4039 NewDeduced = getDerived().TransformType(OldDeduced);
4040 if (NewDeduced.isNull())
4041 return QualType();
4042 }
4043
4044 QualType Result = TL.getType();
4045 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4046 Result = getDerived().RebuildAutoType(NewDeduced);
4047 if (Result.isNull())
4048 return QualType();
4049 }
4050
4051 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4052 NewTL.setNameLoc(TL.getNameLoc());
4053
4054 return Result;
4055}
4056
4057template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004058QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004059 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004060 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004061 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004062 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4063 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004064 if (!Record)
4065 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004066
John McCall550e0c22009-10-21 00:40:46 +00004067 QualType Result = TL.getType();
4068 if (getDerived().AlwaysRebuild() ||
4069 Record != T->getDecl()) {
4070 Result = getDerived().RebuildRecordType(Record);
4071 if (Result.isNull())
4072 return QualType();
4073 }
Mike Stump11289f42009-09-09 15:08:12 +00004074
John McCall550e0c22009-10-21 00:40:46 +00004075 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4076 NewTL.setNameLoc(TL.getNameLoc());
4077
4078 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004079}
Mike Stump11289f42009-09-09 15:08:12 +00004080
4081template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004082QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004083 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004084 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004085 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004086 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4087 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004088 if (!Enum)
4089 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004090
John McCall550e0c22009-10-21 00:40:46 +00004091 QualType Result = TL.getType();
4092 if (getDerived().AlwaysRebuild() ||
4093 Enum != T->getDecl()) {
4094 Result = getDerived().RebuildEnumType(Enum);
4095 if (Result.isNull())
4096 return QualType();
4097 }
Mike Stump11289f42009-09-09 15:08:12 +00004098
John McCall550e0c22009-10-21 00:40:46 +00004099 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4100 NewTL.setNameLoc(TL.getNameLoc());
4101
4102 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004103}
John McCallfcc33b02009-09-05 00:15:47 +00004104
John McCalle78aac42010-03-10 03:28:59 +00004105template<typename Derived>
4106QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4107 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004108 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004109 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4110 TL.getTypePtr()->getDecl());
4111 if (!D) return QualType();
4112
4113 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4114 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4115 return T;
4116}
4117
Douglas Gregord6ff3322009-08-04 16:50:30 +00004118template<typename Derived>
4119QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004120 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004121 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004122 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004123}
4124
Mike Stump11289f42009-09-09 15:08:12 +00004125template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004126QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004127 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004128 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004129 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00004130}
4131
4132template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004133QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4134 TypeLocBuilder &TLB,
4135 SubstTemplateTypeParmPackTypeLoc TL) {
4136 return TransformTypeSpecType(TLB, TL);
4137}
4138
4139template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004140QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004141 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004142 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004143 const TemplateSpecializationType *T = TL.getTypePtr();
4144
Douglas Gregordf846d12011-03-02 18:46:51 +00004145 // The nested-name-specifier never matters in a TemplateSpecializationType,
4146 // because we can't have a dependent nested-name-specifier anyway.
4147 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004148 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004149 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4150 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004151 if (Template.isNull())
4152 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004153
John McCall31f82722010-11-12 08:19:04 +00004154 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4155}
4156
Douglas Gregorfe921a72010-12-20 23:36:19 +00004157namespace {
4158 /// \brief Simple iterator that traverses the template arguments in a
4159 /// container that provides a \c getArgLoc() member function.
4160 ///
4161 /// This iterator is intended to be used with the iterator form of
4162 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4163 template<typename ArgLocContainer>
4164 class TemplateArgumentLocContainerIterator {
4165 ArgLocContainer *Container;
4166 unsigned Index;
4167
4168 public:
4169 typedef TemplateArgumentLoc value_type;
4170 typedef TemplateArgumentLoc reference;
4171 typedef int difference_type;
4172 typedef std::input_iterator_tag iterator_category;
4173
4174 class pointer {
4175 TemplateArgumentLoc Arg;
4176
4177 public:
4178 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4179
4180 const TemplateArgumentLoc *operator->() const {
4181 return &Arg;
4182 }
4183 };
4184
4185
4186 TemplateArgumentLocContainerIterator() {}
4187
4188 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4189 unsigned Index)
4190 : Container(&Container), Index(Index) { }
4191
4192 TemplateArgumentLocContainerIterator &operator++() {
4193 ++Index;
4194 return *this;
4195 }
4196
4197 TemplateArgumentLocContainerIterator operator++(int) {
4198 TemplateArgumentLocContainerIterator Old(*this);
4199 ++(*this);
4200 return Old;
4201 }
4202
4203 TemplateArgumentLoc operator*() const {
4204 return Container->getArgLoc(Index);
4205 }
4206
4207 pointer operator->() const {
4208 return pointer(Container->getArgLoc(Index));
4209 }
4210
4211 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004212 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004213 return X.Container == Y.Container && X.Index == Y.Index;
4214 }
4215
4216 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004217 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004218 return !(X == Y);
4219 }
4220 };
4221}
4222
4223
John McCall31f82722010-11-12 08:19:04 +00004224template <typename Derived>
4225QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4226 TypeLocBuilder &TLB,
4227 TemplateSpecializationTypeLoc TL,
4228 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004229 TemplateArgumentListInfo NewTemplateArgs;
4230 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4231 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004232 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4233 ArgIterator;
4234 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4235 ArgIterator(TL, TL.getNumArgs()),
4236 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004237 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004238
John McCall0ad16662009-10-29 08:12:44 +00004239 // FIXME: maybe don't rebuild if all the template arguments are the same.
4240
4241 QualType Result =
4242 getDerived().RebuildTemplateSpecializationType(Template,
4243 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004244 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004245
4246 if (!Result.isNull()) {
4247 TemplateSpecializationTypeLoc NewTL
4248 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4249 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4250 NewTL.setLAngleLoc(TL.getLAngleLoc());
4251 NewTL.setRAngleLoc(TL.getRAngleLoc());
4252 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4253 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004254 }
Mike Stump11289f42009-09-09 15:08:12 +00004255
John McCall0ad16662009-10-29 08:12:44 +00004256 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004257}
Mike Stump11289f42009-09-09 15:08:12 +00004258
Douglas Gregor5a064722011-02-28 17:23:35 +00004259template <typename Derived>
4260QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4261 TypeLocBuilder &TLB,
4262 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004263 TemplateName Template,
4264 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004265 TemplateArgumentListInfo NewTemplateArgs;
4266 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4267 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4268 typedef TemplateArgumentLocContainerIterator<
4269 DependentTemplateSpecializationTypeLoc> ArgIterator;
4270 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4271 ArgIterator(TL, TL.getNumArgs()),
4272 NewTemplateArgs))
4273 return QualType();
4274
4275 // FIXME: maybe don't rebuild if all the template arguments are the same.
4276
4277 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4278 QualType Result
4279 = getSema().Context.getDependentTemplateSpecializationType(
4280 TL.getTypePtr()->getKeyword(),
4281 DTN->getQualifier(),
4282 DTN->getIdentifier(),
4283 NewTemplateArgs);
4284
4285 DependentTemplateSpecializationTypeLoc NewTL
4286 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4287 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004288
Douglas Gregora7a795b2011-03-01 20:11:18 +00004289 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004290 NewTL.setNameLoc(TL.getNameLoc());
4291 NewTL.setLAngleLoc(TL.getLAngleLoc());
4292 NewTL.setRAngleLoc(TL.getRAngleLoc());
4293 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4294 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4295 return Result;
4296 }
4297
4298 QualType Result
4299 = getDerived().RebuildTemplateSpecializationType(Template,
4300 TL.getNameLoc(),
4301 NewTemplateArgs);
4302
4303 if (!Result.isNull()) {
4304 /// FIXME: Wrap this in an elaborated-type-specifier?
4305 TemplateSpecializationTypeLoc NewTL
4306 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4307 NewTL.setTemplateNameLoc(TL.getNameLoc());
4308 NewTL.setLAngleLoc(TL.getLAngleLoc());
4309 NewTL.setRAngleLoc(TL.getRAngleLoc());
4310 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4311 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4312 }
4313
4314 return Result;
4315}
4316
Mike Stump11289f42009-09-09 15:08:12 +00004317template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004318QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004319TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004320 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004321 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004322
Douglas Gregor844cb502011-03-01 18:12:44 +00004323 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004324 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004325 if (TL.getQualifierLoc()) {
4326 QualifierLoc
4327 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4328 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004329 return QualType();
4330 }
Mike Stump11289f42009-09-09 15:08:12 +00004331
John McCall31f82722010-11-12 08:19:04 +00004332 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4333 if (NamedT.isNull())
4334 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004335
John McCall550e0c22009-10-21 00:40:46 +00004336 QualType Result = TL.getType();
4337 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004338 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004339 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004340 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004341 T->getKeyword(),
4342 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004343 if (Result.isNull())
4344 return QualType();
4345 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004346
Abramo Bagnara6150c882010-05-11 21:36:43 +00004347 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004348 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004349 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004350 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004351}
Mike Stump11289f42009-09-09 15:08:12 +00004352
4353template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004354QualType TreeTransform<Derived>::TransformAttributedType(
4355 TypeLocBuilder &TLB,
4356 AttributedTypeLoc TL) {
4357 const AttributedType *oldType = TL.getTypePtr();
4358 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4359 if (modifiedType.isNull())
4360 return QualType();
4361
4362 QualType result = TL.getType();
4363
4364 // FIXME: dependent operand expressions?
4365 if (getDerived().AlwaysRebuild() ||
4366 modifiedType != oldType->getModifiedType()) {
4367 // TODO: this is really lame; we should really be rebuilding the
4368 // equivalent type from first principles.
4369 QualType equivalentType
4370 = getDerived().TransformType(oldType->getEquivalentType());
4371 if (equivalentType.isNull())
4372 return QualType();
4373 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4374 modifiedType,
4375 equivalentType);
4376 }
4377
4378 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4379 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4380 if (TL.hasAttrOperand())
4381 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4382 if (TL.hasAttrExprOperand())
4383 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4384 else if (TL.hasAttrEnumOperand())
4385 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4386
4387 return result;
4388}
4389
4390template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004391QualType
4392TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4393 ParenTypeLoc TL) {
4394 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4395 if (Inner.isNull())
4396 return QualType();
4397
4398 QualType Result = TL.getType();
4399 if (getDerived().AlwaysRebuild() ||
4400 Inner != TL.getInnerLoc().getType()) {
4401 Result = getDerived().RebuildParenType(Inner);
4402 if (Result.isNull())
4403 return QualType();
4404 }
4405
4406 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4407 NewTL.setLParenLoc(TL.getLParenLoc());
4408 NewTL.setRParenLoc(TL.getRParenLoc());
4409 return Result;
4410}
4411
4412template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004413QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004414 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004415 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004416
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004417 NestedNameSpecifierLoc QualifierLoc
4418 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4419 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004420 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004421
John McCallc392f372010-06-11 00:33:02 +00004422 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004423 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004424 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004425 QualifierLoc,
4426 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004427 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004428 if (Result.isNull())
4429 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004430
Abramo Bagnarad7548482010-05-19 21:37:53 +00004431 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4432 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004433 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4434
Abramo Bagnarad7548482010-05-19 21:37:53 +00004435 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4436 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004437 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004438 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004439 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4440 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004441 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004442 NewTL.setNameLoc(TL.getNameLoc());
4443 }
John McCall550e0c22009-10-21 00:40:46 +00004444 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004445}
Mike Stump11289f42009-09-09 15:08:12 +00004446
Douglas Gregord6ff3322009-08-04 16:50:30 +00004447template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004448QualType TreeTransform<Derived>::
4449 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004450 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004451 NestedNameSpecifierLoc QualifierLoc;
4452 if (TL.getQualifierLoc()) {
4453 QualifierLoc
4454 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4455 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004456 return QualType();
4457 }
4458
John McCall31f82722010-11-12 08:19:04 +00004459 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004460 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004461}
4462
4463template<typename Derived>
4464QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00004465TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4466 DependentTemplateSpecializationTypeLoc TL,
4467 NestedNameSpecifierLoc QualifierLoc) {
4468 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4469
4470 TemplateArgumentListInfo NewTemplateArgs;
4471 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4472 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4473
4474 typedef TemplateArgumentLocContainerIterator<
4475 DependentTemplateSpecializationTypeLoc> ArgIterator;
4476 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4477 ArgIterator(TL, TL.getNumArgs()),
4478 NewTemplateArgs))
4479 return QualType();
4480
4481 QualType Result
4482 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4483 QualifierLoc,
4484 T->getIdentifier(),
4485 TL.getNameLoc(),
4486 NewTemplateArgs);
4487 if (Result.isNull())
4488 return QualType();
4489
4490 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4491 QualType NamedT = ElabT->getNamedType();
4492
4493 // Copy information relevant to the template specialization.
4494 TemplateSpecializationTypeLoc NamedTL
4495 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4496 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4497 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4498 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4499 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4500
4501 // Copy information relevant to the elaborated type.
4502 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4503 NewTL.setKeywordLoc(TL.getKeywordLoc());
4504 NewTL.setQualifierLoc(QualifierLoc);
4505 } else {
4506 TypeLoc NewTL(Result, TL.getOpaqueData());
4507 TLB.pushFullCopy(NewTL);
4508 }
4509 return Result;
4510}
4511
4512template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004513QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4514 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004515 QualType Pattern
4516 = getDerived().TransformType(TLB, TL.getPatternLoc());
4517 if (Pattern.isNull())
4518 return QualType();
4519
4520 QualType Result = TL.getType();
4521 if (getDerived().AlwaysRebuild() ||
4522 Pattern != TL.getPatternLoc().getType()) {
4523 Result = getDerived().RebuildPackExpansionType(Pattern,
4524 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004525 TL.getEllipsisLoc(),
4526 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004527 if (Result.isNull())
4528 return QualType();
4529 }
4530
4531 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4532 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4533 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004534}
4535
4536template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004537QualType
4538TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004539 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004540 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004541 TLB.pushFullCopy(TL);
4542 return TL.getType();
4543}
4544
4545template<typename Derived>
4546QualType
4547TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004548 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004549 // ObjCObjectType is never dependent.
4550 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004551 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004552}
Mike Stump11289f42009-09-09 15:08:12 +00004553
4554template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004555QualType
4556TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004557 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004558 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004559 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004560 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004561}
4562
Douglas Gregord6ff3322009-08-04 16:50:30 +00004563//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004564// Statement transformation
4565//===----------------------------------------------------------------------===//
4566template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004567StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004568TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004569 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004570}
4571
4572template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004573StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004574TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4575 return getDerived().TransformCompoundStmt(S, false);
4576}
4577
4578template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004579StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004580TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004581 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004582 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004583 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004584 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004585 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4586 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004587 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004588 if (Result.isInvalid()) {
4589 // Immediately fail if this was a DeclStmt, since it's very
4590 // likely that this will cause problems for future statements.
4591 if (isa<DeclStmt>(*B))
4592 return StmtError();
4593
4594 // Otherwise, just keep processing substatements and fail later.
4595 SubStmtInvalid = true;
4596 continue;
4597 }
Mike Stump11289f42009-09-09 15:08:12 +00004598
Douglas Gregorebe10102009-08-20 07:17:43 +00004599 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4600 Statements.push_back(Result.takeAs<Stmt>());
4601 }
Mike Stump11289f42009-09-09 15:08:12 +00004602
John McCall1ababa62010-08-27 19:56:05 +00004603 if (SubStmtInvalid)
4604 return StmtError();
4605
Douglas Gregorebe10102009-08-20 07:17:43 +00004606 if (!getDerived().AlwaysRebuild() &&
4607 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004608 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004609
4610 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4611 move_arg(Statements),
4612 S->getRBracLoc(),
4613 IsStmtExpr);
4614}
Mike Stump11289f42009-09-09 15:08:12 +00004615
Douglas Gregorebe10102009-08-20 07:17:43 +00004616template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004617StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004618TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004619 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004620 {
4621 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004622 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004623
Eli Friedman06577382009-11-19 03:14:00 +00004624 // Transform the left-hand case value.
4625 LHS = getDerived().TransformExpr(S->getLHS());
4626 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004627 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004628
Eli Friedman06577382009-11-19 03:14:00 +00004629 // Transform the right-hand case value (for the GNU case-range extension).
4630 RHS = getDerived().TransformExpr(S->getRHS());
4631 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004632 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004633 }
Mike Stump11289f42009-09-09 15:08:12 +00004634
Douglas Gregorebe10102009-08-20 07:17:43 +00004635 // Build the case statement.
4636 // Case statements are always rebuilt so that they will attached to their
4637 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004638 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004639 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004640 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004641 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004642 S->getColonLoc());
4643 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004644 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004645
Douglas Gregorebe10102009-08-20 07:17:43 +00004646 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004647 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004648 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004649 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004650
Douglas Gregorebe10102009-08-20 07:17:43 +00004651 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004652 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004653}
4654
4655template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004656StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004657TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004658 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004659 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004660 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004661 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004662
Douglas Gregorebe10102009-08-20 07:17:43 +00004663 // Default statements are always rebuilt
4664 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004665 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004666}
Mike Stump11289f42009-09-09 15:08:12 +00004667
Douglas Gregorebe10102009-08-20 07:17:43 +00004668template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004669StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004670TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004671 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004672 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004673 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004674
Chris Lattnercab02a62011-02-17 20:34:02 +00004675 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4676 S->getDecl());
4677 if (!LD)
4678 return StmtError();
4679
4680
Douglas Gregorebe10102009-08-20 07:17:43 +00004681 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004682 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004683 cast<LabelDecl>(LD), SourceLocation(),
4684 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004685}
Mike Stump11289f42009-09-09 15:08:12 +00004686
Douglas Gregorebe10102009-08-20 07:17:43 +00004687template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004688StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004689TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004690 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004691 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004692 VarDecl *ConditionVar = 0;
4693 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004694 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004695 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004696 getDerived().TransformDefinition(
4697 S->getConditionVariable()->getLocation(),
4698 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004699 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004700 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004701 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004702 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004703
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004704 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004705 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004706
4707 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004708 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004709 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4710 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004711 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004712 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004713
John McCallb268a282010-08-23 23:25:46 +00004714 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004715 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004716 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004717
John McCallb268a282010-08-23 23:25:46 +00004718 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4719 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004720 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004721
Douglas Gregorebe10102009-08-20 07:17:43 +00004722 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004723 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004724 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004725 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004726
Douglas Gregorebe10102009-08-20 07:17:43 +00004727 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004728 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004729 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004730 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004731
Douglas Gregorebe10102009-08-20 07:17:43 +00004732 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004733 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004734 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004735 Then.get() == S->getThen() &&
4736 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004737 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004738
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004739 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004740 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004741 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004742}
4743
4744template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004745StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004746TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004747 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004748 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004749 VarDecl *ConditionVar = 0;
4750 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004751 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004752 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004753 getDerived().TransformDefinition(
4754 S->getConditionVariable()->getLocation(),
4755 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004756 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004757 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004758 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004759 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004760
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004761 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004762 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004763 }
Mike Stump11289f42009-09-09 15:08:12 +00004764
Douglas Gregorebe10102009-08-20 07:17:43 +00004765 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004766 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004767 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004768 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004769 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004770 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004771
Douglas Gregorebe10102009-08-20 07:17:43 +00004772 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004773 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004774 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004775 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004776
Douglas Gregorebe10102009-08-20 07:17:43 +00004777 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004778 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4779 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004780}
Mike Stump11289f42009-09-09 15:08:12 +00004781
Douglas Gregorebe10102009-08-20 07:17:43 +00004782template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004783StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004784TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004785 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004786 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004787 VarDecl *ConditionVar = 0;
4788 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004789 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004790 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004791 getDerived().TransformDefinition(
4792 S->getConditionVariable()->getLocation(),
4793 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004794 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004795 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004796 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004797 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004798
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004799 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004800 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004801
4802 if (S->getCond()) {
4803 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004804 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4805 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004806 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004807 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004808 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004809 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004810 }
Mike Stump11289f42009-09-09 15:08:12 +00004811
John McCallb268a282010-08-23 23:25:46 +00004812 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4813 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004814 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004815
Douglas Gregorebe10102009-08-20 07:17:43 +00004816 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004817 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004818 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004819 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004820
Douglas Gregorebe10102009-08-20 07:17:43 +00004821 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004822 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004823 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004824 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004825 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004826
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004827 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004828 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004829}
Mike Stump11289f42009-09-09 15:08:12 +00004830
Douglas Gregorebe10102009-08-20 07:17:43 +00004831template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004832StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004833TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004834 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004835 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004836 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004837 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004838
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004839 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004840 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004841 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004842 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004843
Douglas Gregorebe10102009-08-20 07:17:43 +00004844 if (!getDerived().AlwaysRebuild() &&
4845 Cond.get() == S->getCond() &&
4846 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004847 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004848
John McCallb268a282010-08-23 23:25:46 +00004849 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4850 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004851 S->getRParenLoc());
4852}
Mike Stump11289f42009-09-09 15:08:12 +00004853
Douglas Gregorebe10102009-08-20 07:17:43 +00004854template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004855StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004856TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004857 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004858 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004859 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004860 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004861
Douglas Gregorebe10102009-08-20 07:17:43 +00004862 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004863 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004864 VarDecl *ConditionVar = 0;
4865 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004866 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004867 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004868 getDerived().TransformDefinition(
4869 S->getConditionVariable()->getLocation(),
4870 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004871 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004872 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004873 } else {
4874 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004875
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004876 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004877 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004878
4879 if (S->getCond()) {
4880 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004881 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4882 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004883 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004884 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004885
John McCallb268a282010-08-23 23:25:46 +00004886 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004887 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004888 }
Mike Stump11289f42009-09-09 15:08:12 +00004889
John McCallb268a282010-08-23 23:25:46 +00004890 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4891 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004892 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004893
Douglas Gregorebe10102009-08-20 07:17:43 +00004894 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00004895 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00004896 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004897 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004898
John McCallb268a282010-08-23 23:25:46 +00004899 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4900 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004901 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004902
Douglas Gregorebe10102009-08-20 07:17:43 +00004903 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004904 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004905 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004906 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004907
Douglas Gregorebe10102009-08-20 07:17:43 +00004908 if (!getDerived().AlwaysRebuild() &&
4909 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00004910 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004911 Inc.get() == S->getInc() &&
4912 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004913 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004914
Douglas Gregorebe10102009-08-20 07:17:43 +00004915 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004916 Init.get(), FullCond, ConditionVar,
4917 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004918}
4919
4920template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004921StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004922TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00004923 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
4924 S->getLabel());
4925 if (!LD)
4926 return StmtError();
4927
Douglas Gregorebe10102009-08-20 07:17:43 +00004928 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00004929 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004930 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00004931}
4932
4933template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004934StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004935TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004936 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00004937 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004938 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004939
Douglas Gregorebe10102009-08-20 07:17:43 +00004940 if (!getDerived().AlwaysRebuild() &&
4941 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00004942 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004943
4944 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00004945 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004946}
4947
4948template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004949StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004950TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004951 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004952}
Mike Stump11289f42009-09-09 15:08:12 +00004953
Douglas Gregorebe10102009-08-20 07:17:43 +00004954template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004955StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004956TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004957 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004958}
Mike Stump11289f42009-09-09 15:08:12 +00004959
Douglas Gregorebe10102009-08-20 07:17:43 +00004960template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004961StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004962TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004963 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00004964 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004965 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004966
Mike Stump11289f42009-09-09 15:08:12 +00004967 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00004968 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00004969 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004970}
Mike Stump11289f42009-09-09 15:08:12 +00004971
Douglas Gregorebe10102009-08-20 07:17:43 +00004972template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004973StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004974TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004975 bool DeclChanged = false;
4976 llvm::SmallVector<Decl *, 4> Decls;
4977 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4978 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00004979 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4980 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00004981 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00004982 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004983
Douglas Gregorebe10102009-08-20 07:17:43 +00004984 if (Transformed != *D)
4985 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00004986
Douglas Gregorebe10102009-08-20 07:17:43 +00004987 Decls.push_back(Transformed);
4988 }
Mike Stump11289f42009-09-09 15:08:12 +00004989
Douglas Gregorebe10102009-08-20 07:17:43 +00004990 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00004991 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004992
4993 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004994 S->getStartLoc(), S->getEndLoc());
4995}
Mike Stump11289f42009-09-09 15:08:12 +00004996
Douglas Gregorebe10102009-08-20 07:17:43 +00004997template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004998StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004999TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005000
John McCall37ad5512010-08-23 06:44:23 +00005001 ASTOwningVector<Expr*> Constraints(getSema());
5002 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00005003 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005004
John McCalldadc5752010-08-24 06:29:42 +00005005 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005006 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005007
5008 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005009
Anders Carlssonaaeef072010-01-24 05:50:09 +00005010 // Go through the outputs.
5011 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005012 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005013
Anders Carlssonaaeef072010-01-24 05:50:09 +00005014 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005015 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005016
Anders Carlssonaaeef072010-01-24 05:50:09 +00005017 // Transform the output expr.
5018 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005019 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005020 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005021 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005022
Anders Carlssonaaeef072010-01-24 05:50:09 +00005023 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005024
John McCallb268a282010-08-23 23:25:46 +00005025 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005026 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005027
Anders Carlssonaaeef072010-01-24 05:50:09 +00005028 // Go through the inputs.
5029 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005030 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005031
Anders Carlssonaaeef072010-01-24 05:50:09 +00005032 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005033 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005034
Anders Carlssonaaeef072010-01-24 05:50:09 +00005035 // Transform the input expr.
5036 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005037 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005038 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005039 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005040
Anders Carlssonaaeef072010-01-24 05:50:09 +00005041 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005042
John McCallb268a282010-08-23 23:25:46 +00005043 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005044 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005045
Anders Carlssonaaeef072010-01-24 05:50:09 +00005046 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005047 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005048
5049 // Go through the clobbers.
5050 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005051 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005052
5053 // No need to transform the asm string literal.
5054 AsmString = SemaRef.Owned(S->getAsmString());
5055
5056 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5057 S->isSimple(),
5058 S->isVolatile(),
5059 S->getNumOutputs(),
5060 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005061 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005062 move_arg(Constraints),
5063 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005064 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005065 move_arg(Clobbers),
5066 S->getRParenLoc(),
5067 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005068}
5069
5070
5071template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005072StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005073TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005074 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005075 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005076 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005077 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005078
Douglas Gregor96c79492010-04-23 22:50:49 +00005079 // Transform the @catch statements (if present).
5080 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005081 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005082 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005083 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005084 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005085 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005086 if (Catch.get() != S->getCatchStmt(I))
5087 AnyCatchChanged = true;
5088 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005089 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005090
Douglas Gregor306de2f2010-04-22 23:59:56 +00005091 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005092 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005093 if (S->getFinallyStmt()) {
5094 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5095 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005096 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005097 }
5098
5099 // If nothing changed, just retain this statement.
5100 if (!getDerived().AlwaysRebuild() &&
5101 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005102 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005103 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005104 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005105
Douglas Gregor306de2f2010-04-22 23:59:56 +00005106 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005107 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5108 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005109}
Mike Stump11289f42009-09-09 15:08:12 +00005110
Douglas Gregorebe10102009-08-20 07:17:43 +00005111template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005112StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005113TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005114 // Transform the @catch parameter, if there is one.
5115 VarDecl *Var = 0;
5116 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5117 TypeSourceInfo *TSInfo = 0;
5118 if (FromVar->getTypeSourceInfo()) {
5119 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5120 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005121 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005122 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005123
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005124 QualType T;
5125 if (TSInfo)
5126 T = TSInfo->getType();
5127 else {
5128 T = getDerived().TransformType(FromVar->getType());
5129 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005130 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005131 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005132
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005133 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5134 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005135 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005136 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005137
John McCalldadc5752010-08-24 06:29:42 +00005138 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005139 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005140 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005141
5142 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005143 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005144 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005145}
Mike Stump11289f42009-09-09 15:08:12 +00005146
Douglas Gregorebe10102009-08-20 07:17:43 +00005147template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005148StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005149TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005150 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005151 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005152 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005153 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005154
Douglas Gregor306de2f2010-04-22 23:59:56 +00005155 // If nothing changed, just retain this statement.
5156 if (!getDerived().AlwaysRebuild() &&
5157 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005158 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005159
5160 // Build a new statement.
5161 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005162 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005163}
Mike Stump11289f42009-09-09 15:08:12 +00005164
Douglas Gregorebe10102009-08-20 07:17:43 +00005165template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005166StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005167TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005168 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005169 if (S->getThrowExpr()) {
5170 Operand = getDerived().TransformExpr(S->getThrowExpr());
5171 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005172 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005173 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005174
Douglas Gregor2900c162010-04-22 21:44:01 +00005175 if (!getDerived().AlwaysRebuild() &&
5176 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005177 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005178
John McCallb268a282010-08-23 23:25:46 +00005179 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005180}
Mike Stump11289f42009-09-09 15:08:12 +00005181
Douglas Gregorebe10102009-08-20 07:17:43 +00005182template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005183StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005184TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005185 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005186 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005187 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005188 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005189 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005190
Douglas Gregor6148de72010-04-22 22:01:21 +00005191 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005192 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005193 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005194 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005195
Douglas Gregor6148de72010-04-22 22:01:21 +00005196 // If nothing change, just retain the current statement.
5197 if (!getDerived().AlwaysRebuild() &&
5198 Object.get() == S->getSynchExpr() &&
5199 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005200 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005201
5202 // Build a new statement.
5203 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005204 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005205}
5206
5207template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005208StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005209TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005210 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005211 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005212 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005213 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005214 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005215
Douglas Gregorf68a5082010-04-22 23:10:45 +00005216 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005217 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005218 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005219 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005220
Douglas Gregorf68a5082010-04-22 23:10:45 +00005221 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005222 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005223 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005224 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005225
Douglas Gregorf68a5082010-04-22 23:10:45 +00005226 // If nothing changed, just retain this statement.
5227 if (!getDerived().AlwaysRebuild() &&
5228 Element.get() == S->getElement() &&
5229 Collection.get() == S->getCollection() &&
5230 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005231 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005232
Douglas Gregorf68a5082010-04-22 23:10:45 +00005233 // Build a new statement.
5234 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5235 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005236 Element.get(),
5237 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005238 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005239 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005240}
5241
5242
5243template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005244StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005245TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5246 // Transform the exception declaration, if any.
5247 VarDecl *Var = 0;
5248 if (S->getExceptionDecl()) {
5249 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005250 TypeSourceInfo *T = getDerived().TransformType(
5251 ExceptionDecl->getTypeSourceInfo());
5252 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005253 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005254
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005255 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00005256 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005257 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00005258 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005259 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005260 }
Mike Stump11289f42009-09-09 15:08:12 +00005261
Douglas Gregorebe10102009-08-20 07:17:43 +00005262 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005263 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005264 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005265 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005266
Douglas Gregorebe10102009-08-20 07:17:43 +00005267 if (!getDerived().AlwaysRebuild() &&
5268 !Var &&
5269 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005270 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005271
5272 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5273 Var,
John McCallb268a282010-08-23 23:25:46 +00005274 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005275}
Mike Stump11289f42009-09-09 15:08:12 +00005276
Douglas Gregorebe10102009-08-20 07:17:43 +00005277template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005278StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005279TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5280 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005281 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005282 = getDerived().TransformCompoundStmt(S->getTryBlock());
5283 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005284 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005285
Douglas Gregorebe10102009-08-20 07:17:43 +00005286 // Transform the handlers.
5287 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005288 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005289 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005290 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005291 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5292 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005293 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005294
Douglas Gregorebe10102009-08-20 07:17:43 +00005295 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5296 Handlers.push_back(Handler.takeAs<Stmt>());
5297 }
Mike Stump11289f42009-09-09 15:08:12 +00005298
Douglas Gregorebe10102009-08-20 07:17:43 +00005299 if (!getDerived().AlwaysRebuild() &&
5300 TryBlock.get() == S->getTryBlock() &&
5301 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005302 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005303
John McCallb268a282010-08-23 23:25:46 +00005304 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005305 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005306}
Mike Stump11289f42009-09-09 15:08:12 +00005307
Douglas Gregorebe10102009-08-20 07:17:43 +00005308//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005309// Expression transformation
5310//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005311template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005312ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005313TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005314 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005315}
Mike Stump11289f42009-09-09 15:08:12 +00005316
5317template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005318ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005319TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005320 NestedNameSpecifierLoc QualifierLoc;
5321 if (E->getQualifierLoc()) {
5322 QualifierLoc
5323 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5324 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005325 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005326 }
John McCallce546572009-12-08 09:08:17 +00005327
5328 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005329 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5330 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005331 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005332 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005333
John McCall815039a2010-08-17 21:27:17 +00005334 DeclarationNameInfo NameInfo = E->getNameInfo();
5335 if (NameInfo.getName()) {
5336 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5337 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005338 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005339 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005340
5341 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005342 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005343 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005344 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005345 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005346
5347 // Mark it referenced in the new context regardless.
5348 // FIXME: this is a bit instantiation-specific.
5349 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5350
John McCallc3007a22010-10-26 07:05:15 +00005351 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005352 }
John McCallce546572009-12-08 09:08:17 +00005353
5354 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005355 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005356 TemplateArgs = &TransArgs;
5357 TransArgs.setLAngleLoc(E->getLAngleLoc());
5358 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005359 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5360 E->getNumTemplateArgs(),
5361 TransArgs))
5362 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005363 }
5364
Douglas Gregorea972d32011-02-28 21:54:11 +00005365 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5366 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005367}
Mike Stump11289f42009-09-09 15:08:12 +00005368
Douglas Gregora16548e2009-08-11 05:31:07 +00005369template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005370ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005371TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005372 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005373}
Mike Stump11289f42009-09-09 15:08:12 +00005374
Douglas Gregora16548e2009-08-11 05:31:07 +00005375template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005376ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005377TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005378 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005379}
Mike Stump11289f42009-09-09 15:08:12 +00005380
Douglas Gregora16548e2009-08-11 05:31:07 +00005381template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005382ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005383TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005384 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005385}
Mike Stump11289f42009-09-09 15:08:12 +00005386
Douglas Gregora16548e2009-08-11 05:31:07 +00005387template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005388ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005389TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005390 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005391}
Mike Stump11289f42009-09-09 15:08:12 +00005392
Douglas Gregora16548e2009-08-11 05:31:07 +00005393template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005394ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005395TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005396 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005397}
5398
5399template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005400ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005401TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005402 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005403 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005404 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005405
Douglas Gregora16548e2009-08-11 05:31:07 +00005406 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005407 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005408
John McCallb268a282010-08-23 23:25:46 +00005409 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005410 E->getRParen());
5411}
5412
Mike Stump11289f42009-09-09 15:08:12 +00005413template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005414ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005415TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005416 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005417 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005418 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005419
Douglas Gregora16548e2009-08-11 05:31:07 +00005420 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005421 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005422
Douglas Gregora16548e2009-08-11 05:31:07 +00005423 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5424 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005425 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005426}
Mike Stump11289f42009-09-09 15:08:12 +00005427
Douglas Gregora16548e2009-08-11 05:31:07 +00005428template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005429ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005430TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5431 // Transform the type.
5432 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5433 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005434 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005435
Douglas Gregor882211c2010-04-28 22:16:22 +00005436 // Transform all of the components into components similar to what the
5437 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005438 // FIXME: It would be slightly more efficient in the non-dependent case to
5439 // just map FieldDecls, rather than requiring the rebuilder to look for
5440 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005441 // template code that we don't care.
5442 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005443 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005444 typedef OffsetOfExpr::OffsetOfNode Node;
5445 llvm::SmallVector<Component, 4> Components;
5446 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5447 const Node &ON = E->getComponent(I);
5448 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005449 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00005450 Comp.LocStart = ON.getRange().getBegin();
5451 Comp.LocEnd = ON.getRange().getEnd();
5452 switch (ON.getKind()) {
5453 case Node::Array: {
5454 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005455 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005456 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005457 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005458
Douglas Gregor882211c2010-04-28 22:16:22 +00005459 ExprChanged = ExprChanged || Index.get() != FromIndex;
5460 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005461 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005462 break;
5463 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005464
Douglas Gregor882211c2010-04-28 22:16:22 +00005465 case Node::Field:
5466 case Node::Identifier:
5467 Comp.isBrackets = false;
5468 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005469 if (!Comp.U.IdentInfo)
5470 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005471
Douglas Gregor882211c2010-04-28 22:16:22 +00005472 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005473
Douglas Gregord1702062010-04-29 00:18:15 +00005474 case Node::Base:
5475 // Will be recomputed during the rebuild.
5476 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005477 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005478
Douglas Gregor882211c2010-04-28 22:16:22 +00005479 Components.push_back(Comp);
5480 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005481
Douglas Gregor882211c2010-04-28 22:16:22 +00005482 // If nothing changed, retain the existing expression.
5483 if (!getDerived().AlwaysRebuild() &&
5484 Type == E->getTypeSourceInfo() &&
5485 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005486 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005487
Douglas Gregor882211c2010-04-28 22:16:22 +00005488 // Build a new offsetof expression.
5489 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5490 Components.data(), Components.size(),
5491 E->getRParenLoc());
5492}
5493
5494template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005495ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005496TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5497 assert(getDerived().AlreadyTransformed(E->getType()) &&
5498 "opaque value expression requires transformation");
5499 return SemaRef.Owned(E);
5500}
5501
5502template<typename Derived>
5503ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005504TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005505 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005506 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005507
John McCallbcd03502009-12-07 02:54:59 +00005508 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005509 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005510 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005511
John McCall4c98fd82009-11-04 07:28:41 +00005512 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005513 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005514
John McCall4c98fd82009-11-04 07:28:41 +00005515 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005516 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005517 E->getSourceRange());
5518 }
Mike Stump11289f42009-09-09 15:08:12 +00005519
John McCalldadc5752010-08-24 06:29:42 +00005520 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005521 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005522 // C++0x [expr.sizeof]p1:
5523 // The operand is either an expression, which is an unevaluated operand
5524 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005525 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005526
Douglas Gregora16548e2009-08-11 05:31:07 +00005527 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5528 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005529 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005530
Douglas Gregora16548e2009-08-11 05:31:07 +00005531 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005532 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005533 }
Mike Stump11289f42009-09-09 15:08:12 +00005534
John McCallb268a282010-08-23 23:25:46 +00005535 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005536 E->isSizeOf(),
5537 E->getSourceRange());
5538}
Mike Stump11289f42009-09-09 15:08:12 +00005539
Douglas Gregora16548e2009-08-11 05:31:07 +00005540template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005541ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005542TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005543 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005544 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005545 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005546
John McCalldadc5752010-08-24 06:29:42 +00005547 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005548 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005549 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005550
5551
Douglas Gregora16548e2009-08-11 05:31:07 +00005552 if (!getDerived().AlwaysRebuild() &&
5553 LHS.get() == E->getLHS() &&
5554 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005555 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005556
John McCallb268a282010-08-23 23:25:46 +00005557 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005558 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005559 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005560 E->getRBracketLoc());
5561}
Mike Stump11289f42009-09-09 15:08:12 +00005562
5563template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005564ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005565TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005566 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005567 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005568 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005569 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005570
5571 // Transform arguments.
5572 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005573 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005574 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5575 &ArgChanged))
5576 return ExprError();
5577
Douglas Gregora16548e2009-08-11 05:31:07 +00005578 if (!getDerived().AlwaysRebuild() &&
5579 Callee.get() == E->getCallee() &&
5580 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005581 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005582
Douglas Gregora16548e2009-08-11 05:31:07 +00005583 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005584 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005585 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005586 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005587 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005588 E->getRParenLoc());
5589}
Mike Stump11289f42009-09-09 15:08:12 +00005590
5591template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005592ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005593TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005594 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005595 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005596 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005597
Douglas Gregorea972d32011-02-28 21:54:11 +00005598 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005599 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005600 QualifierLoc
5601 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5602
5603 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005604 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005605 }
Mike Stump11289f42009-09-09 15:08:12 +00005606
Eli Friedman2cfcef62009-12-04 06:40:45 +00005607 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005608 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5609 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005610 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005611 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005612
John McCall16df1e52010-03-30 21:47:33 +00005613 NamedDecl *FoundDecl = E->getFoundDecl();
5614 if (FoundDecl == E->getMemberDecl()) {
5615 FoundDecl = Member;
5616 } else {
5617 FoundDecl = cast_or_null<NamedDecl>(
5618 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5619 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005620 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005621 }
5622
Douglas Gregora16548e2009-08-11 05:31:07 +00005623 if (!getDerived().AlwaysRebuild() &&
5624 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005625 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005626 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005627 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005628 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005629
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005630 // Mark it referenced in the new context regardless.
5631 // FIXME: this is a bit instantiation-specific.
5632 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005633 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005634 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005635
John McCall6b51f282009-11-23 01:53:49 +00005636 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005637 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005638 TransArgs.setLAngleLoc(E->getLAngleLoc());
5639 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005640 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5641 E->getNumTemplateArgs(),
5642 TransArgs))
5643 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005644 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005645
Douglas Gregora16548e2009-08-11 05:31:07 +00005646 // FIXME: Bogus source location for the operator
5647 SourceLocation FakeOperatorLoc
5648 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5649
John McCall38836f02010-01-15 08:34:02 +00005650 // FIXME: to do this check properly, we will need to preserve the
5651 // first-qualifier-in-scope here, just in case we had a dependent
5652 // base (and therefore couldn't do the check) and a
5653 // nested-name-qualifier (and therefore could do the lookup).
5654 NamedDecl *FirstQualifierInScope = 0;
5655
John McCallb268a282010-08-23 23:25:46 +00005656 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005657 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00005658 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005659 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005660 Member,
John McCall16df1e52010-03-30 21:47:33 +00005661 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005662 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005663 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005664 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005665}
Mike Stump11289f42009-09-09 15:08:12 +00005666
Douglas Gregora16548e2009-08-11 05:31:07 +00005667template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005668ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005669TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005670 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005671 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005672 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005673
John McCalldadc5752010-08-24 06:29:42 +00005674 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005675 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005676 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005677
Douglas Gregora16548e2009-08-11 05:31:07 +00005678 if (!getDerived().AlwaysRebuild() &&
5679 LHS.get() == E->getLHS() &&
5680 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005681 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005682
Douglas Gregora16548e2009-08-11 05:31:07 +00005683 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005684 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005685}
5686
Mike Stump11289f42009-09-09 15:08:12 +00005687template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005688ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005689TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005690 CompoundAssignOperator *E) {
5691 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005692}
Mike Stump11289f42009-09-09 15:08:12 +00005693
Douglas Gregora16548e2009-08-11 05:31:07 +00005694template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00005695ExprResult TreeTransform<Derived>::
5696TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
5697 // Just rebuild the common and RHS expressions and see whether we
5698 // get any changes.
5699
5700 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
5701 if (commonExpr.isInvalid())
5702 return ExprError();
5703
5704 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
5705 if (rhs.isInvalid())
5706 return ExprError();
5707
5708 if (!getDerived().AlwaysRebuild() &&
5709 commonExpr.get() == e->getCommon() &&
5710 rhs.get() == e->getFalseExpr())
5711 return SemaRef.Owned(e);
5712
5713 return getDerived().RebuildConditionalOperator(commonExpr.take(),
5714 e->getQuestionLoc(),
5715 0,
5716 e->getColonLoc(),
5717 rhs.get());
5718}
5719
5720template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005721ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005722TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005723 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005724 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005725 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005726
John McCalldadc5752010-08-24 06:29:42 +00005727 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005728 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005729 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005730
John McCalldadc5752010-08-24 06:29:42 +00005731 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005732 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005733 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005734
Douglas Gregora16548e2009-08-11 05:31:07 +00005735 if (!getDerived().AlwaysRebuild() &&
5736 Cond.get() == E->getCond() &&
5737 LHS.get() == E->getLHS() &&
5738 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005739 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005740
John McCallb268a282010-08-23 23:25:46 +00005741 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005742 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005743 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005744 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005745 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005746}
Mike Stump11289f42009-09-09 15:08:12 +00005747
5748template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005749ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005750TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005751 // Implicit casts are eliminated during transformation, since they
5752 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005753 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005754}
Mike Stump11289f42009-09-09 15:08:12 +00005755
Douglas Gregora16548e2009-08-11 05:31:07 +00005756template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005757ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005758TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005759 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5760 if (!Type)
5761 return ExprError();
5762
John McCalldadc5752010-08-24 06:29:42 +00005763 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005764 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005765 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005766 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005767
Douglas Gregora16548e2009-08-11 05:31:07 +00005768 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005769 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005770 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005771 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005772
John McCall97513962010-01-15 18:39:57 +00005773 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005774 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005775 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005776 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005777}
Mike Stump11289f42009-09-09 15:08:12 +00005778
Douglas Gregora16548e2009-08-11 05:31:07 +00005779template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005780ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005781TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005782 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5783 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5784 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005785 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005786
John McCalldadc5752010-08-24 06:29:42 +00005787 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005788 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005789 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005790
Douglas Gregora16548e2009-08-11 05:31:07 +00005791 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005792 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005793 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005794 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005795
John McCall5d7aa7f2010-01-19 22:33:45 +00005796 // Note: the expression type doesn't necessarily match the
5797 // type-as-written, but that's okay, because it should always be
5798 // derivable from the initializer.
5799
John McCalle15bbff2010-01-18 19:35:47 +00005800 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005801 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005802 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005803}
Mike Stump11289f42009-09-09 15:08:12 +00005804
Douglas Gregora16548e2009-08-11 05:31:07 +00005805template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005806ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005807TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005808 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005809 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005810 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005811
Douglas Gregora16548e2009-08-11 05:31:07 +00005812 if (!getDerived().AlwaysRebuild() &&
5813 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00005814 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005815
Douglas Gregora16548e2009-08-11 05:31:07 +00005816 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005817 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005818 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005819 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005820 E->getAccessorLoc(),
5821 E->getAccessor());
5822}
Mike Stump11289f42009-09-09 15:08:12 +00005823
Douglas Gregora16548e2009-08-11 05:31:07 +00005824template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005825ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005826TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005827 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005828
John McCall37ad5512010-08-23 06:44:23 +00005829 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005830 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5831 Inits, &InitChanged))
5832 return ExprError();
5833
Douglas Gregora16548e2009-08-11 05:31:07 +00005834 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005835 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005836
Douglas Gregora16548e2009-08-11 05:31:07 +00005837 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005838 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005839}
Mike Stump11289f42009-09-09 15:08:12 +00005840
Douglas Gregora16548e2009-08-11 05:31:07 +00005841template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005842ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005843TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005844 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005845
Douglas Gregorebe10102009-08-20 07:17:43 +00005846 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005847 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005848 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005849 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005850
Douglas Gregorebe10102009-08-20 07:17:43 +00005851 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005852 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005853 bool ExprChanged = false;
5854 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5855 DEnd = E->designators_end();
5856 D != DEnd; ++D) {
5857 if (D->isFieldDesignator()) {
5858 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5859 D->getDotLoc(),
5860 D->getFieldLoc()));
5861 continue;
5862 }
Mike Stump11289f42009-09-09 15:08:12 +00005863
Douglas Gregora16548e2009-08-11 05:31:07 +00005864 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005865 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005866 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005867 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005868
5869 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005870 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005871
Douglas Gregora16548e2009-08-11 05:31:07 +00005872 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5873 ArrayExprs.push_back(Index.release());
5874 continue;
5875 }
Mike Stump11289f42009-09-09 15:08:12 +00005876
Douglas Gregora16548e2009-08-11 05:31:07 +00005877 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00005878 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00005879 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5880 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005881 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005882
John McCalldadc5752010-08-24 06:29:42 +00005883 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005884 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005885 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005886
5887 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005888 End.get(),
5889 D->getLBracketLoc(),
5890 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005891
Douglas Gregora16548e2009-08-11 05:31:07 +00005892 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5893 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00005894
Douglas Gregora16548e2009-08-11 05:31:07 +00005895 ArrayExprs.push_back(Start.release());
5896 ArrayExprs.push_back(End.release());
5897 }
Mike Stump11289f42009-09-09 15:08:12 +00005898
Douglas Gregora16548e2009-08-11 05:31:07 +00005899 if (!getDerived().AlwaysRebuild() &&
5900 Init.get() == E->getInit() &&
5901 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005902 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005903
Douglas Gregora16548e2009-08-11 05:31:07 +00005904 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5905 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005906 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005907}
Mike Stump11289f42009-09-09 15:08:12 +00005908
Douglas Gregora16548e2009-08-11 05:31:07 +00005909template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005910ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005911TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005912 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00005913 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005914
Douglas Gregor3da3c062009-10-28 00:29:27 +00005915 // FIXME: Will we ever have proper type location here? Will we actually
5916 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00005917 QualType T = getDerived().TransformType(E->getType());
5918 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005919 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005920
Douglas Gregora16548e2009-08-11 05:31:07 +00005921 if (!getDerived().AlwaysRebuild() &&
5922 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005923 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005924
Douglas Gregora16548e2009-08-11 05:31:07 +00005925 return getDerived().RebuildImplicitValueInitExpr(T);
5926}
Mike Stump11289f42009-09-09 15:08:12 +00005927
Douglas Gregora16548e2009-08-11 05:31:07 +00005928template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005929ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005930TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00005931 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5932 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005933 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005934
John McCalldadc5752010-08-24 06:29:42 +00005935 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005936 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005937 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005938
Douglas Gregora16548e2009-08-11 05:31:07 +00005939 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00005940 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005941 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005942 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005943
John McCallb268a282010-08-23 23:25:46 +00005944 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00005945 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005946}
5947
5948template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005949ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005950TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005951 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005952 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005953 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5954 &ArgumentChanged))
5955 return ExprError();
5956
Douglas Gregora16548e2009-08-11 05:31:07 +00005957 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5958 move_arg(Inits),
5959 E->getRParenLoc());
5960}
Mike Stump11289f42009-09-09 15:08:12 +00005961
Douglas Gregora16548e2009-08-11 05:31:07 +00005962/// \brief Transform an address-of-label expression.
5963///
5964/// By default, the transformation of an address-of-label expression always
5965/// rebuilds the expression, so that the label identifier can be resolved to
5966/// the corresponding label statement by semantic analysis.
5967template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005968ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005969TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005970 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
5971 E->getLabel());
5972 if (!LD)
5973 return ExprError();
5974
Douglas Gregora16548e2009-08-11 05:31:07 +00005975 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005976 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00005977}
Mike Stump11289f42009-09-09 15:08:12 +00005978
5979template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005980ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005981TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005982 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00005983 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5984 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005985 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005986
Douglas Gregora16548e2009-08-11 05:31:07 +00005987 if (!getDerived().AlwaysRebuild() &&
5988 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00005989 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005990
5991 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005992 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005993 E->getRParenLoc());
5994}
Mike Stump11289f42009-09-09 15:08:12 +00005995
Douglas Gregora16548e2009-08-11 05:31:07 +00005996template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005997ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005998TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005999 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006000 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006001 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006002
John McCalldadc5752010-08-24 06:29:42 +00006003 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006004 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006005 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006006
John McCalldadc5752010-08-24 06:29:42 +00006007 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006008 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006009 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006010
Douglas Gregora16548e2009-08-11 05:31:07 +00006011 if (!getDerived().AlwaysRebuild() &&
6012 Cond.get() == E->getCond() &&
6013 LHS.get() == E->getLHS() &&
6014 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006015 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006016
Douglas Gregora16548e2009-08-11 05:31:07 +00006017 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006018 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006019 E->getRParenLoc());
6020}
Mike Stump11289f42009-09-09 15:08:12 +00006021
Douglas Gregora16548e2009-08-11 05:31:07 +00006022template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006023ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006024TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006025 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006026}
6027
6028template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006029ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006030TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006031 switch (E->getOperator()) {
6032 case OO_New:
6033 case OO_Delete:
6034 case OO_Array_New:
6035 case OO_Array_Delete:
6036 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006037 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006038
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006039 case OO_Call: {
6040 // This is a call to an object's operator().
6041 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6042
6043 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006044 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006045 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006046 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006047
6048 // FIXME: Poor location information
6049 SourceLocation FakeLParenLoc
6050 = SemaRef.PP.getLocForEndOfToken(
6051 static_cast<Expr *>(Object.get())->getLocEnd());
6052
6053 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006054 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006055 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6056 Args))
6057 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006058
John McCallb268a282010-08-23 23:25:46 +00006059 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006060 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006061 E->getLocEnd());
6062 }
6063
6064#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6065 case OO_##Name:
6066#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6067#include "clang/Basic/OperatorKinds.def"
6068 case OO_Subscript:
6069 // Handled below.
6070 break;
6071
6072 case OO_Conditional:
6073 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006074 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006075
6076 case OO_None:
6077 case NUM_OVERLOADED_OPERATORS:
6078 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006079 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006080 }
6081
John McCalldadc5752010-08-24 06:29:42 +00006082 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006083 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006084 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006085
John McCalldadc5752010-08-24 06:29:42 +00006086 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006087 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006088 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006089
John McCalldadc5752010-08-24 06:29:42 +00006090 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006091 if (E->getNumArgs() == 2) {
6092 Second = getDerived().TransformExpr(E->getArg(1));
6093 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006094 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006095 }
Mike Stump11289f42009-09-09 15:08:12 +00006096
Douglas Gregora16548e2009-08-11 05:31:07 +00006097 if (!getDerived().AlwaysRebuild() &&
6098 Callee.get() == E->getCallee() &&
6099 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006100 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006101 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006102
Douglas Gregora16548e2009-08-11 05:31:07 +00006103 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6104 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006105 Callee.get(),
6106 First.get(),
6107 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006108}
Mike Stump11289f42009-09-09 15:08:12 +00006109
Douglas Gregora16548e2009-08-11 05:31:07 +00006110template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006111ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006112TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6113 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006114}
Mike Stump11289f42009-09-09 15:08:12 +00006115
Douglas Gregora16548e2009-08-11 05:31:07 +00006116template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006117ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006118TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6119 // Transform the callee.
6120 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6121 if (Callee.isInvalid())
6122 return ExprError();
6123
6124 // Transform exec config.
6125 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6126 if (EC.isInvalid())
6127 return ExprError();
6128
6129 // Transform arguments.
6130 bool ArgChanged = false;
6131 ASTOwningVector<Expr*> Args(SemaRef);
6132 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6133 &ArgChanged))
6134 return ExprError();
6135
6136 if (!getDerived().AlwaysRebuild() &&
6137 Callee.get() == E->getCallee() &&
6138 !ArgChanged)
6139 return SemaRef.Owned(E);
6140
6141 // FIXME: Wrong source location information for the '('.
6142 SourceLocation FakeLParenLoc
6143 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6144 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6145 move_arg(Args),
6146 E->getRParenLoc(), EC.get());
6147}
6148
6149template<typename Derived>
6150ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006151TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006152 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6153 if (!Type)
6154 return ExprError();
6155
John McCalldadc5752010-08-24 06:29:42 +00006156 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006157 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006158 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006159 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006160
Douglas Gregora16548e2009-08-11 05:31:07 +00006161 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006162 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006163 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006164 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006165
Douglas Gregora16548e2009-08-11 05:31:07 +00006166 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006167 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006168 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6169 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6170 SourceLocation FakeRParenLoc
6171 = SemaRef.PP.getLocForEndOfToken(
6172 E->getSubExpr()->getSourceRange().getEnd());
6173 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006174 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006175 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006176 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006177 FakeRAngleLoc,
6178 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006179 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006180 FakeRParenLoc);
6181}
Mike Stump11289f42009-09-09 15:08:12 +00006182
Douglas Gregora16548e2009-08-11 05:31:07 +00006183template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006184ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006185TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6186 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006187}
Mike Stump11289f42009-09-09 15:08:12 +00006188
6189template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006190ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006191TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6192 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006193}
6194
Douglas Gregora16548e2009-08-11 05:31:07 +00006195template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006196ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006197TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006198 CXXReinterpretCastExpr *E) {
6199 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006200}
Mike Stump11289f42009-09-09 15:08:12 +00006201
Douglas Gregora16548e2009-08-11 05:31:07 +00006202template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006203ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006204TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6205 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006206}
Mike Stump11289f42009-09-09 15:08:12 +00006207
Douglas Gregora16548e2009-08-11 05:31:07 +00006208template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006209ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006210TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006211 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006212 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6213 if (!Type)
6214 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006215
John McCalldadc5752010-08-24 06:29:42 +00006216 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006217 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006218 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006219 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006220
Douglas Gregora16548e2009-08-11 05:31:07 +00006221 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006222 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006223 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006224 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006225
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006226 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006227 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006228 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006229 E->getRParenLoc());
6230}
Mike Stump11289f42009-09-09 15:08:12 +00006231
Douglas Gregora16548e2009-08-11 05:31:07 +00006232template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006233ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006234TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006235 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006236 TypeSourceInfo *TInfo
6237 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6238 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006239 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006240
Douglas Gregora16548e2009-08-11 05:31:07 +00006241 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006242 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006243 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006244
Douglas Gregor9da64192010-04-26 22:37:10 +00006245 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6246 E->getLocStart(),
6247 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006248 E->getLocEnd());
6249 }
Mike Stump11289f42009-09-09 15:08:12 +00006250
Douglas Gregora16548e2009-08-11 05:31:07 +00006251 // We don't know whether the expression is potentially evaluated until
6252 // after we perform semantic analysis, so the expression is potentially
6253 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006254 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006255 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006256
John McCalldadc5752010-08-24 06:29:42 +00006257 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
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() &&
6262 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006263 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006264
Douglas Gregor9da64192010-04-26 22:37:10 +00006265 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6266 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006267 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006268 E->getLocEnd());
6269}
6270
6271template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006272ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006273TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6274 if (E->isTypeOperand()) {
6275 TypeSourceInfo *TInfo
6276 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6277 if (!TInfo)
6278 return ExprError();
6279
6280 if (!getDerived().AlwaysRebuild() &&
6281 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006282 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006283
6284 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6285 E->getLocStart(),
6286 TInfo,
6287 E->getLocEnd());
6288 }
6289
6290 // We don't know whether the expression is potentially evaluated until
6291 // after we perform semantic analysis, so the expression is potentially
6292 // potentially evaluated.
6293 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6294
6295 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6296 if (SubExpr.isInvalid())
6297 return ExprError();
6298
6299 if (!getDerived().AlwaysRebuild() &&
6300 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006301 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006302
6303 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6304 E->getLocStart(),
6305 SubExpr.get(),
6306 E->getLocEnd());
6307}
6308
6309template<typename Derived>
6310ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006311TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006312 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006313}
Mike Stump11289f42009-09-09 15:08:12 +00006314
Douglas Gregora16548e2009-08-11 05:31:07 +00006315template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006316ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006317TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006318 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006319 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006320}
Mike Stump11289f42009-09-09 15:08:12 +00006321
Douglas Gregora16548e2009-08-11 05:31:07 +00006322template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006323ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006324TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006325 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6326 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6327 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006328
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006329 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006330 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006331
Douglas Gregorb15af892010-01-07 23:12:05 +00006332 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006333}
Mike Stump11289f42009-09-09 15:08:12 +00006334
Douglas Gregora16548e2009-08-11 05:31:07 +00006335template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006336ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006337TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006338 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006339 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006340 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006341
Douglas Gregora16548e2009-08-11 05:31:07 +00006342 if (!getDerived().AlwaysRebuild() &&
6343 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006344 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006345
John McCallb268a282010-08-23 23:25:46 +00006346 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006347}
Mike Stump11289f42009-09-09 15:08:12 +00006348
Douglas Gregora16548e2009-08-11 05:31:07 +00006349template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006350ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006351TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006352 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006353 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6354 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006355 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006356 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006357
Chandler Carruth794da4c2010-02-08 06:42:49 +00006358 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006359 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006360 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006361
Douglas Gregor033f6752009-12-23 23:03:06 +00006362 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006363}
Mike Stump11289f42009-09-09 15:08:12 +00006364
Douglas Gregora16548e2009-08-11 05:31:07 +00006365template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006366ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006367TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6368 CXXScalarValueInitExpr *E) {
6369 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6370 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006371 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006372
Douglas Gregora16548e2009-08-11 05:31:07 +00006373 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006374 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006375 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006376
Douglas Gregor2b88c112010-09-08 00:15:04 +00006377 return getDerived().RebuildCXXScalarValueInitExpr(T,
6378 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006379 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006380}
Mike Stump11289f42009-09-09 15:08:12 +00006381
Douglas Gregora16548e2009-08-11 05:31:07 +00006382template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006383ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006384TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006385 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006386 TypeSourceInfo *AllocTypeInfo
6387 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6388 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006389 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006390
Douglas Gregora16548e2009-08-11 05:31:07 +00006391 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006392 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006393 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006394 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006395
Douglas Gregora16548e2009-08-11 05:31:07 +00006396 // Transform the placement arguments (if any).
6397 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006398 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006399 if (getDerived().TransformExprs(E->getPlacementArgs(),
6400 E->getNumPlacementArgs(), true,
6401 PlacementArgs, &ArgumentChanged))
6402 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006403
Douglas Gregorebe10102009-08-20 07:17:43 +00006404 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006405 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006406 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6407 ConstructorArgs, &ArgumentChanged))
6408 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006409
Douglas Gregord2d9da02010-02-26 00:38:10 +00006410 // Transform constructor, new operator, and delete operator.
6411 CXXConstructorDecl *Constructor = 0;
6412 if (E->getConstructor()) {
6413 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006414 getDerived().TransformDecl(E->getLocStart(),
6415 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006416 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006417 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006418 }
6419
6420 FunctionDecl *OperatorNew = 0;
6421 if (E->getOperatorNew()) {
6422 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006423 getDerived().TransformDecl(E->getLocStart(),
6424 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006425 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006426 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006427 }
6428
6429 FunctionDecl *OperatorDelete = 0;
6430 if (E->getOperatorDelete()) {
6431 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006432 getDerived().TransformDecl(E->getLocStart(),
6433 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006434 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006435 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006436 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006437
Douglas Gregora16548e2009-08-11 05:31:07 +00006438 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006439 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006440 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006441 Constructor == E->getConstructor() &&
6442 OperatorNew == E->getOperatorNew() &&
6443 OperatorDelete == E->getOperatorDelete() &&
6444 !ArgumentChanged) {
6445 // Mark any declarations we need as referenced.
6446 // FIXME: instantiation-specific.
6447 if (Constructor)
6448 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6449 if (OperatorNew)
6450 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6451 if (OperatorDelete)
6452 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006453 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006454 }
Mike Stump11289f42009-09-09 15:08:12 +00006455
Douglas Gregor0744ef62010-09-07 21:49:58 +00006456 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006457 if (!ArraySize.get()) {
6458 // If no array size was specified, but the new expression was
6459 // instantiated with an array type (e.g., "new T" where T is
6460 // instantiated with "int[4]"), extract the outer bound from the
6461 // array type as our array size. We do this with constant and
6462 // dependently-sized array types.
6463 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6464 if (!ArrayT) {
6465 // Do nothing
6466 } else if (const ConstantArrayType *ConsArrayT
6467 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006468 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006469 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6470 ConsArrayT->getSize(),
6471 SemaRef.Context.getSizeType(),
6472 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006473 AllocType = ConsArrayT->getElementType();
6474 } else if (const DependentSizedArrayType *DepArrayT
6475 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6476 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006477 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006478 AllocType = DepArrayT->getElementType();
6479 }
6480 }
6481 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006482
Douglas Gregora16548e2009-08-11 05:31:07 +00006483 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6484 E->isGlobalNew(),
6485 /*FIXME:*/E->getLocStart(),
6486 move_arg(PlacementArgs),
6487 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006488 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006489 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006490 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006491 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006492 /*FIXME:*/E->getLocStart(),
6493 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006494 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006495}
Mike Stump11289f42009-09-09 15:08:12 +00006496
Douglas Gregora16548e2009-08-11 05:31:07 +00006497template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006498ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006499TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006500 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006501 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006502 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006503
Douglas Gregord2d9da02010-02-26 00:38:10 +00006504 // Transform the delete operator, if known.
6505 FunctionDecl *OperatorDelete = 0;
6506 if (E->getOperatorDelete()) {
6507 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006508 getDerived().TransformDecl(E->getLocStart(),
6509 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006510 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006511 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006512 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006513
Douglas Gregora16548e2009-08-11 05:31:07 +00006514 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006515 Operand.get() == E->getArgument() &&
6516 OperatorDelete == E->getOperatorDelete()) {
6517 // Mark any declarations we need as referenced.
6518 // FIXME: instantiation-specific.
6519 if (OperatorDelete)
6520 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006521
6522 if (!E->getArgument()->isTypeDependent()) {
6523 QualType Destroyed = SemaRef.Context.getBaseElementType(
6524 E->getDestroyedType());
6525 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6526 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6527 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6528 SemaRef.LookupDestructor(Record));
6529 }
6530 }
6531
John McCallc3007a22010-10-26 07:05:15 +00006532 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006533 }
Mike Stump11289f42009-09-09 15:08:12 +00006534
Douglas Gregora16548e2009-08-11 05:31:07 +00006535 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6536 E->isGlobalDelete(),
6537 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006538 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006539}
Mike Stump11289f42009-09-09 15:08:12 +00006540
Douglas Gregora16548e2009-08-11 05:31:07 +00006541template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006542ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006543TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006544 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006545 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006546 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006547 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006548
John McCallba7bf592010-08-24 05:47:05 +00006549 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006550 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006551 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006552 E->getOperatorLoc(),
6553 E->isArrow()? tok::arrow : tok::period,
6554 ObjectTypePtr,
6555 MayBePseudoDestructor);
6556 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006557 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006558
John McCallba7bf592010-08-24 05:47:05 +00006559 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00006560 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6561 if (QualifierLoc) {
6562 QualifierLoc
6563 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6564 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00006565 return ExprError();
6566 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00006567 CXXScopeSpec SS;
6568 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00006569
Douglas Gregor678f90d2010-02-25 01:56:36 +00006570 PseudoDestructorTypeStorage Destroyed;
6571 if (E->getDestroyedTypeInfo()) {
6572 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006573 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00006574 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00006575 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006576 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006577 Destroyed = DestroyedTypeInfo;
6578 } else if (ObjectType->isDependentType()) {
6579 // We aren't likely to be able to resolve the identifier down to a type
6580 // now anyway, so just retain the identifier.
6581 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6582 E->getDestroyedTypeLoc());
6583 } else {
6584 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00006585 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006586 *E->getDestroyedTypeIdentifier(),
6587 E->getDestroyedTypeLoc(),
6588 /*Scope=*/0,
6589 SS, ObjectTypePtr,
6590 false);
6591 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006592 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006593
Douglas Gregor678f90d2010-02-25 01:56:36 +00006594 Destroyed
6595 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6596 E->getDestroyedTypeLoc());
6597 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006598
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006599 TypeSourceInfo *ScopeTypeInfo = 0;
6600 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006601 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006602 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006603 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006604 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006605
John McCallb268a282010-08-23 23:25:46 +00006606 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006607 E->getOperatorLoc(),
6608 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006609 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006610 ScopeTypeInfo,
6611 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006612 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006613 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006614}
Mike Stump11289f42009-09-09 15:08:12 +00006615
Douglas Gregorad8a3362009-09-04 17:36:40 +00006616template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006617ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006618TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006619 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006620 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6621 Sema::LookupOrdinaryName);
6622
6623 // Transform all the decls.
6624 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6625 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006626 NamedDecl *InstD = static_cast<NamedDecl*>(
6627 getDerived().TransformDecl(Old->getNameLoc(),
6628 *I));
John McCall84d87672009-12-10 09:41:52 +00006629 if (!InstD) {
6630 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6631 // This can happen because of dependent hiding.
6632 if (isa<UsingShadowDecl>(*I))
6633 continue;
6634 else
John McCallfaf5fb42010-08-26 23:41:50 +00006635 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006636 }
John McCalle66edc12009-11-24 19:00:30 +00006637
6638 // Expand using declarations.
6639 if (isa<UsingDecl>(InstD)) {
6640 UsingDecl *UD = cast<UsingDecl>(InstD);
6641 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6642 E = UD->shadow_end(); I != E; ++I)
6643 R.addDecl(*I);
6644 continue;
6645 }
6646
6647 R.addDecl(InstD);
6648 }
6649
6650 // Resolve a kind, but don't do any further analysis. If it's
6651 // ambiguous, the callee needs to deal with it.
6652 R.resolveKind();
6653
6654 // Rebuild the nested-name qualifier, if present.
6655 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00006656 if (Old->getQualifierLoc()) {
6657 NestedNameSpecifierLoc QualifierLoc
6658 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
6659 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006660 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006661
Douglas Gregor0da1d432011-02-28 20:01:57 +00006662 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006663 }
6664
Douglas Gregor9262f472010-04-27 18:19:34 +00006665 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006666 CXXRecordDecl *NamingClass
6667 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6668 Old->getNameLoc(),
6669 Old->getNamingClass()));
6670 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006671 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006672
Douglas Gregorda7be082010-04-27 16:10:10 +00006673 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006674 }
6675
6676 // If we have no template arguments, it's a normal declaration name.
6677 if (!Old->hasExplicitTemplateArgs())
6678 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6679
6680 // If we have template arguments, rebuild them, then rebuild the
6681 // templateid expression.
6682 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006683 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6684 Old->getNumTemplateArgs(),
6685 TransArgs))
6686 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006687
6688 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6689 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006690}
Mike Stump11289f42009-09-09 15:08:12 +00006691
Douglas Gregora16548e2009-08-11 05:31:07 +00006692template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006693ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006694TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006695 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6696 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006697 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006698
Douglas Gregora16548e2009-08-11 05:31:07 +00006699 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006700 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006701 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006702
Mike Stump11289f42009-09-09 15:08:12 +00006703 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006704 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006705 T,
6706 E->getLocEnd());
6707}
Mike Stump11289f42009-09-09 15:08:12 +00006708
Douglas Gregora16548e2009-08-11 05:31:07 +00006709template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006710ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006711TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6712 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6713 if (!LhsT)
6714 return ExprError();
6715
6716 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6717 if (!RhsT)
6718 return ExprError();
6719
6720 if (!getDerived().AlwaysRebuild() &&
6721 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6722 return SemaRef.Owned(E);
6723
6724 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6725 E->getLocStart(),
6726 LhsT, RhsT,
6727 E->getLocEnd());
6728}
6729
6730template<typename Derived>
6731ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006732TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006733 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006734 NestedNameSpecifierLoc QualifierLoc
6735 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6736 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006737 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006738
John McCall31f82722010-11-12 08:19:04 +00006739 // TODO: If this is a conversion-function-id, verify that the
6740 // destination type name (if present) resolves the same way after
6741 // instantiation as it did in the local scope.
6742
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006743 DeclarationNameInfo NameInfo
6744 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6745 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006746 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006747
John McCalle66edc12009-11-24 19:00:30 +00006748 if (!E->hasExplicitTemplateArgs()) {
6749 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006750 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006751 // Note: it is sufficient to compare the Name component of NameInfo:
6752 // if name has not changed, DNLoc has not changed either.
6753 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006754 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006755
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006756 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006757 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006758 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006759 }
John McCall6b51f282009-11-23 01:53:49 +00006760
6761 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006762 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6763 E->getNumTemplateArgs(),
6764 TransArgs))
6765 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006766
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006767 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006768 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006769 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006770}
6771
6772template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006773ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006774TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006775 // CXXConstructExprs are always implicit, so when we have a
6776 // 1-argument construction we just transform that argument.
6777 if (E->getNumArgs() == 1 ||
6778 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6779 return getDerived().TransformExpr(E->getArg(0));
6780
Douglas Gregora16548e2009-08-11 05:31:07 +00006781 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6782
6783 QualType T = getDerived().TransformType(E->getType());
6784 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006785 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006786
6787 CXXConstructorDecl *Constructor
6788 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006789 getDerived().TransformDecl(E->getLocStart(),
6790 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006791 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006792 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006793
Douglas Gregora16548e2009-08-11 05:31:07 +00006794 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006795 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006796 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6797 &ArgumentChanged))
6798 return ExprError();
6799
Douglas Gregora16548e2009-08-11 05:31:07 +00006800 if (!getDerived().AlwaysRebuild() &&
6801 T == E->getType() &&
6802 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006803 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006804 // Mark the constructor as referenced.
6805 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006806 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006807 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006808 }
Mike Stump11289f42009-09-09 15:08:12 +00006809
Douglas Gregordb121ba2009-12-14 16:27:04 +00006810 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6811 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006812 move_arg(Args),
6813 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006814 E->getConstructionKind(),
6815 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006816}
Mike Stump11289f42009-09-09 15:08:12 +00006817
Douglas Gregora16548e2009-08-11 05:31:07 +00006818/// \brief Transform a C++ temporary-binding expression.
6819///
Douglas Gregor363b1512009-12-24 18:51:59 +00006820/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6821/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006822template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006823ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006824TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006825 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006826}
Mike Stump11289f42009-09-09 15:08:12 +00006827
John McCall5d413782010-12-06 08:20:24 +00006828/// \brief Transform a C++ expression that contains cleanups that should
6829/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006830///
John McCall5d413782010-12-06 08:20:24 +00006831/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006832/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006833template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006834ExprResult
John McCall5d413782010-12-06 08:20:24 +00006835TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006836 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006837}
Mike Stump11289f42009-09-09 15:08:12 +00006838
Douglas Gregora16548e2009-08-11 05:31:07 +00006839template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006840ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006841TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006842 CXXTemporaryObjectExpr *E) {
6843 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6844 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006845 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006846
Douglas Gregora16548e2009-08-11 05:31:07 +00006847 CXXConstructorDecl *Constructor
6848 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006849 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006850 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006851 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006852 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006853
Douglas Gregora16548e2009-08-11 05:31:07 +00006854 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006855 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006856 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00006857 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6858 &ArgumentChanged))
6859 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006860
Douglas Gregora16548e2009-08-11 05:31:07 +00006861 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006862 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006863 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006864 !ArgumentChanged) {
6865 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006866 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006867 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006868 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006869
6870 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6871 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006872 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006873 E->getLocEnd());
6874}
Mike Stump11289f42009-09-09 15:08:12 +00006875
Douglas Gregora16548e2009-08-11 05:31:07 +00006876template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006877ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006878TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006879 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00006880 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6881 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006882 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006883
Douglas Gregora16548e2009-08-11 05:31:07 +00006884 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006885 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006886 Args.reserve(E->arg_size());
6887 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6888 &ArgumentChanged))
6889 return ExprError();
6890
Douglas Gregora16548e2009-08-11 05:31:07 +00006891 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006892 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006893 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006894 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006895
Douglas Gregora16548e2009-08-11 05:31:07 +00006896 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00006897 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00006898 E->getLParenLoc(),
6899 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006900 E->getRParenLoc());
6901}
Mike Stump11289f42009-09-09 15:08:12 +00006902
Douglas Gregora16548e2009-08-11 05:31:07 +00006903template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006904ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006905TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006906 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006907 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006908 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006909 Expr *OldBase;
6910 QualType BaseType;
6911 QualType ObjectType;
6912 if (!E->isImplicitAccess()) {
6913 OldBase = E->getBase();
6914 Base = getDerived().TransformExpr(OldBase);
6915 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006916 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006917
John McCall2d74de92009-12-01 22:10:20 +00006918 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00006919 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00006920 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006921 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006922 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006923 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00006924 ObjectTy,
6925 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00006926 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006927 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006928
John McCallba7bf592010-08-24 05:47:05 +00006929 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00006930 BaseType = ((Expr*) Base.get())->getType();
6931 } else {
6932 OldBase = 0;
6933 BaseType = getDerived().TransformType(E->getBaseType());
6934 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6935 }
Mike Stump11289f42009-09-09 15:08:12 +00006936
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006937 // Transform the first part of the nested-name-specifier that qualifies
6938 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006939 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006940 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00006941 E->getFirstQualifierFoundInScope(),
6942 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00006943
Douglas Gregore16af532011-02-28 18:50:33 +00006944 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006945 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00006946 QualifierLoc
6947 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
6948 ObjectType,
6949 FirstQualifierInScope);
6950 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006951 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006952 }
Mike Stump11289f42009-09-09 15:08:12 +00006953
John McCall31f82722010-11-12 08:19:04 +00006954 // TODO: If this is a conversion-function-id, verify that the
6955 // destination type name (if present) resolves the same way after
6956 // instantiation as it did in the local scope.
6957
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006958 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00006959 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006960 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006961 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006962
John McCall2d74de92009-12-01 22:10:20 +00006963 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00006964 // This is a reference to a member without an explicitly-specified
6965 // template argument list. Optimize for this common case.
6966 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00006967 Base.get() == OldBase &&
6968 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00006969 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006970 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006971 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00006972 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006973
John McCallb268a282010-08-23 23:25:46 +00006974 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006975 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00006976 E->isArrow(),
6977 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00006978 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00006979 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006980 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006981 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00006982 }
6983
John McCall6b51f282009-11-23 01:53:49 +00006984 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006985 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6986 E->getNumTemplateArgs(),
6987 TransArgs))
6988 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006989
John McCallb268a282010-08-23 23:25:46 +00006990 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006991 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006992 E->isArrow(),
6993 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00006994 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00006995 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006996 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006997 &TransArgs);
6998}
6999
7000template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007001ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007002TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007003 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007004 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007005 QualType BaseType;
7006 if (!Old->isImplicitAccess()) {
7007 Base = getDerived().TransformExpr(Old->getBase());
7008 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007009 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007010 BaseType = ((Expr*) Base.get())->getType();
7011 } else {
7012 BaseType = getDerived().TransformType(Old->getBaseType());
7013 }
John McCall10eae182009-11-30 22:42:35 +00007014
Douglas Gregor0da1d432011-02-28 20:01:57 +00007015 NestedNameSpecifierLoc QualifierLoc;
7016 if (Old->getQualifierLoc()) {
7017 QualifierLoc
7018 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7019 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007020 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007021 }
7022
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007023 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007024 Sema::LookupOrdinaryName);
7025
7026 // Transform all the decls.
7027 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7028 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007029 NamedDecl *InstD = static_cast<NamedDecl*>(
7030 getDerived().TransformDecl(Old->getMemberLoc(),
7031 *I));
John McCall84d87672009-12-10 09:41:52 +00007032 if (!InstD) {
7033 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7034 // This can happen because of dependent hiding.
7035 if (isa<UsingShadowDecl>(*I))
7036 continue;
7037 else
John McCallfaf5fb42010-08-26 23:41:50 +00007038 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00007039 }
John McCall10eae182009-11-30 22:42:35 +00007040
7041 // Expand using declarations.
7042 if (isa<UsingDecl>(InstD)) {
7043 UsingDecl *UD = cast<UsingDecl>(InstD);
7044 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7045 E = UD->shadow_end(); I != E; ++I)
7046 R.addDecl(*I);
7047 continue;
7048 }
7049
7050 R.addDecl(InstD);
7051 }
7052
7053 R.resolveKind();
7054
Douglas Gregor9262f472010-04-27 18:19:34 +00007055 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007056 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007057 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007058 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007059 Old->getMemberLoc(),
7060 Old->getNamingClass()));
7061 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007062 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007063
Douglas Gregorda7be082010-04-27 16:10:10 +00007064 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007065 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007066
John McCall10eae182009-11-30 22:42:35 +00007067 TemplateArgumentListInfo TransArgs;
7068 if (Old->hasExplicitTemplateArgs()) {
7069 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7070 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007071 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7072 Old->getNumTemplateArgs(),
7073 TransArgs))
7074 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007075 }
John McCall38836f02010-01-15 08:34:02 +00007076
7077 // FIXME: to do this check properly, we will need to preserve the
7078 // first-qualifier-in-scope here, just in case we had a dependent
7079 // base (and therefore couldn't do the check) and a
7080 // nested-name-qualifier (and therefore could do the lookup).
7081 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007082
John McCallb268a282010-08-23 23:25:46 +00007083 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007084 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007085 Old->getOperatorLoc(),
7086 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007087 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007088 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007089 R,
7090 (Old->hasExplicitTemplateArgs()
7091 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007092}
7093
7094template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007095ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007096TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7097 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7098 if (SubExpr.isInvalid())
7099 return ExprError();
7100
7101 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007102 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007103
7104 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7105}
7106
7107template<typename Derived>
7108ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007109TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007110 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7111 if (Pattern.isInvalid())
7112 return ExprError();
7113
7114 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7115 return SemaRef.Owned(E);
7116
Douglas Gregorb8840002011-01-14 21:20:45 +00007117 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7118 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007119}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007120
7121template<typename Derived>
7122ExprResult
7123TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7124 // If E is not value-dependent, then nothing will change when we transform it.
7125 // Note: This is an instantiation-centric view.
7126 if (!E->isValueDependent())
7127 return SemaRef.Owned(E);
7128
7129 // Note: None of the implementations of TryExpandParameterPacks can ever
7130 // produce a diagnostic when given only a single unexpanded parameter pack,
7131 // so
7132 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7133 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007134 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007135 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007136 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7137 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007138 ShouldExpand, RetainExpansion,
7139 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007140 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007141
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007142 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007143 return SemaRef.Owned(E);
7144
7145 // We now know the length of the parameter pack, so build a new expression
7146 // that stores that length.
7147 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7148 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007149 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007150}
7151
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007152template<typename Derived>
7153ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007154TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7155 SubstNonTypeTemplateParmPackExpr *E) {
7156 // Default behavior is to do nothing with this transformation.
7157 return SemaRef.Owned(E);
7158}
7159
7160template<typename Derived>
7161ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007162TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007163 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007164}
7165
Mike Stump11289f42009-09-09 15:08:12 +00007166template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007167ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007168TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007169 TypeSourceInfo *EncodedTypeInfo
7170 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7171 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007172 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007173
Douglas Gregora16548e2009-08-11 05:31:07 +00007174 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007175 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007176 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007177
7178 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007179 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007180 E->getRParenLoc());
7181}
Mike Stump11289f42009-09-09 15:08:12 +00007182
Douglas Gregora16548e2009-08-11 05:31:07 +00007183template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007184ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007185TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007186 // Transform arguments.
7187 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007188 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007189 Args.reserve(E->getNumArgs());
7190 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7191 &ArgChanged))
7192 return ExprError();
7193
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007194 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7195 // Class message: transform the receiver type.
7196 TypeSourceInfo *ReceiverTypeInfo
7197 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7198 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007199 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007200
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007201 // If nothing changed, just retain the existing message send.
7202 if (!getDerived().AlwaysRebuild() &&
7203 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007204 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007205
7206 // Build a new class message send.
7207 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7208 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007209 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007210 E->getMethodDecl(),
7211 E->getLeftLoc(),
7212 move_arg(Args),
7213 E->getRightLoc());
7214 }
7215
7216 // Instance message: transform the receiver
7217 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7218 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007219 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007220 = getDerived().TransformExpr(E->getInstanceReceiver());
7221 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007222 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007223
7224 // If nothing changed, just retain the existing message send.
7225 if (!getDerived().AlwaysRebuild() &&
7226 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007227 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007228
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007229 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007230 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007231 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007232 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007233 E->getMethodDecl(),
7234 E->getLeftLoc(),
7235 move_arg(Args),
7236 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007237}
7238
Mike Stump11289f42009-09-09 15:08:12 +00007239template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007240ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007241TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007242 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007243}
7244
Mike Stump11289f42009-09-09 15:08:12 +00007245template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007246ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007247TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007248 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007249}
7250
Mike Stump11289f42009-09-09 15:08:12 +00007251template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007252ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007253TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007254 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007255 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007256 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007257 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007258
7259 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007260
Douglas Gregord51d90d2010-04-26 20:11:03 +00007261 // If nothing changed, just retain the existing expression.
7262 if (!getDerived().AlwaysRebuild() &&
7263 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007264 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007265
John McCallb268a282010-08-23 23:25:46 +00007266 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007267 E->getLocation(),
7268 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007269}
7270
Mike Stump11289f42009-09-09 15:08:12 +00007271template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007272ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007273TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007274 // 'super' and types never change. Property never changes. Just
7275 // retain the existing expression.
7276 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007277 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007278
Douglas Gregor9faee212010-04-26 20:47:02 +00007279 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007280 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007281 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007282 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007283
Douglas Gregor9faee212010-04-26 20:47:02 +00007284 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007285
Douglas Gregor9faee212010-04-26 20:47:02 +00007286 // If nothing changed, just retain the existing expression.
7287 if (!getDerived().AlwaysRebuild() &&
7288 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007289 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007290
John McCallb7bd14f2010-12-02 01:19:52 +00007291 if (E->isExplicitProperty())
7292 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7293 E->getExplicitProperty(),
7294 E->getLocation());
7295
7296 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7297 E->getType(),
7298 E->getImplicitPropertyGetter(),
7299 E->getImplicitPropertySetter(),
7300 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007301}
7302
Mike Stump11289f42009-09-09 15:08:12 +00007303template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007304ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007305TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007306 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007307 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007308 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007309 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007310
Douglas Gregord51d90d2010-04-26 20:11:03 +00007311 // If nothing changed, just retain the existing expression.
7312 if (!getDerived().AlwaysRebuild() &&
7313 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007314 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007315
John McCallb268a282010-08-23 23:25:46 +00007316 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007317 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007318}
7319
Mike Stump11289f42009-09-09 15:08:12 +00007320template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007321ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007322TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007323 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007324 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007325 SubExprs.reserve(E->getNumSubExprs());
7326 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7327 SubExprs, &ArgumentChanged))
7328 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007329
Douglas Gregora16548e2009-08-11 05:31:07 +00007330 if (!getDerived().AlwaysRebuild() &&
7331 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007332 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007333
Douglas Gregora16548e2009-08-11 05:31:07 +00007334 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7335 move_arg(SubExprs),
7336 E->getRParenLoc());
7337}
7338
Mike Stump11289f42009-09-09 15:08:12 +00007339template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007340ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007341TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007342 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007343
John McCall490112f2011-02-04 18:33:18 +00007344 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7345 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7346
7347 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7348 llvm::SmallVector<ParmVarDecl*, 4> params;
7349 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007350
7351 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007352 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7353 oldBlock->param_begin(),
7354 oldBlock->param_size(),
7355 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007356 return true;
John McCall490112f2011-02-04 18:33:18 +00007357
7358 const FunctionType *exprFunctionType = E->getFunctionType();
7359 QualType exprResultType = exprFunctionType->getResultType();
7360 if (!exprResultType.isNull()) {
7361 if (!exprResultType->isDependentType())
7362 blockScope->ReturnType = exprResultType;
7363 else if (exprResultType != getSema().Context.DependentTy)
7364 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007365 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007366
7367 // If the return type has not been determined yet, leave it as a dependent
7368 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007369 if (blockScope->ReturnType.isNull())
7370 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007371
7372 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007373 if (blockScope->ReturnType->isObjCObjectType()) {
7374 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007375 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007376 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007377 return ExprError();
7378 }
John McCall3882ace2011-01-05 12:14:39 +00007379
John McCall490112f2011-02-04 18:33:18 +00007380 QualType functionType = getDerived().RebuildFunctionProtoType(
7381 blockScope->ReturnType,
7382 paramTypes.data(),
7383 paramTypes.size(),
7384 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007385 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007386 exprFunctionType->getExtInfo());
7387 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007388
7389 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007390 if (!params.empty())
7391 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007392
7393 // If the return type wasn't explicitly set, it will have been marked as a
7394 // dependent type (DependentTy); clear out the return type setting so
7395 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007396 if (blockScope->ReturnType == getSema().Context.DependentTy)
7397 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007398
John McCall3882ace2011-01-05 12:14:39 +00007399 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007400 StmtResult body = getDerived().TransformStmt(E->getBody());
7401 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007402 return ExprError();
7403
John McCall490112f2011-02-04 18:33:18 +00007404#ifndef NDEBUG
7405 // In builds with assertions, make sure that we captured everything we
7406 // captured before.
7407
7408 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7409
7410 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7411 e = oldBlock->capture_end(); i != e; ++i) {
John McCall351762c2011-02-07 10:33:21 +00007412 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007413
7414 // Ignore parameter packs.
7415 if (isa<ParmVarDecl>(oldCapture) &&
7416 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7417 continue;
7418
7419 VarDecl *newCapture =
7420 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7421 oldCapture));
John McCall351762c2011-02-07 10:33:21 +00007422 assert(blockScope->CaptureMap.count(newCapture));
John McCall490112f2011-02-04 18:33:18 +00007423 }
7424#endif
7425
7426 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7427 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007428}
7429
Mike Stump11289f42009-09-09 15:08:12 +00007430template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007431ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007432TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007433 ValueDecl *ND
7434 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7435 E->getDecl()));
7436 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007437 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007438
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007439 if (!getDerived().AlwaysRebuild() &&
7440 ND == E->getDecl()) {
7441 // Mark it referenced in the new context regardless.
7442 // FIXME: this is a bit instantiation-specific.
7443 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7444
John McCallc3007a22010-10-26 07:05:15 +00007445 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007446 }
7447
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007448 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00007449 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007450 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007451}
Mike Stump11289f42009-09-09 15:08:12 +00007452
Douglas Gregora16548e2009-08-11 05:31:07 +00007453//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007454// Type reconstruction
7455//===----------------------------------------------------------------------===//
7456
Mike Stump11289f42009-09-09 15:08:12 +00007457template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007458QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7459 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007460 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007461 getDerived().getBaseEntity());
7462}
7463
Mike Stump11289f42009-09-09 15:08:12 +00007464template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007465QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7466 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007467 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007468 getDerived().getBaseEntity());
7469}
7470
Mike Stump11289f42009-09-09 15:08:12 +00007471template<typename Derived>
7472QualType
John McCall70dd5f62009-10-30 00:06:24 +00007473TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7474 bool WrittenAsLValue,
7475 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007476 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007477 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007478}
7479
7480template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007481QualType
John McCall70dd5f62009-10-30 00:06:24 +00007482TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7483 QualType ClassType,
7484 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007485 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007486 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007487}
7488
7489template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007490QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007491TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7492 ArrayType::ArraySizeModifier SizeMod,
7493 const llvm::APInt *Size,
7494 Expr *SizeExpr,
7495 unsigned IndexTypeQuals,
7496 SourceRange BracketsRange) {
7497 if (SizeExpr || !Size)
7498 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7499 IndexTypeQuals, BracketsRange,
7500 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007501
7502 QualType Types[] = {
7503 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7504 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7505 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007506 };
7507 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7508 QualType SizeType;
7509 for (unsigned I = 0; I != NumTypes; ++I)
7510 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7511 SizeType = Types[I];
7512 break;
7513 }
Mike Stump11289f42009-09-09 15:08:12 +00007514
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007515 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7516 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007517 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007518 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007519 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007520}
Mike Stump11289f42009-09-09 15:08:12 +00007521
Douglas Gregord6ff3322009-08-04 16:50:30 +00007522template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007523QualType
7524TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007525 ArrayType::ArraySizeModifier SizeMod,
7526 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007527 unsigned IndexTypeQuals,
7528 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007529 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007530 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007531}
7532
7533template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007534QualType
Mike Stump11289f42009-09-09 15:08:12 +00007535TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007536 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007537 unsigned IndexTypeQuals,
7538 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007539 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007540 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007541}
Mike Stump11289f42009-09-09 15:08:12 +00007542
Douglas Gregord6ff3322009-08-04 16:50:30 +00007543template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007544QualType
7545TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007546 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007547 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007548 unsigned IndexTypeQuals,
7549 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007550 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007551 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007552 IndexTypeQuals, BracketsRange);
7553}
7554
7555template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007556QualType
7557TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007558 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007559 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007560 unsigned IndexTypeQuals,
7561 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007562 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007563 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007564 IndexTypeQuals, BracketsRange);
7565}
7566
7567template<typename Derived>
7568QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007569 unsigned NumElements,
7570 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007571 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007572 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007573}
Mike Stump11289f42009-09-09 15:08:12 +00007574
Douglas Gregord6ff3322009-08-04 16:50:30 +00007575template<typename Derived>
7576QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7577 unsigned NumElements,
7578 SourceLocation AttributeLoc) {
7579 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7580 NumElements, true);
7581 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007582 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7583 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007584 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007585}
Mike Stump11289f42009-09-09 15:08:12 +00007586
Douglas Gregord6ff3322009-08-04 16:50:30 +00007587template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007588QualType
7589TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007590 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007591 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007592 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007593}
Mike Stump11289f42009-09-09 15:08:12 +00007594
Douglas Gregord6ff3322009-08-04 16:50:30 +00007595template<typename Derived>
7596QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007597 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007598 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007599 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007600 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007601 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00007602 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007603 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007604 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007605 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007606 getDerived().getBaseEntity(),
7607 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007608}
Mike Stump11289f42009-09-09 15:08:12 +00007609
Douglas Gregord6ff3322009-08-04 16:50:30 +00007610template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007611QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7612 return SemaRef.Context.getFunctionNoProtoType(T);
7613}
7614
7615template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007616QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7617 assert(D && "no decl found");
7618 if (D->isInvalidDecl()) return QualType();
7619
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007620 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007621 TypeDecl *Ty;
7622 if (isa<UsingDecl>(D)) {
7623 UsingDecl *Using = cast<UsingDecl>(D);
7624 assert(Using->isTypeName() &&
7625 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7626
7627 // A valid resolved using typename decl points to exactly one type decl.
7628 assert(++Using->shadow_begin() == Using->shadow_end());
7629 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007630
John McCallb96ec562009-12-04 22:46:56 +00007631 } else {
7632 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7633 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7634 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7635 }
7636
7637 return SemaRef.Context.getTypeDeclType(Ty);
7638}
7639
7640template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007641QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7642 SourceLocation Loc) {
7643 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007644}
7645
7646template<typename Derived>
7647QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7648 return SemaRef.Context.getTypeOfType(Underlying);
7649}
7650
7651template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007652QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7653 SourceLocation Loc) {
7654 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007655}
7656
7657template<typename Derived>
7658QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007659 TemplateName Template,
7660 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00007661 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00007662 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007663}
Mike Stump11289f42009-09-09 15:08:12 +00007664
Douglas Gregor1135c352009-08-06 05:28:30 +00007665template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007666TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007667TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007668 bool TemplateKW,
7669 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00007670 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007671 Template);
7672}
7673
7674template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007675TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007676TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
7677 const IdentifierInfo &Name,
7678 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00007679 QualType ObjectType,
7680 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00007681 UnqualifiedId TemplateName;
7682 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00007683 Sema::TemplateTy Template;
7684 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00007685 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007686 SS,
Douglas Gregor9db53502011-03-02 18:07:45 +00007687 TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00007688 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007689 /*EnteringContext=*/false,
7690 Template);
John McCall31f82722010-11-12 08:19:04 +00007691 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007692}
Mike Stump11289f42009-09-09 15:08:12 +00007693
Douglas Gregora16548e2009-08-11 05:31:07 +00007694template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007695TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007696TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007697 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00007698 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007699 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00007700 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00007701 // FIXME: Bogus location information.
7702 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
7703 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007704 Sema::TemplateTy Template;
7705 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00007706 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007707 SS,
7708 Name,
John McCallba7bf592010-08-24 05:47:05 +00007709 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007710 /*EnteringContext=*/false,
7711 Template);
7712 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007713}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007714
Douglas Gregor71395fa2009-11-04 00:56:37 +00007715template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007716ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007717TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7718 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007719 Expr *OrigCallee,
7720 Expr *First,
7721 Expr *Second) {
7722 Expr *Callee = OrigCallee->IgnoreParenCasts();
7723 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007724
Douglas Gregora16548e2009-08-11 05:31:07 +00007725 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007726 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007727 if (!First->getType()->isOverloadableType() &&
7728 !Second->getType()->isOverloadableType())
7729 return getSema().CreateBuiltinArraySubscriptExpr(First,
7730 Callee->getLocStart(),
7731 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007732 } else if (Op == OO_Arrow) {
7733 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007734 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7735 } else if (Second == 0 || isPostIncDec) {
7736 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007737 // The argument is not of overloadable type, so try to create a
7738 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007739 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007740 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007741
John McCallb268a282010-08-23 23:25:46 +00007742 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007743 }
7744 } else {
John McCallb268a282010-08-23 23:25:46 +00007745 if (!First->getType()->isOverloadableType() &&
7746 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007747 // Neither of the arguments is an overloadable type, so try to
7748 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007749 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007750 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007751 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007752 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007753 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007754
Douglas Gregora16548e2009-08-11 05:31:07 +00007755 return move(Result);
7756 }
7757 }
Mike Stump11289f42009-09-09 15:08:12 +00007758
7759 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007760 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007761 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007762
John McCallb268a282010-08-23 23:25:46 +00007763 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007764 assert(ULE->requiresADL());
7765
7766 // FIXME: Do we have to check
7767 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007768 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007769 } else {
John McCallb268a282010-08-23 23:25:46 +00007770 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007771 }
Mike Stump11289f42009-09-09 15:08:12 +00007772
Douglas Gregora16548e2009-08-11 05:31:07 +00007773 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007774 Expr *Args[2] = { First, Second };
7775 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007776
Douglas Gregora16548e2009-08-11 05:31:07 +00007777 // Create the overloaded operator invocation for unary operators.
7778 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007779 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007780 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007781 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007782 }
Mike Stump11289f42009-09-09 15:08:12 +00007783
Sebastian Redladba46e2009-10-29 20:17:01 +00007784 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007785 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007786 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007787 First,
7788 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007789
Douglas Gregora16548e2009-08-11 05:31:07 +00007790 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007791 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007792 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007793 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7794 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007795 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007796
Mike Stump11289f42009-09-09 15:08:12 +00007797 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007798}
Mike Stump11289f42009-09-09 15:08:12 +00007799
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007800template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007801ExprResult
John McCallb268a282010-08-23 23:25:46 +00007802TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007803 SourceLocation OperatorLoc,
7804 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00007805 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007806 TypeSourceInfo *ScopeType,
7807 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007808 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007809 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00007810 QualType BaseType = Base->getType();
7811 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007812 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007813 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007814 !BaseType->getAs<PointerType>()->getPointeeType()
7815 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007816 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00007817 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007818 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007819 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007820 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007821 /*FIXME?*/true);
7822 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007823
Douglas Gregor678f90d2010-02-25 01:56:36 +00007824 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007825 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7826 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7827 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7828 NameInfo.setNamedTypeInfo(DestroyedType);
7829
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007830 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007831
John McCallb268a282010-08-23 23:25:46 +00007832 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007833 OperatorLoc, isArrow,
7834 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007835 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007836 /*TemplateArgs*/ 0);
7837}
7838
Douglas Gregord6ff3322009-08-04 16:50:30 +00007839} // end namespace clang
7840
7841#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H