blob: 870f992c6d718a8827f83f3a3dadfae343d2c92f [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) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004129 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4130
4131 // Substitute into the replacement type, which itself might involve something
4132 // that needs to be transformed. This only tends to occur with default
4133 // template arguments of template template parameters.
4134 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4135 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4136 if (Replacement.isNull())
4137 return QualType();
4138
4139 // Always canonicalize the replacement type.
4140 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4141 QualType Result
4142 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4143 Replacement);
4144
4145 // Propagate type-source information.
4146 SubstTemplateTypeParmTypeLoc NewTL
4147 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4148 NewTL.setNameLoc(TL.getNameLoc());
4149 return Result;
4150
John McCallcebee162009-10-18 09:09:24 +00004151}
4152
4153template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004154QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4155 TypeLocBuilder &TLB,
4156 SubstTemplateTypeParmPackTypeLoc TL) {
4157 return TransformTypeSpecType(TLB, TL);
4158}
4159
4160template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004161QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004162 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004163 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004164 const TemplateSpecializationType *T = TL.getTypePtr();
4165
Douglas Gregordf846d12011-03-02 18:46:51 +00004166 // The nested-name-specifier never matters in a TemplateSpecializationType,
4167 // because we can't have a dependent nested-name-specifier anyway.
4168 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004169 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004170 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4171 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004172 if (Template.isNull())
4173 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004174
John McCall31f82722010-11-12 08:19:04 +00004175 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4176}
4177
Douglas Gregorfe921a72010-12-20 23:36:19 +00004178namespace {
4179 /// \brief Simple iterator that traverses the template arguments in a
4180 /// container that provides a \c getArgLoc() member function.
4181 ///
4182 /// This iterator is intended to be used with the iterator form of
4183 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4184 template<typename ArgLocContainer>
4185 class TemplateArgumentLocContainerIterator {
4186 ArgLocContainer *Container;
4187 unsigned Index;
4188
4189 public:
4190 typedef TemplateArgumentLoc value_type;
4191 typedef TemplateArgumentLoc reference;
4192 typedef int difference_type;
4193 typedef std::input_iterator_tag iterator_category;
4194
4195 class pointer {
4196 TemplateArgumentLoc Arg;
4197
4198 public:
4199 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4200
4201 const TemplateArgumentLoc *operator->() const {
4202 return &Arg;
4203 }
4204 };
4205
4206
4207 TemplateArgumentLocContainerIterator() {}
4208
4209 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4210 unsigned Index)
4211 : Container(&Container), Index(Index) { }
4212
4213 TemplateArgumentLocContainerIterator &operator++() {
4214 ++Index;
4215 return *this;
4216 }
4217
4218 TemplateArgumentLocContainerIterator operator++(int) {
4219 TemplateArgumentLocContainerIterator Old(*this);
4220 ++(*this);
4221 return Old;
4222 }
4223
4224 TemplateArgumentLoc operator*() const {
4225 return Container->getArgLoc(Index);
4226 }
4227
4228 pointer operator->() const {
4229 return pointer(Container->getArgLoc(Index));
4230 }
4231
4232 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004233 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004234 return X.Container == Y.Container && X.Index == Y.Index;
4235 }
4236
4237 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004238 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004239 return !(X == Y);
4240 }
4241 };
4242}
4243
4244
John McCall31f82722010-11-12 08:19:04 +00004245template <typename Derived>
4246QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4247 TypeLocBuilder &TLB,
4248 TemplateSpecializationTypeLoc TL,
4249 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004250 TemplateArgumentListInfo NewTemplateArgs;
4251 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4252 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004253 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4254 ArgIterator;
4255 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4256 ArgIterator(TL, TL.getNumArgs()),
4257 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004258 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004259
John McCall0ad16662009-10-29 08:12:44 +00004260 // FIXME: maybe don't rebuild if all the template arguments are the same.
4261
4262 QualType Result =
4263 getDerived().RebuildTemplateSpecializationType(Template,
4264 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004265 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004266
4267 if (!Result.isNull()) {
4268 TemplateSpecializationTypeLoc NewTL
4269 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4270 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4271 NewTL.setLAngleLoc(TL.getLAngleLoc());
4272 NewTL.setRAngleLoc(TL.getRAngleLoc());
4273 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4274 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004275 }
Mike Stump11289f42009-09-09 15:08:12 +00004276
John McCall0ad16662009-10-29 08:12:44 +00004277 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004278}
Mike Stump11289f42009-09-09 15:08:12 +00004279
Douglas Gregor5a064722011-02-28 17:23:35 +00004280template <typename Derived>
4281QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4282 TypeLocBuilder &TLB,
4283 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004284 TemplateName Template,
4285 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004286 TemplateArgumentListInfo NewTemplateArgs;
4287 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4288 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4289 typedef TemplateArgumentLocContainerIterator<
4290 DependentTemplateSpecializationTypeLoc> ArgIterator;
4291 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4292 ArgIterator(TL, TL.getNumArgs()),
4293 NewTemplateArgs))
4294 return QualType();
4295
4296 // FIXME: maybe don't rebuild if all the template arguments are the same.
4297
4298 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4299 QualType Result
4300 = getSema().Context.getDependentTemplateSpecializationType(
4301 TL.getTypePtr()->getKeyword(),
4302 DTN->getQualifier(),
4303 DTN->getIdentifier(),
4304 NewTemplateArgs);
4305
4306 DependentTemplateSpecializationTypeLoc NewTL
4307 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4308 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004309
Douglas Gregora7a795b2011-03-01 20:11:18 +00004310 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004311 NewTL.setNameLoc(TL.getNameLoc());
4312 NewTL.setLAngleLoc(TL.getLAngleLoc());
4313 NewTL.setRAngleLoc(TL.getRAngleLoc());
4314 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4315 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4316 return Result;
4317 }
4318
4319 QualType Result
4320 = getDerived().RebuildTemplateSpecializationType(Template,
4321 TL.getNameLoc(),
4322 NewTemplateArgs);
4323
4324 if (!Result.isNull()) {
4325 /// FIXME: Wrap this in an elaborated-type-specifier?
4326 TemplateSpecializationTypeLoc NewTL
4327 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4328 NewTL.setTemplateNameLoc(TL.getNameLoc());
4329 NewTL.setLAngleLoc(TL.getLAngleLoc());
4330 NewTL.setRAngleLoc(TL.getRAngleLoc());
4331 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4332 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4333 }
4334
4335 return Result;
4336}
4337
Mike Stump11289f42009-09-09 15:08:12 +00004338template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004339QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004340TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004341 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004342 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004343
Douglas Gregor844cb502011-03-01 18:12:44 +00004344 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004345 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004346 if (TL.getQualifierLoc()) {
4347 QualifierLoc
4348 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4349 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004350 return QualType();
4351 }
Mike Stump11289f42009-09-09 15:08:12 +00004352
John McCall31f82722010-11-12 08:19:04 +00004353 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4354 if (NamedT.isNull())
4355 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004356
John McCall550e0c22009-10-21 00:40:46 +00004357 QualType Result = TL.getType();
4358 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004359 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004360 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004361 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004362 T->getKeyword(),
4363 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004364 if (Result.isNull())
4365 return QualType();
4366 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004367
Abramo Bagnara6150c882010-05-11 21:36:43 +00004368 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004369 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004370 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004371 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004372}
Mike Stump11289f42009-09-09 15:08:12 +00004373
4374template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004375QualType TreeTransform<Derived>::TransformAttributedType(
4376 TypeLocBuilder &TLB,
4377 AttributedTypeLoc TL) {
4378 const AttributedType *oldType = TL.getTypePtr();
4379 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4380 if (modifiedType.isNull())
4381 return QualType();
4382
4383 QualType result = TL.getType();
4384
4385 // FIXME: dependent operand expressions?
4386 if (getDerived().AlwaysRebuild() ||
4387 modifiedType != oldType->getModifiedType()) {
4388 // TODO: this is really lame; we should really be rebuilding the
4389 // equivalent type from first principles.
4390 QualType equivalentType
4391 = getDerived().TransformType(oldType->getEquivalentType());
4392 if (equivalentType.isNull())
4393 return QualType();
4394 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4395 modifiedType,
4396 equivalentType);
4397 }
4398
4399 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4400 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4401 if (TL.hasAttrOperand())
4402 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4403 if (TL.hasAttrExprOperand())
4404 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4405 else if (TL.hasAttrEnumOperand())
4406 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4407
4408 return result;
4409}
4410
4411template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004412QualType
4413TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4414 ParenTypeLoc TL) {
4415 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4416 if (Inner.isNull())
4417 return QualType();
4418
4419 QualType Result = TL.getType();
4420 if (getDerived().AlwaysRebuild() ||
4421 Inner != TL.getInnerLoc().getType()) {
4422 Result = getDerived().RebuildParenType(Inner);
4423 if (Result.isNull())
4424 return QualType();
4425 }
4426
4427 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4428 NewTL.setLParenLoc(TL.getLParenLoc());
4429 NewTL.setRParenLoc(TL.getRParenLoc());
4430 return Result;
4431}
4432
4433template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004434QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004435 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004436 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004437
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004438 NestedNameSpecifierLoc QualifierLoc
4439 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4440 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004441 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004442
John McCallc392f372010-06-11 00:33:02 +00004443 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004444 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004445 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004446 QualifierLoc,
4447 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004448 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004449 if (Result.isNull())
4450 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004451
Abramo Bagnarad7548482010-05-19 21:37:53 +00004452 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4453 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004454 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4455
Abramo Bagnarad7548482010-05-19 21:37:53 +00004456 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4457 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004458 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004459 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004460 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4461 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004462 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004463 NewTL.setNameLoc(TL.getNameLoc());
4464 }
John McCall550e0c22009-10-21 00:40:46 +00004465 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004466}
Mike Stump11289f42009-09-09 15:08:12 +00004467
Douglas Gregord6ff3322009-08-04 16:50:30 +00004468template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004469QualType TreeTransform<Derived>::
4470 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004471 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004472 NestedNameSpecifierLoc QualifierLoc;
4473 if (TL.getQualifierLoc()) {
4474 QualifierLoc
4475 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4476 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004477 return QualType();
4478 }
4479
John McCall31f82722010-11-12 08:19:04 +00004480 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004481 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004482}
4483
4484template<typename Derived>
4485QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00004486TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4487 DependentTemplateSpecializationTypeLoc TL,
4488 NestedNameSpecifierLoc QualifierLoc) {
4489 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4490
4491 TemplateArgumentListInfo NewTemplateArgs;
4492 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4493 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4494
4495 typedef TemplateArgumentLocContainerIterator<
4496 DependentTemplateSpecializationTypeLoc> ArgIterator;
4497 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4498 ArgIterator(TL, TL.getNumArgs()),
4499 NewTemplateArgs))
4500 return QualType();
4501
4502 QualType Result
4503 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4504 QualifierLoc,
4505 T->getIdentifier(),
4506 TL.getNameLoc(),
4507 NewTemplateArgs);
4508 if (Result.isNull())
4509 return QualType();
4510
4511 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4512 QualType NamedT = ElabT->getNamedType();
4513
4514 // Copy information relevant to the template specialization.
4515 TemplateSpecializationTypeLoc NamedTL
4516 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4517 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4518 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4519 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4520 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4521
4522 // Copy information relevant to the elaborated type.
4523 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4524 NewTL.setKeywordLoc(TL.getKeywordLoc());
4525 NewTL.setQualifierLoc(QualifierLoc);
4526 } else {
4527 TypeLoc NewTL(Result, TL.getOpaqueData());
4528 TLB.pushFullCopy(NewTL);
4529 }
4530 return Result;
4531}
4532
4533template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004534QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4535 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004536 QualType Pattern
4537 = getDerived().TransformType(TLB, TL.getPatternLoc());
4538 if (Pattern.isNull())
4539 return QualType();
4540
4541 QualType Result = TL.getType();
4542 if (getDerived().AlwaysRebuild() ||
4543 Pattern != TL.getPatternLoc().getType()) {
4544 Result = getDerived().RebuildPackExpansionType(Pattern,
4545 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004546 TL.getEllipsisLoc(),
4547 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004548 if (Result.isNull())
4549 return QualType();
4550 }
4551
4552 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4553 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4554 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004555}
4556
4557template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004558QualType
4559TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004560 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004561 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004562 TLB.pushFullCopy(TL);
4563 return TL.getType();
4564}
4565
4566template<typename Derived>
4567QualType
4568TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004569 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004570 // ObjCObjectType is never dependent.
4571 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004572 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004573}
Mike Stump11289f42009-09-09 15:08:12 +00004574
4575template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004576QualType
4577TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004578 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004579 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004580 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004581 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004582}
4583
Douglas Gregord6ff3322009-08-04 16:50:30 +00004584//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004585// Statement transformation
4586//===----------------------------------------------------------------------===//
4587template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004588StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004589TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004590 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004591}
4592
4593template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004594StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004595TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4596 return getDerived().TransformCompoundStmt(S, false);
4597}
4598
4599template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004600StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004601TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004602 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004603 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004604 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004605 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004606 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4607 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004608 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004609 if (Result.isInvalid()) {
4610 // Immediately fail if this was a DeclStmt, since it's very
4611 // likely that this will cause problems for future statements.
4612 if (isa<DeclStmt>(*B))
4613 return StmtError();
4614
4615 // Otherwise, just keep processing substatements and fail later.
4616 SubStmtInvalid = true;
4617 continue;
4618 }
Mike Stump11289f42009-09-09 15:08:12 +00004619
Douglas Gregorebe10102009-08-20 07:17:43 +00004620 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4621 Statements.push_back(Result.takeAs<Stmt>());
4622 }
Mike Stump11289f42009-09-09 15:08:12 +00004623
John McCall1ababa62010-08-27 19:56:05 +00004624 if (SubStmtInvalid)
4625 return StmtError();
4626
Douglas Gregorebe10102009-08-20 07:17:43 +00004627 if (!getDerived().AlwaysRebuild() &&
4628 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004629 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004630
4631 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4632 move_arg(Statements),
4633 S->getRBracLoc(),
4634 IsStmtExpr);
4635}
Mike Stump11289f42009-09-09 15:08:12 +00004636
Douglas Gregorebe10102009-08-20 07:17:43 +00004637template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004638StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004639TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004640 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004641 {
4642 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004643 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004644
Eli Friedman06577382009-11-19 03:14:00 +00004645 // Transform the left-hand case value.
4646 LHS = getDerived().TransformExpr(S->getLHS());
4647 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004648 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004649
Eli Friedman06577382009-11-19 03:14:00 +00004650 // Transform the right-hand case value (for the GNU case-range extension).
4651 RHS = getDerived().TransformExpr(S->getRHS());
4652 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004653 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004654 }
Mike Stump11289f42009-09-09 15:08:12 +00004655
Douglas Gregorebe10102009-08-20 07:17:43 +00004656 // Build the case statement.
4657 // Case statements are always rebuilt so that they will attached to their
4658 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004659 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004660 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004661 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004662 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004663 S->getColonLoc());
4664 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004665 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004666
Douglas Gregorebe10102009-08-20 07:17:43 +00004667 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004668 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004669 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004670 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004671
Douglas Gregorebe10102009-08-20 07:17:43 +00004672 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004673 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004674}
4675
4676template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004677StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004678TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004679 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004680 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004681 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004682 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004683
Douglas Gregorebe10102009-08-20 07:17:43 +00004684 // Default statements are always rebuilt
4685 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004686 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004687}
Mike Stump11289f42009-09-09 15:08:12 +00004688
Douglas Gregorebe10102009-08-20 07:17:43 +00004689template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004690StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004691TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004692 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004693 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004694 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004695
Chris Lattnercab02a62011-02-17 20:34:02 +00004696 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4697 S->getDecl());
4698 if (!LD)
4699 return StmtError();
4700
4701
Douglas Gregorebe10102009-08-20 07:17:43 +00004702 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004703 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004704 cast<LabelDecl>(LD), SourceLocation(),
4705 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004706}
Mike Stump11289f42009-09-09 15:08:12 +00004707
Douglas Gregorebe10102009-08-20 07:17:43 +00004708template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004709StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004710TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004711 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004712 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004713 VarDecl *ConditionVar = 0;
4714 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004715 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004716 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004717 getDerived().TransformDefinition(
4718 S->getConditionVariable()->getLocation(),
4719 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004720 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004721 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004722 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004723 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004724
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004725 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004726 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004727
4728 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004729 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004730 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4731 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004732 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004733 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004734
John McCallb268a282010-08-23 23:25:46 +00004735 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004736 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004737 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004738
John McCallb268a282010-08-23 23:25:46 +00004739 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4740 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004741 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004742
Douglas Gregorebe10102009-08-20 07:17:43 +00004743 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004744 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004745 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004746 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004747
Douglas Gregorebe10102009-08-20 07:17:43 +00004748 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004749 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004750 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004751 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004752
Douglas Gregorebe10102009-08-20 07:17:43 +00004753 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004754 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004755 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004756 Then.get() == S->getThen() &&
4757 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004758 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004759
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004760 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004761 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004762 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004763}
4764
4765template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004766StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004767TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004768 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004769 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004770 VarDecl *ConditionVar = 0;
4771 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004772 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004773 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004774 getDerived().TransformDefinition(
4775 S->getConditionVariable()->getLocation(),
4776 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004777 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004778 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004779 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004780 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004781
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004782 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004783 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004784 }
Mike Stump11289f42009-09-09 15:08:12 +00004785
Douglas Gregorebe10102009-08-20 07:17:43 +00004786 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004787 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004788 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004789 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004790 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004791 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004792
Douglas Gregorebe10102009-08-20 07:17:43 +00004793 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004794 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004795 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004796 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004797
Douglas Gregorebe10102009-08-20 07:17:43 +00004798 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004799 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4800 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004801}
Mike Stump11289f42009-09-09 15:08:12 +00004802
Douglas Gregorebe10102009-08-20 07:17:43 +00004803template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004804StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004805TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004806 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004807 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004808 VarDecl *ConditionVar = 0;
4809 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004810 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004811 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004812 getDerived().TransformDefinition(
4813 S->getConditionVariable()->getLocation(),
4814 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004815 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004816 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004817 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004818 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004819
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004820 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004821 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004822
4823 if (S->getCond()) {
4824 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004825 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4826 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004827 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004828 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004829 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004830 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004831 }
Mike Stump11289f42009-09-09 15:08:12 +00004832
John McCallb268a282010-08-23 23:25:46 +00004833 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4834 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004835 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004836
Douglas Gregorebe10102009-08-20 07:17:43 +00004837 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004838 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004839 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004840 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004841
Douglas Gregorebe10102009-08-20 07:17:43 +00004842 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004843 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004844 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004845 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004846 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004847
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004848 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004849 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004850}
Mike Stump11289f42009-09-09 15:08:12 +00004851
Douglas Gregorebe10102009-08-20 07:17:43 +00004852template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004853StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004854TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004855 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004856 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004857 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004858 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004859
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004860 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004861 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004862 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004863 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004864
Douglas Gregorebe10102009-08-20 07:17:43 +00004865 if (!getDerived().AlwaysRebuild() &&
4866 Cond.get() == S->getCond() &&
4867 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004868 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004869
John McCallb268a282010-08-23 23:25:46 +00004870 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4871 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004872 S->getRParenLoc());
4873}
Mike Stump11289f42009-09-09 15:08:12 +00004874
Douglas Gregorebe10102009-08-20 07:17:43 +00004875template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004876StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004877TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004878 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004879 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004880 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004881 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004882
Douglas Gregorebe10102009-08-20 07:17:43 +00004883 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004884 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004885 VarDecl *ConditionVar = 0;
4886 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004887 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004888 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004889 getDerived().TransformDefinition(
4890 S->getConditionVariable()->getLocation(),
4891 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004892 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004893 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004894 } else {
4895 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004896
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004897 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004898 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004899
4900 if (S->getCond()) {
4901 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004902 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4903 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004904 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004905 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004906
John McCallb268a282010-08-23 23:25:46 +00004907 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004908 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004909 }
Mike Stump11289f42009-09-09 15:08:12 +00004910
John McCallb268a282010-08-23 23:25:46 +00004911 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4912 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004913 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004914
Douglas Gregorebe10102009-08-20 07:17:43 +00004915 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00004916 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00004917 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004918 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004919
John McCallb268a282010-08-23 23:25:46 +00004920 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4921 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004922 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004923
Douglas Gregorebe10102009-08-20 07:17:43 +00004924 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004925 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004926 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004927 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004928
Douglas Gregorebe10102009-08-20 07:17:43 +00004929 if (!getDerived().AlwaysRebuild() &&
4930 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00004931 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004932 Inc.get() == S->getInc() &&
4933 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004934 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004935
Douglas Gregorebe10102009-08-20 07:17:43 +00004936 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004937 Init.get(), FullCond, ConditionVar,
4938 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004939}
4940
4941template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004942StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004943TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00004944 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
4945 S->getLabel());
4946 if (!LD)
4947 return StmtError();
4948
Douglas Gregorebe10102009-08-20 07:17:43 +00004949 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00004950 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004951 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00004952}
4953
4954template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004955StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004956TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004957 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00004958 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004959 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004960
Douglas Gregorebe10102009-08-20 07:17:43 +00004961 if (!getDerived().AlwaysRebuild() &&
4962 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00004963 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004964
4965 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00004966 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004967}
4968
4969template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004970StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004971TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004972 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004973}
Mike Stump11289f42009-09-09 15:08:12 +00004974
Douglas Gregorebe10102009-08-20 07:17:43 +00004975template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004976StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004977TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004978 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004979}
Mike Stump11289f42009-09-09 15:08:12 +00004980
Douglas Gregorebe10102009-08-20 07:17:43 +00004981template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004982StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004983TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004984 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00004985 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004986 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004987
Mike Stump11289f42009-09-09 15:08:12 +00004988 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00004989 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00004990 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004991}
Mike Stump11289f42009-09-09 15:08:12 +00004992
Douglas Gregorebe10102009-08-20 07:17:43 +00004993template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004994StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004995TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004996 bool DeclChanged = false;
4997 llvm::SmallVector<Decl *, 4> Decls;
4998 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4999 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005000 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5001 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005002 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005003 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005004
Douglas Gregorebe10102009-08-20 07:17:43 +00005005 if (Transformed != *D)
5006 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005007
Douglas Gregorebe10102009-08-20 07:17:43 +00005008 Decls.push_back(Transformed);
5009 }
Mike Stump11289f42009-09-09 15:08:12 +00005010
Douglas Gregorebe10102009-08-20 07:17:43 +00005011 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005012 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005013
5014 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005015 S->getStartLoc(), S->getEndLoc());
5016}
Mike Stump11289f42009-09-09 15:08:12 +00005017
Douglas Gregorebe10102009-08-20 07:17:43 +00005018template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005019StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005020TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005021
John McCall37ad5512010-08-23 06:44:23 +00005022 ASTOwningVector<Expr*> Constraints(getSema());
5023 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00005024 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005025
John McCalldadc5752010-08-24 06:29:42 +00005026 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005027 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005028
5029 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005030
Anders Carlssonaaeef072010-01-24 05:50:09 +00005031 // Go through the outputs.
5032 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005033 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005034
Anders Carlssonaaeef072010-01-24 05:50:09 +00005035 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005036 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005037
Anders Carlssonaaeef072010-01-24 05:50:09 +00005038 // Transform the output expr.
5039 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005040 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005041 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005042 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005043
Anders Carlssonaaeef072010-01-24 05:50:09 +00005044 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005045
John McCallb268a282010-08-23 23:25:46 +00005046 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005047 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005048
Anders Carlssonaaeef072010-01-24 05:50:09 +00005049 // Go through the inputs.
5050 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005051 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005052
Anders Carlssonaaeef072010-01-24 05:50:09 +00005053 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005054 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005055
Anders Carlssonaaeef072010-01-24 05:50:09 +00005056 // Transform the input expr.
5057 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005058 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005059 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005060 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005061
Anders Carlssonaaeef072010-01-24 05:50:09 +00005062 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005063
John McCallb268a282010-08-23 23:25:46 +00005064 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005065 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005066
Anders Carlssonaaeef072010-01-24 05:50:09 +00005067 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005068 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005069
5070 // Go through the clobbers.
5071 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005072 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005073
5074 // No need to transform the asm string literal.
5075 AsmString = SemaRef.Owned(S->getAsmString());
5076
5077 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5078 S->isSimple(),
5079 S->isVolatile(),
5080 S->getNumOutputs(),
5081 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005082 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005083 move_arg(Constraints),
5084 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005085 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005086 move_arg(Clobbers),
5087 S->getRParenLoc(),
5088 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005089}
5090
5091
5092template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005093StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005094TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005095 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005096 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005097 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005098 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005099
Douglas Gregor96c79492010-04-23 22:50:49 +00005100 // Transform the @catch statements (if present).
5101 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005102 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005103 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005104 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005105 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005106 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005107 if (Catch.get() != S->getCatchStmt(I))
5108 AnyCatchChanged = true;
5109 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005110 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005111
Douglas Gregor306de2f2010-04-22 23:59:56 +00005112 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005113 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005114 if (S->getFinallyStmt()) {
5115 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5116 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005117 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005118 }
5119
5120 // If nothing changed, just retain this statement.
5121 if (!getDerived().AlwaysRebuild() &&
5122 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005123 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005124 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005125 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005126
Douglas Gregor306de2f2010-04-22 23:59:56 +00005127 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005128 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5129 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005130}
Mike Stump11289f42009-09-09 15:08:12 +00005131
Douglas Gregorebe10102009-08-20 07:17:43 +00005132template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005133StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005134TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005135 // Transform the @catch parameter, if there is one.
5136 VarDecl *Var = 0;
5137 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5138 TypeSourceInfo *TSInfo = 0;
5139 if (FromVar->getTypeSourceInfo()) {
5140 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5141 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005142 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005143 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005144
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005145 QualType T;
5146 if (TSInfo)
5147 T = TSInfo->getType();
5148 else {
5149 T = getDerived().TransformType(FromVar->getType());
5150 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005151 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005152 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005153
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005154 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5155 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005156 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005157 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005158
John McCalldadc5752010-08-24 06:29:42 +00005159 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005160 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005161 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005162
5163 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005164 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005165 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005166}
Mike Stump11289f42009-09-09 15:08:12 +00005167
Douglas Gregorebe10102009-08-20 07:17:43 +00005168template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005169StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005170TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005171 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005172 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005173 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005174 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005175
Douglas Gregor306de2f2010-04-22 23:59:56 +00005176 // If nothing changed, just retain this statement.
5177 if (!getDerived().AlwaysRebuild() &&
5178 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005179 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005180
5181 // Build a new statement.
5182 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005183 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005184}
Mike Stump11289f42009-09-09 15:08:12 +00005185
Douglas Gregorebe10102009-08-20 07:17:43 +00005186template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005187StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005188TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005189 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005190 if (S->getThrowExpr()) {
5191 Operand = getDerived().TransformExpr(S->getThrowExpr());
5192 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005193 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005194 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005195
Douglas Gregor2900c162010-04-22 21:44:01 +00005196 if (!getDerived().AlwaysRebuild() &&
5197 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005198 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005199
John McCallb268a282010-08-23 23:25:46 +00005200 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005201}
Mike Stump11289f42009-09-09 15:08:12 +00005202
Douglas Gregorebe10102009-08-20 07:17:43 +00005203template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005204StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005205TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005206 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005207 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005208 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005209 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005210 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005211
Douglas Gregor6148de72010-04-22 22:01:21 +00005212 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005213 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005214 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005215 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005216
Douglas Gregor6148de72010-04-22 22:01:21 +00005217 // If nothing change, just retain the current statement.
5218 if (!getDerived().AlwaysRebuild() &&
5219 Object.get() == S->getSynchExpr() &&
5220 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005221 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005222
5223 // Build a new statement.
5224 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005225 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005226}
5227
5228template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005229StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005230TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005231 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005232 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005233 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005234 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005235 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005236
Douglas Gregorf68a5082010-04-22 23:10:45 +00005237 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005238 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005239 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005240 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005241
Douglas Gregorf68a5082010-04-22 23:10:45 +00005242 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005243 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005244 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005245 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005246
Douglas Gregorf68a5082010-04-22 23:10:45 +00005247 // If nothing changed, just retain this statement.
5248 if (!getDerived().AlwaysRebuild() &&
5249 Element.get() == S->getElement() &&
5250 Collection.get() == S->getCollection() &&
5251 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005252 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005253
Douglas Gregorf68a5082010-04-22 23:10:45 +00005254 // Build a new statement.
5255 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5256 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005257 Element.get(),
5258 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005259 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005260 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005261}
5262
5263
5264template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005265StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005266TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5267 // Transform the exception declaration, if any.
5268 VarDecl *Var = 0;
5269 if (S->getExceptionDecl()) {
5270 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005271 TypeSourceInfo *T = getDerived().TransformType(
5272 ExceptionDecl->getTypeSourceInfo());
5273 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005274 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005275
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005276 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00005277 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005278 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00005279 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005280 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005281 }
Mike Stump11289f42009-09-09 15:08:12 +00005282
Douglas Gregorebe10102009-08-20 07:17:43 +00005283 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005284 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005285 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005286 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005287
Douglas Gregorebe10102009-08-20 07:17:43 +00005288 if (!getDerived().AlwaysRebuild() &&
5289 !Var &&
5290 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005291 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005292
5293 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5294 Var,
John McCallb268a282010-08-23 23:25:46 +00005295 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005296}
Mike Stump11289f42009-09-09 15:08:12 +00005297
Douglas Gregorebe10102009-08-20 07:17:43 +00005298template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005299StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005300TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5301 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005302 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005303 = getDerived().TransformCompoundStmt(S->getTryBlock());
5304 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005305 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005306
Douglas Gregorebe10102009-08-20 07:17:43 +00005307 // Transform the handlers.
5308 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005309 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005310 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005311 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005312 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5313 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005314 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005315
Douglas Gregorebe10102009-08-20 07:17:43 +00005316 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5317 Handlers.push_back(Handler.takeAs<Stmt>());
5318 }
Mike Stump11289f42009-09-09 15:08:12 +00005319
Douglas Gregorebe10102009-08-20 07:17:43 +00005320 if (!getDerived().AlwaysRebuild() &&
5321 TryBlock.get() == S->getTryBlock() &&
5322 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005323 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005324
John McCallb268a282010-08-23 23:25:46 +00005325 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005326 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005327}
Mike Stump11289f42009-09-09 15:08:12 +00005328
Douglas Gregorebe10102009-08-20 07:17:43 +00005329//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005330// Expression transformation
5331//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005332template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005333ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005334TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005335 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005336}
Mike Stump11289f42009-09-09 15:08:12 +00005337
5338template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005339ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005340TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005341 NestedNameSpecifierLoc QualifierLoc;
5342 if (E->getQualifierLoc()) {
5343 QualifierLoc
5344 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5345 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005346 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005347 }
John McCallce546572009-12-08 09:08:17 +00005348
5349 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005350 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5351 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005352 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005353 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005354
John McCall815039a2010-08-17 21:27:17 +00005355 DeclarationNameInfo NameInfo = E->getNameInfo();
5356 if (NameInfo.getName()) {
5357 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5358 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005359 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005360 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005361
5362 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005363 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005364 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005365 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005366 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005367
5368 // Mark it referenced in the new context regardless.
5369 // FIXME: this is a bit instantiation-specific.
5370 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5371
John McCallc3007a22010-10-26 07:05:15 +00005372 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005373 }
John McCallce546572009-12-08 09:08:17 +00005374
5375 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005376 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005377 TemplateArgs = &TransArgs;
5378 TransArgs.setLAngleLoc(E->getLAngleLoc());
5379 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005380 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5381 E->getNumTemplateArgs(),
5382 TransArgs))
5383 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005384 }
5385
Douglas Gregorea972d32011-02-28 21:54:11 +00005386 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5387 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005388}
Mike Stump11289f42009-09-09 15:08:12 +00005389
Douglas Gregora16548e2009-08-11 05:31:07 +00005390template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005391ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005392TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005393 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005394}
Mike Stump11289f42009-09-09 15:08:12 +00005395
Douglas Gregora16548e2009-08-11 05:31:07 +00005396template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005397ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005398TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005399 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005400}
Mike Stump11289f42009-09-09 15:08:12 +00005401
Douglas Gregora16548e2009-08-11 05:31:07 +00005402template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005403ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005404TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005405 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005406}
Mike Stump11289f42009-09-09 15:08:12 +00005407
Douglas Gregora16548e2009-08-11 05:31:07 +00005408template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005409ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005410TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005411 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005412}
Mike Stump11289f42009-09-09 15:08:12 +00005413
Douglas Gregora16548e2009-08-11 05:31:07 +00005414template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005415ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005416TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005417 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005418}
5419
5420template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005421ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005422TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005423 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005424 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005425 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005426
Douglas Gregora16548e2009-08-11 05:31:07 +00005427 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005428 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005429
John McCallb268a282010-08-23 23:25:46 +00005430 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005431 E->getRParen());
5432}
5433
Mike Stump11289f42009-09-09 15:08:12 +00005434template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005435ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005436TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005437 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005438 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005439 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005440
Douglas Gregora16548e2009-08-11 05:31:07 +00005441 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005442 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005443
Douglas Gregora16548e2009-08-11 05:31:07 +00005444 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5445 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005446 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005447}
Mike Stump11289f42009-09-09 15:08:12 +00005448
Douglas Gregora16548e2009-08-11 05:31:07 +00005449template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005450ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005451TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5452 // Transform the type.
5453 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5454 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005455 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005456
Douglas Gregor882211c2010-04-28 22:16:22 +00005457 // Transform all of the components into components similar to what the
5458 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005459 // FIXME: It would be slightly more efficient in the non-dependent case to
5460 // just map FieldDecls, rather than requiring the rebuilder to look for
5461 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005462 // template code that we don't care.
5463 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005464 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005465 typedef OffsetOfExpr::OffsetOfNode Node;
5466 llvm::SmallVector<Component, 4> Components;
5467 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5468 const Node &ON = E->getComponent(I);
5469 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005470 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00005471 Comp.LocStart = ON.getRange().getBegin();
5472 Comp.LocEnd = ON.getRange().getEnd();
5473 switch (ON.getKind()) {
5474 case Node::Array: {
5475 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005476 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005477 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005478 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005479
Douglas Gregor882211c2010-04-28 22:16:22 +00005480 ExprChanged = ExprChanged || Index.get() != FromIndex;
5481 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005482 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005483 break;
5484 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005485
Douglas Gregor882211c2010-04-28 22:16:22 +00005486 case Node::Field:
5487 case Node::Identifier:
5488 Comp.isBrackets = false;
5489 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005490 if (!Comp.U.IdentInfo)
5491 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005492
Douglas Gregor882211c2010-04-28 22:16:22 +00005493 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005494
Douglas Gregord1702062010-04-29 00:18:15 +00005495 case Node::Base:
5496 // Will be recomputed during the rebuild.
5497 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005498 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005499
Douglas Gregor882211c2010-04-28 22:16:22 +00005500 Components.push_back(Comp);
5501 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005502
Douglas Gregor882211c2010-04-28 22:16:22 +00005503 // If nothing changed, retain the existing expression.
5504 if (!getDerived().AlwaysRebuild() &&
5505 Type == E->getTypeSourceInfo() &&
5506 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005507 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005508
Douglas Gregor882211c2010-04-28 22:16:22 +00005509 // Build a new offsetof expression.
5510 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5511 Components.data(), Components.size(),
5512 E->getRParenLoc());
5513}
5514
5515template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005516ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005517TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5518 assert(getDerived().AlreadyTransformed(E->getType()) &&
5519 "opaque value expression requires transformation");
5520 return SemaRef.Owned(E);
5521}
5522
5523template<typename Derived>
5524ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005525TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005526 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005527 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005528
John McCallbcd03502009-12-07 02:54:59 +00005529 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005530 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005531 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005532
John McCall4c98fd82009-11-04 07:28:41 +00005533 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005534 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005535
John McCall4c98fd82009-11-04 07:28:41 +00005536 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005537 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005538 E->getSourceRange());
5539 }
Mike Stump11289f42009-09-09 15:08:12 +00005540
John McCalldadc5752010-08-24 06:29:42 +00005541 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005542 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005543 // C++0x [expr.sizeof]p1:
5544 // The operand is either an expression, which is an unevaluated operand
5545 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005546 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005547
Douglas Gregora16548e2009-08-11 05:31:07 +00005548 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5549 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005550 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005551
Douglas Gregora16548e2009-08-11 05:31:07 +00005552 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005553 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005554 }
Mike Stump11289f42009-09-09 15:08:12 +00005555
John McCallb268a282010-08-23 23:25:46 +00005556 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005557 E->isSizeOf(),
5558 E->getSourceRange());
5559}
Mike Stump11289f42009-09-09 15:08:12 +00005560
Douglas Gregora16548e2009-08-11 05:31:07 +00005561template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005562ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005563TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005564 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005565 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005566 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005567
John McCalldadc5752010-08-24 06:29:42 +00005568 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005569 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005570 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005571
5572
Douglas Gregora16548e2009-08-11 05:31:07 +00005573 if (!getDerived().AlwaysRebuild() &&
5574 LHS.get() == E->getLHS() &&
5575 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005576 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005577
John McCallb268a282010-08-23 23:25:46 +00005578 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005579 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005580 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005581 E->getRBracketLoc());
5582}
Mike Stump11289f42009-09-09 15:08:12 +00005583
5584template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005585ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005586TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005587 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005588 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005589 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005590 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005591
5592 // Transform arguments.
5593 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005594 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005595 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5596 &ArgChanged))
5597 return ExprError();
5598
Douglas Gregora16548e2009-08-11 05:31:07 +00005599 if (!getDerived().AlwaysRebuild() &&
5600 Callee.get() == E->getCallee() &&
5601 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005602 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005603
Douglas Gregora16548e2009-08-11 05:31:07 +00005604 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005605 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005606 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005607 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005608 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005609 E->getRParenLoc());
5610}
Mike Stump11289f42009-09-09 15:08:12 +00005611
5612template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005613ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005614TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005615 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005616 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005617 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005618
Douglas Gregorea972d32011-02-28 21:54:11 +00005619 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005620 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005621 QualifierLoc
5622 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5623
5624 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005625 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005626 }
Mike Stump11289f42009-09-09 15:08:12 +00005627
Eli Friedman2cfcef62009-12-04 06:40:45 +00005628 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005629 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5630 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005631 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005632 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005633
John McCall16df1e52010-03-30 21:47:33 +00005634 NamedDecl *FoundDecl = E->getFoundDecl();
5635 if (FoundDecl == E->getMemberDecl()) {
5636 FoundDecl = Member;
5637 } else {
5638 FoundDecl = cast_or_null<NamedDecl>(
5639 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5640 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005641 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005642 }
5643
Douglas Gregora16548e2009-08-11 05:31:07 +00005644 if (!getDerived().AlwaysRebuild() &&
5645 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005646 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005647 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005648 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005649 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005650
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005651 // Mark it referenced in the new context regardless.
5652 // FIXME: this is a bit instantiation-specific.
5653 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005654 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005655 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005656
John McCall6b51f282009-11-23 01:53:49 +00005657 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005658 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005659 TransArgs.setLAngleLoc(E->getLAngleLoc());
5660 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005661 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5662 E->getNumTemplateArgs(),
5663 TransArgs))
5664 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005665 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005666
Douglas Gregora16548e2009-08-11 05:31:07 +00005667 // FIXME: Bogus source location for the operator
5668 SourceLocation FakeOperatorLoc
5669 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5670
John McCall38836f02010-01-15 08:34:02 +00005671 // FIXME: to do this check properly, we will need to preserve the
5672 // first-qualifier-in-scope here, just in case we had a dependent
5673 // base (and therefore couldn't do the check) and a
5674 // nested-name-qualifier (and therefore could do the lookup).
5675 NamedDecl *FirstQualifierInScope = 0;
5676
John McCallb268a282010-08-23 23:25:46 +00005677 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005678 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00005679 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005680 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005681 Member,
John McCall16df1e52010-03-30 21:47:33 +00005682 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005683 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005684 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005685 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005686}
Mike Stump11289f42009-09-09 15:08:12 +00005687
Douglas Gregora16548e2009-08-11 05:31:07 +00005688template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005689ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005690TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005691 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005692 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005693 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005694
John McCalldadc5752010-08-24 06:29:42 +00005695 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005696 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005697 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005698
Douglas Gregora16548e2009-08-11 05:31:07 +00005699 if (!getDerived().AlwaysRebuild() &&
5700 LHS.get() == E->getLHS() &&
5701 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005702 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005703
Douglas Gregora16548e2009-08-11 05:31:07 +00005704 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005705 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005706}
5707
Mike Stump11289f42009-09-09 15:08:12 +00005708template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005709ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005710TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005711 CompoundAssignOperator *E) {
5712 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005713}
Mike Stump11289f42009-09-09 15:08:12 +00005714
Douglas Gregora16548e2009-08-11 05:31:07 +00005715template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00005716ExprResult TreeTransform<Derived>::
5717TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
5718 // Just rebuild the common and RHS expressions and see whether we
5719 // get any changes.
5720
5721 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
5722 if (commonExpr.isInvalid())
5723 return ExprError();
5724
5725 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
5726 if (rhs.isInvalid())
5727 return ExprError();
5728
5729 if (!getDerived().AlwaysRebuild() &&
5730 commonExpr.get() == e->getCommon() &&
5731 rhs.get() == e->getFalseExpr())
5732 return SemaRef.Owned(e);
5733
5734 return getDerived().RebuildConditionalOperator(commonExpr.take(),
5735 e->getQuestionLoc(),
5736 0,
5737 e->getColonLoc(),
5738 rhs.get());
5739}
5740
5741template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005742ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005743TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005744 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005745 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005746 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005747
John McCalldadc5752010-08-24 06:29:42 +00005748 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005749 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005750 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005751
John McCalldadc5752010-08-24 06:29:42 +00005752 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005753 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005754 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005755
Douglas Gregora16548e2009-08-11 05:31:07 +00005756 if (!getDerived().AlwaysRebuild() &&
5757 Cond.get() == E->getCond() &&
5758 LHS.get() == E->getLHS() &&
5759 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005760 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005761
John McCallb268a282010-08-23 23:25:46 +00005762 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005763 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005764 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005765 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005766 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005767}
Mike Stump11289f42009-09-09 15:08:12 +00005768
5769template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005770ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005771TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005772 // Implicit casts are eliminated during transformation, since they
5773 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005774 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005775}
Mike Stump11289f42009-09-09 15:08:12 +00005776
Douglas Gregora16548e2009-08-11 05:31:07 +00005777template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005778ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005779TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005780 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5781 if (!Type)
5782 return ExprError();
5783
John McCalldadc5752010-08-24 06:29:42 +00005784 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005785 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005786 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005787 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005788
Douglas Gregora16548e2009-08-11 05:31:07 +00005789 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005790 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005791 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005792 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005793
John McCall97513962010-01-15 18:39:57 +00005794 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005795 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005796 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005797 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005798}
Mike Stump11289f42009-09-09 15:08:12 +00005799
Douglas Gregora16548e2009-08-11 05:31:07 +00005800template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005801ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005802TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005803 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5804 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5805 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005806 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005807
John McCalldadc5752010-08-24 06:29:42 +00005808 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005809 if (Init.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() &&
John McCalle15bbff2010-01-18 19:35:47 +00005813 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005814 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005815 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005816
John McCall5d7aa7f2010-01-19 22:33:45 +00005817 // Note: the expression type doesn't necessarily match the
5818 // type-as-written, but that's okay, because it should always be
5819 // derivable from the initializer.
5820
John McCalle15bbff2010-01-18 19:35:47 +00005821 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005822 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005823 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005824}
Mike Stump11289f42009-09-09 15:08:12 +00005825
Douglas Gregora16548e2009-08-11 05:31:07 +00005826template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005827ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005828TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005829 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005830 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005831 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005832
Douglas Gregora16548e2009-08-11 05:31:07 +00005833 if (!getDerived().AlwaysRebuild() &&
5834 Base.get() == E->getBase())
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 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005838 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005839 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005840 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005841 E->getAccessorLoc(),
5842 E->getAccessor());
5843}
Mike Stump11289f42009-09-09 15:08:12 +00005844
Douglas Gregora16548e2009-08-11 05:31:07 +00005845template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005846ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005847TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005848 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005849
John McCall37ad5512010-08-23 06:44:23 +00005850 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005851 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5852 Inits, &InitChanged))
5853 return ExprError();
5854
Douglas Gregora16548e2009-08-11 05:31:07 +00005855 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005856 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005857
Douglas Gregora16548e2009-08-11 05:31:07 +00005858 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005859 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005860}
Mike Stump11289f42009-09-09 15:08:12 +00005861
Douglas Gregora16548e2009-08-11 05:31:07 +00005862template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005863ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005864TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005865 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005866
Douglas Gregorebe10102009-08-20 07:17:43 +00005867 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005868 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005869 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005870 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005871
Douglas Gregorebe10102009-08-20 07:17:43 +00005872 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005873 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005874 bool ExprChanged = false;
5875 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5876 DEnd = E->designators_end();
5877 D != DEnd; ++D) {
5878 if (D->isFieldDesignator()) {
5879 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5880 D->getDotLoc(),
5881 D->getFieldLoc()));
5882 continue;
5883 }
Mike Stump11289f42009-09-09 15:08:12 +00005884
Douglas Gregora16548e2009-08-11 05:31:07 +00005885 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005886 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005887 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005888 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005889
5890 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005891 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005892
Douglas Gregora16548e2009-08-11 05:31:07 +00005893 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5894 ArrayExprs.push_back(Index.release());
5895 continue;
5896 }
Mike Stump11289f42009-09-09 15:08:12 +00005897
Douglas Gregora16548e2009-08-11 05:31:07 +00005898 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00005899 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00005900 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5901 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005902 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005903
John McCalldadc5752010-08-24 06:29:42 +00005904 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005905 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005906 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005907
5908 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005909 End.get(),
5910 D->getLBracketLoc(),
5911 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005912
Douglas Gregora16548e2009-08-11 05:31:07 +00005913 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5914 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00005915
Douglas Gregora16548e2009-08-11 05:31:07 +00005916 ArrayExprs.push_back(Start.release());
5917 ArrayExprs.push_back(End.release());
5918 }
Mike Stump11289f42009-09-09 15:08:12 +00005919
Douglas Gregora16548e2009-08-11 05:31:07 +00005920 if (!getDerived().AlwaysRebuild() &&
5921 Init.get() == E->getInit() &&
5922 !ExprChanged)
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().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5926 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005927 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005928}
Mike Stump11289f42009-09-09 15:08:12 +00005929
Douglas Gregora16548e2009-08-11 05:31:07 +00005930template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005931ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005932TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005933 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00005934 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005935
Douglas Gregor3da3c062009-10-28 00:29:27 +00005936 // FIXME: Will we ever have proper type location here? Will we actually
5937 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00005938 QualType T = getDerived().TransformType(E->getType());
5939 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005940 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005941
Douglas Gregora16548e2009-08-11 05:31:07 +00005942 if (!getDerived().AlwaysRebuild() &&
5943 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005944 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005945
Douglas Gregora16548e2009-08-11 05:31:07 +00005946 return getDerived().RebuildImplicitValueInitExpr(T);
5947}
Mike Stump11289f42009-09-09 15:08:12 +00005948
Douglas Gregora16548e2009-08-11 05:31:07 +00005949template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005950ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005951TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00005952 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5953 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005954 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005955
John McCalldadc5752010-08-24 06:29:42 +00005956 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005957 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005958 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005959
Douglas Gregora16548e2009-08-11 05:31:07 +00005960 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00005961 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005962 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005963 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005964
John McCallb268a282010-08-23 23:25:46 +00005965 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00005966 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005967}
5968
5969template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005970ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005971TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005972 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005973 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005974 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5975 &ArgumentChanged))
5976 return ExprError();
5977
Douglas Gregora16548e2009-08-11 05:31:07 +00005978 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5979 move_arg(Inits),
5980 E->getRParenLoc());
5981}
Mike Stump11289f42009-09-09 15:08:12 +00005982
Douglas Gregora16548e2009-08-11 05:31:07 +00005983/// \brief Transform an address-of-label expression.
5984///
5985/// By default, the transformation of an address-of-label expression always
5986/// rebuilds the expression, so that the label identifier can be resolved to
5987/// the corresponding label statement by semantic analysis.
5988template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005989ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005990TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005991 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
5992 E->getLabel());
5993 if (!LD)
5994 return ExprError();
5995
Douglas Gregora16548e2009-08-11 05:31:07 +00005996 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005997 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00005998}
Mike Stump11289f42009-09-09 15:08:12 +00005999
6000template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006001ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006002TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006003 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006004 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6005 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006006 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006007
Douglas Gregora16548e2009-08-11 05:31:07 +00006008 if (!getDerived().AlwaysRebuild() &&
6009 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006010 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006011
6012 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006013 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006014 E->getRParenLoc());
6015}
Mike Stump11289f42009-09-09 15:08:12 +00006016
Douglas Gregora16548e2009-08-11 05:31:07 +00006017template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006018ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006019TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006020 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006021 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006022 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006023
John McCalldadc5752010-08-24 06:29:42 +00006024 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006025 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006026 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006027
John McCalldadc5752010-08-24 06:29:42 +00006028 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006029 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006030 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006031
Douglas Gregora16548e2009-08-11 05:31:07 +00006032 if (!getDerived().AlwaysRebuild() &&
6033 Cond.get() == E->getCond() &&
6034 LHS.get() == E->getLHS() &&
6035 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006036 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006037
Douglas Gregora16548e2009-08-11 05:31:07 +00006038 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006039 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006040 E->getRParenLoc());
6041}
Mike Stump11289f42009-09-09 15:08:12 +00006042
Douglas Gregora16548e2009-08-11 05:31:07 +00006043template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006044ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006045TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006046 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006047}
6048
6049template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006050ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006051TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006052 switch (E->getOperator()) {
6053 case OO_New:
6054 case OO_Delete:
6055 case OO_Array_New:
6056 case OO_Array_Delete:
6057 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006058 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006059
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006060 case OO_Call: {
6061 // This is a call to an object's operator().
6062 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6063
6064 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006065 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006066 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006067 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006068
6069 // FIXME: Poor location information
6070 SourceLocation FakeLParenLoc
6071 = SemaRef.PP.getLocForEndOfToken(
6072 static_cast<Expr *>(Object.get())->getLocEnd());
6073
6074 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006075 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006076 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6077 Args))
6078 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006079
John McCallb268a282010-08-23 23:25:46 +00006080 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006081 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006082 E->getLocEnd());
6083 }
6084
6085#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6086 case OO_##Name:
6087#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6088#include "clang/Basic/OperatorKinds.def"
6089 case OO_Subscript:
6090 // Handled below.
6091 break;
6092
6093 case OO_Conditional:
6094 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006095 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006096
6097 case OO_None:
6098 case NUM_OVERLOADED_OPERATORS:
6099 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006100 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006101 }
6102
John McCalldadc5752010-08-24 06:29:42 +00006103 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006104 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006105 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006106
John McCalldadc5752010-08-24 06:29:42 +00006107 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006108 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006109 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006110
John McCalldadc5752010-08-24 06:29:42 +00006111 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006112 if (E->getNumArgs() == 2) {
6113 Second = getDerived().TransformExpr(E->getArg(1));
6114 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006115 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006116 }
Mike Stump11289f42009-09-09 15:08:12 +00006117
Douglas Gregora16548e2009-08-11 05:31:07 +00006118 if (!getDerived().AlwaysRebuild() &&
6119 Callee.get() == E->getCallee() &&
6120 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006121 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006122 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006123
Douglas Gregora16548e2009-08-11 05:31:07 +00006124 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6125 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006126 Callee.get(),
6127 First.get(),
6128 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006129}
Mike Stump11289f42009-09-09 15:08:12 +00006130
Douglas Gregora16548e2009-08-11 05:31:07 +00006131template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006132ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006133TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6134 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006135}
Mike Stump11289f42009-09-09 15:08:12 +00006136
Douglas Gregora16548e2009-08-11 05:31:07 +00006137template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006138ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006139TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6140 // Transform the callee.
6141 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6142 if (Callee.isInvalid())
6143 return ExprError();
6144
6145 // Transform exec config.
6146 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6147 if (EC.isInvalid())
6148 return ExprError();
6149
6150 // Transform arguments.
6151 bool ArgChanged = false;
6152 ASTOwningVector<Expr*> Args(SemaRef);
6153 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6154 &ArgChanged))
6155 return ExprError();
6156
6157 if (!getDerived().AlwaysRebuild() &&
6158 Callee.get() == E->getCallee() &&
6159 !ArgChanged)
6160 return SemaRef.Owned(E);
6161
6162 // FIXME: Wrong source location information for the '('.
6163 SourceLocation FakeLParenLoc
6164 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6165 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6166 move_arg(Args),
6167 E->getRParenLoc(), EC.get());
6168}
6169
6170template<typename Derived>
6171ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006172TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006173 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6174 if (!Type)
6175 return ExprError();
6176
John McCalldadc5752010-08-24 06:29:42 +00006177 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006178 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006179 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006180 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006181
Douglas Gregora16548e2009-08-11 05:31:07 +00006182 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006183 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006184 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006185 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006186
Douglas Gregora16548e2009-08-11 05:31:07 +00006187 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006188 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006189 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6190 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6191 SourceLocation FakeRParenLoc
6192 = SemaRef.PP.getLocForEndOfToken(
6193 E->getSubExpr()->getSourceRange().getEnd());
6194 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006195 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006196 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006197 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006198 FakeRAngleLoc,
6199 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006200 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006201 FakeRParenLoc);
6202}
Mike Stump11289f42009-09-09 15:08:12 +00006203
Douglas Gregora16548e2009-08-11 05:31:07 +00006204template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006205ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006206TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6207 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006208}
Mike Stump11289f42009-09-09 15:08:12 +00006209
6210template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006211ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006212TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6213 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006214}
6215
Douglas Gregora16548e2009-08-11 05:31:07 +00006216template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006217ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006218TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006219 CXXReinterpretCastExpr *E) {
6220 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006221}
Mike Stump11289f42009-09-09 15:08:12 +00006222
Douglas Gregora16548e2009-08-11 05:31:07 +00006223template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006224ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006225TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6226 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006227}
Mike Stump11289f42009-09-09 15:08:12 +00006228
Douglas Gregora16548e2009-08-11 05:31:07 +00006229template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006230ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006231TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006232 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006233 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6234 if (!Type)
6235 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006236
John McCalldadc5752010-08-24 06:29:42 +00006237 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006238 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006239 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006240 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006241
Douglas Gregora16548e2009-08-11 05:31:07 +00006242 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006243 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006244 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006245 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006246
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006247 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006248 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006249 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006250 E->getRParenLoc());
6251}
Mike Stump11289f42009-09-09 15:08:12 +00006252
Douglas Gregora16548e2009-08-11 05:31:07 +00006253template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006254ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006255TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006256 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006257 TypeSourceInfo *TInfo
6258 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6259 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006260 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006261
Douglas Gregora16548e2009-08-11 05:31:07 +00006262 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006263 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006264 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006265
Douglas Gregor9da64192010-04-26 22:37:10 +00006266 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6267 E->getLocStart(),
6268 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006269 E->getLocEnd());
6270 }
Mike Stump11289f42009-09-09 15:08:12 +00006271
Douglas Gregora16548e2009-08-11 05:31:07 +00006272 // We don't know whether the expression is potentially evaluated until
6273 // after we perform semantic analysis, so the expression is potentially
6274 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006275 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006276 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006277
John McCalldadc5752010-08-24 06:29:42 +00006278 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006279 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006280 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006281
Douglas Gregora16548e2009-08-11 05:31:07 +00006282 if (!getDerived().AlwaysRebuild() &&
6283 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006284 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006285
Douglas Gregor9da64192010-04-26 22:37:10 +00006286 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6287 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006288 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006289 E->getLocEnd());
6290}
6291
6292template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006293ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006294TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6295 if (E->isTypeOperand()) {
6296 TypeSourceInfo *TInfo
6297 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6298 if (!TInfo)
6299 return ExprError();
6300
6301 if (!getDerived().AlwaysRebuild() &&
6302 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006303 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006304
Douglas Gregor69735112011-03-06 17:40:41 +00006305 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00006306 E->getLocStart(),
6307 TInfo,
6308 E->getLocEnd());
6309 }
6310
6311 // We don't know whether the expression is potentially evaluated until
6312 // after we perform semantic analysis, so the expression is potentially
6313 // potentially evaluated.
6314 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6315
6316 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6317 if (SubExpr.isInvalid())
6318 return ExprError();
6319
6320 if (!getDerived().AlwaysRebuild() &&
6321 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006322 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006323
6324 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6325 E->getLocStart(),
6326 SubExpr.get(),
6327 E->getLocEnd());
6328}
6329
6330template<typename Derived>
6331ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006332TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006333 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006334}
Mike Stump11289f42009-09-09 15:08:12 +00006335
Douglas Gregora16548e2009-08-11 05:31:07 +00006336template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006337ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006338TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006339 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006340 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006341}
Mike Stump11289f42009-09-09 15:08:12 +00006342
Douglas Gregora16548e2009-08-11 05:31:07 +00006343template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006344ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006345TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006346 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6347 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6348 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006349
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006350 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006351 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006352
Douglas Gregorb15af892010-01-07 23:12:05 +00006353 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006354}
Mike Stump11289f42009-09-09 15:08:12 +00006355
Douglas Gregora16548e2009-08-11 05:31:07 +00006356template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006357ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006358TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006359 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006360 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006361 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006362
Douglas Gregora16548e2009-08-11 05:31:07 +00006363 if (!getDerived().AlwaysRebuild() &&
6364 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006365 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006366
John McCallb268a282010-08-23 23:25:46 +00006367 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006368}
Mike Stump11289f42009-09-09 15:08:12 +00006369
Douglas Gregora16548e2009-08-11 05:31:07 +00006370template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006371ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006372TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006373 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006374 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6375 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006376 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006377 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006378
Chandler Carruth794da4c2010-02-08 06:42:49 +00006379 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006380 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006381 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006382
Douglas Gregor033f6752009-12-23 23:03:06 +00006383 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006384}
Mike Stump11289f42009-09-09 15:08:12 +00006385
Douglas Gregora16548e2009-08-11 05:31:07 +00006386template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006387ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006388TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6389 CXXScalarValueInitExpr *E) {
6390 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6391 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006392 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006393
Douglas Gregora16548e2009-08-11 05:31:07 +00006394 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006395 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006396 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006397
Douglas Gregor2b88c112010-09-08 00:15:04 +00006398 return getDerived().RebuildCXXScalarValueInitExpr(T,
6399 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006400 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006401}
Mike Stump11289f42009-09-09 15:08:12 +00006402
Douglas Gregora16548e2009-08-11 05:31:07 +00006403template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006404ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006405TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006406 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006407 TypeSourceInfo *AllocTypeInfo
6408 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6409 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006410 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006411
Douglas Gregora16548e2009-08-11 05:31:07 +00006412 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006413 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006414 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006415 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006416
Douglas Gregora16548e2009-08-11 05:31:07 +00006417 // Transform the placement arguments (if any).
6418 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006419 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006420 if (getDerived().TransformExprs(E->getPlacementArgs(),
6421 E->getNumPlacementArgs(), true,
6422 PlacementArgs, &ArgumentChanged))
6423 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006424
Douglas Gregorebe10102009-08-20 07:17:43 +00006425 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006426 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006427 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6428 ConstructorArgs, &ArgumentChanged))
6429 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006430
Douglas Gregord2d9da02010-02-26 00:38:10 +00006431 // Transform constructor, new operator, and delete operator.
6432 CXXConstructorDecl *Constructor = 0;
6433 if (E->getConstructor()) {
6434 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006435 getDerived().TransformDecl(E->getLocStart(),
6436 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006437 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006438 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006439 }
6440
6441 FunctionDecl *OperatorNew = 0;
6442 if (E->getOperatorNew()) {
6443 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006444 getDerived().TransformDecl(E->getLocStart(),
6445 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006446 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006447 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006448 }
6449
6450 FunctionDecl *OperatorDelete = 0;
6451 if (E->getOperatorDelete()) {
6452 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006453 getDerived().TransformDecl(E->getLocStart(),
6454 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006455 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006456 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006457 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006458
Douglas Gregora16548e2009-08-11 05:31:07 +00006459 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006460 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006461 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006462 Constructor == E->getConstructor() &&
6463 OperatorNew == E->getOperatorNew() &&
6464 OperatorDelete == E->getOperatorDelete() &&
6465 !ArgumentChanged) {
6466 // Mark any declarations we need as referenced.
6467 // FIXME: instantiation-specific.
6468 if (Constructor)
6469 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6470 if (OperatorNew)
6471 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6472 if (OperatorDelete)
6473 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006474 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006475 }
Mike Stump11289f42009-09-09 15:08:12 +00006476
Douglas Gregor0744ef62010-09-07 21:49:58 +00006477 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006478 if (!ArraySize.get()) {
6479 // If no array size was specified, but the new expression was
6480 // instantiated with an array type (e.g., "new T" where T is
6481 // instantiated with "int[4]"), extract the outer bound from the
6482 // array type as our array size. We do this with constant and
6483 // dependently-sized array types.
6484 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6485 if (!ArrayT) {
6486 // Do nothing
6487 } else if (const ConstantArrayType *ConsArrayT
6488 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006489 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006490 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6491 ConsArrayT->getSize(),
6492 SemaRef.Context.getSizeType(),
6493 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006494 AllocType = ConsArrayT->getElementType();
6495 } else if (const DependentSizedArrayType *DepArrayT
6496 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6497 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006498 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006499 AllocType = DepArrayT->getElementType();
6500 }
6501 }
6502 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006503
Douglas Gregora16548e2009-08-11 05:31:07 +00006504 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6505 E->isGlobalNew(),
6506 /*FIXME:*/E->getLocStart(),
6507 move_arg(PlacementArgs),
6508 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006509 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006510 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006511 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006512 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006513 /*FIXME:*/E->getLocStart(),
6514 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006515 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006516}
Mike Stump11289f42009-09-09 15:08:12 +00006517
Douglas Gregora16548e2009-08-11 05:31:07 +00006518template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006519ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006520TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006521 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006522 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006523 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006524
Douglas Gregord2d9da02010-02-26 00:38:10 +00006525 // Transform the delete operator, if known.
6526 FunctionDecl *OperatorDelete = 0;
6527 if (E->getOperatorDelete()) {
6528 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006529 getDerived().TransformDecl(E->getLocStart(),
6530 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006531 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006532 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006533 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006534
Douglas Gregora16548e2009-08-11 05:31:07 +00006535 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006536 Operand.get() == E->getArgument() &&
6537 OperatorDelete == E->getOperatorDelete()) {
6538 // Mark any declarations we need as referenced.
6539 // FIXME: instantiation-specific.
6540 if (OperatorDelete)
6541 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006542
6543 if (!E->getArgument()->isTypeDependent()) {
6544 QualType Destroyed = SemaRef.Context.getBaseElementType(
6545 E->getDestroyedType());
6546 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6547 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6548 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6549 SemaRef.LookupDestructor(Record));
6550 }
6551 }
6552
John McCallc3007a22010-10-26 07:05:15 +00006553 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006554 }
Mike Stump11289f42009-09-09 15:08:12 +00006555
Douglas Gregora16548e2009-08-11 05:31:07 +00006556 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6557 E->isGlobalDelete(),
6558 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006559 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006560}
Mike Stump11289f42009-09-09 15:08:12 +00006561
Douglas Gregora16548e2009-08-11 05:31:07 +00006562template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006563ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006564TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006565 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006566 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006567 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006568 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006569
John McCallba7bf592010-08-24 05:47:05 +00006570 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006571 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006572 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006573 E->getOperatorLoc(),
6574 E->isArrow()? tok::arrow : tok::period,
6575 ObjectTypePtr,
6576 MayBePseudoDestructor);
6577 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006578 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006579
John McCallba7bf592010-08-24 05:47:05 +00006580 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00006581 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6582 if (QualifierLoc) {
6583 QualifierLoc
6584 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6585 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00006586 return ExprError();
6587 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00006588 CXXScopeSpec SS;
6589 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00006590
Douglas Gregor678f90d2010-02-25 01:56:36 +00006591 PseudoDestructorTypeStorage Destroyed;
6592 if (E->getDestroyedTypeInfo()) {
6593 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006594 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00006595 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00006596 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006597 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006598 Destroyed = DestroyedTypeInfo;
6599 } else if (ObjectType->isDependentType()) {
6600 // We aren't likely to be able to resolve the identifier down to a type
6601 // now anyway, so just retain the identifier.
6602 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6603 E->getDestroyedTypeLoc());
6604 } else {
6605 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00006606 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006607 *E->getDestroyedTypeIdentifier(),
6608 E->getDestroyedTypeLoc(),
6609 /*Scope=*/0,
6610 SS, ObjectTypePtr,
6611 false);
6612 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006613 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006614
Douglas Gregor678f90d2010-02-25 01:56:36 +00006615 Destroyed
6616 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6617 E->getDestroyedTypeLoc());
6618 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006619
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006620 TypeSourceInfo *ScopeTypeInfo = 0;
6621 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006622 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006623 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006624 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006625 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006626
John McCallb268a282010-08-23 23:25:46 +00006627 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006628 E->getOperatorLoc(),
6629 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006630 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006631 ScopeTypeInfo,
6632 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006633 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006634 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006635}
Mike Stump11289f42009-09-09 15:08:12 +00006636
Douglas Gregorad8a3362009-09-04 17:36:40 +00006637template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006638ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006639TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006640 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006641 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6642 Sema::LookupOrdinaryName);
6643
6644 // Transform all the decls.
6645 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6646 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006647 NamedDecl *InstD = static_cast<NamedDecl*>(
6648 getDerived().TransformDecl(Old->getNameLoc(),
6649 *I));
John McCall84d87672009-12-10 09:41:52 +00006650 if (!InstD) {
6651 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6652 // This can happen because of dependent hiding.
6653 if (isa<UsingShadowDecl>(*I))
6654 continue;
6655 else
John McCallfaf5fb42010-08-26 23:41:50 +00006656 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006657 }
John McCalle66edc12009-11-24 19:00:30 +00006658
6659 // Expand using declarations.
6660 if (isa<UsingDecl>(InstD)) {
6661 UsingDecl *UD = cast<UsingDecl>(InstD);
6662 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6663 E = UD->shadow_end(); I != E; ++I)
6664 R.addDecl(*I);
6665 continue;
6666 }
6667
6668 R.addDecl(InstD);
6669 }
6670
6671 // Resolve a kind, but don't do any further analysis. If it's
6672 // ambiguous, the callee needs to deal with it.
6673 R.resolveKind();
6674
6675 // Rebuild the nested-name qualifier, if present.
6676 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00006677 if (Old->getQualifierLoc()) {
6678 NestedNameSpecifierLoc QualifierLoc
6679 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
6680 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006681 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006682
Douglas Gregor0da1d432011-02-28 20:01:57 +00006683 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006684 }
6685
Douglas Gregor9262f472010-04-27 18:19:34 +00006686 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006687 CXXRecordDecl *NamingClass
6688 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6689 Old->getNameLoc(),
6690 Old->getNamingClass()));
6691 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006692 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006693
Douglas Gregorda7be082010-04-27 16:10:10 +00006694 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006695 }
6696
6697 // If we have no template arguments, it's a normal declaration name.
6698 if (!Old->hasExplicitTemplateArgs())
6699 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6700
6701 // If we have template arguments, rebuild them, then rebuild the
6702 // templateid expression.
6703 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006704 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6705 Old->getNumTemplateArgs(),
6706 TransArgs))
6707 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006708
6709 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6710 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006711}
Mike Stump11289f42009-09-09 15:08:12 +00006712
Douglas Gregora16548e2009-08-11 05:31:07 +00006713template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006714ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006715TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006716 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6717 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006718 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006719
Douglas Gregora16548e2009-08-11 05:31:07 +00006720 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006721 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006722 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006723
Mike Stump11289f42009-09-09 15:08:12 +00006724 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006725 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006726 T,
6727 E->getLocEnd());
6728}
Mike Stump11289f42009-09-09 15:08:12 +00006729
Douglas Gregora16548e2009-08-11 05:31:07 +00006730template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006731ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006732TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6733 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6734 if (!LhsT)
6735 return ExprError();
6736
6737 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6738 if (!RhsT)
6739 return ExprError();
6740
6741 if (!getDerived().AlwaysRebuild() &&
6742 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6743 return SemaRef.Owned(E);
6744
6745 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6746 E->getLocStart(),
6747 LhsT, RhsT,
6748 E->getLocEnd());
6749}
6750
6751template<typename Derived>
6752ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006753TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006754 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006755 NestedNameSpecifierLoc QualifierLoc
6756 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6757 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006758 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006759
John McCall31f82722010-11-12 08:19:04 +00006760 // TODO: If this is a conversion-function-id, verify that the
6761 // destination type name (if present) resolves the same way after
6762 // instantiation as it did in the local scope.
6763
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006764 DeclarationNameInfo NameInfo
6765 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6766 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006767 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006768
John McCalle66edc12009-11-24 19:00:30 +00006769 if (!E->hasExplicitTemplateArgs()) {
6770 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006771 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006772 // Note: it is sufficient to compare the Name component of NameInfo:
6773 // if name has not changed, DNLoc has not changed either.
6774 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006775 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006776
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006777 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006778 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006779 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006780 }
John McCall6b51f282009-11-23 01:53:49 +00006781
6782 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006783 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6784 E->getNumTemplateArgs(),
6785 TransArgs))
6786 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006787
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006788 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006789 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006790 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006791}
6792
6793template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006794ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006795TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006796 // CXXConstructExprs are always implicit, so when we have a
6797 // 1-argument construction we just transform that argument.
6798 if (E->getNumArgs() == 1 ||
6799 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6800 return getDerived().TransformExpr(E->getArg(0));
6801
Douglas Gregora16548e2009-08-11 05:31:07 +00006802 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6803
6804 QualType T = getDerived().TransformType(E->getType());
6805 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006806 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006807
6808 CXXConstructorDecl *Constructor
6809 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006810 getDerived().TransformDecl(E->getLocStart(),
6811 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006812 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006813 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006814
Douglas Gregora16548e2009-08-11 05:31:07 +00006815 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006816 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006817 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6818 &ArgumentChanged))
6819 return ExprError();
6820
Douglas Gregora16548e2009-08-11 05:31:07 +00006821 if (!getDerived().AlwaysRebuild() &&
6822 T == E->getType() &&
6823 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006824 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006825 // Mark the constructor as referenced.
6826 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006827 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006828 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006829 }
Mike Stump11289f42009-09-09 15:08:12 +00006830
Douglas Gregordb121ba2009-12-14 16:27:04 +00006831 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6832 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006833 move_arg(Args),
6834 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006835 E->getConstructionKind(),
6836 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006837}
Mike Stump11289f42009-09-09 15:08:12 +00006838
Douglas Gregora16548e2009-08-11 05:31:07 +00006839/// \brief Transform a C++ temporary-binding expression.
6840///
Douglas Gregor363b1512009-12-24 18:51:59 +00006841/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6842/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006843template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006844ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006845TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006846 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006847}
Mike Stump11289f42009-09-09 15:08:12 +00006848
John McCall5d413782010-12-06 08:20:24 +00006849/// \brief Transform a C++ expression that contains cleanups that should
6850/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006851///
John McCall5d413782010-12-06 08:20:24 +00006852/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006853/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006854template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006855ExprResult
John McCall5d413782010-12-06 08:20:24 +00006856TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006857 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006858}
Mike Stump11289f42009-09-09 15:08:12 +00006859
Douglas Gregora16548e2009-08-11 05:31:07 +00006860template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006861ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006862TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006863 CXXTemporaryObjectExpr *E) {
6864 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6865 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006866 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006867
Douglas Gregora16548e2009-08-11 05:31:07 +00006868 CXXConstructorDecl *Constructor
6869 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006870 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006871 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006872 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006873 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006874
Douglas Gregora16548e2009-08-11 05:31:07 +00006875 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006876 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006877 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00006878 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6879 &ArgumentChanged))
6880 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006881
Douglas Gregora16548e2009-08-11 05:31:07 +00006882 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006883 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006884 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006885 !ArgumentChanged) {
6886 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006887 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006888 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006889 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006890
6891 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6892 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006893 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006894 E->getLocEnd());
6895}
Mike Stump11289f42009-09-09 15:08:12 +00006896
Douglas Gregora16548e2009-08-11 05:31:07 +00006897template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006898ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006899TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006900 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00006901 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6902 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006903 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006904
Douglas Gregora16548e2009-08-11 05:31:07 +00006905 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006906 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006907 Args.reserve(E->arg_size());
6908 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6909 &ArgumentChanged))
6910 return ExprError();
6911
Douglas Gregora16548e2009-08-11 05:31:07 +00006912 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006913 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006914 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006915 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006916
Douglas Gregora16548e2009-08-11 05:31:07 +00006917 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00006918 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00006919 E->getLParenLoc(),
6920 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006921 E->getRParenLoc());
6922}
Mike Stump11289f42009-09-09 15:08:12 +00006923
Douglas Gregora16548e2009-08-11 05:31:07 +00006924template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006925ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006926TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006927 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006928 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006929 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006930 Expr *OldBase;
6931 QualType BaseType;
6932 QualType ObjectType;
6933 if (!E->isImplicitAccess()) {
6934 OldBase = E->getBase();
6935 Base = getDerived().TransformExpr(OldBase);
6936 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006937 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006938
John McCall2d74de92009-12-01 22:10:20 +00006939 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00006940 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00006941 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006942 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006943 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006944 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00006945 ObjectTy,
6946 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00006947 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006948 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006949
John McCallba7bf592010-08-24 05:47:05 +00006950 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00006951 BaseType = ((Expr*) Base.get())->getType();
6952 } else {
6953 OldBase = 0;
6954 BaseType = getDerived().TransformType(E->getBaseType());
6955 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6956 }
Mike Stump11289f42009-09-09 15:08:12 +00006957
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006958 // Transform the first part of the nested-name-specifier that qualifies
6959 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006960 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006961 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00006962 E->getFirstQualifierFoundInScope(),
6963 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00006964
Douglas Gregore16af532011-02-28 18:50:33 +00006965 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006966 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00006967 QualifierLoc
6968 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
6969 ObjectType,
6970 FirstQualifierInScope);
6971 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006972 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006973 }
Mike Stump11289f42009-09-09 15:08:12 +00006974
John McCall31f82722010-11-12 08:19:04 +00006975 // TODO: If this is a conversion-function-id, verify that the
6976 // destination type name (if present) resolves the same way after
6977 // instantiation as it did in the local scope.
6978
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006979 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00006980 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006981 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006982 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006983
John McCall2d74de92009-12-01 22:10:20 +00006984 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00006985 // This is a reference to a member without an explicitly-specified
6986 // template argument list. Optimize for this common case.
6987 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00006988 Base.get() == OldBase &&
6989 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00006990 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006991 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006992 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00006993 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006994
John McCallb268a282010-08-23 23:25:46 +00006995 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006996 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00006997 E->isArrow(),
6998 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00006999 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007000 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007001 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007002 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007003 }
7004
John McCall6b51f282009-11-23 01:53:49 +00007005 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007006 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7007 E->getNumTemplateArgs(),
7008 TransArgs))
7009 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007010
John McCallb268a282010-08-23 23:25:46 +00007011 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007012 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007013 E->isArrow(),
7014 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007015 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007016 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007017 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007018 &TransArgs);
7019}
7020
7021template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007022ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007023TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007024 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007025 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007026 QualType BaseType;
7027 if (!Old->isImplicitAccess()) {
7028 Base = getDerived().TransformExpr(Old->getBase());
7029 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007030 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007031 BaseType = ((Expr*) Base.get())->getType();
7032 } else {
7033 BaseType = getDerived().TransformType(Old->getBaseType());
7034 }
John McCall10eae182009-11-30 22:42:35 +00007035
Douglas Gregor0da1d432011-02-28 20:01:57 +00007036 NestedNameSpecifierLoc QualifierLoc;
7037 if (Old->getQualifierLoc()) {
7038 QualifierLoc
7039 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7040 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007041 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007042 }
7043
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007044 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007045 Sema::LookupOrdinaryName);
7046
7047 // Transform all the decls.
7048 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7049 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007050 NamedDecl *InstD = static_cast<NamedDecl*>(
7051 getDerived().TransformDecl(Old->getMemberLoc(),
7052 *I));
John McCall84d87672009-12-10 09:41:52 +00007053 if (!InstD) {
7054 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7055 // This can happen because of dependent hiding.
7056 if (isa<UsingShadowDecl>(*I))
7057 continue;
7058 else
John McCallfaf5fb42010-08-26 23:41:50 +00007059 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00007060 }
John McCall10eae182009-11-30 22:42:35 +00007061
7062 // Expand using declarations.
7063 if (isa<UsingDecl>(InstD)) {
7064 UsingDecl *UD = cast<UsingDecl>(InstD);
7065 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7066 E = UD->shadow_end(); I != E; ++I)
7067 R.addDecl(*I);
7068 continue;
7069 }
7070
7071 R.addDecl(InstD);
7072 }
7073
7074 R.resolveKind();
7075
Douglas Gregor9262f472010-04-27 18:19:34 +00007076 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007077 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007078 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007079 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007080 Old->getMemberLoc(),
7081 Old->getNamingClass()));
7082 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007083 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007084
Douglas Gregorda7be082010-04-27 16:10:10 +00007085 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007086 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007087
John McCall10eae182009-11-30 22:42:35 +00007088 TemplateArgumentListInfo TransArgs;
7089 if (Old->hasExplicitTemplateArgs()) {
7090 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7091 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007092 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7093 Old->getNumTemplateArgs(),
7094 TransArgs))
7095 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007096 }
John McCall38836f02010-01-15 08:34:02 +00007097
7098 // FIXME: to do this check properly, we will need to preserve the
7099 // first-qualifier-in-scope here, just in case we had a dependent
7100 // base (and therefore couldn't do the check) and a
7101 // nested-name-qualifier (and therefore could do the lookup).
7102 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007103
John McCallb268a282010-08-23 23:25:46 +00007104 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007105 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007106 Old->getOperatorLoc(),
7107 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007108 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007109 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007110 R,
7111 (Old->hasExplicitTemplateArgs()
7112 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007113}
7114
7115template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007116ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007117TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7118 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7119 if (SubExpr.isInvalid())
7120 return ExprError();
7121
7122 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007123 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007124
7125 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7126}
7127
7128template<typename Derived>
7129ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007130TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007131 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7132 if (Pattern.isInvalid())
7133 return ExprError();
7134
7135 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7136 return SemaRef.Owned(E);
7137
Douglas Gregorb8840002011-01-14 21:20:45 +00007138 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7139 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007140}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007141
7142template<typename Derived>
7143ExprResult
7144TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7145 // If E is not value-dependent, then nothing will change when we transform it.
7146 // Note: This is an instantiation-centric view.
7147 if (!E->isValueDependent())
7148 return SemaRef.Owned(E);
7149
7150 // Note: None of the implementations of TryExpandParameterPacks can ever
7151 // produce a diagnostic when given only a single unexpanded parameter pack,
7152 // so
7153 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7154 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007155 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007156 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007157 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7158 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007159 ShouldExpand, RetainExpansion,
7160 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007161 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007162
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007163 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007164 return SemaRef.Owned(E);
7165
7166 // We now know the length of the parameter pack, so build a new expression
7167 // that stores that length.
7168 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7169 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007170 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007171}
7172
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007173template<typename Derived>
7174ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007175TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7176 SubstNonTypeTemplateParmPackExpr *E) {
7177 // Default behavior is to do nothing with this transformation.
7178 return SemaRef.Owned(E);
7179}
7180
7181template<typename Derived>
7182ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007183TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007184 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007185}
7186
Mike Stump11289f42009-09-09 15:08:12 +00007187template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007188ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007189TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007190 TypeSourceInfo *EncodedTypeInfo
7191 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7192 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007193 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007194
Douglas Gregora16548e2009-08-11 05:31:07 +00007195 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007196 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007197 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007198
7199 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007200 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007201 E->getRParenLoc());
7202}
Mike Stump11289f42009-09-09 15:08:12 +00007203
Douglas Gregora16548e2009-08-11 05:31:07 +00007204template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007205ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007206TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007207 // Transform arguments.
7208 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007209 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007210 Args.reserve(E->getNumArgs());
7211 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7212 &ArgChanged))
7213 return ExprError();
7214
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007215 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7216 // Class message: transform the receiver type.
7217 TypeSourceInfo *ReceiverTypeInfo
7218 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7219 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007220 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007221
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007222 // If nothing changed, just retain the existing message send.
7223 if (!getDerived().AlwaysRebuild() &&
7224 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007225 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007226
7227 // Build a new class message send.
7228 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7229 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007230 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007231 E->getMethodDecl(),
7232 E->getLeftLoc(),
7233 move_arg(Args),
7234 E->getRightLoc());
7235 }
7236
7237 // Instance message: transform the receiver
7238 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7239 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007240 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007241 = getDerived().TransformExpr(E->getInstanceReceiver());
7242 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007243 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007244
7245 // If nothing changed, just retain the existing message send.
7246 if (!getDerived().AlwaysRebuild() &&
7247 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007248 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007249
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007250 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007251 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007252 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007253 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007254 E->getMethodDecl(),
7255 E->getLeftLoc(),
7256 move_arg(Args),
7257 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007258}
7259
Mike Stump11289f42009-09-09 15:08:12 +00007260template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007261ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007262TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007263 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007264}
7265
Mike Stump11289f42009-09-09 15:08:12 +00007266template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007267ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007268TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007269 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007270}
7271
Mike Stump11289f42009-09-09 15:08:12 +00007272template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007273ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007274TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007275 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007276 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007277 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007278 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007279
7280 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007281
Douglas Gregord51d90d2010-04-26 20:11:03 +00007282 // If nothing changed, just retain the existing expression.
7283 if (!getDerived().AlwaysRebuild() &&
7284 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007285 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007286
John McCallb268a282010-08-23 23:25:46 +00007287 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007288 E->getLocation(),
7289 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007290}
7291
Mike Stump11289f42009-09-09 15:08:12 +00007292template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007293ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007294TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007295 // 'super' and types never change. Property never changes. Just
7296 // retain the existing expression.
7297 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007298 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007299
Douglas Gregor9faee212010-04-26 20:47:02 +00007300 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007301 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007302 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007303 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007304
Douglas Gregor9faee212010-04-26 20:47:02 +00007305 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007306
Douglas Gregor9faee212010-04-26 20:47:02 +00007307 // If nothing changed, just retain the existing expression.
7308 if (!getDerived().AlwaysRebuild() &&
7309 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007310 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007311
John McCallb7bd14f2010-12-02 01:19:52 +00007312 if (E->isExplicitProperty())
7313 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7314 E->getExplicitProperty(),
7315 E->getLocation());
7316
7317 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7318 E->getType(),
7319 E->getImplicitPropertyGetter(),
7320 E->getImplicitPropertySetter(),
7321 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007322}
7323
Mike Stump11289f42009-09-09 15:08:12 +00007324template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007325ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007326TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007327 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007328 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007329 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007330 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007331
Douglas Gregord51d90d2010-04-26 20:11:03 +00007332 // If nothing changed, just retain the existing expression.
7333 if (!getDerived().AlwaysRebuild() &&
7334 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007335 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007336
John McCallb268a282010-08-23 23:25:46 +00007337 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007338 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007339}
7340
Mike Stump11289f42009-09-09 15:08:12 +00007341template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007342ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007343TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007344 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007345 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007346 SubExprs.reserve(E->getNumSubExprs());
7347 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7348 SubExprs, &ArgumentChanged))
7349 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007350
Douglas Gregora16548e2009-08-11 05:31:07 +00007351 if (!getDerived().AlwaysRebuild() &&
7352 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007353 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007354
Douglas Gregora16548e2009-08-11 05:31:07 +00007355 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7356 move_arg(SubExprs),
7357 E->getRParenLoc());
7358}
7359
Mike Stump11289f42009-09-09 15:08:12 +00007360template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007361ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007362TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007363 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007364
John McCall490112f2011-02-04 18:33:18 +00007365 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7366 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7367
7368 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7369 llvm::SmallVector<ParmVarDecl*, 4> params;
7370 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007371
7372 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007373 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7374 oldBlock->param_begin(),
7375 oldBlock->param_size(),
7376 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007377 return true;
John McCall490112f2011-02-04 18:33:18 +00007378
7379 const FunctionType *exprFunctionType = E->getFunctionType();
7380 QualType exprResultType = exprFunctionType->getResultType();
7381 if (!exprResultType.isNull()) {
7382 if (!exprResultType->isDependentType())
7383 blockScope->ReturnType = exprResultType;
7384 else if (exprResultType != getSema().Context.DependentTy)
7385 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007386 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007387
7388 // If the return type has not been determined yet, leave it as a dependent
7389 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007390 if (blockScope->ReturnType.isNull())
7391 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007392
7393 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007394 if (blockScope->ReturnType->isObjCObjectType()) {
7395 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007396 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007397 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007398 return ExprError();
7399 }
John McCall3882ace2011-01-05 12:14:39 +00007400
John McCall490112f2011-02-04 18:33:18 +00007401 QualType functionType = getDerived().RebuildFunctionProtoType(
7402 blockScope->ReturnType,
7403 paramTypes.data(),
7404 paramTypes.size(),
7405 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007406 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007407 exprFunctionType->getExtInfo());
7408 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007409
7410 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007411 if (!params.empty())
7412 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007413
7414 // If the return type wasn't explicitly set, it will have been marked as a
7415 // dependent type (DependentTy); clear out the return type setting so
7416 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007417 if (blockScope->ReturnType == getSema().Context.DependentTy)
7418 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007419
John McCall3882ace2011-01-05 12:14:39 +00007420 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007421 StmtResult body = getDerived().TransformStmt(E->getBody());
7422 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007423 return ExprError();
7424
John McCall490112f2011-02-04 18:33:18 +00007425#ifndef NDEBUG
7426 // In builds with assertions, make sure that we captured everything we
7427 // captured before.
7428
7429 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7430
7431 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7432 e = oldBlock->capture_end(); i != e; ++i) {
John McCall351762c2011-02-07 10:33:21 +00007433 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007434
7435 // Ignore parameter packs.
7436 if (isa<ParmVarDecl>(oldCapture) &&
7437 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7438 continue;
7439
7440 VarDecl *newCapture =
7441 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7442 oldCapture));
John McCall351762c2011-02-07 10:33:21 +00007443 assert(blockScope->CaptureMap.count(newCapture));
John McCall490112f2011-02-04 18:33:18 +00007444 }
7445#endif
7446
7447 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7448 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007449}
7450
Mike Stump11289f42009-09-09 15:08:12 +00007451template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007452ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007453TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007454 ValueDecl *ND
7455 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7456 E->getDecl()));
7457 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007458 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007459
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007460 if (!getDerived().AlwaysRebuild() &&
7461 ND == E->getDecl()) {
7462 // Mark it referenced in the new context regardless.
7463 // FIXME: this is a bit instantiation-specific.
7464 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7465
John McCallc3007a22010-10-26 07:05:15 +00007466 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007467 }
7468
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007469 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00007470 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007471 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007472}
Mike Stump11289f42009-09-09 15:08:12 +00007473
Douglas Gregora16548e2009-08-11 05:31:07 +00007474//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007475// Type reconstruction
7476//===----------------------------------------------------------------------===//
7477
Mike Stump11289f42009-09-09 15:08:12 +00007478template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007479QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7480 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007481 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007482 getDerived().getBaseEntity());
7483}
7484
Mike Stump11289f42009-09-09 15:08:12 +00007485template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007486QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7487 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007488 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007489 getDerived().getBaseEntity());
7490}
7491
Mike Stump11289f42009-09-09 15:08:12 +00007492template<typename Derived>
7493QualType
John McCall70dd5f62009-10-30 00:06:24 +00007494TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7495 bool WrittenAsLValue,
7496 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007497 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007498 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007499}
7500
7501template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007502QualType
John McCall70dd5f62009-10-30 00:06:24 +00007503TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7504 QualType ClassType,
7505 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007506 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007507 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007508}
7509
7510template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007511QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007512TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7513 ArrayType::ArraySizeModifier SizeMod,
7514 const llvm::APInt *Size,
7515 Expr *SizeExpr,
7516 unsigned IndexTypeQuals,
7517 SourceRange BracketsRange) {
7518 if (SizeExpr || !Size)
7519 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7520 IndexTypeQuals, BracketsRange,
7521 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007522
7523 QualType Types[] = {
7524 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7525 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7526 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007527 };
7528 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7529 QualType SizeType;
7530 for (unsigned I = 0; I != NumTypes; ++I)
7531 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7532 SizeType = Types[I];
7533 break;
7534 }
Mike Stump11289f42009-09-09 15:08:12 +00007535
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007536 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7537 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007538 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007539 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007540 getDerived().getBaseEntity());
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>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007546 ArrayType::ArraySizeModifier SizeMod,
7547 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007548 unsigned IndexTypeQuals,
7549 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007550 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007551 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007552}
7553
7554template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007555QualType
Mike Stump11289f42009-09-09 15:08:12 +00007556TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007557 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007558 unsigned IndexTypeQuals,
7559 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007560 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007561 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007562}
Mike Stump11289f42009-09-09 15:08:12 +00007563
Douglas Gregord6ff3322009-08-04 16:50:30 +00007564template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007565QualType
7566TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007567 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007568 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007569 unsigned IndexTypeQuals,
7570 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007571 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007572 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007573 IndexTypeQuals, BracketsRange);
7574}
7575
7576template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007577QualType
7578TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007579 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007580 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007581 unsigned IndexTypeQuals,
7582 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007583 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007584 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007585 IndexTypeQuals, BracketsRange);
7586}
7587
7588template<typename Derived>
7589QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007590 unsigned NumElements,
7591 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007592 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007593 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007594}
Mike Stump11289f42009-09-09 15:08:12 +00007595
Douglas Gregord6ff3322009-08-04 16:50:30 +00007596template<typename Derived>
7597QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7598 unsigned NumElements,
7599 SourceLocation AttributeLoc) {
7600 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7601 NumElements, true);
7602 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007603 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7604 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007605 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007606}
Mike Stump11289f42009-09-09 15:08:12 +00007607
Douglas Gregord6ff3322009-08-04 16:50:30 +00007608template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007609QualType
7610TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007611 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007612 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007613 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007614}
Mike Stump11289f42009-09-09 15:08:12 +00007615
Douglas Gregord6ff3322009-08-04 16:50:30 +00007616template<typename Derived>
7617QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007618 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007619 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007620 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007621 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007622 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00007623 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007624 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007625 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007626 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007627 getDerived().getBaseEntity(),
7628 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007629}
Mike Stump11289f42009-09-09 15:08:12 +00007630
Douglas Gregord6ff3322009-08-04 16:50:30 +00007631template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007632QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7633 return SemaRef.Context.getFunctionNoProtoType(T);
7634}
7635
7636template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007637QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7638 assert(D && "no decl found");
7639 if (D->isInvalidDecl()) return QualType();
7640
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007641 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007642 TypeDecl *Ty;
7643 if (isa<UsingDecl>(D)) {
7644 UsingDecl *Using = cast<UsingDecl>(D);
7645 assert(Using->isTypeName() &&
7646 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7647
7648 // A valid resolved using typename decl points to exactly one type decl.
7649 assert(++Using->shadow_begin() == Using->shadow_end());
7650 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007651
John McCallb96ec562009-12-04 22:46:56 +00007652 } else {
7653 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7654 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7655 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7656 }
7657
7658 return SemaRef.Context.getTypeDeclType(Ty);
7659}
7660
7661template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007662QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7663 SourceLocation Loc) {
7664 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007665}
7666
7667template<typename Derived>
7668QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7669 return SemaRef.Context.getTypeOfType(Underlying);
7670}
7671
7672template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007673QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7674 SourceLocation Loc) {
7675 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007676}
7677
7678template<typename Derived>
7679QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007680 TemplateName Template,
7681 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00007682 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00007683 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007684}
Mike Stump11289f42009-09-09 15:08:12 +00007685
Douglas Gregor1135c352009-08-06 05:28:30 +00007686template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007687TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007688TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007689 bool TemplateKW,
7690 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00007691 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007692 Template);
7693}
7694
7695template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007696TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007697TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
7698 const IdentifierInfo &Name,
7699 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00007700 QualType ObjectType,
7701 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00007702 UnqualifiedId TemplateName;
7703 TemplateName.setIdentifier(&Name, NameLoc);
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,
Douglas Gregor9db53502011-03-02 18:07:45 +00007708 TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00007709 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007710 /*EnteringContext=*/false,
7711 Template);
John McCall31f82722010-11-12 08:19:04 +00007712 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007713}
Mike Stump11289f42009-09-09 15:08:12 +00007714
Douglas Gregora16548e2009-08-11 05:31:07 +00007715template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007716TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007717TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007718 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00007719 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007720 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00007721 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00007722 // FIXME: Bogus location information.
7723 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
7724 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007725 Sema::TemplateTy Template;
7726 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00007727 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007728 SS,
7729 Name,
John McCallba7bf592010-08-24 05:47:05 +00007730 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007731 /*EnteringContext=*/false,
7732 Template);
7733 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007734}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007735
Douglas Gregor71395fa2009-11-04 00:56:37 +00007736template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007737ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007738TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7739 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007740 Expr *OrigCallee,
7741 Expr *First,
7742 Expr *Second) {
7743 Expr *Callee = OrigCallee->IgnoreParenCasts();
7744 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007745
Douglas Gregora16548e2009-08-11 05:31:07 +00007746 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007747 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007748 if (!First->getType()->isOverloadableType() &&
7749 !Second->getType()->isOverloadableType())
7750 return getSema().CreateBuiltinArraySubscriptExpr(First,
7751 Callee->getLocStart(),
7752 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007753 } else if (Op == OO_Arrow) {
7754 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007755 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7756 } else if (Second == 0 || isPostIncDec) {
7757 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007758 // The argument is not of overloadable type, so try to create a
7759 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007760 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007761 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007762
John McCallb268a282010-08-23 23:25:46 +00007763 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007764 }
7765 } else {
John McCallb268a282010-08-23 23:25:46 +00007766 if (!First->getType()->isOverloadableType() &&
7767 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007768 // Neither of the arguments is an overloadable type, so try to
7769 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007770 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007771 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007772 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007773 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007774 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007775
Douglas Gregora16548e2009-08-11 05:31:07 +00007776 return move(Result);
7777 }
7778 }
Mike Stump11289f42009-09-09 15:08:12 +00007779
7780 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007781 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007782 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007783
John McCallb268a282010-08-23 23:25:46 +00007784 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007785 assert(ULE->requiresADL());
7786
7787 // FIXME: Do we have to check
7788 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007789 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007790 } else {
John McCallb268a282010-08-23 23:25:46 +00007791 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007792 }
Mike Stump11289f42009-09-09 15:08:12 +00007793
Douglas Gregora16548e2009-08-11 05:31:07 +00007794 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007795 Expr *Args[2] = { First, Second };
7796 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007797
Douglas Gregora16548e2009-08-11 05:31:07 +00007798 // Create the overloaded operator invocation for unary operators.
7799 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007800 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007801 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007802 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007803 }
Mike Stump11289f42009-09-09 15:08:12 +00007804
Sebastian Redladba46e2009-10-29 20:17:01 +00007805 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007806 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007807 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007808 First,
7809 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007810
Douglas Gregora16548e2009-08-11 05:31:07 +00007811 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007812 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007813 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007814 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7815 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007816 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007817
Mike Stump11289f42009-09-09 15:08:12 +00007818 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007819}
Mike Stump11289f42009-09-09 15:08:12 +00007820
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007821template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007822ExprResult
John McCallb268a282010-08-23 23:25:46 +00007823TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007824 SourceLocation OperatorLoc,
7825 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00007826 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007827 TypeSourceInfo *ScopeType,
7828 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007829 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007830 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00007831 QualType BaseType = Base->getType();
7832 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007833 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007834 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007835 !BaseType->getAs<PointerType>()->getPointeeType()
7836 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007837 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00007838 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007839 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007840 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007841 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007842 /*FIXME?*/true);
7843 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007844
Douglas Gregor678f90d2010-02-25 01:56:36 +00007845 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007846 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7847 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7848 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7849 NameInfo.setNamedTypeInfo(DestroyedType);
7850
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007851 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007852
John McCallb268a282010-08-23 23:25:46 +00007853 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007854 OperatorLoc, isArrow,
7855 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007856 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007857 /*TemplateArgs*/ 0);
7858}
7859
Douglas Gregord6ff3322009-08-04 16:50:30 +00007860} // end namespace clang
7861
7862#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H