blob: 2a71e14265a8c7ec481b097b3b8dba417bc75184 [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 Wiegley1c0675e2011-04-28 01:08:34 +0000493 StmtResult
494 TransformSEHHandler(Stmt *Handler);
495
John McCall31f82722010-11-12 08:19:04 +0000496 QualType
497 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
498 TemplateSpecializationTypeLoc TL,
499 TemplateName Template);
500
501 QualType
502 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
503 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000504 TemplateName Template,
505 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000506
507 QualType
508 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000509 DependentTemplateSpecializationTypeLoc TL,
510 NestedNameSpecifierLoc QualifierLoc);
511
John McCall58f10c32010-03-11 09:03:00 +0000512 /// \brief Transforms the parameters of a function type into the
513 /// given vectors.
514 ///
515 /// The result vectors should be kept in sync; null entries in the
516 /// variables vector are acceptable.
517 ///
518 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000519 bool TransformFunctionTypeParams(SourceLocation Loc,
520 ParmVarDecl **Params, unsigned NumParams,
521 const QualType *ParamTypes,
John McCall58f10c32010-03-11 09:03:00 +0000522 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregordd472162011-01-07 00:20:55 +0000523 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000524
525 /// \brief Transforms a single function-type parameter. Return null
526 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000527 ///
528 /// \param indexAdjustment - A number to add to the parameter's
529 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000530 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000531 int indexAdjustment,
Douglas Gregor715e4612011-01-14 22:40:04 +0000532 llvm::Optional<unsigned> NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +0000533
John McCall31f82722010-11-12 08:19:04 +0000534 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000535
John McCalldadc5752010-08-24 06:29:42 +0000536 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
537 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000538
Douglas Gregorebe10102009-08-20 07:17:43 +0000539#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000540 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000541#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000542 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000543#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000544#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000545
Douglas Gregord6ff3322009-08-04 16:50:30 +0000546 /// \brief Build a new pointer type given its pointee type.
547 ///
548 /// By default, performs semantic analysis when building the pointer type.
549 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000550 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000551
552 /// \brief Build a new block pointer type given its pointee type.
553 ///
Mike Stump11289f42009-09-09 15:08:12 +0000554 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000555 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000556 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000557
John McCall70dd5f62009-10-30 00:06:24 +0000558 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000559 ///
John McCall70dd5f62009-10-30 00:06:24 +0000560 /// By default, performs semantic analysis when building the
561 /// reference type. Subclasses may override this routine to provide
562 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000563 ///
John McCall70dd5f62009-10-30 00:06:24 +0000564 /// \param LValue whether the type was written with an lvalue sigil
565 /// or an rvalue sigil.
566 QualType RebuildReferenceType(QualType ReferentType,
567 bool LValue,
568 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000569
Douglas Gregord6ff3322009-08-04 16:50:30 +0000570 /// \brief Build a new member pointer type given the pointee type and the
571 /// class type it refers into.
572 ///
573 /// By default, performs semantic analysis when building the member pointer
574 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000575 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
576 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000577
Douglas Gregord6ff3322009-08-04 16:50:30 +0000578 /// \brief Build a new array type given the element type, size
579 /// modifier, size of the array (if known), size expression, and index type
580 /// qualifiers.
581 ///
582 /// By default, performs semantic analysis when building the array type.
583 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000584 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000585 QualType RebuildArrayType(QualType ElementType,
586 ArrayType::ArraySizeModifier SizeMod,
587 const llvm::APInt *Size,
588 Expr *SizeExpr,
589 unsigned IndexTypeQuals,
590 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000591
Douglas Gregord6ff3322009-08-04 16:50:30 +0000592 /// \brief Build a new constant array type given the element type, size
593 /// modifier, (known) size of the array, and index type qualifiers.
594 ///
595 /// By default, performs semantic analysis when building the array type.
596 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000597 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000598 ArrayType::ArraySizeModifier SizeMod,
599 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000600 unsigned IndexTypeQuals,
601 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000602
Douglas Gregord6ff3322009-08-04 16:50:30 +0000603 /// \brief Build a new incomplete array type given the element type, size
604 /// modifier, and index type qualifiers.
605 ///
606 /// By default, performs semantic analysis when building the array type.
607 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000608 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000609 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000610 unsigned IndexTypeQuals,
611 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000612
Mike Stump11289f42009-09-09 15:08:12 +0000613 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000614 /// size modifier, size expression, and index type qualifiers.
615 ///
616 /// By default, performs semantic analysis when building the array type.
617 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000618 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000619 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000620 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000621 unsigned IndexTypeQuals,
622 SourceRange BracketsRange);
623
Mike Stump11289f42009-09-09 15:08:12 +0000624 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000625 /// size modifier, size expression, and index type qualifiers.
626 ///
627 /// By default, performs semantic analysis when building the array type.
628 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000629 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000630 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000631 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000632 unsigned IndexTypeQuals,
633 SourceRange BracketsRange);
634
635 /// \brief Build a new vector type given the element type and
636 /// number of elements.
637 ///
638 /// By default, performs semantic analysis when building the vector type.
639 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000640 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000641 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000642
Douglas Gregord6ff3322009-08-04 16:50:30 +0000643 /// \brief Build a new extended vector type given the element type and
644 /// number of elements.
645 ///
646 /// By default, performs semantic analysis when building the vector type.
647 /// Subclasses may override this routine to provide different behavior.
648 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
649 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000650
651 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000652 /// given the element type and number of elements.
653 ///
654 /// By default, performs semantic analysis when building the vector type.
655 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000656 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000657 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000658 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000659
Douglas Gregord6ff3322009-08-04 16:50:30 +0000660 /// \brief Build a new function type.
661 ///
662 /// By default, performs semantic analysis when building the function type.
663 /// Subclasses may override this routine to provide different behavior.
664 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000665 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000666 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000667 bool Variadic, unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +0000668 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +0000669 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000670
John McCall550e0c22009-10-21 00:40:46 +0000671 /// \brief Build a new unprototyped function type.
672 QualType RebuildFunctionNoProtoType(QualType ResultType);
673
John McCallb96ec562009-12-04 22:46:56 +0000674 /// \brief Rebuild an unresolved typename type, given the decl that
675 /// the UnresolvedUsingTypenameDecl was transformed to.
676 QualType RebuildUnresolvedUsingType(Decl *D);
677
Douglas Gregord6ff3322009-08-04 16:50:30 +0000678 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000679 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000680 return SemaRef.Context.getTypeDeclType(Typedef);
681 }
682
683 /// \brief Build a new class/struct/union type.
684 QualType RebuildRecordType(RecordDecl *Record) {
685 return SemaRef.Context.getTypeDeclType(Record);
686 }
687
688 /// \brief Build a new Enum type.
689 QualType RebuildEnumType(EnumDecl *Enum) {
690 return SemaRef.Context.getTypeDeclType(Enum);
691 }
John McCallfcc33b02009-09-05 00:15:47 +0000692
Mike Stump11289f42009-09-09 15:08:12 +0000693 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000694 ///
695 /// By default, performs semantic analysis when building the typeof type.
696 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000697 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000698
Mike Stump11289f42009-09-09 15:08:12 +0000699 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000700 ///
701 /// By default, builds a new TypeOfType with the given underlying type.
702 QualType RebuildTypeOfType(QualType Underlying);
703
Mike Stump11289f42009-09-09 15:08:12 +0000704 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000705 ///
706 /// By default, performs semantic analysis when building the decltype type.
707 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000708 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000709
Richard Smith30482bc2011-02-20 03:19:35 +0000710 /// \brief Build a new C++0x auto type.
711 ///
712 /// By default, builds a new AutoType with the given deduced type.
713 QualType RebuildAutoType(QualType Deduced) {
714 return SemaRef.Context.getAutoType(Deduced);
715 }
716
Douglas Gregord6ff3322009-08-04 16:50:30 +0000717 /// \brief Build a new template specialization type.
718 ///
719 /// By default, performs semantic analysis when building the template
720 /// specialization type. Subclasses may override this routine to provide
721 /// different behavior.
722 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000723 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000724 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000725
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000726 /// \brief Build a new parenthesized type.
727 ///
728 /// By default, builds a new ParenType type from the inner type.
729 /// Subclasses may override this routine to provide different behavior.
730 QualType RebuildParenType(QualType InnerType) {
731 return SemaRef.Context.getParenType(InnerType);
732 }
733
Douglas Gregord6ff3322009-08-04 16:50:30 +0000734 /// \brief Build a new qualified name type.
735 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000736 /// By default, builds a new ElaboratedType type from the keyword,
737 /// the nested-name-specifier and the named type.
738 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000739 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
740 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000741 NestedNameSpecifierLoc QualifierLoc,
742 QualType Named) {
743 return SemaRef.Context.getElaboratedType(Keyword,
744 QualifierLoc.getNestedNameSpecifier(),
745 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000746 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000747
748 /// \brief Build a new typename type that refers to a template-id.
749 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000750 /// By default, builds a new DependentNameType type from the
751 /// nested-name-specifier and the given type. Subclasses may override
752 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000753 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000754 ElaboratedTypeKeyword Keyword,
755 NestedNameSpecifierLoc QualifierLoc,
756 const IdentifierInfo *Name,
757 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000758 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000759 // Rebuild the template name.
760 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000761 CXXScopeSpec SS;
762 SS.Adopt(QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000763 TemplateName InstName
Douglas Gregor9db53502011-03-02 18:07:45 +0000764 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000765
766 if (InstName.isNull())
767 return QualType();
768
769 // If it's still dependent, make a dependent specialization.
770 if (InstName.getAsDependentTemplateName())
771 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
772 QualifierLoc.getNestedNameSpecifier(),
773 Name,
774 Args);
775
776 // Otherwise, make an elaborated type wrapping a non-dependent
777 // specialization.
778 QualType T =
779 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
780 if (T.isNull()) return QualType();
781
782 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
783 return T;
784
785 return SemaRef.Context.getElaboratedType(Keyword,
786 QualifierLoc.getNestedNameSpecifier(),
787 T);
788 }
789
Douglas Gregord6ff3322009-08-04 16:50:30 +0000790 /// \brief Build a new typename type that refers to an identifier.
791 ///
792 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000793 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000794 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000795 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000796 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000797 NestedNameSpecifierLoc QualifierLoc,
798 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000799 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000800 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000801 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000802
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000803 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000804 // If the name is still dependent, just build a new dependent name type.
805 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000806 return SemaRef.Context.getDependentNameType(Keyword,
807 QualifierLoc.getNestedNameSpecifier(),
808 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000809 }
810
Abramo Bagnara6150c882010-05-11 21:36:43 +0000811 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000812 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000813 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000814
815 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
816
Abramo Bagnarad7548482010-05-19 21:37:53 +0000817 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000818 // into a non-dependent elaborated-type-specifier. Find the tag we're
819 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000820 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000821 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
822 if (!DC)
823 return QualType();
824
John McCallbf8c5192010-05-27 06:40:31 +0000825 if (SemaRef.RequireCompleteDeclContext(SS, DC))
826 return QualType();
827
Douglas Gregore677daf2010-03-31 22:19:08 +0000828 TagDecl *Tag = 0;
829 SemaRef.LookupQualifiedName(Result, DC);
830 switch (Result.getResultKind()) {
831 case LookupResult::NotFound:
832 case LookupResult::NotFoundInCurrentInstantiation:
833 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000834
Douglas Gregore677daf2010-03-31 22:19:08 +0000835 case LookupResult::Found:
836 Tag = Result.getAsSingle<TagDecl>();
837 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000838
Douglas Gregore677daf2010-03-31 22:19:08 +0000839 case LookupResult::FoundOverloaded:
840 case LookupResult::FoundUnresolvedValue:
841 llvm_unreachable("Tag lookup cannot find non-tags");
842 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000843
Douglas Gregore677daf2010-03-31 22:19:08 +0000844 case LookupResult::Ambiguous:
845 // Let the LookupResult structure handle ambiguities.
846 return QualType();
847 }
848
849 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000850 // Check where the name exists but isn't a tag type and use that to emit
851 // better diagnostics.
852 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
853 SemaRef.LookupQualifiedName(Result, DC);
854 switch (Result.getResultKind()) {
855 case LookupResult::Found:
856 case LookupResult::FoundOverloaded:
857 case LookupResult::FoundUnresolvedValue: {
858 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
859 unsigned Kind = 0;
860 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000861 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
862 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000863 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
864 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
865 break;
866 }
867 default:
868 // FIXME: Would be nice to highlight just the source range.
869 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
870 << Kind << Id << DC;
871 break;
872 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000873 return QualType();
874 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000875
Abramo Bagnarad7548482010-05-19 21:37:53 +0000876 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
877 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000878 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
879 return QualType();
880 }
881
882 // Build the elaborated-type-specifier type.
883 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000884 return SemaRef.Context.getElaboratedType(Keyword,
885 QualifierLoc.getNestedNameSpecifier(),
886 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000887 }
Mike Stump11289f42009-09-09 15:08:12 +0000888
Douglas Gregor822d0302011-01-12 17:07:58 +0000889 /// \brief Build a new pack expansion type.
890 ///
891 /// By default, builds a new PackExpansionType type from the given pattern.
892 /// Subclasses may override this routine to provide different behavior.
893 QualType RebuildPackExpansionType(QualType Pattern,
894 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000895 SourceLocation EllipsisLoc,
896 llvm::Optional<unsigned> NumExpansions) {
897 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
898 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000899 }
900
Douglas Gregor71dc5092009-08-06 06:41:21 +0000901 /// \brief Build a new template name given a nested name specifier, a flag
902 /// indicating whether the "template" keyword was provided, and the template
903 /// that the template name refers to.
904 ///
905 /// By default, builds the new template name directly. Subclasses may override
906 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000907 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +0000908 bool TemplateKW,
909 TemplateDecl *Template);
910
Douglas Gregor71dc5092009-08-06 06:41:21 +0000911 /// \brief Build a new template name given a nested name specifier and the
912 /// name that is referred to as a template.
913 ///
914 /// By default, performs semantic analysis to determine whether the name can
915 /// be resolved to a specific template, then builds the appropriate kind of
916 /// template name. Subclasses may override this routine to provide different
917 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000918 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
919 const IdentifierInfo &Name,
920 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +0000921 QualType ObjectType,
922 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000923
Douglas Gregor71395fa2009-11-04 00:56:37 +0000924 /// \brief Build a new template name given a nested name specifier and the
925 /// overloaded operator name that is referred to as a template.
926 ///
927 /// By default, performs semantic analysis to determine whether the name can
928 /// be resolved to a specific template, then builds the appropriate kind of
929 /// template name. Subclasses may override this routine to provide different
930 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000931 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000932 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +0000933 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000934 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000935
936 /// \brief Build a new template name given a template template parameter pack
937 /// and the
938 ///
939 /// By default, performs semantic analysis to determine whether the name can
940 /// be resolved to a specific template, then builds the appropriate kind of
941 /// template name. Subclasses may override this routine to provide different
942 /// behavior.
943 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
944 const TemplateArgument &ArgPack) {
945 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
946 }
947
Douglas Gregorebe10102009-08-20 07:17:43 +0000948 /// \brief Build a new compound statement.
949 ///
950 /// By default, performs semantic analysis to build the new statement.
951 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000952 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000953 MultiStmtArg Statements,
954 SourceLocation RBraceLoc,
955 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000956 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000957 IsStmtExpr);
958 }
959
960 /// \brief Build a new case statement.
961 ///
962 /// By default, performs semantic analysis to build the new statement.
963 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000964 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000965 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000966 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000967 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000968 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000969 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000970 ColonLoc);
971 }
Mike Stump11289f42009-09-09 15:08:12 +0000972
Douglas Gregorebe10102009-08-20 07:17:43 +0000973 /// \brief Attach the body to a new case statement.
974 ///
975 /// By default, performs semantic analysis to build the new statement.
976 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000977 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000978 getSema().ActOnCaseStmtBody(S, Body);
979 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000980 }
Mike Stump11289f42009-09-09 15:08:12 +0000981
Douglas Gregorebe10102009-08-20 07:17:43 +0000982 /// \brief Build a new default statement.
983 ///
984 /// By default, performs semantic analysis to build the new statement.
985 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000986 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000987 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000988 Stmt *SubStmt) {
989 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000990 /*CurScope=*/0);
991 }
Mike Stump11289f42009-09-09 15:08:12 +0000992
Douglas Gregorebe10102009-08-20 07:17:43 +0000993 /// \brief Build a new label statement.
994 ///
995 /// By default, performs semantic analysis to build the new statement.
996 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +0000997 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
998 SourceLocation ColonLoc, Stmt *SubStmt) {
999 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001000 }
Mike Stump11289f42009-09-09 15:08:12 +00001001
Douglas Gregorebe10102009-08-20 07:17:43 +00001002 /// \brief Build a new "if" statement.
1003 ///
1004 /// By default, performs semantic analysis to build the new statement.
1005 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001006 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattnercab02a62011-02-17 20:34:02 +00001007 VarDecl *CondVar, Stmt *Then,
1008 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001009 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001010 }
Mike Stump11289f42009-09-09 15:08:12 +00001011
Douglas Gregorebe10102009-08-20 07:17:43 +00001012 /// \brief Start building a new switch statement.
1013 ///
1014 /// By default, performs semantic analysis to build the new statement.
1015 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001016 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001017 Expr *Cond, VarDecl *CondVar) {
John McCallb268a282010-08-23 23:25:46 +00001018 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001019 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001020 }
Mike Stump11289f42009-09-09 15:08:12 +00001021
Douglas Gregorebe10102009-08-20 07:17:43 +00001022 /// \brief Attach the body to the switch statement.
1023 ///
1024 /// By default, performs semantic analysis to build the new statement.
1025 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001026 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001027 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001028 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001029 }
1030
1031 /// \brief Build a new while statement.
1032 ///
1033 /// By default, performs semantic analysis to build the new statement.
1034 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001035 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1036 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001037 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001038 }
Mike Stump11289f42009-09-09 15:08:12 +00001039
Douglas Gregorebe10102009-08-20 07:17:43 +00001040 /// \brief Build a new do-while statement.
1041 ///
1042 /// By default, performs semantic analysis to build the new statement.
1043 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001044 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001045 SourceLocation WhileLoc, SourceLocation LParenLoc,
1046 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001047 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1048 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001049 }
1050
1051 /// \brief Build a new for statement.
1052 ///
1053 /// By default, performs semantic analysis to build the new statement.
1054 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001055 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1056 Stmt *Init, Sema::FullExprArg Cond,
1057 VarDecl *CondVar, Sema::FullExprArg Inc,
1058 SourceLocation RParenLoc, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001059 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001060 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001061 }
Mike Stump11289f42009-09-09 15:08:12 +00001062
Douglas Gregorebe10102009-08-20 07:17:43 +00001063 /// \brief Build a new goto statement.
1064 ///
1065 /// By default, performs semantic analysis to build the new statement.
1066 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001067 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1068 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001069 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001070 }
1071
1072 /// \brief Build a new indirect goto statement.
1073 ///
1074 /// By default, performs semantic analysis to build the new statement.
1075 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001076 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001077 SourceLocation StarLoc,
1078 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001079 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
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 return statement.
1083 ///
1084 /// By default, performs semantic analysis to build the new statement.
1085 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001086 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001087 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001088 }
Mike Stump11289f42009-09-09 15:08:12 +00001089
Douglas Gregorebe10102009-08-20 07:17:43 +00001090 /// \brief Build a new declaration statement.
1091 ///
1092 /// By default, performs semantic analysis to build the new statement.
1093 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001094 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001095 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001096 SourceLocation EndLoc) {
Richard Smith2abf6762011-02-23 00:37:57 +00001097 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1098 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001099 }
Mike Stump11289f42009-09-09 15:08:12 +00001100
Anders Carlssonaaeef072010-01-24 05:50:09 +00001101 /// \brief Build a new inline asm statement.
1102 ///
1103 /// By default, performs semantic analysis to build the new statement.
1104 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001105 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001106 bool IsSimple,
1107 bool IsVolatile,
1108 unsigned NumOutputs,
1109 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001110 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001111 MultiExprArg Constraints,
1112 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001113 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001114 MultiExprArg Clobbers,
1115 SourceLocation RParenLoc,
1116 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001117 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001118 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001119 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001120 RParenLoc, MSAsm);
1121 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001122
1123 /// \brief Build a new Objective-C @try statement.
1124 ///
1125 /// By default, performs semantic analysis to build the new statement.
1126 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001127 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001128 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001129 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001130 Stmt *Finally) {
1131 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1132 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001133 }
1134
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001135 /// \brief Rebuild an Objective-C exception declaration.
1136 ///
1137 /// By default, performs semantic analysis to build the new declaration.
1138 /// Subclasses may override this routine to provide different behavior.
1139 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1140 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001141 return getSema().BuildObjCExceptionDecl(TInfo, T,
1142 ExceptionDecl->getInnerLocStart(),
1143 ExceptionDecl->getLocation(),
1144 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001145 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001146
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001147 /// \brief Build a new Objective-C @catch statement.
1148 ///
1149 /// By default, performs semantic analysis to build the new statement.
1150 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001151 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001152 SourceLocation RParenLoc,
1153 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001154 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001155 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001156 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001157 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001158
Douglas Gregor306de2f2010-04-22 23:59:56 +00001159 /// \brief Build a new Objective-C @finally statement.
1160 ///
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 RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001164 Stmt *Body) {
1165 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001166 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001167
Douglas Gregor6148de72010-04-22 22:01:21 +00001168 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001169 ///
1170 /// 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 RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001173 Expr *Operand) {
1174 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001175 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001176
Douglas Gregor6148de72010-04-22 22:01:21 +00001177 /// \brief Build a new Objective-C @synchronized statement.
1178 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001179 /// By default, performs semantic analysis to build the new statement.
1180 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001181 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001182 Expr *Object,
1183 Stmt *Body) {
1184 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1185 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001186 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001187
1188 /// \brief Build a new Objective-C fast enumeration statement.
1189 ///
1190 /// By default, performs semantic analysis to build the new statement.
1191 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001192 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001193 SourceLocation LParenLoc,
1194 Stmt *Element,
1195 Expr *Collection,
1196 SourceLocation RParenLoc,
1197 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001198 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001199 Element,
1200 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001201 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001202 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001203 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001204
Douglas Gregorebe10102009-08-20 07:17:43 +00001205 /// \brief Build a new C++ exception declaration.
1206 ///
1207 /// By default, performs semantic analysis to build the new decaration.
1208 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001209 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001210 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001211 SourceLocation StartLoc,
1212 SourceLocation IdLoc,
1213 IdentifierInfo *Id) {
Douglas Gregor40965fa2011-04-14 22:32:28 +00001214 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1215 StartLoc, IdLoc, Id);
1216 if (Var)
1217 getSema().CurContext->addDecl(Var);
1218 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001219 }
1220
1221 /// \brief Build a new C++ catch statement.
1222 ///
1223 /// By default, performs semantic analysis to build the new statement.
1224 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001225 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001226 VarDecl *ExceptionDecl,
1227 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001228 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1229 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001230 }
Mike Stump11289f42009-09-09 15:08:12 +00001231
Douglas Gregorebe10102009-08-20 07:17:43 +00001232 /// \brief Build a new C++ try statement.
1233 ///
1234 /// By default, performs semantic analysis to build the new statement.
1235 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001236 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001237 Stmt *TryBlock,
1238 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001239 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001240 }
Mike Stump11289f42009-09-09 15:08:12 +00001241
Richard Smith02e85f32011-04-14 22:09:26 +00001242 /// \brief Build a new C++0x range-based for statement.
1243 ///
1244 /// By default, performs semantic analysis to build the new statement.
1245 /// Subclasses may override this routine to provide different behavior.
1246 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1247 SourceLocation ColonLoc,
1248 Stmt *Range, Stmt *BeginEnd,
1249 Expr *Cond, Expr *Inc,
1250 Stmt *LoopVar,
1251 SourceLocation RParenLoc) {
1252 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1253 Cond, Inc, LoopVar, RParenLoc);
1254 }
1255
1256 /// \brief Attach body to a C++0x range-based for statement.
1257 ///
1258 /// By default, performs semantic analysis to finish the new statement.
1259 /// Subclasses may override this routine to provide different behavior.
1260 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1261 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1262 }
1263
John Wiegley1c0675e2011-04-28 01:08:34 +00001264 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1265 SourceLocation TryLoc,
1266 Stmt *TryBlock,
1267 Stmt *Handler) {
1268 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1269 }
1270
1271 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1272 Expr *FilterExpr,
1273 Stmt *Block) {
1274 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1275 }
1276
1277 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1278 Stmt *Block) {
1279 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1280 }
1281
Douglas Gregora16548e2009-08-11 05:31:07 +00001282 /// \brief Build a new expression that references a declaration.
1283 ///
1284 /// By default, performs semantic analysis to build the new expression.
1285 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001286 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001287 LookupResult &R,
1288 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001289 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1290 }
1291
1292
1293 /// \brief Build a new expression that references a declaration.
1294 ///
1295 /// By default, performs semantic analysis to build the new expression.
1296 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001297 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001298 ValueDecl *VD,
1299 const DeclarationNameInfo &NameInfo,
1300 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001301 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001302 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001303
1304 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001305
1306 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001307 }
Mike Stump11289f42009-09-09 15:08:12 +00001308
Douglas Gregora16548e2009-08-11 05:31:07 +00001309 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001310 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001311 /// By default, performs semantic analysis to build the new expression.
1312 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001313 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001314 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001315 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001316 }
1317
Douglas Gregorad8a3362009-09-04 17:36:40 +00001318 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001319 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001320 /// By default, performs semantic analysis to build the new expression.
1321 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001322 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001323 SourceLocation OperatorLoc,
1324 bool isArrow,
1325 CXXScopeSpec &SS,
1326 TypeSourceInfo *ScopeType,
1327 SourceLocation CCLoc,
1328 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001329 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001330
Douglas Gregora16548e2009-08-11 05:31:07 +00001331 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001332 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 /// By default, performs semantic analysis to build the new expression.
1334 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001335 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001336 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001337 Expr *SubExpr) {
1338 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001339 }
Mike Stump11289f42009-09-09 15:08:12 +00001340
Douglas Gregor882211c2010-04-28 22:16:22 +00001341 /// \brief Build a new builtin offsetof expression.
1342 ///
1343 /// By default, performs semantic analysis to build the new expression.
1344 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001345 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001346 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001347 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001348 unsigned NumComponents,
1349 SourceLocation RParenLoc) {
1350 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1351 NumComponents, RParenLoc);
1352 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001353
Peter Collingbournee190dee2011-03-11 19:24:49 +00001354 /// \brief Build a new sizeof, alignof or vec_step expression with a
1355 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001356 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001357 /// By default, performs semantic analysis to build the new expression.
1358 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001359 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1360 SourceLocation OpLoc,
1361 UnaryExprOrTypeTrait ExprKind,
1362 SourceRange R) {
1363 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001364 }
1365
Peter Collingbournee190dee2011-03-11 19:24:49 +00001366 /// \brief Build a new sizeof, alignof or vec step expression with an
1367 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001368 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001369 /// By default, performs semantic analysis to build the new expression.
1370 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001371 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1372 UnaryExprOrTypeTrait ExprKind,
1373 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001374 ExprResult Result
Peter Collingbournee190dee2011-03-11 19:24:49 +00001375 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001376 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001377 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001378
Douglas Gregora16548e2009-08-11 05:31:07 +00001379 return move(Result);
1380 }
Mike Stump11289f42009-09-09 15:08:12 +00001381
Douglas Gregora16548e2009-08-11 05:31:07 +00001382 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001383 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001384 /// By default, performs semantic analysis to build the new expression.
1385 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001386 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001387 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001388 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001389 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001390 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1391 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001392 RBracketLoc);
1393 }
1394
1395 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001396 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001397 /// By default, performs semantic analysis to build the new expression.
1398 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001399 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001400 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001401 SourceLocation RParenLoc,
1402 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001403 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001404 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001405 }
1406
1407 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001408 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 /// By default, performs semantic analysis to build the new expression.
1410 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001411 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001412 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001413 NestedNameSpecifierLoc QualifierLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001414 const DeclarationNameInfo &MemberNameInfo,
1415 ValueDecl *Member,
1416 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001417 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001418 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001419 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001420 // We have a reference to an unnamed field. This is always the
1421 // base of an anonymous struct/union member access, i.e. the
1422 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001423 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001424 assert(Member->getType()->isRecordType() &&
1425 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001426
John Wiegley01296292011-04-08 18:41:53 +00001427 ExprResult BaseResult =
1428 getSema().PerformObjectMemberConversion(Base,
1429 QualifierLoc.getNestedNameSpecifier(),
1430 FoundDecl, Member);
1431 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001432 return ExprError();
John Wiegley01296292011-04-08 18:41:53 +00001433 Base = BaseResult.take();
John McCall7decc9e2010-11-18 06:31:45 +00001434 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001435 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001436 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001437 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001438 cast<FieldDecl>(Member)->getType(),
1439 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001440 return getSema().Owned(ME);
1441 }
Mike Stump11289f42009-09-09 15:08:12 +00001442
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001443 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001444 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001445
John Wiegley01296292011-04-08 18:41:53 +00001446 ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base);
1447 if (BaseResult.isInvalid())
1448 return ExprError();
1449 Base = BaseResult.take();
John McCallb268a282010-08-23 23:25:46 +00001450 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001451
John McCall16df1e52010-03-30 21:47:33 +00001452 // FIXME: this involves duplicating earlier analysis in a lot of
1453 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001454 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001455 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001456 R.resolveKind();
1457
John McCallb268a282010-08-23 23:25:46 +00001458 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001459 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001460 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001461 }
Mike Stump11289f42009-09-09 15:08:12 +00001462
Douglas Gregora16548e2009-08-11 05:31:07 +00001463 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001464 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001465 /// By default, performs semantic analysis to build the new expression.
1466 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001467 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001468 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001469 Expr *LHS, Expr *RHS) {
1470 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001471 }
1472
1473 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001474 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001475 /// By default, performs semantic analysis to build the new expression.
1476 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001477 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001478 SourceLocation QuestionLoc,
1479 Expr *LHS,
1480 SourceLocation ColonLoc,
1481 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001482 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1483 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001484 }
1485
Douglas Gregora16548e2009-08-11 05:31:07 +00001486 /// \brief Build a new C-style cast 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 RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001491 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001493 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001494 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001495 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001496 }
Mike Stump11289f42009-09-09 15:08:12 +00001497
Douglas Gregora16548e2009-08-11 05:31:07 +00001498 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001499 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001500 /// By default, performs semantic analysis to build the new expression.
1501 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001502 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001503 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001505 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001506 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001507 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001508 }
Mike Stump11289f42009-09-09 15:08:12 +00001509
Douglas Gregora16548e2009-08-11 05:31:07 +00001510 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001511 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001512 /// By default, performs semantic analysis to build the new expression.
1513 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001514 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001515 SourceLocation OpLoc,
1516 SourceLocation AccessorLoc,
1517 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001518
John McCall10eae182009-11-30 22:42:35 +00001519 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001520 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001521 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001522 OpLoc, /*IsArrow*/ false,
1523 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001524 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001525 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001526 }
Mike Stump11289f42009-09-09 15:08:12 +00001527
Douglas Gregora16548e2009-08-11 05:31:07 +00001528 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001529 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001530 /// By default, performs semantic analysis to build the new expression.
1531 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001532 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001533 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001534 SourceLocation RBraceLoc,
1535 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001536 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001537 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1538 if (Result.isInvalid() || ResultTy->isDependentType())
1539 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001540
Douglas Gregord3d93062009-11-09 17:16:50 +00001541 // Patch in the result type we were given, which may have been computed
1542 // when the initial InitListExpr was built.
1543 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1544 ILE->setType(ResultTy);
1545 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001546 }
Mike Stump11289f42009-09-09 15:08:12 +00001547
Douglas Gregora16548e2009-08-11 05:31:07 +00001548 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001549 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001550 /// By default, performs semantic analysis to build the new expression.
1551 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001552 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001553 MultiExprArg ArrayExprs,
1554 SourceLocation EqualOrColonLoc,
1555 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001556 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001557 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001558 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001559 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001560 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001561 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001562
Douglas Gregora16548e2009-08-11 05:31:07 +00001563 ArrayExprs.release();
1564 return move(Result);
1565 }
Mike Stump11289f42009-09-09 15:08:12 +00001566
Douglas Gregora16548e2009-08-11 05:31:07 +00001567 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001568 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001569 /// By default, builds the implicit value initialization without performing
1570 /// any semantic analysis. Subclasses may override this routine to provide
1571 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001572 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001573 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1574 }
Mike Stump11289f42009-09-09 15:08:12 +00001575
Douglas Gregora16548e2009-08-11 05:31:07 +00001576 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001577 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001578 /// By default, performs semantic analysis to build the new expression.
1579 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001580 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001581 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001582 SourceLocation RParenLoc) {
1583 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001584 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001585 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001586 }
1587
1588 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001589 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001590 /// By default, performs semantic analysis to build the new expression.
1591 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001592 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001593 MultiExprArg SubExprs,
1594 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001595 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001596 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001597 }
Mike Stump11289f42009-09-09 15:08:12 +00001598
Douglas Gregora16548e2009-08-11 05:31:07 +00001599 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001600 ///
1601 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001602 /// rather than attempting to map the label statement itself.
1603 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001604 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001605 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001606 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001607 }
Mike Stump11289f42009-09-09 15:08:12 +00001608
Douglas Gregora16548e2009-08-11 05:31:07 +00001609 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001610 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001611 /// By default, performs semantic analysis to build the new expression.
1612 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001613 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001614 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001615 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001616 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001617 }
Mike Stump11289f42009-09-09 15:08:12 +00001618
Douglas Gregora16548e2009-08-11 05:31:07 +00001619 /// \brief Build a new __builtin_choose_expr expression.
1620 ///
1621 /// By default, performs semantic analysis to build the new expression.
1622 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001623 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001624 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001625 SourceLocation RParenLoc) {
1626 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001627 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001628 RParenLoc);
1629 }
Mike Stump11289f42009-09-09 15:08:12 +00001630
Peter Collingbourne91147592011-04-15 00:35:48 +00001631 /// \brief Build a new generic selection expression.
1632 ///
1633 /// By default, performs semantic analysis to build the new expression.
1634 /// Subclasses may override this routine to provide different behavior.
1635 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1636 SourceLocation DefaultLoc,
1637 SourceLocation RParenLoc,
1638 Expr *ControllingExpr,
1639 TypeSourceInfo **Types,
1640 Expr **Exprs,
1641 unsigned NumAssocs) {
1642 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1643 ControllingExpr, Types, Exprs,
1644 NumAssocs);
1645 }
1646
Douglas Gregora16548e2009-08-11 05:31:07 +00001647 /// \brief Build a new overloaded operator call expression.
1648 ///
1649 /// By default, performs semantic analysis to build the new expression.
1650 /// The semantic analysis provides the behavior of template instantiation,
1651 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001652 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001653 /// argument-dependent lookup, etc. Subclasses may override this routine to
1654 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001655 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001656 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001657 Expr *Callee,
1658 Expr *First,
1659 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001660
1661 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001662 /// reinterpret_cast.
1663 ///
1664 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001665 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001666 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001667 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001668 Stmt::StmtClass Class,
1669 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001670 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001671 SourceLocation RAngleLoc,
1672 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001673 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001674 SourceLocation RParenLoc) {
1675 switch (Class) {
1676 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001677 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001678 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001679 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001680
1681 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001682 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001683 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001684 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001685
Douglas Gregora16548e2009-08-11 05:31:07 +00001686 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001687 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001688 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001689 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001690 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001691
Douglas Gregora16548e2009-08-11 05:31:07 +00001692 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001693 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001694 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001695 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001696
Douglas Gregora16548e2009-08-11 05:31:07 +00001697 default:
1698 assert(false && "Invalid C++ named cast");
1699 break;
1700 }
Mike Stump11289f42009-09-09 15:08:12 +00001701
John McCallfaf5fb42010-08-26 23:41:50 +00001702 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001703 }
Mike Stump11289f42009-09-09 15:08:12 +00001704
Douglas Gregora16548e2009-08-11 05:31:07 +00001705 /// \brief Build a new C++ static_cast expression.
1706 ///
1707 /// By default, performs semantic analysis to build the new expression.
1708 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001709 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001710 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001711 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001712 SourceLocation RAngleLoc,
1713 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001714 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001715 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001716 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001717 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001718 SourceRange(LAngleLoc, RAngleLoc),
1719 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001720 }
1721
1722 /// \brief Build a new C++ dynamic_cast expression.
1723 ///
1724 /// By default, performs semantic analysis to build the new expression.
1725 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001726 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001727 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001728 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001729 SourceLocation RAngleLoc,
1730 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001731 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001732 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001733 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001734 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001735 SourceRange(LAngleLoc, RAngleLoc),
1736 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001737 }
1738
1739 /// \brief Build a new C++ reinterpret_cast expression.
1740 ///
1741 /// By default, performs semantic analysis to build the new expression.
1742 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001743 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001744 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001745 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001746 SourceLocation RAngleLoc,
1747 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001748 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001749 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001750 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001751 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001752 SourceRange(LAngleLoc, RAngleLoc),
1753 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001754 }
1755
1756 /// \brief Build a new C++ const_cast expression.
1757 ///
1758 /// By default, performs semantic analysis to build the new expression.
1759 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001760 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001761 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001762 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001763 SourceLocation RAngleLoc,
1764 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001765 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001766 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001767 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001768 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001769 SourceRange(LAngleLoc, RAngleLoc),
1770 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001771 }
Mike Stump11289f42009-09-09 15:08:12 +00001772
Douglas Gregora16548e2009-08-11 05:31:07 +00001773 /// \brief Build a new C++ functional-style cast expression.
1774 ///
1775 /// By default, performs semantic analysis to build the new expression.
1776 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001777 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1778 SourceLocation LParenLoc,
1779 Expr *Sub,
1780 SourceLocation RParenLoc) {
1781 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001782 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001783 RParenLoc);
1784 }
Mike Stump11289f42009-09-09 15:08:12 +00001785
Douglas Gregora16548e2009-08-11 05:31:07 +00001786 /// \brief Build a new C++ typeid(type) expression.
1787 ///
1788 /// By default, performs semantic analysis to build the new expression.
1789 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001790 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001791 SourceLocation TypeidLoc,
1792 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001793 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001794 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001795 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001796 }
Mike Stump11289f42009-09-09 15:08:12 +00001797
Francois Pichet9f4f2072010-09-08 12:20:18 +00001798
Douglas Gregora16548e2009-08-11 05:31:07 +00001799 /// \brief Build a new C++ typeid(expr) expression.
1800 ///
1801 /// By default, performs semantic analysis to build the new expression.
1802 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001803 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001804 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001805 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001806 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001807 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001808 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001809 }
1810
Francois Pichet9f4f2072010-09-08 12:20:18 +00001811 /// \brief Build a new C++ __uuidof(type) expression.
1812 ///
1813 /// By default, performs semantic analysis to build the new expression.
1814 /// Subclasses may override this routine to provide different behavior.
1815 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1816 SourceLocation TypeidLoc,
1817 TypeSourceInfo *Operand,
1818 SourceLocation RParenLoc) {
1819 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1820 RParenLoc);
1821 }
1822
1823 /// \brief Build a new C++ __uuidof(expr) expression.
1824 ///
1825 /// By default, performs semantic analysis to build the new expression.
1826 /// Subclasses may override this routine to provide different behavior.
1827 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1828 SourceLocation TypeidLoc,
1829 Expr *Operand,
1830 SourceLocation RParenLoc) {
1831 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1832 RParenLoc);
1833 }
1834
Douglas Gregora16548e2009-08-11 05:31:07 +00001835 /// \brief Build a new C++ "this" expression.
1836 ///
1837 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001838 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001839 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001840 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001841 QualType ThisType,
1842 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001843 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001844 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1845 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001846 }
1847
1848 /// \brief Build a new C++ throw expression.
1849 ///
1850 /// By default, performs semantic analysis to build the new expression.
1851 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001852 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001853 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001854 }
1855
1856 /// \brief Build a new C++ default-argument expression.
1857 ///
1858 /// By default, builds a new default-argument expression, which does not
1859 /// require any semantic analysis. Subclasses may override this routine to
1860 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001861 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001862 ParmVarDecl *Param) {
1863 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1864 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001865 }
1866
1867 /// \brief Build a new C++ zero-initialization expression.
1868 ///
1869 /// By default, performs semantic analysis to build the new expression.
1870 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001871 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1872 SourceLocation LParenLoc,
1873 SourceLocation RParenLoc) {
1874 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001875 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001876 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001877 }
Mike Stump11289f42009-09-09 15:08:12 +00001878
Douglas Gregora16548e2009-08-11 05:31:07 +00001879 /// \brief Build a new C++ "new" expression.
1880 ///
1881 /// By default, performs semantic analysis to build the new expression.
1882 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001883 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001884 bool UseGlobal,
1885 SourceLocation PlacementLParen,
1886 MultiExprArg PlacementArgs,
1887 SourceLocation PlacementRParen,
1888 SourceRange TypeIdParens,
1889 QualType AllocatedType,
1890 TypeSourceInfo *AllocatedTypeInfo,
1891 Expr *ArraySize,
1892 SourceLocation ConstructorLParen,
1893 MultiExprArg ConstructorArgs,
1894 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001895 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001896 PlacementLParen,
1897 move(PlacementArgs),
1898 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001899 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001900 AllocatedType,
1901 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001902 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001903 ConstructorLParen,
1904 move(ConstructorArgs),
1905 ConstructorRParen);
1906 }
Mike Stump11289f42009-09-09 15:08:12 +00001907
Douglas Gregora16548e2009-08-11 05:31:07 +00001908 /// \brief Build a new C++ "delete" expression.
1909 ///
1910 /// By default, performs semantic analysis to build the new expression.
1911 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001912 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001913 bool IsGlobalDelete,
1914 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001915 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001916 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001917 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001918 }
Mike Stump11289f42009-09-09 15:08:12 +00001919
Douglas Gregora16548e2009-08-11 05:31:07 +00001920 /// \brief Build a new unary type trait expression.
1921 ///
1922 /// By default, performs semantic analysis to build the new expression.
1923 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001924 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001925 SourceLocation StartLoc,
1926 TypeSourceInfo *T,
1927 SourceLocation RParenLoc) {
1928 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001929 }
1930
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001931 /// \brief Build a new binary type trait expression.
1932 ///
1933 /// By default, performs semantic analysis to build the new expression.
1934 /// Subclasses may override this routine to provide different behavior.
1935 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1936 SourceLocation StartLoc,
1937 TypeSourceInfo *LhsT,
1938 TypeSourceInfo *RhsT,
1939 SourceLocation RParenLoc) {
1940 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1941 }
1942
John Wiegley6242b6a2011-04-28 00:16:57 +00001943 /// \brief Build a new array type trait expression.
1944 ///
1945 /// By default, performs semantic analysis to build the new expression.
1946 /// Subclasses may override this routine to provide different behavior.
1947 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
1948 SourceLocation StartLoc,
1949 TypeSourceInfo *TSInfo,
1950 Expr *DimExpr,
1951 SourceLocation RParenLoc) {
1952 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
1953 }
1954
John Wiegleyf9f65842011-04-25 06:54:41 +00001955 /// \brief Build a new expression trait expression.
1956 ///
1957 /// By default, performs semantic analysis to build the new expression.
1958 /// Subclasses may override this routine to provide different behavior.
1959 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
1960 SourceLocation StartLoc,
1961 Expr *Queried,
1962 SourceLocation RParenLoc) {
1963 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
1964 }
1965
Mike Stump11289f42009-09-09 15:08:12 +00001966 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001967 /// expression.
1968 ///
1969 /// By default, performs semantic analysis to build the new expression.
1970 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001971 ExprResult RebuildDependentScopeDeclRefExpr(
1972 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001973 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001974 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001975 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001976 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00001977
1978 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001979 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001980 *TemplateArgs);
1981
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001982 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001983 }
1984
1985 /// \brief Build a new template-id expression.
1986 ///
1987 /// By default, performs semantic analysis to build the new expression.
1988 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001989 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001990 LookupResult &R,
1991 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001992 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001993 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001994 }
1995
1996 /// \brief Build a new object-construction expression.
1997 ///
1998 /// By default, performs semantic analysis to build the new expression.
1999 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002000 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002001 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002002 CXXConstructorDecl *Constructor,
2003 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00002004 MultiExprArg Args,
2005 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002006 CXXConstructExpr::ConstructionKind ConstructKind,
2007 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00002008 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002009 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002010 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002011 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002012
Douglas Gregordb121ba2009-12-14 16:27:04 +00002013 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00002014 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00002015 RequiresZeroInit, ConstructKind,
2016 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002017 }
2018
2019 /// \brief Build a new object-construction expression.
2020 ///
2021 /// By default, performs semantic analysis to build the new expression.
2022 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002023 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2024 SourceLocation LParenLoc,
2025 MultiExprArg Args,
2026 SourceLocation RParenLoc) {
2027 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002028 LParenLoc,
2029 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002030 RParenLoc);
2031 }
2032
2033 /// \brief Build a new object-construction expression.
2034 ///
2035 /// By default, performs semantic analysis to build the new expression.
2036 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002037 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2038 SourceLocation LParenLoc,
2039 MultiExprArg Args,
2040 SourceLocation RParenLoc) {
2041 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002042 LParenLoc,
2043 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002044 RParenLoc);
2045 }
Mike Stump11289f42009-09-09 15:08:12 +00002046
Douglas Gregora16548e2009-08-11 05:31:07 +00002047 /// \brief Build a new member reference expression.
2048 ///
2049 /// By default, performs semantic analysis to build the new expression.
2050 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002051 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002052 QualType BaseType,
2053 bool IsArrow,
2054 SourceLocation OperatorLoc,
2055 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00002056 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002057 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002058 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002059 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002060 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002061
John McCallb268a282010-08-23 23:25:46 +00002062 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002063 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00002064 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002065 MemberNameInfo,
2066 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002067 }
2068
John McCall10eae182009-11-30 22:42:35 +00002069 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002070 ///
2071 /// By default, performs semantic analysis to build the new expression.
2072 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002073 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00002074 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00002075 SourceLocation OperatorLoc,
2076 bool IsArrow,
Douglas Gregor0da1d432011-02-28 20:01:57 +00002077 NestedNameSpecifierLoc QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00002078 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00002079 LookupResult &R,
2080 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002081 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002082 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002083
John McCallb268a282010-08-23 23:25:46 +00002084 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002085 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00002086 SS, FirstQualifierInScope,
2087 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002088 }
Mike Stump11289f42009-09-09 15:08:12 +00002089
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002090 /// \brief Build a new noexcept expression.
2091 ///
2092 /// By default, performs semantic analysis to build the new expression.
2093 /// Subclasses may override this routine to provide different behavior.
2094 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2095 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2096 }
2097
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002098 /// \brief Build a new expression to compute the length of a parameter pack.
2099 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2100 SourceLocation PackLoc,
2101 SourceLocation RParenLoc,
2102 unsigned Length) {
2103 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2104 OperatorLoc, Pack, PackLoc,
2105 RParenLoc, Length);
2106 }
2107
Douglas Gregora16548e2009-08-11 05:31:07 +00002108 /// \brief Build a new Objective-C @encode expression.
2109 ///
2110 /// By default, performs semantic analysis to build the new expression.
2111 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002112 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002113 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002114 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002115 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002116 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002117 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002118
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002119 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002120 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002121 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002122 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002123 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002124 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002125 MultiExprArg Args,
2126 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002127 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2128 ReceiverTypeInfo->getType(),
2129 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002130 Sel, Method, LBracLoc, SelectorLoc,
2131 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002132 }
2133
2134 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002135 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002136 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002137 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002138 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002139 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002140 MultiExprArg Args,
2141 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002142 return SemaRef.BuildInstanceMessage(Receiver,
2143 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002144 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002145 Sel, Method, LBracLoc, SelectorLoc,
2146 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002147 }
2148
Douglas Gregord51d90d2010-04-26 20:11:03 +00002149 /// \brief Build a new Objective-C ivar reference expression.
2150 ///
2151 /// By default, performs semantic analysis to build the new expression.
2152 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002153 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002154 SourceLocation IvarLoc,
2155 bool IsArrow, bool IsFreeIvar) {
2156 // FIXME: We lose track of the IsFreeIvar bit.
2157 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002158 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002159 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2160 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002161 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002162 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002163 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002164 false);
John Wiegley01296292011-04-08 18:41:53 +00002165 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002166 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002167
Douglas Gregord51d90d2010-04-26 20:11:03 +00002168 if (Result.get())
2169 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002170
John Wiegley01296292011-04-08 18:41:53 +00002171 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002172 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002173 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002174 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002175 /*TemplateArgs=*/0);
2176 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002177
2178 /// \brief Build a new Objective-C property reference expression.
2179 ///
2180 /// By default, performs semantic analysis to build the new expression.
2181 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002182 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002183 ObjCPropertyDecl *Property,
2184 SourceLocation PropertyLoc) {
2185 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002186 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002187 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2188 Sema::LookupMemberName);
2189 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002190 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002191 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002192 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002193 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002194 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002195
Douglas Gregor9faee212010-04-26 20:47:02 +00002196 if (Result.get())
2197 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002198
John Wiegley01296292011-04-08 18:41:53 +00002199 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002200 /*FIXME:*/PropertyLoc, IsArrow,
2201 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002202 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002203 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002204 /*TemplateArgs=*/0);
2205 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002206
John McCallb7bd14f2010-12-02 01:19:52 +00002207 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002208 ///
2209 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002210 /// Subclasses may override this routine to provide different behavior.
2211 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2212 ObjCMethodDecl *Getter,
2213 ObjCMethodDecl *Setter,
2214 SourceLocation PropertyLoc) {
2215 // Since these expressions can only be value-dependent, we do not
2216 // need to perform semantic analysis again.
2217 return Owned(
2218 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2219 VK_LValue, OK_ObjCProperty,
2220 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002221 }
2222
Douglas Gregord51d90d2010-04-26 20:11:03 +00002223 /// \brief Build a new Objective-C "isa" expression.
2224 ///
2225 /// By default, performs semantic analysis to build the new expression.
2226 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002227 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002228 bool IsArrow) {
2229 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002230 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002231 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2232 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002233 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002234 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002235 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002236 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002237 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002238
Douglas Gregord51d90d2010-04-26 20:11:03 +00002239 if (Result.get())
2240 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002241
John Wiegley01296292011-04-08 18:41:53 +00002242 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002243 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002244 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002245 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002246 /*TemplateArgs=*/0);
2247 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002248
Douglas Gregora16548e2009-08-11 05:31:07 +00002249 /// \brief Build a new shuffle vector expression.
2250 ///
2251 /// By default, performs semantic analysis to build the new expression.
2252 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002253 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002254 MultiExprArg SubExprs,
2255 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002256 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002257 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002258 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2259 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2260 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2261 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002262
Douglas Gregora16548e2009-08-11 05:31:07 +00002263 // Build a reference to the __builtin_shufflevector builtin
2264 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley01296292011-04-08 18:41:53 +00002265 ExprResult Callee
2266 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2267 VK_LValue, BuiltinLoc));
2268 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2269 if (Callee.isInvalid())
2270 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002271
2272 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002273 unsigned NumSubExprs = SubExprs.size();
2274 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley01296292011-04-08 18:41:53 +00002275 ExprResult TheCall = SemaRef.Owned(
2276 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregora16548e2009-08-11 05:31:07 +00002277 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002278 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002279 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley01296292011-04-08 18:41:53 +00002280 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002281
Douglas Gregora16548e2009-08-11 05:31:07 +00002282 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002283 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002284 }
John McCall31f82722010-11-12 08:19:04 +00002285
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002286 /// \brief Build a new template argument pack expansion.
2287 ///
2288 /// By default, performs semantic analysis to build a new pack expansion
2289 /// for a template argument. Subclasses may override this routine to provide
2290 /// different behavior.
2291 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002292 SourceLocation EllipsisLoc,
2293 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002294 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002295 case TemplateArgument::Expression: {
2296 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002297 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2298 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002299 if (Result.isInvalid())
2300 return TemplateArgumentLoc();
2301
2302 return TemplateArgumentLoc(Result.get(), Result.get());
2303 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002304
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002305 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002306 return TemplateArgumentLoc(TemplateArgument(
2307 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002308 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002309 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002310 Pattern.getTemplateNameLoc(),
2311 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002312
2313 case TemplateArgument::Null:
2314 case TemplateArgument::Integral:
2315 case TemplateArgument::Declaration:
2316 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002317 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002318 llvm_unreachable("Pack expansion pattern has no parameter packs");
2319
2320 case TemplateArgument::Type:
2321 if (TypeSourceInfo *Expansion
2322 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002323 EllipsisLoc,
2324 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002325 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2326 Expansion);
2327 break;
2328 }
2329
2330 return TemplateArgumentLoc();
2331 }
2332
Douglas Gregor968f23a2011-01-03 19:31:53 +00002333 /// \brief Build a new expression pack expansion.
2334 ///
2335 /// By default, performs semantic analysis to build a new pack expansion
2336 /// for an expression. Subclasses may override this routine to provide
2337 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002338 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2339 llvm::Optional<unsigned> NumExpansions) {
2340 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002341 }
2342
John McCall31f82722010-11-12 08:19:04 +00002343private:
Douglas Gregor14454802011-02-25 02:25:35 +00002344 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2345 QualType ObjectType,
2346 NamedDecl *FirstQualifierInScope,
2347 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002348
2349 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2350 QualType ObjectType,
2351 NamedDecl *FirstQualifierInScope,
2352 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002353};
Douglas Gregora16548e2009-08-11 05:31:07 +00002354
Douglas Gregorebe10102009-08-20 07:17:43 +00002355template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002356StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002357 if (!S)
2358 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002359
Douglas Gregorebe10102009-08-20 07:17:43 +00002360 switch (S->getStmtClass()) {
2361 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002362
Douglas Gregorebe10102009-08-20 07:17:43 +00002363 // Transform individual statement nodes
2364#define STMT(Node, Parent) \
2365 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002366#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002367#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002368#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002369
Douglas Gregorebe10102009-08-20 07:17:43 +00002370 // Transform expressions by calling TransformExpr.
2371#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002372#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002373#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002374#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002375 {
John McCalldadc5752010-08-24 06:29:42 +00002376 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002377 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002378 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002379
John McCallb268a282010-08-23 23:25:46 +00002380 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002381 }
Mike Stump11289f42009-09-09 15:08:12 +00002382 }
2383
John McCallc3007a22010-10-26 07:05:15 +00002384 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002385}
Mike Stump11289f42009-09-09 15:08:12 +00002386
2387
Douglas Gregore922c772009-08-04 22:27:00 +00002388template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002389ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002390 if (!E)
2391 return SemaRef.Owned(E);
2392
2393 switch (E->getStmtClass()) {
2394 case Stmt::NoStmtClass: break;
2395#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002396#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002397#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002398 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002399#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002400 }
2401
John McCallc3007a22010-10-26 07:05:15 +00002402 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002403}
2404
2405template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002406bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2407 unsigned NumInputs,
2408 bool IsCall,
2409 llvm::SmallVectorImpl<Expr *> &Outputs,
2410 bool *ArgChanged) {
2411 for (unsigned I = 0; I != NumInputs; ++I) {
2412 // If requested, drop call arguments that need to be dropped.
2413 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2414 if (ArgChanged)
2415 *ArgChanged = true;
2416
2417 break;
2418 }
2419
Douglas Gregor968f23a2011-01-03 19:31:53 +00002420 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2421 Expr *Pattern = Expansion->getPattern();
2422
2423 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2424 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2425 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2426
2427 // Determine whether the set of unexpanded parameter packs can and should
2428 // be expanded.
2429 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002430 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002431 llvm::Optional<unsigned> OrigNumExpansions
2432 = Expansion->getNumExpansions();
2433 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002434 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2435 Pattern->getSourceRange(),
2436 Unexpanded.data(),
2437 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002438 Expand, RetainExpansion,
2439 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002440 return true;
2441
2442 if (!Expand) {
2443 // The transform has determined that we should perform a simple
2444 // transformation on the pack expansion, producing another pack
2445 // expansion.
2446 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2447 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2448 if (OutPattern.isInvalid())
2449 return true;
2450
2451 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002452 Expansion->getEllipsisLoc(),
2453 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002454 if (Out.isInvalid())
2455 return true;
2456
2457 if (ArgChanged)
2458 *ArgChanged = true;
2459 Outputs.push_back(Out.get());
2460 continue;
2461 }
2462
2463 // The transform has determined that we should perform an elementwise
2464 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002465 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002466 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2467 ExprResult Out = getDerived().TransformExpr(Pattern);
2468 if (Out.isInvalid())
2469 return true;
2470
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002471 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002472 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2473 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002474 if (Out.isInvalid())
2475 return true;
2476 }
2477
Douglas Gregor968f23a2011-01-03 19:31:53 +00002478 if (ArgChanged)
2479 *ArgChanged = true;
2480 Outputs.push_back(Out.get());
2481 }
2482
2483 continue;
2484 }
2485
Douglas Gregora3efea12011-01-03 19:04:46 +00002486 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2487 if (Result.isInvalid())
2488 return true;
2489
2490 if (Result.get() != Inputs[I] && ArgChanged)
2491 *ArgChanged = true;
2492
2493 Outputs.push_back(Result.get());
2494 }
2495
2496 return false;
2497}
2498
2499template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002500NestedNameSpecifierLoc
2501TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2502 NestedNameSpecifierLoc NNS,
2503 QualType ObjectType,
2504 NamedDecl *FirstQualifierInScope) {
2505 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2506 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2507 Qualifier = Qualifier.getPrefix())
2508 Qualifiers.push_back(Qualifier);
2509
2510 CXXScopeSpec SS;
2511 while (!Qualifiers.empty()) {
2512 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2513 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2514
2515 switch (QNNS->getKind()) {
2516 case NestedNameSpecifier::Identifier:
2517 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2518 *QNNS->getAsIdentifier(),
2519 Q.getLocalBeginLoc(),
2520 Q.getLocalEndLoc(),
2521 ObjectType, false, SS,
2522 FirstQualifierInScope, false))
2523 return NestedNameSpecifierLoc();
2524
2525 break;
2526
2527 case NestedNameSpecifier::Namespace: {
2528 NamespaceDecl *NS
2529 = cast_or_null<NamespaceDecl>(
2530 getDerived().TransformDecl(
2531 Q.getLocalBeginLoc(),
2532 QNNS->getAsNamespace()));
2533 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2534 break;
2535 }
2536
2537 case NestedNameSpecifier::NamespaceAlias: {
2538 NamespaceAliasDecl *Alias
2539 = cast_or_null<NamespaceAliasDecl>(
2540 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2541 QNNS->getAsNamespaceAlias()));
2542 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2543 Q.getLocalEndLoc());
2544 break;
2545 }
2546
2547 case NestedNameSpecifier::Global:
2548 // There is no meaningful transformation that one could perform on the
2549 // global scope.
2550 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2551 break;
2552
2553 case NestedNameSpecifier::TypeSpecWithTemplate:
2554 case NestedNameSpecifier::TypeSpec: {
2555 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2556 FirstQualifierInScope, SS);
2557
2558 if (!TL)
2559 return NestedNameSpecifierLoc();
2560
2561 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2562 (SemaRef.getLangOptions().CPlusPlus0x &&
2563 TL.getType()->isEnumeralType())) {
2564 assert(!TL.getType().hasLocalQualifiers() &&
2565 "Can't get cv-qualifiers here");
2566 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2567 Q.getLocalEndLoc());
2568 break;
2569 }
2570
2571 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2572 << TL.getType() << SS.getRange();
2573 return NestedNameSpecifierLoc();
2574 }
Douglas Gregore16af532011-02-28 18:50:33 +00002575 }
Douglas Gregor14454802011-02-25 02:25:35 +00002576
Douglas Gregore16af532011-02-28 18:50:33 +00002577 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002578 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002579 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002580 }
2581
2582 // Don't rebuild the nested-name-specifier if we don't have to.
2583 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2584 !getDerived().AlwaysRebuild())
2585 return NNS;
2586
2587 // If we can re-use the source-location data from the original
2588 // nested-name-specifier, do so.
2589 if (SS.location_size() == NNS.getDataLength() &&
2590 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2591 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2592
2593 // Allocate new nested-name-specifier location information.
2594 return SS.getWithLocInContext(SemaRef.Context);
2595}
2596
2597template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002598DeclarationNameInfo
2599TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002600::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002601 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002602 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002603 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002604
2605 switch (Name.getNameKind()) {
2606 case DeclarationName::Identifier:
2607 case DeclarationName::ObjCZeroArgSelector:
2608 case DeclarationName::ObjCOneArgSelector:
2609 case DeclarationName::ObjCMultiArgSelector:
2610 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002611 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002612 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002613 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002614
Douglas Gregorf816bd72009-09-03 22:13:48 +00002615 case DeclarationName::CXXConstructorName:
2616 case DeclarationName::CXXDestructorName:
2617 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002618 TypeSourceInfo *NewTInfo;
2619 CanQualType NewCanTy;
2620 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002621 NewTInfo = getDerived().TransformType(OldTInfo);
2622 if (!NewTInfo)
2623 return DeclarationNameInfo();
2624 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002625 }
2626 else {
2627 NewTInfo = 0;
2628 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002629 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002630 if (NewT.isNull())
2631 return DeclarationNameInfo();
2632 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2633 }
Mike Stump11289f42009-09-09 15:08:12 +00002634
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002635 DeclarationName NewName
2636 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2637 NewCanTy);
2638 DeclarationNameInfo NewNameInfo(NameInfo);
2639 NewNameInfo.setName(NewName);
2640 NewNameInfo.setNamedTypeInfo(NewTInfo);
2641 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002642 }
Mike Stump11289f42009-09-09 15:08:12 +00002643 }
2644
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002645 assert(0 && "Unknown name kind.");
2646 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002647}
2648
2649template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002650TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00002651TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2652 TemplateName Name,
2653 SourceLocation NameLoc,
2654 QualType ObjectType,
2655 NamedDecl *FirstQualifierInScope) {
2656 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2657 TemplateDecl *Template = QTN->getTemplateDecl();
2658 assert(Template && "qualified template name must refer to a template");
2659
2660 TemplateDecl *TransTemplate
2661 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2662 Template));
2663 if (!TransTemplate)
2664 return TemplateName();
2665
2666 if (!getDerived().AlwaysRebuild() &&
2667 SS.getScopeRep() == QTN->getQualifier() &&
2668 TransTemplate == Template)
2669 return Name;
2670
2671 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2672 TransTemplate);
2673 }
2674
2675 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2676 if (SS.getScopeRep()) {
2677 // These apply to the scope specifier, not the template.
2678 ObjectType = QualType();
2679 FirstQualifierInScope = 0;
2680 }
2681
2682 if (!getDerived().AlwaysRebuild() &&
2683 SS.getScopeRep() == DTN->getQualifier() &&
2684 ObjectType.isNull())
2685 return Name;
2686
2687 if (DTN->isIdentifier()) {
2688 return getDerived().RebuildTemplateName(SS,
2689 *DTN->getIdentifier(),
2690 NameLoc,
2691 ObjectType,
2692 FirstQualifierInScope);
2693 }
2694
2695 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2696 ObjectType);
2697 }
2698
2699 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2700 TemplateDecl *TransTemplate
2701 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2702 Template));
2703 if (!TransTemplate)
2704 return TemplateName();
2705
2706 if (!getDerived().AlwaysRebuild() &&
2707 TransTemplate == Template)
2708 return Name;
2709
2710 return TemplateName(TransTemplate);
2711 }
2712
2713 if (SubstTemplateTemplateParmPackStorage *SubstPack
2714 = Name.getAsSubstTemplateTemplateParmPack()) {
2715 TemplateTemplateParmDecl *TransParam
2716 = cast_or_null<TemplateTemplateParmDecl>(
2717 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2718 if (!TransParam)
2719 return TemplateName();
2720
2721 if (!getDerived().AlwaysRebuild() &&
2722 TransParam == SubstPack->getParameterPack())
2723 return Name;
2724
2725 return getDerived().RebuildTemplateName(TransParam,
2726 SubstPack->getArgumentPack());
2727 }
2728
2729 // These should be getting filtered out before they reach the AST.
2730 llvm_unreachable("overloaded function decl survived to here");
2731 return TemplateName();
2732}
2733
2734template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002735void TreeTransform<Derived>::InventTemplateArgumentLoc(
2736 const TemplateArgument &Arg,
2737 TemplateArgumentLoc &Output) {
2738 SourceLocation Loc = getDerived().getBaseLocation();
2739 switch (Arg.getKind()) {
2740 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002741 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002742 break;
2743
2744 case TemplateArgument::Type:
2745 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002746 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002747
John McCall0ad16662009-10-29 08:12:44 +00002748 break;
2749
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002750 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00002751 case TemplateArgument::TemplateExpansion: {
2752 NestedNameSpecifierLocBuilder Builder;
2753 TemplateName Template = Arg.getAsTemplate();
2754 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2755 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2756 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2757 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2758
2759 if (Arg.getKind() == TemplateArgument::Template)
2760 Output = TemplateArgumentLoc(Arg,
2761 Builder.getWithLocInContext(SemaRef.Context),
2762 Loc);
2763 else
2764 Output = TemplateArgumentLoc(Arg,
2765 Builder.getWithLocInContext(SemaRef.Context),
2766 Loc, Loc);
2767
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002768 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00002769 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002770
John McCall0ad16662009-10-29 08:12:44 +00002771 case TemplateArgument::Expression:
2772 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2773 break;
2774
2775 case TemplateArgument::Declaration:
2776 case TemplateArgument::Integral:
2777 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002778 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002779 break;
2780 }
2781}
2782
2783template<typename Derived>
2784bool TreeTransform<Derived>::TransformTemplateArgument(
2785 const TemplateArgumentLoc &Input,
2786 TemplateArgumentLoc &Output) {
2787 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002788 switch (Arg.getKind()) {
2789 case TemplateArgument::Null:
2790 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002791 Output = Input;
2792 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002793
Douglas Gregore922c772009-08-04 22:27:00 +00002794 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002795 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002796 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002797 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002798
2799 DI = getDerived().TransformType(DI);
2800 if (!DI) return true;
2801
2802 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2803 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002804 }
Mike Stump11289f42009-09-09 15:08:12 +00002805
Douglas Gregore922c772009-08-04 22:27:00 +00002806 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002807 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002808 DeclarationName Name;
2809 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2810 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002811 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002812 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002813 if (!D) return true;
2814
John McCall0d07eb32009-10-29 18:45:58 +00002815 Expr *SourceExpr = Input.getSourceDeclExpression();
2816 if (SourceExpr) {
2817 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002818 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002819 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002820 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002821 }
2822
2823 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002824 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002825 }
Mike Stump11289f42009-09-09 15:08:12 +00002826
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002827 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00002828 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2829 if (QualifierLoc) {
2830 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2831 if (!QualifierLoc)
2832 return true;
2833 }
2834
Douglas Gregordf846d12011-03-02 18:46:51 +00002835 CXXScopeSpec SS;
2836 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002837 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00002838 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2839 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002840 if (Template.isNull())
2841 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002842
Douglas Gregor9d802122011-03-02 17:09:35 +00002843 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002844 Input.getTemplateNameLoc());
2845 return false;
2846 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002847
2848 case TemplateArgument::TemplateExpansion:
2849 llvm_unreachable("Caller should expand pack expansions");
2850
Douglas Gregore922c772009-08-04 22:27:00 +00002851 case TemplateArgument::Expression: {
2852 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002853 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002854 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002855
John McCall0ad16662009-10-29 08:12:44 +00002856 Expr *InputExpr = Input.getSourceExpression();
2857 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2858
Chris Lattnercdb591a2011-04-25 20:37:58 +00002859 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall0ad16662009-10-29 08:12:44 +00002860 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002861 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002862 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002863 }
Mike Stump11289f42009-09-09 15:08:12 +00002864
Douglas Gregore922c772009-08-04 22:27:00 +00002865 case TemplateArgument::Pack: {
2866 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2867 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002868 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002869 AEnd = Arg.pack_end();
2870 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002871
John McCall0ad16662009-10-29 08:12:44 +00002872 // FIXME: preserve source information here when we start
2873 // caring about parameter packs.
2874
John McCall0d07eb32009-10-29 18:45:58 +00002875 TemplateArgumentLoc InputArg;
2876 TemplateArgumentLoc OutputArg;
2877 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2878 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002879 return true;
2880
John McCall0d07eb32009-10-29 18:45:58 +00002881 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002882 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002883
2884 TemplateArgument *TransformedArgsPtr
2885 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2886 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2887 TransformedArgsPtr);
2888 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2889 TransformedArgs.size()),
2890 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002891 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002892 }
2893 }
Mike Stump11289f42009-09-09 15:08:12 +00002894
Douglas Gregore922c772009-08-04 22:27:00 +00002895 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002896 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002897}
2898
Douglas Gregorfe921a72010-12-20 23:36:19 +00002899/// \brief Iterator adaptor that invents template argument location information
2900/// for each of the template arguments in its underlying iterator.
2901template<typename Derived, typename InputIterator>
2902class TemplateArgumentLocInventIterator {
2903 TreeTransform<Derived> &Self;
2904 InputIterator Iter;
2905
2906public:
2907 typedef TemplateArgumentLoc value_type;
2908 typedef TemplateArgumentLoc reference;
2909 typedef typename std::iterator_traits<InputIterator>::difference_type
2910 difference_type;
2911 typedef std::input_iterator_tag iterator_category;
2912
2913 class pointer {
2914 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002915
Douglas Gregorfe921a72010-12-20 23:36:19 +00002916 public:
2917 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2918
2919 const TemplateArgumentLoc *operator->() const { return &Arg; }
2920 };
2921
2922 TemplateArgumentLocInventIterator() { }
2923
2924 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2925 InputIterator Iter)
2926 : Self(Self), Iter(Iter) { }
2927
2928 TemplateArgumentLocInventIterator &operator++() {
2929 ++Iter;
2930 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002931 }
2932
Douglas Gregorfe921a72010-12-20 23:36:19 +00002933 TemplateArgumentLocInventIterator operator++(int) {
2934 TemplateArgumentLocInventIterator Old(*this);
2935 ++(*this);
2936 return Old;
2937 }
2938
2939 reference operator*() const {
2940 TemplateArgumentLoc Result;
2941 Self.InventTemplateArgumentLoc(*Iter, Result);
2942 return Result;
2943 }
2944
2945 pointer operator->() const { return pointer(**this); }
2946
2947 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2948 const TemplateArgumentLocInventIterator &Y) {
2949 return X.Iter == Y.Iter;
2950 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002951
Douglas Gregorfe921a72010-12-20 23:36:19 +00002952 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2953 const TemplateArgumentLocInventIterator &Y) {
2954 return X.Iter != Y.Iter;
2955 }
2956};
2957
Douglas Gregor42cafa82010-12-20 17:42:22 +00002958template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002959template<typename InputIterator>
2960bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2961 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002962 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002963 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002964 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002965 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002966
2967 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2968 // Unpack argument packs, which we translate them into separate
2969 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002970 // FIXME: We could do much better if we could guarantee that the
2971 // TemplateArgumentLocInfo for the pack expansion would be usable for
2972 // all of the template arguments in the argument pack.
2973 typedef TemplateArgumentLocInventIterator<Derived,
2974 TemplateArgument::pack_iterator>
2975 PackLocIterator;
2976 if (TransformTemplateArguments(PackLocIterator(*this,
2977 In.getArgument().pack_begin()),
2978 PackLocIterator(*this,
2979 In.getArgument().pack_end()),
2980 Outputs))
2981 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002982
2983 continue;
2984 }
2985
2986 if (In.getArgument().isPackExpansion()) {
2987 // We have a pack expansion, for which we will be substituting into
2988 // the pattern.
2989 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002990 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002991 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002992 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2993 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002994
2995 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2996 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2997 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2998
2999 // Determine whether the set of unexpanded parameter packs can and should
3000 // be expanded.
3001 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003002 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003003 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003004 if (getDerived().TryExpandParameterPacks(Ellipsis,
3005 Pattern.getSourceRange(),
3006 Unexpanded.data(),
3007 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003008 Expand,
3009 RetainExpansion,
3010 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003011 return true;
3012
3013 if (!Expand) {
3014 // The transform has determined that we should perform a simple
3015 // transformation on the pack expansion, producing another pack
3016 // expansion.
3017 TemplateArgumentLoc OutPattern;
3018 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3019 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3020 return true;
3021
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003022 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3023 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003024 if (Out.getArgument().isNull())
3025 return true;
3026
3027 Outputs.addArgument(Out);
3028 continue;
3029 }
3030
3031 // The transform has determined that we should perform an elementwise
3032 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003033 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003034 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3035
3036 if (getDerived().TransformTemplateArgument(Pattern, Out))
3037 return true;
3038
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003039 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003040 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3041 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003042 if (Out.getArgument().isNull())
3043 return true;
3044 }
3045
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003046 Outputs.addArgument(Out);
3047 }
3048
Douglas Gregor48d24112011-01-10 20:53:55 +00003049 // If we're supposed to retain a pack expansion, do so by temporarily
3050 // forgetting the partially-substituted parameter pack.
3051 if (RetainExpansion) {
3052 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3053
3054 if (getDerived().TransformTemplateArgument(Pattern, Out))
3055 return true;
3056
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003057 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3058 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003059 if (Out.getArgument().isNull())
3060 return true;
3061
3062 Outputs.addArgument(Out);
3063 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003064
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003065 continue;
3066 }
3067
3068 // The simple case:
3069 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003070 return true;
3071
3072 Outputs.addArgument(Out);
3073 }
3074
3075 return false;
3076
3077}
3078
Douglas Gregord6ff3322009-08-04 16:50:30 +00003079//===----------------------------------------------------------------------===//
3080// Type transformation
3081//===----------------------------------------------------------------------===//
3082
3083template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003084QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003085 if (getDerived().AlreadyTransformed(T))
3086 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003087
John McCall550e0c22009-10-21 00:40:46 +00003088 // Temporary workaround. All of these transformations should
3089 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003090 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3091 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003092
John McCall31f82722010-11-12 08:19:04 +00003093 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003094
John McCall550e0c22009-10-21 00:40:46 +00003095 if (!NewDI)
3096 return QualType();
3097
3098 return NewDI->getType();
3099}
3100
3101template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003102TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003103 if (getDerived().AlreadyTransformed(DI->getType()))
3104 return DI;
3105
3106 TypeLocBuilder TLB;
3107
3108 TypeLoc TL = DI->getTypeLoc();
3109 TLB.reserve(TL.getFullDataSize());
3110
John McCall31f82722010-11-12 08:19:04 +00003111 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003112 if (Result.isNull())
3113 return 0;
3114
John McCallbcd03502009-12-07 02:54:59 +00003115 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003116}
3117
3118template<typename Derived>
3119QualType
John McCall31f82722010-11-12 08:19:04 +00003120TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003121 switch (T.getTypeLocClass()) {
3122#define ABSTRACT_TYPELOC(CLASS, PARENT)
3123#define TYPELOC(CLASS, PARENT) \
3124 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003125 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003126#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003127 }
Mike Stump11289f42009-09-09 15:08:12 +00003128
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003129 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003130 return QualType();
3131}
3132
3133/// FIXME: By default, this routine adds type qualifiers only to types
3134/// that can have qualifiers, and silently suppresses those qualifiers
3135/// that are not permitted (e.g., qualifiers on reference or function
3136/// types). This is the right thing for template instantiation, but
3137/// probably not for other clients.
3138template<typename Derived>
3139QualType
3140TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003141 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003142 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003143
John McCall31f82722010-11-12 08:19:04 +00003144 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003145 if (Result.isNull())
3146 return QualType();
3147
3148 // Silently suppress qualifiers if the result type can't be qualified.
3149 // FIXME: this is the right thing for template instantiation, but
3150 // probably not for other clients.
3151 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003152 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003153
John McCallcb0f89a2010-06-05 06:41:15 +00003154 if (!Quals.empty()) {
3155 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3156 TLB.push<QualifiedTypeLoc>(Result);
3157 // No location information to preserve.
3158 }
John McCall550e0c22009-10-21 00:40:46 +00003159
3160 return Result;
3161}
3162
Douglas Gregor14454802011-02-25 02:25:35 +00003163template<typename Derived>
3164TypeLoc
3165TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3166 QualType ObjectType,
3167 NamedDecl *UnqualLookup,
3168 CXXScopeSpec &SS) {
Douglas Gregor14454802011-02-25 02:25:35 +00003169 QualType T = TL.getType();
3170 if (getDerived().AlreadyTransformed(T))
3171 return TL;
3172
3173 TypeLocBuilder TLB;
3174 QualType Result;
3175
3176 if (isa<TemplateSpecializationType>(T)) {
3177 TemplateSpecializationTypeLoc SpecTL
3178 = cast<TemplateSpecializationTypeLoc>(TL);
3179
3180 TemplateName Template =
Douglas Gregor9db53502011-03-02 18:07:45 +00003181 getDerived().TransformTemplateName(SS,
3182 SpecTL.getTypePtr()->getTemplateName(),
3183 SpecTL.getTemplateNameLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003184 ObjectType, UnqualLookup);
3185 if (Template.isNull())
3186 return TypeLoc();
3187
3188 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3189 Template);
3190 } else if (isa<DependentTemplateSpecializationType>(T)) {
3191 DependentTemplateSpecializationTypeLoc SpecTL
3192 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3193
Douglas Gregor5a064722011-02-28 17:23:35 +00003194 TemplateName Template
Douglas Gregor9db53502011-03-02 18:07:45 +00003195 = getDerived().RebuildTemplateName(SS,
Douglas Gregore16af532011-02-28 18:50:33 +00003196 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003197 SpecTL.getNameLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00003198 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003199 if (Template.isNull())
3200 return TypeLoc();
3201
Douglas Gregor14454802011-02-25 02:25:35 +00003202 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003203 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003204 Template,
3205 SS);
Douglas Gregor14454802011-02-25 02:25:35 +00003206 } else {
3207 // Nothing special needs to be done for these.
3208 Result = getDerived().TransformType(TLB, TL);
3209 }
3210
3211 if (Result.isNull())
3212 return TypeLoc();
3213
3214 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3215}
3216
Douglas Gregor579c15f2011-03-02 18:32:08 +00003217template<typename Derived>
3218TypeSourceInfo *
3219TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3220 QualType ObjectType,
3221 NamedDecl *UnqualLookup,
3222 CXXScopeSpec &SS) {
3223 // FIXME: Painfully copy-paste from the above!
3224
3225 QualType T = TSInfo->getType();
3226 if (getDerived().AlreadyTransformed(T))
3227 return TSInfo;
3228
3229 TypeLocBuilder TLB;
3230 QualType Result;
3231
3232 TypeLoc TL = TSInfo->getTypeLoc();
3233 if (isa<TemplateSpecializationType>(T)) {
3234 TemplateSpecializationTypeLoc SpecTL
3235 = cast<TemplateSpecializationTypeLoc>(TL);
3236
3237 TemplateName Template
3238 = getDerived().TransformTemplateName(SS,
3239 SpecTL.getTypePtr()->getTemplateName(),
3240 SpecTL.getTemplateNameLoc(),
3241 ObjectType, UnqualLookup);
3242 if (Template.isNull())
3243 return 0;
3244
3245 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3246 Template);
3247 } else if (isa<DependentTemplateSpecializationType>(T)) {
3248 DependentTemplateSpecializationTypeLoc SpecTL
3249 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3250
3251 TemplateName Template
3252 = getDerived().RebuildTemplateName(SS,
3253 *SpecTL.getTypePtr()->getIdentifier(),
3254 SpecTL.getNameLoc(),
3255 ObjectType, UnqualLookup);
3256 if (Template.isNull())
3257 return 0;
3258
3259 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3260 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003261 Template,
3262 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003263 } else {
3264 // Nothing special needs to be done for these.
3265 Result = getDerived().TransformType(TLB, TL);
3266 }
3267
3268 if (Result.isNull())
3269 return 0;
3270
3271 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3272}
3273
John McCall550e0c22009-10-21 00:40:46 +00003274template <class TyLoc> static inline
3275QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3276 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3277 NewT.setNameLoc(T.getNameLoc());
3278 return T.getType();
3279}
3280
John McCall550e0c22009-10-21 00:40:46 +00003281template<typename Derived>
3282QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003283 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003284 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3285 NewT.setBuiltinLoc(T.getBuiltinLoc());
3286 if (T.needsExtraLocalData())
3287 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3288 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003289}
Mike Stump11289f42009-09-09 15:08:12 +00003290
Douglas Gregord6ff3322009-08-04 16:50:30 +00003291template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003292QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003293 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003294 // FIXME: recurse?
3295 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003296}
Mike Stump11289f42009-09-09 15:08:12 +00003297
Douglas Gregord6ff3322009-08-04 16:50:30 +00003298template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003299QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003300 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003301 QualType PointeeType
3302 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003303 if (PointeeType.isNull())
3304 return QualType();
3305
3306 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003307 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003308 // A dependent pointer type 'T *' has is being transformed such
3309 // that an Objective-C class type is being replaced for 'T'. The
3310 // resulting pointer type is an ObjCObjectPointerType, not a
3311 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003312 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003313
John McCall8b07ec22010-05-15 11:32:37 +00003314 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3315 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003316 return Result;
3317 }
John McCall31f82722010-11-12 08:19:04 +00003318
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003319 if (getDerived().AlwaysRebuild() ||
3320 PointeeType != TL.getPointeeLoc().getType()) {
3321 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3322 if (Result.isNull())
3323 return QualType();
3324 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003325
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003326 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3327 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003328 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003329}
Mike Stump11289f42009-09-09 15:08:12 +00003330
3331template<typename Derived>
3332QualType
John McCall550e0c22009-10-21 00:40:46 +00003333TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003334 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003335 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003336 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3337 if (PointeeType.isNull())
3338 return QualType();
3339
3340 QualType Result = TL.getType();
3341 if (getDerived().AlwaysRebuild() ||
3342 PointeeType != TL.getPointeeLoc().getType()) {
3343 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003344 TL.getSigilLoc());
3345 if (Result.isNull())
3346 return QualType();
3347 }
3348
Douglas Gregor049211a2010-04-22 16:50:51 +00003349 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003350 NewT.setSigilLoc(TL.getSigilLoc());
3351 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003352}
3353
John McCall70dd5f62009-10-30 00:06:24 +00003354/// Transforms a reference type. Note that somewhat paradoxically we
3355/// don't care whether the type itself is an l-value type or an r-value
3356/// type; we only care if the type was *written* as an l-value type
3357/// or an r-value type.
3358template<typename Derived>
3359QualType
3360TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003361 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003362 const ReferenceType *T = TL.getTypePtr();
3363
3364 // Note that this works with the pointee-as-written.
3365 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3366 if (PointeeType.isNull())
3367 return QualType();
3368
3369 QualType Result = TL.getType();
3370 if (getDerived().AlwaysRebuild() ||
3371 PointeeType != T->getPointeeTypeAsWritten()) {
3372 Result = getDerived().RebuildReferenceType(PointeeType,
3373 T->isSpelledAsLValue(),
3374 TL.getSigilLoc());
3375 if (Result.isNull())
3376 return QualType();
3377 }
3378
3379 // r-value references can be rebuilt as l-value references.
3380 ReferenceTypeLoc NewTL;
3381 if (isa<LValueReferenceType>(Result))
3382 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3383 else
3384 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3385 NewTL.setSigilLoc(TL.getSigilLoc());
3386
3387 return Result;
3388}
3389
Mike Stump11289f42009-09-09 15:08:12 +00003390template<typename Derived>
3391QualType
John McCall550e0c22009-10-21 00:40:46 +00003392TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003393 LValueReferenceTypeLoc TL) {
3394 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003395}
3396
Mike Stump11289f42009-09-09 15:08:12 +00003397template<typename Derived>
3398QualType
John McCall550e0c22009-10-21 00:40:46 +00003399TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003400 RValueReferenceTypeLoc TL) {
3401 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003402}
Mike Stump11289f42009-09-09 15:08:12 +00003403
Douglas Gregord6ff3322009-08-04 16:50:30 +00003404template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003405QualType
John McCall550e0c22009-10-21 00:40:46 +00003406TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003407 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003408 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003409 if (PointeeType.isNull())
3410 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003411
Abramo Bagnara509357842011-03-05 14:42:21 +00003412 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3413 TypeSourceInfo* NewClsTInfo = 0;
3414 if (OldClsTInfo) {
3415 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3416 if (!NewClsTInfo)
3417 return QualType();
3418 }
3419
3420 const MemberPointerType *T = TL.getTypePtr();
3421 QualType OldClsType = QualType(T->getClass(), 0);
3422 QualType NewClsType;
3423 if (NewClsTInfo)
3424 NewClsType = NewClsTInfo->getType();
3425 else {
3426 NewClsType = getDerived().TransformType(OldClsType);
3427 if (NewClsType.isNull())
3428 return QualType();
3429 }
Mike Stump11289f42009-09-09 15:08:12 +00003430
John McCall550e0c22009-10-21 00:40:46 +00003431 QualType Result = TL.getType();
3432 if (getDerived().AlwaysRebuild() ||
3433 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003434 NewClsType != OldClsType) {
3435 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003436 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003437 if (Result.isNull())
3438 return QualType();
3439 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003440
John McCall550e0c22009-10-21 00:40:46 +00003441 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3442 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003443 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003444
3445 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003446}
3447
Mike Stump11289f42009-09-09 15:08:12 +00003448template<typename Derived>
3449QualType
John McCall550e0c22009-10-21 00:40:46 +00003450TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003451 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003452 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003453 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003454 if (ElementType.isNull())
3455 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003456
John McCall550e0c22009-10-21 00:40:46 +00003457 QualType Result = TL.getType();
3458 if (getDerived().AlwaysRebuild() ||
3459 ElementType != T->getElementType()) {
3460 Result = getDerived().RebuildConstantArrayType(ElementType,
3461 T->getSizeModifier(),
3462 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003463 T->getIndexTypeCVRQualifiers(),
3464 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003465 if (Result.isNull())
3466 return QualType();
3467 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003468
John McCall550e0c22009-10-21 00:40:46 +00003469 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3470 NewTL.setLBracketLoc(TL.getLBracketLoc());
3471 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003472
John McCall550e0c22009-10-21 00:40:46 +00003473 Expr *Size = TL.getSizeExpr();
3474 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003475 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003476 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3477 }
3478 NewTL.setSizeExpr(Size);
3479
3480 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003481}
Mike Stump11289f42009-09-09 15:08:12 +00003482
Douglas Gregord6ff3322009-08-04 16:50:30 +00003483template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003484QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003485 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003486 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003487 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003488 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003489 if (ElementType.isNull())
3490 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003491
John McCall550e0c22009-10-21 00:40:46 +00003492 QualType Result = TL.getType();
3493 if (getDerived().AlwaysRebuild() ||
3494 ElementType != T->getElementType()) {
3495 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003496 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003497 T->getIndexTypeCVRQualifiers(),
3498 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003499 if (Result.isNull())
3500 return QualType();
3501 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003502
John McCall550e0c22009-10-21 00:40:46 +00003503 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3504 NewTL.setLBracketLoc(TL.getLBracketLoc());
3505 NewTL.setRBracketLoc(TL.getRBracketLoc());
3506 NewTL.setSizeExpr(0);
3507
3508 return Result;
3509}
3510
3511template<typename Derived>
3512QualType
3513TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003514 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003515 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003516 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3517 if (ElementType.isNull())
3518 return QualType();
3519
3520 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003521 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003522
John McCalldadc5752010-08-24 06:29:42 +00003523 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003524 = getDerived().TransformExpr(T->getSizeExpr());
3525 if (SizeResult.isInvalid())
3526 return QualType();
3527
John McCallb268a282010-08-23 23:25:46 +00003528 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003529
3530 QualType Result = TL.getType();
3531 if (getDerived().AlwaysRebuild() ||
3532 ElementType != T->getElementType() ||
3533 Size != T->getSizeExpr()) {
3534 Result = getDerived().RebuildVariableArrayType(ElementType,
3535 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003536 Size,
John McCall550e0c22009-10-21 00:40:46 +00003537 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003538 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003539 if (Result.isNull())
3540 return QualType();
3541 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003542
John McCall550e0c22009-10-21 00:40:46 +00003543 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3544 NewTL.setLBracketLoc(TL.getLBracketLoc());
3545 NewTL.setRBracketLoc(TL.getRBracketLoc());
3546 NewTL.setSizeExpr(Size);
3547
3548 return Result;
3549}
3550
3551template<typename Derived>
3552QualType
3553TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003554 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003555 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003556 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3557 if (ElementType.isNull())
3558 return QualType();
3559
3560 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003561 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003562
John McCall33ddac02011-01-19 10:06:00 +00003563 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3564 Expr *origSize = TL.getSizeExpr();
3565 if (!origSize) origSize = T->getSizeExpr();
3566
3567 ExprResult sizeResult
3568 = getDerived().TransformExpr(origSize);
3569 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003570 return QualType();
3571
John McCall33ddac02011-01-19 10:06:00 +00003572 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003573
3574 QualType Result = TL.getType();
3575 if (getDerived().AlwaysRebuild() ||
3576 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003577 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003578 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3579 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003580 size,
John McCall550e0c22009-10-21 00:40:46 +00003581 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003582 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003583 if (Result.isNull())
3584 return QualType();
3585 }
John McCall550e0c22009-10-21 00:40:46 +00003586
3587 // We might have any sort of array type now, but fortunately they
3588 // all have the same location layout.
3589 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3590 NewTL.setLBracketLoc(TL.getLBracketLoc());
3591 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003592 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003593
3594 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003595}
Mike Stump11289f42009-09-09 15:08:12 +00003596
3597template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003598QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003599 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003600 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003601 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003602
3603 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003604 QualType ElementType = getDerived().TransformType(T->getElementType());
3605 if (ElementType.isNull())
3606 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003607
Douglas Gregore922c772009-08-04 22:27:00 +00003608 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003609 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003610
John McCalldadc5752010-08-24 06:29:42 +00003611 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003612 if (Size.isInvalid())
3613 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003614
John McCall550e0c22009-10-21 00:40:46 +00003615 QualType Result = TL.getType();
3616 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003617 ElementType != T->getElementType() ||
3618 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003619 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003620 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003621 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003622 if (Result.isNull())
3623 return QualType();
3624 }
John McCall550e0c22009-10-21 00:40:46 +00003625
3626 // Result might be dependent or not.
3627 if (isa<DependentSizedExtVectorType>(Result)) {
3628 DependentSizedExtVectorTypeLoc NewTL
3629 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3630 NewTL.setNameLoc(TL.getNameLoc());
3631 } else {
3632 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3633 NewTL.setNameLoc(TL.getNameLoc());
3634 }
3635
3636 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003637}
Mike Stump11289f42009-09-09 15:08:12 +00003638
3639template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003640QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003641 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003642 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003643 QualType ElementType = getDerived().TransformType(T->getElementType());
3644 if (ElementType.isNull())
3645 return QualType();
3646
John McCall550e0c22009-10-21 00:40:46 +00003647 QualType Result = TL.getType();
3648 if (getDerived().AlwaysRebuild() ||
3649 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003650 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003651 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003652 if (Result.isNull())
3653 return QualType();
3654 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003655
John McCall550e0c22009-10-21 00:40:46 +00003656 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3657 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003658
John McCall550e0c22009-10-21 00:40:46 +00003659 return Result;
3660}
3661
3662template<typename Derived>
3663QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003664 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003665 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003666 QualType ElementType = getDerived().TransformType(T->getElementType());
3667 if (ElementType.isNull())
3668 return QualType();
3669
3670 QualType Result = TL.getType();
3671 if (getDerived().AlwaysRebuild() ||
3672 ElementType != T->getElementType()) {
3673 Result = getDerived().RebuildExtVectorType(ElementType,
3674 T->getNumElements(),
3675 /*FIXME*/ SourceLocation());
3676 if (Result.isNull())
3677 return QualType();
3678 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003679
John McCall550e0c22009-10-21 00:40:46 +00003680 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3681 NewTL.setNameLoc(TL.getNameLoc());
3682
3683 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003684}
Mike Stump11289f42009-09-09 15:08:12 +00003685
3686template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003687ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003688TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003689 int indexAdjustment,
Douglas Gregor715e4612011-01-14 22:40:04 +00003690 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003691 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003692 TypeSourceInfo *NewDI = 0;
3693
3694 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3695 // If we're substituting into a pack expansion type and we know the
3696 TypeLoc OldTL = OldDI->getTypeLoc();
3697 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3698
3699 TypeLocBuilder TLB;
3700 TypeLoc NewTL = OldDI->getTypeLoc();
3701 TLB.reserve(NewTL.getFullDataSize());
3702
3703 QualType Result = getDerived().TransformType(TLB,
3704 OldExpansionTL.getPatternLoc());
3705 if (Result.isNull())
3706 return 0;
3707
3708 Result = RebuildPackExpansionType(Result,
3709 OldExpansionTL.getPatternLoc().getSourceRange(),
3710 OldExpansionTL.getEllipsisLoc(),
3711 NumExpansions);
3712 if (Result.isNull())
3713 return 0;
3714
3715 PackExpansionTypeLoc NewExpansionTL
3716 = TLB.push<PackExpansionTypeLoc>(Result);
3717 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3718 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3719 } else
3720 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003721 if (!NewDI)
3722 return 0;
3723
John McCall8fb0d9d2011-05-01 22:35:37 +00003724 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00003725 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00003726
3727 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3728 OldParm->getDeclContext(),
3729 OldParm->getInnerLocStart(),
3730 OldParm->getLocation(),
3731 OldParm->getIdentifier(),
3732 NewDI->getType(),
3733 NewDI,
3734 OldParm->getStorageClass(),
3735 OldParm->getStorageClassAsWritten(),
3736 /* DefArg */ NULL);
3737 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3738 OldParm->getFunctionScopeIndex() + indexAdjustment);
3739 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00003740}
3741
3742template<typename Derived>
3743bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003744 TransformFunctionTypeParams(SourceLocation Loc,
3745 ParmVarDecl **Params, unsigned NumParams,
3746 const QualType *ParamTypes,
3747 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3748 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003749 int indexAdjustment = 0;
3750
Douglas Gregordd472162011-01-07 00:20:55 +00003751 for (unsigned i = 0; i != NumParams; ++i) {
3752 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003753 assert(OldParm->getFunctionScopeIndex() == i);
3754
Douglas Gregor715e4612011-01-14 22:40:04 +00003755 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003756 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00003757 if (OldParm->isParameterPack()) {
3758 // We have a function parameter pack that may need to be expanded.
3759 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003760
Douglas Gregor5499af42011-01-05 23:12:31 +00003761 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003762 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3763 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3764 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3765 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00003766 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3767
Douglas Gregor5499af42011-01-05 23:12:31 +00003768 // Determine whether we should expand the parameter packs.
3769 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003770 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003771 llvm::Optional<unsigned> OrigNumExpansions
3772 = ExpansionTL.getTypePtr()->getNumExpansions();
3773 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003774 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3775 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003776 Unexpanded.data(),
3777 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003778 ShouldExpand,
3779 RetainExpansion,
3780 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003781 return true;
3782 }
3783
3784 if (ShouldExpand) {
3785 // Expand the function parameter pack into multiple, separate
3786 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003787 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003788 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003789 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3790 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003791 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003792 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003793 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003794 if (!NewParm)
3795 return true;
3796
Douglas Gregordd472162011-01-07 00:20:55 +00003797 OutParamTypes.push_back(NewParm->getType());
3798 if (PVars)
3799 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003800 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003801
3802 // If we're supposed to retain a pack expansion, do so by temporarily
3803 // forgetting the partially-substituted parameter pack.
3804 if (RetainExpansion) {
3805 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3806 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003807 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003808 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003809 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003810 if (!NewParm)
3811 return true;
3812
3813 OutParamTypes.push_back(NewParm->getType());
3814 if (PVars)
3815 PVars->push_back(NewParm);
3816 }
3817
John McCall8fb0d9d2011-05-01 22:35:37 +00003818 // The next parameter should have the same adjustment as the
3819 // last thing we pushed, but we post-incremented indexAdjustment
3820 // on every push. Also, if we push nothing, the adjustment should
3821 // go down by one.
3822 indexAdjustment--;
3823
Douglas Gregor5499af42011-01-05 23:12:31 +00003824 // We're done with the pack expansion.
3825 continue;
3826 }
3827
3828 // We'll substitute the parameter now without expanding the pack
3829 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00003830 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3831 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003832 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003833 NumExpansions);
3834 } else {
3835 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003836 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003837 llvm::Optional<unsigned>());
Douglas Gregor5499af42011-01-05 23:12:31 +00003838 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00003839
John McCall58f10c32010-03-11 09:03:00 +00003840 if (!NewParm)
3841 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003842
Douglas Gregordd472162011-01-07 00:20:55 +00003843 OutParamTypes.push_back(NewParm->getType());
3844 if (PVars)
3845 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003846 continue;
3847 }
John McCall58f10c32010-03-11 09:03:00 +00003848
3849 // Deal with the possibility that we don't have a parameter
3850 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003851 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003852 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003853 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003854 QualType NewType;
Douglas Gregor5499af42011-01-05 23:12:31 +00003855 if (const PackExpansionType *Expansion
3856 = dyn_cast<PackExpansionType>(OldType)) {
3857 // We have a function parameter pack that may need to be expanded.
3858 QualType Pattern = Expansion->getPattern();
3859 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3860 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3861
3862 // Determine whether we should expand the parameter packs.
3863 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003864 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003865 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003866 Unexpanded.data(),
3867 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003868 ShouldExpand,
3869 RetainExpansion,
3870 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003871 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003872 }
3873
3874 if (ShouldExpand) {
3875 // Expand the function parameter pack into multiple, separate
3876 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003877 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003878 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3879 QualType NewType = getDerived().TransformType(Pattern);
3880 if (NewType.isNull())
3881 return true;
John McCall58f10c32010-03-11 09:03:00 +00003882
Douglas Gregordd472162011-01-07 00:20:55 +00003883 OutParamTypes.push_back(NewType);
3884 if (PVars)
3885 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003886 }
3887
3888 // We're done with the pack expansion.
3889 continue;
3890 }
3891
Douglas Gregor48d24112011-01-10 20:53:55 +00003892 // If we're supposed to retain a pack expansion, do so by temporarily
3893 // forgetting the partially-substituted parameter pack.
3894 if (RetainExpansion) {
3895 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3896 QualType NewType = getDerived().TransformType(Pattern);
3897 if (NewType.isNull())
3898 return true;
3899
3900 OutParamTypes.push_back(NewType);
3901 if (PVars)
3902 PVars->push_back(0);
3903 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003904
Douglas Gregor5499af42011-01-05 23:12:31 +00003905 // We'll substitute the parameter now without expanding the pack
3906 // expansion.
3907 OldType = Expansion->getPattern();
3908 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003909 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3910 NewType = getDerived().TransformType(OldType);
3911 } else {
3912 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00003913 }
3914
Douglas Gregor5499af42011-01-05 23:12:31 +00003915 if (NewType.isNull())
3916 return true;
3917
3918 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003919 NewType = getSema().Context.getPackExpansionType(NewType,
3920 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003921
Douglas Gregordd472162011-01-07 00:20:55 +00003922 OutParamTypes.push_back(NewType);
3923 if (PVars)
3924 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003925 }
3926
John McCall8fb0d9d2011-05-01 22:35:37 +00003927#ifndef NDEBUG
3928 if (PVars) {
3929 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
3930 if (ParmVarDecl *parm = (*PVars)[i])
3931 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00003932 }
John McCall8fb0d9d2011-05-01 22:35:37 +00003933#endif
3934
3935 return false;
3936}
John McCall58f10c32010-03-11 09:03:00 +00003937
3938template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003939QualType
John McCall550e0c22009-10-21 00:40:46 +00003940TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003941 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003942 // Transform the parameters and return type.
3943 //
3944 // We instantiate in source order, with the return type first followed by
3945 // the parameters, because users tend to expect this (even if they shouldn't
3946 // rely on it!).
3947 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003948 // When the function has a trailing return type, we instantiate the
3949 // parameters before the return type, since the return type can then refer
3950 // to the parameters themselves (via decltype, sizeof, etc.).
3951 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003952 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003953 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00003954 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003955
Douglas Gregor7fb25412010-10-01 18:44:50 +00003956 QualType ResultType;
3957
3958 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003959 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3960 TL.getParmArray(),
3961 TL.getNumArgs(),
3962 TL.getTypePtr()->arg_type_begin(),
3963 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003964 return QualType();
3965
3966 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3967 if (ResultType.isNull())
3968 return QualType();
3969 }
3970 else {
3971 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3972 if (ResultType.isNull())
3973 return QualType();
3974
Douglas Gregordd472162011-01-07 00:20:55 +00003975 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3976 TL.getParmArray(),
3977 TL.getNumArgs(),
3978 TL.getTypePtr()->arg_type_begin(),
3979 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003980 return QualType();
3981 }
3982
John McCall550e0c22009-10-21 00:40:46 +00003983 QualType Result = TL.getType();
3984 if (getDerived().AlwaysRebuild() ||
3985 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003986 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003987 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3988 Result = getDerived().RebuildFunctionProtoType(ResultType,
3989 ParamTypes.data(),
3990 ParamTypes.size(),
3991 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003992 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00003993 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003994 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003995 if (Result.isNull())
3996 return QualType();
3997 }
Mike Stump11289f42009-09-09 15:08:12 +00003998
John McCall550e0c22009-10-21 00:40:46 +00003999 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004000 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4001 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004002 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00004003 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4004 NewTL.setArg(i, ParamDecls[i]);
4005
4006 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004007}
Mike Stump11289f42009-09-09 15:08:12 +00004008
Douglas Gregord6ff3322009-08-04 16:50:30 +00004009template<typename Derived>
4010QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004011 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004012 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004013 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004014 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4015 if (ResultType.isNull())
4016 return QualType();
4017
4018 QualType Result = TL.getType();
4019 if (getDerived().AlwaysRebuild() ||
4020 ResultType != T->getResultType())
4021 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4022
4023 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004024 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4025 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004026 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00004027
4028 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004029}
Mike Stump11289f42009-09-09 15:08:12 +00004030
John McCallb96ec562009-12-04 22:46:56 +00004031template<typename Derived> QualType
4032TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004033 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004034 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004035 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004036 if (!D)
4037 return QualType();
4038
4039 QualType Result = TL.getType();
4040 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4041 Result = getDerived().RebuildUnresolvedUsingType(D);
4042 if (Result.isNull())
4043 return QualType();
4044 }
4045
4046 // We might get an arbitrary type spec type back. We should at
4047 // least always get a type spec type, though.
4048 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4049 NewTL.setNameLoc(TL.getNameLoc());
4050
4051 return Result;
4052}
4053
Douglas Gregord6ff3322009-08-04 16:50:30 +00004054template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004055QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004056 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004057 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004058 TypedefNameDecl *Typedef
4059 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4060 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004061 if (!Typedef)
4062 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004063
John McCall550e0c22009-10-21 00:40:46 +00004064 QualType Result = TL.getType();
4065 if (getDerived().AlwaysRebuild() ||
4066 Typedef != T->getDecl()) {
4067 Result = getDerived().RebuildTypedefType(Typedef);
4068 if (Result.isNull())
4069 return QualType();
4070 }
Mike Stump11289f42009-09-09 15:08:12 +00004071
John McCall550e0c22009-10-21 00:40:46 +00004072 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4073 NewTL.setNameLoc(TL.getNameLoc());
4074
4075 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004076}
Mike Stump11289f42009-09-09 15:08:12 +00004077
Douglas Gregord6ff3322009-08-04 16:50:30 +00004078template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004079QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004080 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004081 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004082 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004083
John McCalldadc5752010-08-24 06:29:42 +00004084 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004085 if (E.isInvalid())
4086 return QualType();
4087
John McCall550e0c22009-10-21 00:40:46 +00004088 QualType Result = TL.getType();
4089 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004090 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004091 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004092 if (Result.isNull())
4093 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004094 }
John McCall550e0c22009-10-21 00:40:46 +00004095 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004096
John McCall550e0c22009-10-21 00:40:46 +00004097 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004098 NewTL.setTypeofLoc(TL.getTypeofLoc());
4099 NewTL.setLParenLoc(TL.getLParenLoc());
4100 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004101
4102 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004103}
Mike Stump11289f42009-09-09 15:08:12 +00004104
4105template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004106QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004107 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004108 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4109 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4110 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004111 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004112
John McCall550e0c22009-10-21 00:40:46 +00004113 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004114 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4115 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004116 if (Result.isNull())
4117 return QualType();
4118 }
Mike Stump11289f42009-09-09 15:08:12 +00004119
John McCall550e0c22009-10-21 00:40:46 +00004120 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004121 NewTL.setTypeofLoc(TL.getTypeofLoc());
4122 NewTL.setLParenLoc(TL.getLParenLoc());
4123 NewTL.setRParenLoc(TL.getRParenLoc());
4124 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004125
4126 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004127}
Mike Stump11289f42009-09-09 15:08:12 +00004128
4129template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004130QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004131 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004132 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004133
Douglas Gregore922c772009-08-04 22:27:00 +00004134 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004135 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004136
John McCalldadc5752010-08-24 06:29:42 +00004137 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004138 if (E.isInvalid())
4139 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004140
John McCall550e0c22009-10-21 00:40:46 +00004141 QualType Result = TL.getType();
4142 if (getDerived().AlwaysRebuild() ||
4143 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004144 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004145 if (Result.isNull())
4146 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004147 }
John McCall550e0c22009-10-21 00:40:46 +00004148 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004149
John McCall550e0c22009-10-21 00:40:46 +00004150 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4151 NewTL.setNameLoc(TL.getNameLoc());
4152
4153 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004154}
4155
4156template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004157QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4158 AutoTypeLoc TL) {
4159 const AutoType *T = TL.getTypePtr();
4160 QualType OldDeduced = T->getDeducedType();
4161 QualType NewDeduced;
4162 if (!OldDeduced.isNull()) {
4163 NewDeduced = getDerived().TransformType(OldDeduced);
4164 if (NewDeduced.isNull())
4165 return QualType();
4166 }
4167
4168 QualType Result = TL.getType();
4169 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4170 Result = getDerived().RebuildAutoType(NewDeduced);
4171 if (Result.isNull())
4172 return QualType();
4173 }
4174
4175 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4176 NewTL.setNameLoc(TL.getNameLoc());
4177
4178 return Result;
4179}
4180
4181template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004182QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004183 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004184 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004185 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004186 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4187 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004188 if (!Record)
4189 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004190
John McCall550e0c22009-10-21 00:40:46 +00004191 QualType Result = TL.getType();
4192 if (getDerived().AlwaysRebuild() ||
4193 Record != T->getDecl()) {
4194 Result = getDerived().RebuildRecordType(Record);
4195 if (Result.isNull())
4196 return QualType();
4197 }
Mike Stump11289f42009-09-09 15:08:12 +00004198
John McCall550e0c22009-10-21 00:40:46 +00004199 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4200 NewTL.setNameLoc(TL.getNameLoc());
4201
4202 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004203}
Mike Stump11289f42009-09-09 15:08:12 +00004204
4205template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004206QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004207 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004208 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004209 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004210 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4211 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004212 if (!Enum)
4213 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004214
John McCall550e0c22009-10-21 00:40:46 +00004215 QualType Result = TL.getType();
4216 if (getDerived().AlwaysRebuild() ||
4217 Enum != T->getDecl()) {
4218 Result = getDerived().RebuildEnumType(Enum);
4219 if (Result.isNull())
4220 return QualType();
4221 }
Mike Stump11289f42009-09-09 15:08:12 +00004222
John McCall550e0c22009-10-21 00:40:46 +00004223 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4224 NewTL.setNameLoc(TL.getNameLoc());
4225
4226 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004227}
John McCallfcc33b02009-09-05 00:15:47 +00004228
John McCalle78aac42010-03-10 03:28:59 +00004229template<typename Derived>
4230QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4231 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004232 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004233 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4234 TL.getTypePtr()->getDecl());
4235 if (!D) return QualType();
4236
4237 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4238 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4239 return T;
4240}
4241
Douglas Gregord6ff3322009-08-04 16:50:30 +00004242template<typename Derived>
4243QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004244 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004245 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004246 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004247}
4248
Mike Stump11289f42009-09-09 15:08:12 +00004249template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004250QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004251 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004252 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004253 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4254
4255 // Substitute into the replacement type, which itself might involve something
4256 // that needs to be transformed. This only tends to occur with default
4257 // template arguments of template template parameters.
4258 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4259 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4260 if (Replacement.isNull())
4261 return QualType();
4262
4263 // Always canonicalize the replacement type.
4264 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4265 QualType Result
4266 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4267 Replacement);
4268
4269 // Propagate type-source information.
4270 SubstTemplateTypeParmTypeLoc NewTL
4271 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4272 NewTL.setNameLoc(TL.getNameLoc());
4273 return Result;
4274
John McCallcebee162009-10-18 09:09:24 +00004275}
4276
4277template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004278QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4279 TypeLocBuilder &TLB,
4280 SubstTemplateTypeParmPackTypeLoc TL) {
4281 return TransformTypeSpecType(TLB, TL);
4282}
4283
4284template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004285QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004286 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004287 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004288 const TemplateSpecializationType *T = TL.getTypePtr();
4289
Douglas Gregordf846d12011-03-02 18:46:51 +00004290 // The nested-name-specifier never matters in a TemplateSpecializationType,
4291 // because we can't have a dependent nested-name-specifier anyway.
4292 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004293 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004294 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4295 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004296 if (Template.isNull())
4297 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004298
John McCall31f82722010-11-12 08:19:04 +00004299 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4300}
4301
Douglas Gregorfe921a72010-12-20 23:36:19 +00004302namespace {
4303 /// \brief Simple iterator that traverses the template arguments in a
4304 /// container that provides a \c getArgLoc() member function.
4305 ///
4306 /// This iterator is intended to be used with the iterator form of
4307 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4308 template<typename ArgLocContainer>
4309 class TemplateArgumentLocContainerIterator {
4310 ArgLocContainer *Container;
4311 unsigned Index;
4312
4313 public:
4314 typedef TemplateArgumentLoc value_type;
4315 typedef TemplateArgumentLoc reference;
4316 typedef int difference_type;
4317 typedef std::input_iterator_tag iterator_category;
4318
4319 class pointer {
4320 TemplateArgumentLoc Arg;
4321
4322 public:
4323 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4324
4325 const TemplateArgumentLoc *operator->() const {
4326 return &Arg;
4327 }
4328 };
4329
4330
4331 TemplateArgumentLocContainerIterator() {}
4332
4333 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4334 unsigned Index)
4335 : Container(&Container), Index(Index) { }
4336
4337 TemplateArgumentLocContainerIterator &operator++() {
4338 ++Index;
4339 return *this;
4340 }
4341
4342 TemplateArgumentLocContainerIterator operator++(int) {
4343 TemplateArgumentLocContainerIterator Old(*this);
4344 ++(*this);
4345 return Old;
4346 }
4347
4348 TemplateArgumentLoc operator*() const {
4349 return Container->getArgLoc(Index);
4350 }
4351
4352 pointer operator->() const {
4353 return pointer(Container->getArgLoc(Index));
4354 }
4355
4356 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004357 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004358 return X.Container == Y.Container && X.Index == Y.Index;
4359 }
4360
4361 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004362 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004363 return !(X == Y);
4364 }
4365 };
4366}
4367
4368
John McCall31f82722010-11-12 08:19:04 +00004369template <typename Derived>
4370QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4371 TypeLocBuilder &TLB,
4372 TemplateSpecializationTypeLoc TL,
4373 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004374 TemplateArgumentListInfo NewTemplateArgs;
4375 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4376 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004377 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4378 ArgIterator;
4379 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4380 ArgIterator(TL, TL.getNumArgs()),
4381 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004382 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004383
John McCall0ad16662009-10-29 08:12:44 +00004384 // FIXME: maybe don't rebuild if all the template arguments are the same.
4385
4386 QualType Result =
4387 getDerived().RebuildTemplateSpecializationType(Template,
4388 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004389 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004390
4391 if (!Result.isNull()) {
4392 TemplateSpecializationTypeLoc NewTL
4393 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4394 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4395 NewTL.setLAngleLoc(TL.getLAngleLoc());
4396 NewTL.setRAngleLoc(TL.getRAngleLoc());
4397 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4398 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004399 }
Mike Stump11289f42009-09-09 15:08:12 +00004400
John McCall0ad16662009-10-29 08:12:44 +00004401 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004402}
Mike Stump11289f42009-09-09 15:08:12 +00004403
Douglas Gregor5a064722011-02-28 17:23:35 +00004404template <typename Derived>
4405QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4406 TypeLocBuilder &TLB,
4407 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004408 TemplateName Template,
4409 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004410 TemplateArgumentListInfo NewTemplateArgs;
4411 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4412 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4413 typedef TemplateArgumentLocContainerIterator<
4414 DependentTemplateSpecializationTypeLoc> ArgIterator;
4415 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4416 ArgIterator(TL, TL.getNumArgs()),
4417 NewTemplateArgs))
4418 return QualType();
4419
4420 // FIXME: maybe don't rebuild if all the template arguments are the same.
4421
4422 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4423 QualType Result
4424 = getSema().Context.getDependentTemplateSpecializationType(
4425 TL.getTypePtr()->getKeyword(),
4426 DTN->getQualifier(),
4427 DTN->getIdentifier(),
4428 NewTemplateArgs);
4429
4430 DependentTemplateSpecializationTypeLoc NewTL
4431 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4432 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004433
Douglas Gregora7a795b2011-03-01 20:11:18 +00004434 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004435 NewTL.setNameLoc(TL.getNameLoc());
4436 NewTL.setLAngleLoc(TL.getLAngleLoc());
4437 NewTL.setRAngleLoc(TL.getRAngleLoc());
4438 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4439 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4440 return Result;
4441 }
4442
4443 QualType Result
4444 = getDerived().RebuildTemplateSpecializationType(Template,
4445 TL.getNameLoc(),
4446 NewTemplateArgs);
4447
4448 if (!Result.isNull()) {
4449 /// FIXME: Wrap this in an elaborated-type-specifier?
4450 TemplateSpecializationTypeLoc NewTL
4451 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4452 NewTL.setTemplateNameLoc(TL.getNameLoc());
4453 NewTL.setLAngleLoc(TL.getLAngleLoc());
4454 NewTL.setRAngleLoc(TL.getRAngleLoc());
4455 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4456 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4457 }
4458
4459 return Result;
4460}
4461
Mike Stump11289f42009-09-09 15:08:12 +00004462template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004463QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004464TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004465 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004466 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004467
Douglas Gregor844cb502011-03-01 18:12:44 +00004468 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004469 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004470 if (TL.getQualifierLoc()) {
4471 QualifierLoc
4472 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4473 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004474 return QualType();
4475 }
Mike Stump11289f42009-09-09 15:08:12 +00004476
John McCall31f82722010-11-12 08:19:04 +00004477 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4478 if (NamedT.isNull())
4479 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004480
John McCall550e0c22009-10-21 00:40:46 +00004481 QualType Result = TL.getType();
4482 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004483 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004484 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004485 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004486 T->getKeyword(),
4487 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004488 if (Result.isNull())
4489 return QualType();
4490 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004491
Abramo Bagnara6150c882010-05-11 21:36:43 +00004492 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004493 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004494 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004495 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004496}
Mike Stump11289f42009-09-09 15:08:12 +00004497
4498template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004499QualType TreeTransform<Derived>::TransformAttributedType(
4500 TypeLocBuilder &TLB,
4501 AttributedTypeLoc TL) {
4502 const AttributedType *oldType = TL.getTypePtr();
4503 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4504 if (modifiedType.isNull())
4505 return QualType();
4506
4507 QualType result = TL.getType();
4508
4509 // FIXME: dependent operand expressions?
4510 if (getDerived().AlwaysRebuild() ||
4511 modifiedType != oldType->getModifiedType()) {
4512 // TODO: this is really lame; we should really be rebuilding the
4513 // equivalent type from first principles.
4514 QualType equivalentType
4515 = getDerived().TransformType(oldType->getEquivalentType());
4516 if (equivalentType.isNull())
4517 return QualType();
4518 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4519 modifiedType,
4520 equivalentType);
4521 }
4522
4523 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4524 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4525 if (TL.hasAttrOperand())
4526 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4527 if (TL.hasAttrExprOperand())
4528 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4529 else if (TL.hasAttrEnumOperand())
4530 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4531
4532 return result;
4533}
4534
4535template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004536QualType
4537TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4538 ParenTypeLoc TL) {
4539 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4540 if (Inner.isNull())
4541 return QualType();
4542
4543 QualType Result = TL.getType();
4544 if (getDerived().AlwaysRebuild() ||
4545 Inner != TL.getInnerLoc().getType()) {
4546 Result = getDerived().RebuildParenType(Inner);
4547 if (Result.isNull())
4548 return QualType();
4549 }
4550
4551 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4552 NewTL.setLParenLoc(TL.getLParenLoc());
4553 NewTL.setRParenLoc(TL.getRParenLoc());
4554 return Result;
4555}
4556
4557template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004558QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004559 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004560 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004561
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004562 NestedNameSpecifierLoc QualifierLoc
4563 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4564 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004565 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004566
John McCallc392f372010-06-11 00:33:02 +00004567 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004568 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004569 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004570 QualifierLoc,
4571 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004572 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004573 if (Result.isNull())
4574 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004575
Abramo Bagnarad7548482010-05-19 21:37:53 +00004576 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4577 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004578 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4579
Abramo Bagnarad7548482010-05-19 21:37:53 +00004580 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4581 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004582 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004583 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004584 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4585 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004586 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004587 NewTL.setNameLoc(TL.getNameLoc());
4588 }
John McCall550e0c22009-10-21 00:40:46 +00004589 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004590}
Mike Stump11289f42009-09-09 15:08:12 +00004591
Douglas Gregord6ff3322009-08-04 16:50:30 +00004592template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004593QualType TreeTransform<Derived>::
4594 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004595 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004596 NestedNameSpecifierLoc QualifierLoc;
4597 if (TL.getQualifierLoc()) {
4598 QualifierLoc
4599 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4600 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004601 return QualType();
4602 }
4603
John McCall31f82722010-11-12 08:19:04 +00004604 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004605 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004606}
4607
4608template<typename Derived>
4609QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00004610TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4611 DependentTemplateSpecializationTypeLoc TL,
4612 NestedNameSpecifierLoc QualifierLoc) {
4613 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4614
4615 TemplateArgumentListInfo NewTemplateArgs;
4616 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4617 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4618
4619 typedef TemplateArgumentLocContainerIterator<
4620 DependentTemplateSpecializationTypeLoc> ArgIterator;
4621 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4622 ArgIterator(TL, TL.getNumArgs()),
4623 NewTemplateArgs))
4624 return QualType();
4625
4626 QualType Result
4627 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4628 QualifierLoc,
4629 T->getIdentifier(),
4630 TL.getNameLoc(),
4631 NewTemplateArgs);
4632 if (Result.isNull())
4633 return QualType();
4634
4635 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4636 QualType NamedT = ElabT->getNamedType();
4637
4638 // Copy information relevant to the template specialization.
4639 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00004640 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004641 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004642 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4643 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004644 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004645 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004646
4647 // Copy information relevant to the elaborated type.
4648 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4649 NewTL.setKeywordLoc(TL.getKeywordLoc());
4650 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00004651 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4652 DependentTemplateSpecializationTypeLoc SpecTL
4653 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor11ddf132011-03-07 15:13:34 +00004654 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004655 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004656 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004657 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4658 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004659 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004660 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004661 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00004662 TemplateSpecializationTypeLoc SpecTL
4663 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004664 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004665 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4666 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004667 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004668 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004669 }
4670 return Result;
4671}
4672
4673template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004674QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4675 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004676 QualType Pattern
4677 = getDerived().TransformType(TLB, TL.getPatternLoc());
4678 if (Pattern.isNull())
4679 return QualType();
4680
4681 QualType Result = TL.getType();
4682 if (getDerived().AlwaysRebuild() ||
4683 Pattern != TL.getPatternLoc().getType()) {
4684 Result = getDerived().RebuildPackExpansionType(Pattern,
4685 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004686 TL.getEllipsisLoc(),
4687 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004688 if (Result.isNull())
4689 return QualType();
4690 }
4691
4692 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4693 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4694 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004695}
4696
4697template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004698QualType
4699TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004700 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004701 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004702 TLB.pushFullCopy(TL);
4703 return TL.getType();
4704}
4705
4706template<typename Derived>
4707QualType
4708TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004709 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004710 // ObjCObjectType is never dependent.
4711 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004712 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004713}
Mike Stump11289f42009-09-09 15:08:12 +00004714
4715template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004716QualType
4717TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004718 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004719 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004720 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004721 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004722}
4723
Douglas Gregord6ff3322009-08-04 16:50:30 +00004724//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004725// Statement transformation
4726//===----------------------------------------------------------------------===//
4727template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004728StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004729TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004730 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004731}
4732
4733template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004734StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004735TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4736 return getDerived().TransformCompoundStmt(S, false);
4737}
4738
4739template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004740StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004741TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004742 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004743 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004744 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004745 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004746 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4747 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004748 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004749 if (Result.isInvalid()) {
4750 // Immediately fail if this was a DeclStmt, since it's very
4751 // likely that this will cause problems for future statements.
4752 if (isa<DeclStmt>(*B))
4753 return StmtError();
4754
4755 // Otherwise, just keep processing substatements and fail later.
4756 SubStmtInvalid = true;
4757 continue;
4758 }
Mike Stump11289f42009-09-09 15:08:12 +00004759
Douglas Gregorebe10102009-08-20 07:17:43 +00004760 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4761 Statements.push_back(Result.takeAs<Stmt>());
4762 }
Mike Stump11289f42009-09-09 15:08:12 +00004763
John McCall1ababa62010-08-27 19:56:05 +00004764 if (SubStmtInvalid)
4765 return StmtError();
4766
Douglas Gregorebe10102009-08-20 07:17:43 +00004767 if (!getDerived().AlwaysRebuild() &&
4768 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004769 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004770
4771 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4772 move_arg(Statements),
4773 S->getRBracLoc(),
4774 IsStmtExpr);
4775}
Mike Stump11289f42009-09-09 15:08:12 +00004776
Douglas Gregorebe10102009-08-20 07:17:43 +00004777template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004778StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004779TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004780 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004781 {
4782 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004783 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004784
Eli Friedman06577382009-11-19 03:14:00 +00004785 // Transform the left-hand case value.
4786 LHS = getDerived().TransformExpr(S->getLHS());
4787 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004788 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004789
Eli Friedman06577382009-11-19 03:14:00 +00004790 // Transform the right-hand case value (for the GNU case-range extension).
4791 RHS = getDerived().TransformExpr(S->getRHS());
4792 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004793 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004794 }
Mike Stump11289f42009-09-09 15:08:12 +00004795
Douglas Gregorebe10102009-08-20 07:17:43 +00004796 // Build the case statement.
4797 // Case statements are always rebuilt so that they will attached to their
4798 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004799 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004800 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004801 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004802 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004803 S->getColonLoc());
4804 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004805 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004806
Douglas Gregorebe10102009-08-20 07:17:43 +00004807 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004808 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004809 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004810 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004811
Douglas Gregorebe10102009-08-20 07:17:43 +00004812 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004813 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004814}
4815
4816template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004817StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004818TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004819 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004820 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004821 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004822 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004823
Douglas Gregorebe10102009-08-20 07:17:43 +00004824 // Default statements are always rebuilt
4825 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004826 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004827}
Mike Stump11289f42009-09-09 15:08:12 +00004828
Douglas Gregorebe10102009-08-20 07:17:43 +00004829template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004830StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004831TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004832 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004833 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004834 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004835
Chris Lattnercab02a62011-02-17 20:34:02 +00004836 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4837 S->getDecl());
4838 if (!LD)
4839 return StmtError();
4840
4841
Douglas Gregorebe10102009-08-20 07:17:43 +00004842 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004843 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004844 cast<LabelDecl>(LD), SourceLocation(),
4845 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004846}
Mike Stump11289f42009-09-09 15:08:12 +00004847
Douglas Gregorebe10102009-08-20 07:17:43 +00004848template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004849StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004850TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004851 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004852 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004853 VarDecl *ConditionVar = 0;
4854 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004855 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004856 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004857 getDerived().TransformDefinition(
4858 S->getConditionVariable()->getLocation(),
4859 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004860 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004861 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004862 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004863 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004864
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004865 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004866 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004867
4868 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004869 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004870 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4871 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004872 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004873 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004874
John McCallb268a282010-08-23 23:25:46 +00004875 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004876 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004877 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004878
John McCallb268a282010-08-23 23:25:46 +00004879 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4880 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004881 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004882
Douglas Gregorebe10102009-08-20 07:17:43 +00004883 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004884 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004885 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004886 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004887
Douglas Gregorebe10102009-08-20 07:17:43 +00004888 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004889 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004890 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004891 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004892
Douglas Gregorebe10102009-08-20 07:17:43 +00004893 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004894 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004895 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004896 Then.get() == S->getThen() &&
4897 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004898 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004899
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004900 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004901 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004902 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004903}
4904
4905template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004906StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004907TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004908 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004909 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004910 VarDecl *ConditionVar = 0;
4911 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004912 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004913 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004914 getDerived().TransformDefinition(
4915 S->getConditionVariable()->getLocation(),
4916 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004917 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004918 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004919 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004920 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004921
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004922 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004923 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004924 }
Mike Stump11289f42009-09-09 15:08:12 +00004925
Douglas Gregorebe10102009-08-20 07:17:43 +00004926 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004927 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004928 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004929 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004930 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004931 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004932
Douglas Gregorebe10102009-08-20 07:17:43 +00004933 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004934 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004935 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004936 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004937
Douglas Gregorebe10102009-08-20 07:17:43 +00004938 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004939 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4940 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004941}
Mike Stump11289f42009-09-09 15:08:12 +00004942
Douglas Gregorebe10102009-08-20 07:17:43 +00004943template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004944StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004945TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004946 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004947 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004948 VarDecl *ConditionVar = 0;
4949 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004950 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004951 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004952 getDerived().TransformDefinition(
4953 S->getConditionVariable()->getLocation(),
4954 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004955 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004956 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004957 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004958 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004959
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004960 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004961 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004962
4963 if (S->getCond()) {
4964 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004965 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4966 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004967 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004968 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004969 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004970 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004971 }
Mike Stump11289f42009-09-09 15:08:12 +00004972
John McCallb268a282010-08-23 23:25:46 +00004973 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4974 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004975 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004976
Douglas Gregorebe10102009-08-20 07:17:43 +00004977 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004978 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004979 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004980 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004981
Douglas Gregorebe10102009-08-20 07:17:43 +00004982 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004983 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004984 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004985 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004986 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004987
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004988 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004989 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004990}
Mike Stump11289f42009-09-09 15:08:12 +00004991
Douglas Gregorebe10102009-08-20 07:17:43 +00004992template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004993StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004994TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004995 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004996 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004997 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004998 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004999
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005000 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005001 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005002 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005003 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005004
Douglas Gregorebe10102009-08-20 07:17:43 +00005005 if (!getDerived().AlwaysRebuild() &&
5006 Cond.get() == S->getCond() &&
5007 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005008 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005009
John McCallb268a282010-08-23 23:25:46 +00005010 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5011 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005012 S->getRParenLoc());
5013}
Mike Stump11289f42009-09-09 15:08:12 +00005014
Douglas Gregorebe10102009-08-20 07:17:43 +00005015template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005016StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005017TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005018 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005019 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005020 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005021 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005022
Douglas Gregorebe10102009-08-20 07:17:43 +00005023 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005024 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005025 VarDecl *ConditionVar = 0;
5026 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005027 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005028 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005029 getDerived().TransformDefinition(
5030 S->getConditionVariable()->getLocation(),
5031 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005032 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005033 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005034 } else {
5035 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005036
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005037 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005038 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005039
5040 if (S->getCond()) {
5041 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005042 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5043 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005044 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005045 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005046
John McCallb268a282010-08-23 23:25:46 +00005047 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005048 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005049 }
Mike Stump11289f42009-09-09 15:08:12 +00005050
John McCallb268a282010-08-23 23:25:46 +00005051 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5052 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005053 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005054
Douglas Gregorebe10102009-08-20 07:17:43 +00005055 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005056 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005057 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005058 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005059
John McCallb268a282010-08-23 23:25:46 +00005060 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5061 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005062 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005063
Douglas Gregorebe10102009-08-20 07:17:43 +00005064 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005065 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005066 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005067 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005068
Douglas Gregorebe10102009-08-20 07:17:43 +00005069 if (!getDerived().AlwaysRebuild() &&
5070 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005071 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005072 Inc.get() == S->getInc() &&
5073 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005074 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005075
Douglas Gregorebe10102009-08-20 07:17:43 +00005076 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005077 Init.get(), FullCond, ConditionVar,
5078 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005079}
5080
5081template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005082StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005083TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005084 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5085 S->getLabel());
5086 if (!LD)
5087 return StmtError();
5088
Douglas Gregorebe10102009-08-20 07:17:43 +00005089 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005090 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005091 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005092}
5093
5094template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005095StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005096TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005097 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005098 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005099 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005100
Douglas Gregorebe10102009-08-20 07:17:43 +00005101 if (!getDerived().AlwaysRebuild() &&
5102 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005103 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005104
5105 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005106 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005107}
5108
5109template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005110StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005111TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005112 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005113}
Mike Stump11289f42009-09-09 15:08:12 +00005114
Douglas Gregorebe10102009-08-20 07:17:43 +00005115template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005116StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005117TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005118 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005119}
Mike Stump11289f42009-09-09 15:08:12 +00005120
Douglas Gregorebe10102009-08-20 07:17:43 +00005121template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005122StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005123TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005124 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005125 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005126 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005127
Mike Stump11289f42009-09-09 15:08:12 +00005128 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005129 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005130 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005131}
Mike Stump11289f42009-09-09 15:08:12 +00005132
Douglas Gregorebe10102009-08-20 07:17:43 +00005133template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005134StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005135TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005136 bool DeclChanged = false;
5137 llvm::SmallVector<Decl *, 4> Decls;
5138 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5139 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005140 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5141 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005142 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005143 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005144
Douglas Gregorebe10102009-08-20 07:17:43 +00005145 if (Transformed != *D)
5146 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005147
Douglas Gregorebe10102009-08-20 07:17:43 +00005148 Decls.push_back(Transformed);
5149 }
Mike Stump11289f42009-09-09 15:08:12 +00005150
Douglas Gregorebe10102009-08-20 07:17:43 +00005151 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005152 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005153
5154 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005155 S->getStartLoc(), S->getEndLoc());
5156}
Mike Stump11289f42009-09-09 15:08:12 +00005157
Douglas Gregorebe10102009-08-20 07:17:43 +00005158template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005159StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005160TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005161
John McCall37ad5512010-08-23 06:44:23 +00005162 ASTOwningVector<Expr*> Constraints(getSema());
5163 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00005164 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005165
John McCalldadc5752010-08-24 06:29:42 +00005166 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005167 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005168
5169 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005170
Anders Carlssonaaeef072010-01-24 05:50:09 +00005171 // Go through the outputs.
5172 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005173 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005174
Anders Carlssonaaeef072010-01-24 05:50:09 +00005175 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005176 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005177
Anders Carlssonaaeef072010-01-24 05:50:09 +00005178 // Transform the output expr.
5179 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005180 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005181 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005182 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005183
Anders Carlssonaaeef072010-01-24 05:50:09 +00005184 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005185
John McCallb268a282010-08-23 23:25:46 +00005186 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005187 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005188
Anders Carlssonaaeef072010-01-24 05:50:09 +00005189 // Go through the inputs.
5190 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005191 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005192
Anders Carlssonaaeef072010-01-24 05:50:09 +00005193 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005194 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005195
Anders Carlssonaaeef072010-01-24 05:50:09 +00005196 // Transform the input expr.
5197 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005198 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005199 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005200 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005201
Anders Carlssonaaeef072010-01-24 05:50:09 +00005202 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005203
John McCallb268a282010-08-23 23:25:46 +00005204 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005205 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005206
Anders Carlssonaaeef072010-01-24 05:50:09 +00005207 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005208 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005209
5210 // Go through the clobbers.
5211 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005212 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005213
5214 // No need to transform the asm string literal.
5215 AsmString = SemaRef.Owned(S->getAsmString());
5216
5217 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5218 S->isSimple(),
5219 S->isVolatile(),
5220 S->getNumOutputs(),
5221 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005222 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005223 move_arg(Constraints),
5224 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005225 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005226 move_arg(Clobbers),
5227 S->getRParenLoc(),
5228 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005229}
5230
5231
5232template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005233StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005234TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005235 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005236 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005237 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005238 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005239
Douglas Gregor96c79492010-04-23 22:50:49 +00005240 // Transform the @catch statements (if present).
5241 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005242 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005243 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005244 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005245 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005246 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005247 if (Catch.get() != S->getCatchStmt(I))
5248 AnyCatchChanged = true;
5249 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005250 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005251
Douglas Gregor306de2f2010-04-22 23:59:56 +00005252 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005253 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005254 if (S->getFinallyStmt()) {
5255 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5256 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005257 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005258 }
5259
5260 // If nothing changed, just retain this statement.
5261 if (!getDerived().AlwaysRebuild() &&
5262 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005263 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005264 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005265 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005266
Douglas Gregor306de2f2010-04-22 23:59:56 +00005267 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005268 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5269 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005270}
Mike Stump11289f42009-09-09 15:08:12 +00005271
Douglas Gregorebe10102009-08-20 07:17:43 +00005272template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005273StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005274TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005275 // Transform the @catch parameter, if there is one.
5276 VarDecl *Var = 0;
5277 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5278 TypeSourceInfo *TSInfo = 0;
5279 if (FromVar->getTypeSourceInfo()) {
5280 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5281 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005282 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005283 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005284
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005285 QualType T;
5286 if (TSInfo)
5287 T = TSInfo->getType();
5288 else {
5289 T = getDerived().TransformType(FromVar->getType());
5290 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005291 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005292 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005293
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005294 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5295 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005296 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005297 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005298
John McCalldadc5752010-08-24 06:29:42 +00005299 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005300 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005301 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005302
5303 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005304 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005305 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005306}
Mike Stump11289f42009-09-09 15:08:12 +00005307
Douglas Gregorebe10102009-08-20 07:17:43 +00005308template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005309StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005310TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005311 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005312 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005313 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005314 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005315
Douglas Gregor306de2f2010-04-22 23:59:56 +00005316 // If nothing changed, just retain this statement.
5317 if (!getDerived().AlwaysRebuild() &&
5318 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005319 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005320
5321 // Build a new statement.
5322 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005323 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005324}
Mike Stump11289f42009-09-09 15:08:12 +00005325
Douglas Gregorebe10102009-08-20 07:17:43 +00005326template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005327StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005328TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005329 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005330 if (S->getThrowExpr()) {
5331 Operand = getDerived().TransformExpr(S->getThrowExpr());
5332 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005333 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005334 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005335
Douglas Gregor2900c162010-04-22 21:44:01 +00005336 if (!getDerived().AlwaysRebuild() &&
5337 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005338 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005339
John McCallb268a282010-08-23 23:25:46 +00005340 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005341}
Mike Stump11289f42009-09-09 15:08:12 +00005342
Douglas Gregorebe10102009-08-20 07:17:43 +00005343template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005344StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005345TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005346 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005347 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005348 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005349 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005350 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005351
Douglas Gregor6148de72010-04-22 22:01:21 +00005352 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005353 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005354 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005355 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005356
Douglas Gregor6148de72010-04-22 22:01:21 +00005357 // If nothing change, just retain the current statement.
5358 if (!getDerived().AlwaysRebuild() &&
5359 Object.get() == S->getSynchExpr() &&
5360 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005361 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005362
5363 // Build a new statement.
5364 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005365 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005366}
5367
5368template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005369StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005370TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005371 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005372 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005373 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005374 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005375 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005376
Douglas Gregorf68a5082010-04-22 23:10:45 +00005377 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005378 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005379 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005380 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005381
Douglas Gregorf68a5082010-04-22 23:10:45 +00005382 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005383 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005384 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005385 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005386
Douglas Gregorf68a5082010-04-22 23:10:45 +00005387 // If nothing changed, just retain this statement.
5388 if (!getDerived().AlwaysRebuild() &&
5389 Element.get() == S->getElement() &&
5390 Collection.get() == S->getCollection() &&
5391 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005392 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005393
Douglas Gregorf68a5082010-04-22 23:10:45 +00005394 // Build a new statement.
5395 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5396 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005397 Element.get(),
5398 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005399 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005400 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005401}
5402
5403
5404template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005405StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005406TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5407 // Transform the exception declaration, if any.
5408 VarDecl *Var = 0;
5409 if (S->getExceptionDecl()) {
5410 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005411 TypeSourceInfo *T = getDerived().TransformType(
5412 ExceptionDecl->getTypeSourceInfo());
5413 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005414 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005415
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005416 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaradff19302011-03-08 08:55:46 +00005417 ExceptionDecl->getInnerLocStart(),
5418 ExceptionDecl->getLocation(),
5419 ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00005420 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005421 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005422 }
Mike Stump11289f42009-09-09 15:08:12 +00005423
Douglas Gregorebe10102009-08-20 07:17:43 +00005424 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005425 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005426 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005427 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005428
Douglas Gregorebe10102009-08-20 07:17:43 +00005429 if (!getDerived().AlwaysRebuild() &&
5430 !Var &&
5431 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005432 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005433
5434 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5435 Var,
John McCallb268a282010-08-23 23:25:46 +00005436 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005437}
Mike Stump11289f42009-09-09 15:08:12 +00005438
Douglas Gregorebe10102009-08-20 07:17:43 +00005439template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005440StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005441TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5442 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005443 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005444 = getDerived().TransformCompoundStmt(S->getTryBlock());
5445 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005446 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005447
Douglas Gregorebe10102009-08-20 07:17:43 +00005448 // Transform the handlers.
5449 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005450 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005451 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005452 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005453 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5454 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005455 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005456
Douglas Gregorebe10102009-08-20 07:17:43 +00005457 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5458 Handlers.push_back(Handler.takeAs<Stmt>());
5459 }
Mike Stump11289f42009-09-09 15:08:12 +00005460
Douglas Gregorebe10102009-08-20 07:17:43 +00005461 if (!getDerived().AlwaysRebuild() &&
5462 TryBlock.get() == S->getTryBlock() &&
5463 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005464 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005465
John McCallb268a282010-08-23 23:25:46 +00005466 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005467 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005468}
Mike Stump11289f42009-09-09 15:08:12 +00005469
Richard Smith02e85f32011-04-14 22:09:26 +00005470template<typename Derived>
5471StmtResult
5472TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5473 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5474 if (Range.isInvalid())
5475 return StmtError();
5476
5477 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5478 if (BeginEnd.isInvalid())
5479 return StmtError();
5480
5481 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5482 if (Cond.isInvalid())
5483 return StmtError();
5484
5485 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5486 if (Inc.isInvalid())
5487 return StmtError();
5488
5489 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5490 if (LoopVar.isInvalid())
5491 return StmtError();
5492
5493 StmtResult NewStmt = S;
5494 if (getDerived().AlwaysRebuild() ||
5495 Range.get() != S->getRangeStmt() ||
5496 BeginEnd.get() != S->getBeginEndStmt() ||
5497 Cond.get() != S->getCond() ||
5498 Inc.get() != S->getInc() ||
5499 LoopVar.get() != S->getLoopVarStmt())
5500 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5501 S->getColonLoc(), Range.get(),
5502 BeginEnd.get(), Cond.get(),
5503 Inc.get(), LoopVar.get(),
5504 S->getRParenLoc());
5505
5506 StmtResult Body = getDerived().TransformStmt(S->getBody());
5507 if (Body.isInvalid())
5508 return StmtError();
5509
5510 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5511 // it now so we have a new statement to attach the body to.
5512 if (Body.get() != S->getBody() && NewStmt.get() == S)
5513 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5514 S->getColonLoc(), Range.get(),
5515 BeginEnd.get(), Cond.get(),
5516 Inc.get(), LoopVar.get(),
5517 S->getRParenLoc());
5518
5519 if (NewStmt.get() == S)
5520 return SemaRef.Owned(S);
5521
5522 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5523}
5524
John Wiegley1c0675e2011-04-28 01:08:34 +00005525template<typename Derived>
5526StmtResult
5527TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5528 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5529 if(TryBlock.isInvalid()) return StmtError();
5530
5531 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5532 if(!getDerived().AlwaysRebuild() &&
5533 TryBlock.get() == S->getTryBlock() &&
5534 Handler.get() == S->getHandler())
5535 return SemaRef.Owned(S);
5536
5537 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5538 S->getTryLoc(),
5539 TryBlock.take(),
5540 Handler.take());
5541}
5542
5543template<typename Derived>
5544StmtResult
5545TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5546 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5547 if(Block.isInvalid()) return StmtError();
5548
5549 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5550 Block.take());
5551}
5552
5553template<typename Derived>
5554StmtResult
5555TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5556 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5557 if(FilterExpr.isInvalid()) return StmtError();
5558
5559 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5560 if(Block.isInvalid()) return StmtError();
5561
5562 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5563 FilterExpr.take(),
5564 Block.take());
5565}
5566
5567template<typename Derived>
5568StmtResult
5569TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5570 if(isa<SEHFinallyStmt>(Handler))
5571 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5572 else
5573 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5574}
5575
Douglas Gregorebe10102009-08-20 07:17:43 +00005576//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005577// Expression transformation
5578//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005579template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005580ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005581TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005582 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005583}
Mike Stump11289f42009-09-09 15:08:12 +00005584
5585template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005586ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005587TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005588 NestedNameSpecifierLoc QualifierLoc;
5589 if (E->getQualifierLoc()) {
5590 QualifierLoc
5591 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5592 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005593 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005594 }
John McCallce546572009-12-08 09:08:17 +00005595
5596 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005597 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5598 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005599 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005600 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005601
John McCall815039a2010-08-17 21:27:17 +00005602 DeclarationNameInfo NameInfo = E->getNameInfo();
5603 if (NameInfo.getName()) {
5604 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5605 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005606 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005607 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005608
5609 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005610 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005611 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005612 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005613 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005614
5615 // Mark it referenced in the new context regardless.
5616 // FIXME: this is a bit instantiation-specific.
5617 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5618
John McCallc3007a22010-10-26 07:05:15 +00005619 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005620 }
John McCallce546572009-12-08 09:08:17 +00005621
5622 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005623 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005624 TemplateArgs = &TransArgs;
5625 TransArgs.setLAngleLoc(E->getLAngleLoc());
5626 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005627 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5628 E->getNumTemplateArgs(),
5629 TransArgs))
5630 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005631 }
5632
Douglas Gregorea972d32011-02-28 21:54:11 +00005633 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5634 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005635}
Mike Stump11289f42009-09-09 15:08:12 +00005636
Douglas Gregora16548e2009-08-11 05:31:07 +00005637template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005638ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005639TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005640 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005641}
Mike Stump11289f42009-09-09 15:08:12 +00005642
Douglas Gregora16548e2009-08-11 05:31:07 +00005643template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005644ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005645TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005646 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005647}
Mike Stump11289f42009-09-09 15:08:12 +00005648
Douglas Gregora16548e2009-08-11 05:31:07 +00005649template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005650ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005651TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005652 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005653}
Mike Stump11289f42009-09-09 15:08:12 +00005654
Douglas Gregora16548e2009-08-11 05:31:07 +00005655template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005656ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005657TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005658 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005659}
Mike Stump11289f42009-09-09 15:08:12 +00005660
Douglas Gregora16548e2009-08-11 05:31:07 +00005661template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005662ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005663TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005664 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005665}
5666
5667template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005668ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00005669TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5670 ExprResult ControllingExpr =
5671 getDerived().TransformExpr(E->getControllingExpr());
5672 if (ControllingExpr.isInvalid())
5673 return ExprError();
5674
5675 llvm::SmallVector<Expr *, 4> AssocExprs;
5676 llvm::SmallVector<TypeSourceInfo *, 4> AssocTypes;
5677 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5678 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5679 if (TS) {
5680 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5681 if (!AssocType)
5682 return ExprError();
5683 AssocTypes.push_back(AssocType);
5684 } else {
5685 AssocTypes.push_back(0);
5686 }
5687
5688 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5689 if (AssocExpr.isInvalid())
5690 return ExprError();
5691 AssocExprs.push_back(AssocExpr.release());
5692 }
5693
5694 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5695 E->getDefaultLoc(),
5696 E->getRParenLoc(),
5697 ControllingExpr.release(),
5698 AssocTypes.data(),
5699 AssocExprs.data(),
5700 E->getNumAssocs());
5701}
5702
5703template<typename Derived>
5704ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005705TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005706 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005707 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005708 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005709
Douglas Gregora16548e2009-08-11 05:31:07 +00005710 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005711 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005712
John McCallb268a282010-08-23 23:25:46 +00005713 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005714 E->getRParen());
5715}
5716
Mike Stump11289f42009-09-09 15:08:12 +00005717template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005718ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005719TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005720 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005721 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005722 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005723
Douglas Gregora16548e2009-08-11 05:31:07 +00005724 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005725 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005726
Douglas Gregora16548e2009-08-11 05:31:07 +00005727 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5728 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005729 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005730}
Mike Stump11289f42009-09-09 15:08:12 +00005731
Douglas Gregora16548e2009-08-11 05:31:07 +00005732template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005733ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005734TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5735 // Transform the type.
5736 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5737 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005738 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005739
Douglas Gregor882211c2010-04-28 22:16:22 +00005740 // Transform all of the components into components similar to what the
5741 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005742 // FIXME: It would be slightly more efficient in the non-dependent case to
5743 // just map FieldDecls, rather than requiring the rebuilder to look for
5744 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005745 // template code that we don't care.
5746 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005747 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005748 typedef OffsetOfExpr::OffsetOfNode Node;
5749 llvm::SmallVector<Component, 4> Components;
5750 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5751 const Node &ON = E->getComponent(I);
5752 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005753 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00005754 Comp.LocStart = ON.getSourceRange().getBegin();
5755 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00005756 switch (ON.getKind()) {
5757 case Node::Array: {
5758 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005759 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005760 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005761 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005762
Douglas Gregor882211c2010-04-28 22:16:22 +00005763 ExprChanged = ExprChanged || Index.get() != FromIndex;
5764 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005765 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005766 break;
5767 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005768
Douglas Gregor882211c2010-04-28 22:16:22 +00005769 case Node::Field:
5770 case Node::Identifier:
5771 Comp.isBrackets = false;
5772 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005773 if (!Comp.U.IdentInfo)
5774 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005775
Douglas Gregor882211c2010-04-28 22:16:22 +00005776 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005777
Douglas Gregord1702062010-04-29 00:18:15 +00005778 case Node::Base:
5779 // Will be recomputed during the rebuild.
5780 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005781 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005782
Douglas Gregor882211c2010-04-28 22:16:22 +00005783 Components.push_back(Comp);
5784 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005785
Douglas Gregor882211c2010-04-28 22:16:22 +00005786 // If nothing changed, retain the existing expression.
5787 if (!getDerived().AlwaysRebuild() &&
5788 Type == E->getTypeSourceInfo() &&
5789 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005790 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005791
Douglas Gregor882211c2010-04-28 22:16:22 +00005792 // Build a new offsetof expression.
5793 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5794 Components.data(), Components.size(),
5795 E->getRParenLoc());
5796}
5797
5798template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005799ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005800TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5801 assert(getDerived().AlreadyTransformed(E->getType()) &&
5802 "opaque value expression requires transformation");
5803 return SemaRef.Owned(E);
5804}
5805
5806template<typename Derived>
5807ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00005808TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
5809 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005810 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005811 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005812
John McCallbcd03502009-12-07 02:54:59 +00005813 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005814 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005815 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005816
John McCall4c98fd82009-11-04 07:28:41 +00005817 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005818 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005819
Peter Collingbournee190dee2011-03-11 19:24:49 +00005820 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
5821 E->getKind(),
5822 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005823 }
Mike Stump11289f42009-09-09 15:08:12 +00005824
John McCalldadc5752010-08-24 06:29:42 +00005825 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005826 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005827 // C++0x [expr.sizeof]p1:
5828 // The operand is either an expression, which is an unevaluated operand
5829 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005830 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005831
Douglas Gregora16548e2009-08-11 05:31:07 +00005832 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5833 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005834 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005835
Douglas Gregora16548e2009-08-11 05:31:07 +00005836 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005837 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005838 }
Mike Stump11289f42009-09-09 15:08:12 +00005839
Peter Collingbournee190dee2011-03-11 19:24:49 +00005840 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
5841 E->getOperatorLoc(),
5842 E->getKind(),
5843 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005844}
Mike Stump11289f42009-09-09 15:08:12 +00005845
Douglas Gregora16548e2009-08-11 05:31:07 +00005846template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005847ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005848TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005849 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005850 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005851 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005852
John McCalldadc5752010-08-24 06:29:42 +00005853 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005854 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005855 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005856
5857
Douglas Gregora16548e2009-08-11 05:31:07 +00005858 if (!getDerived().AlwaysRebuild() &&
5859 LHS.get() == E->getLHS() &&
5860 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005861 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005862
John McCallb268a282010-08-23 23:25:46 +00005863 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005864 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005865 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005866 E->getRBracketLoc());
5867}
Mike Stump11289f42009-09-09 15:08:12 +00005868
5869template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005870ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005871TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005872 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005873 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005874 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005875 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005876
5877 // Transform arguments.
5878 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005879 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005880 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5881 &ArgChanged))
5882 return ExprError();
5883
Douglas Gregora16548e2009-08-11 05:31:07 +00005884 if (!getDerived().AlwaysRebuild() &&
5885 Callee.get() == E->getCallee() &&
5886 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005887 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005888
Douglas Gregora16548e2009-08-11 05:31:07 +00005889 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005890 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005891 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005892 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005893 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005894 E->getRParenLoc());
5895}
Mike Stump11289f42009-09-09 15:08:12 +00005896
5897template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005898ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005899TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005900 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005901 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005902 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005903
Douglas Gregorea972d32011-02-28 21:54:11 +00005904 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005905 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005906 QualifierLoc
5907 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5908
5909 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005910 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005911 }
Mike Stump11289f42009-09-09 15:08:12 +00005912
Eli Friedman2cfcef62009-12-04 06:40:45 +00005913 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005914 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5915 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005916 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005917 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005918
John McCall16df1e52010-03-30 21:47:33 +00005919 NamedDecl *FoundDecl = E->getFoundDecl();
5920 if (FoundDecl == E->getMemberDecl()) {
5921 FoundDecl = Member;
5922 } else {
5923 FoundDecl = cast_or_null<NamedDecl>(
5924 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5925 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005926 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005927 }
5928
Douglas Gregora16548e2009-08-11 05:31:07 +00005929 if (!getDerived().AlwaysRebuild() &&
5930 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005931 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005932 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005933 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005934 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005935
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005936 // Mark it referenced in the new context regardless.
5937 // FIXME: this is a bit instantiation-specific.
5938 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005939 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005940 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005941
John McCall6b51f282009-11-23 01:53:49 +00005942 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005943 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005944 TransArgs.setLAngleLoc(E->getLAngleLoc());
5945 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005946 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5947 E->getNumTemplateArgs(),
5948 TransArgs))
5949 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005950 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005951
Douglas Gregora16548e2009-08-11 05:31:07 +00005952 // FIXME: Bogus source location for the operator
5953 SourceLocation FakeOperatorLoc
5954 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5955
John McCall38836f02010-01-15 08:34:02 +00005956 // FIXME: to do this check properly, we will need to preserve the
5957 // first-qualifier-in-scope here, just in case we had a dependent
5958 // base (and therefore couldn't do the check) and a
5959 // nested-name-qualifier (and therefore could do the lookup).
5960 NamedDecl *FirstQualifierInScope = 0;
5961
John McCallb268a282010-08-23 23:25:46 +00005962 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005963 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00005964 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005965 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005966 Member,
John McCall16df1e52010-03-30 21:47:33 +00005967 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005968 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005969 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005970 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005971}
Mike Stump11289f42009-09-09 15:08:12 +00005972
Douglas Gregora16548e2009-08-11 05:31:07 +00005973template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005974ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005975TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005976 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005977 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005978 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005979
John McCalldadc5752010-08-24 06:29:42 +00005980 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005981 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005982 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005983
Douglas Gregora16548e2009-08-11 05:31:07 +00005984 if (!getDerived().AlwaysRebuild() &&
5985 LHS.get() == E->getLHS() &&
5986 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005987 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005988
Douglas Gregora16548e2009-08-11 05:31:07 +00005989 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005990 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005991}
5992
Mike Stump11289f42009-09-09 15:08:12 +00005993template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005994ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005995TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005996 CompoundAssignOperator *E) {
5997 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005998}
Mike Stump11289f42009-09-09 15:08:12 +00005999
Douglas Gregora16548e2009-08-11 05:31:07 +00006000template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006001ExprResult TreeTransform<Derived>::
6002TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6003 // Just rebuild the common and RHS expressions and see whether we
6004 // get any changes.
6005
6006 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6007 if (commonExpr.isInvalid())
6008 return ExprError();
6009
6010 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6011 if (rhs.isInvalid())
6012 return ExprError();
6013
6014 if (!getDerived().AlwaysRebuild() &&
6015 commonExpr.get() == e->getCommon() &&
6016 rhs.get() == e->getFalseExpr())
6017 return SemaRef.Owned(e);
6018
6019 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6020 e->getQuestionLoc(),
6021 0,
6022 e->getColonLoc(),
6023 rhs.get());
6024}
6025
6026template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006027ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006028TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006029 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006030 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006031 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006032
John McCalldadc5752010-08-24 06:29:42 +00006033 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006034 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006035 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006036
John McCalldadc5752010-08-24 06:29:42 +00006037 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006038 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006039 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006040
Douglas Gregora16548e2009-08-11 05:31:07 +00006041 if (!getDerived().AlwaysRebuild() &&
6042 Cond.get() == E->getCond() &&
6043 LHS.get() == E->getLHS() &&
6044 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006045 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006046
John McCallb268a282010-08-23 23:25:46 +00006047 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006048 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006049 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006050 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006051 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006052}
Mike Stump11289f42009-09-09 15:08:12 +00006053
6054template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006055ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006056TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006057 // Implicit casts are eliminated during transformation, since they
6058 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006059 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006060}
Mike Stump11289f42009-09-09 15:08:12 +00006061
Douglas Gregora16548e2009-08-11 05:31:07 +00006062template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006063ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006064TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006065 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6066 if (!Type)
6067 return ExprError();
6068
John McCalldadc5752010-08-24 06:29:42 +00006069 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006070 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006071 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006072 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006073
Douglas Gregora16548e2009-08-11 05:31:07 +00006074 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006075 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006076 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006077 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006078
John McCall97513962010-01-15 18:39:57 +00006079 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006080 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006081 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006082 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006083}
Mike Stump11289f42009-09-09 15:08:12 +00006084
Douglas Gregora16548e2009-08-11 05:31:07 +00006085template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006086ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006087TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006088 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6089 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6090 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006091 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006092
John McCalldadc5752010-08-24 06:29:42 +00006093 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006094 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006095 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006096
Douglas Gregora16548e2009-08-11 05:31:07 +00006097 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006098 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006099 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00006100 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006101
John McCall5d7aa7f2010-01-19 22:33:45 +00006102 // Note: the expression type doesn't necessarily match the
6103 // type-as-written, but that's okay, because it should always be
6104 // derivable from the initializer.
6105
John McCalle15bbff2010-01-18 19:35:47 +00006106 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006107 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006108 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006109}
Mike Stump11289f42009-09-09 15:08:12 +00006110
Douglas Gregora16548e2009-08-11 05:31:07 +00006111template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006112ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006113TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006114 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006115 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006116 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006117
Douglas Gregora16548e2009-08-11 05:31:07 +00006118 if (!getDerived().AlwaysRebuild() &&
6119 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006120 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006121
Douglas Gregora16548e2009-08-11 05:31:07 +00006122 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00006123 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006124 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00006125 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006126 E->getAccessorLoc(),
6127 E->getAccessor());
6128}
Mike Stump11289f42009-09-09 15:08:12 +00006129
Douglas Gregora16548e2009-08-11 05:31:07 +00006130template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006131ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006132TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006133 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00006134
John McCall37ad5512010-08-23 06:44:23 +00006135 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006136 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6137 Inits, &InitChanged))
6138 return ExprError();
6139
Douglas Gregora16548e2009-08-11 05:31:07 +00006140 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00006141 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006142
Douglas Gregora16548e2009-08-11 05:31:07 +00006143 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00006144 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00006145}
Mike Stump11289f42009-09-09 15:08:12 +00006146
Douglas Gregora16548e2009-08-11 05:31:07 +00006147template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006148ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006149TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006150 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00006151
Douglas Gregorebe10102009-08-20 07:17:43 +00006152 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00006153 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006154 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006155 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006156
Douglas Gregorebe10102009-08-20 07:17:43 +00006157 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00006158 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006159 bool ExprChanged = false;
6160 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6161 DEnd = E->designators_end();
6162 D != DEnd; ++D) {
6163 if (D->isFieldDesignator()) {
6164 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6165 D->getDotLoc(),
6166 D->getFieldLoc()));
6167 continue;
6168 }
Mike Stump11289f42009-09-09 15:08:12 +00006169
Douglas Gregora16548e2009-08-11 05:31:07 +00006170 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00006171 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006172 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006173 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006174
6175 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006176 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006177
Douglas Gregora16548e2009-08-11 05:31:07 +00006178 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6179 ArrayExprs.push_back(Index.release());
6180 continue;
6181 }
Mike Stump11289f42009-09-09 15:08:12 +00006182
Douglas Gregora16548e2009-08-11 05:31:07 +00006183 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00006184 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00006185 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6186 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006187 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006188
John McCalldadc5752010-08-24 06:29:42 +00006189 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006190 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006191 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006192
6193 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006194 End.get(),
6195 D->getLBracketLoc(),
6196 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006197
Douglas Gregora16548e2009-08-11 05:31:07 +00006198 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6199 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00006200
Douglas Gregora16548e2009-08-11 05:31:07 +00006201 ArrayExprs.push_back(Start.release());
6202 ArrayExprs.push_back(End.release());
6203 }
Mike Stump11289f42009-09-09 15:08:12 +00006204
Douglas Gregora16548e2009-08-11 05:31:07 +00006205 if (!getDerived().AlwaysRebuild() &&
6206 Init.get() == E->getInit() &&
6207 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006208 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006209
Douglas Gregora16548e2009-08-11 05:31:07 +00006210 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6211 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006212 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006213}
Mike Stump11289f42009-09-09 15:08:12 +00006214
Douglas Gregora16548e2009-08-11 05:31:07 +00006215template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006216ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006217TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006218 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00006219 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006220
Douglas Gregor3da3c062009-10-28 00:29:27 +00006221 // FIXME: Will we ever have proper type location here? Will we actually
6222 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00006223 QualType T = getDerived().TransformType(E->getType());
6224 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006225 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006226
Douglas Gregora16548e2009-08-11 05:31:07 +00006227 if (!getDerived().AlwaysRebuild() &&
6228 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006229 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006230
Douglas Gregora16548e2009-08-11 05:31:07 +00006231 return getDerived().RebuildImplicitValueInitExpr(T);
6232}
Mike Stump11289f42009-09-09 15:08:12 +00006233
Douglas Gregora16548e2009-08-11 05:31:07 +00006234template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006235ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006236TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00006237 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6238 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006239 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006240
John McCalldadc5752010-08-24 06:29:42 +00006241 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006242 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006243 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006244
Douglas Gregora16548e2009-08-11 05:31:07 +00006245 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00006246 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006247 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006248 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006249
John McCallb268a282010-08-23 23:25:46 +00006250 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00006251 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006252}
6253
6254template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006255ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006256TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006257 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006258 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006259 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6260 &ArgumentChanged))
6261 return ExprError();
6262
Douglas Gregora16548e2009-08-11 05:31:07 +00006263 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6264 move_arg(Inits),
6265 E->getRParenLoc());
6266}
Mike Stump11289f42009-09-09 15:08:12 +00006267
Douglas Gregora16548e2009-08-11 05:31:07 +00006268/// \brief Transform an address-of-label expression.
6269///
6270/// By default, the transformation of an address-of-label expression always
6271/// rebuilds the expression, so that the label identifier can be resolved to
6272/// the corresponding label statement by semantic analysis.
6273template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006274ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006275TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006276 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6277 E->getLabel());
6278 if (!LD)
6279 return ExprError();
6280
Douglas Gregora16548e2009-08-11 05:31:07 +00006281 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006282 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006283}
Mike Stump11289f42009-09-09 15:08:12 +00006284
6285template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006286ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006287TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006288 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006289 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6290 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006291 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006292
Douglas Gregora16548e2009-08-11 05:31:07 +00006293 if (!getDerived().AlwaysRebuild() &&
6294 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006295 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006296
6297 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006298 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006299 E->getRParenLoc());
6300}
Mike Stump11289f42009-09-09 15:08:12 +00006301
Douglas Gregora16548e2009-08-11 05:31:07 +00006302template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006303ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006304TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006305 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006306 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006307 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006308
John McCalldadc5752010-08-24 06:29:42 +00006309 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006310 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006311 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006312
John McCalldadc5752010-08-24 06:29:42 +00006313 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006314 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006315 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006316
Douglas Gregora16548e2009-08-11 05:31:07 +00006317 if (!getDerived().AlwaysRebuild() &&
6318 Cond.get() == E->getCond() &&
6319 LHS.get() == E->getLHS() &&
6320 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006321 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006322
Douglas Gregora16548e2009-08-11 05:31:07 +00006323 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006324 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006325 E->getRParenLoc());
6326}
Mike Stump11289f42009-09-09 15:08:12 +00006327
Douglas Gregora16548e2009-08-11 05:31:07 +00006328template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006329ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006330TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006331 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006332}
6333
6334template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006335ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006336TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006337 switch (E->getOperator()) {
6338 case OO_New:
6339 case OO_Delete:
6340 case OO_Array_New:
6341 case OO_Array_Delete:
6342 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006343 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006344
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006345 case OO_Call: {
6346 // This is a call to an object's operator().
6347 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6348
6349 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006350 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006351 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006352 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006353
6354 // FIXME: Poor location information
6355 SourceLocation FakeLParenLoc
6356 = SemaRef.PP.getLocForEndOfToken(
6357 static_cast<Expr *>(Object.get())->getLocEnd());
6358
6359 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006360 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006361 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6362 Args))
6363 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006364
John McCallb268a282010-08-23 23:25:46 +00006365 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006366 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006367 E->getLocEnd());
6368 }
6369
6370#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6371 case OO_##Name:
6372#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6373#include "clang/Basic/OperatorKinds.def"
6374 case OO_Subscript:
6375 // Handled below.
6376 break;
6377
6378 case OO_Conditional:
6379 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006380 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006381
6382 case OO_None:
6383 case NUM_OVERLOADED_OPERATORS:
6384 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006385 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006386 }
6387
John McCalldadc5752010-08-24 06:29:42 +00006388 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006389 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006390 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006391
John McCalldadc5752010-08-24 06:29:42 +00006392 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006393 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006394 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006395
John McCalldadc5752010-08-24 06:29:42 +00006396 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006397 if (E->getNumArgs() == 2) {
6398 Second = getDerived().TransformExpr(E->getArg(1));
6399 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006400 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006401 }
Mike Stump11289f42009-09-09 15:08:12 +00006402
Douglas Gregora16548e2009-08-11 05:31:07 +00006403 if (!getDerived().AlwaysRebuild() &&
6404 Callee.get() == E->getCallee() &&
6405 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006406 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006407 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006408
Douglas Gregora16548e2009-08-11 05:31:07 +00006409 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6410 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006411 Callee.get(),
6412 First.get(),
6413 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006414}
Mike Stump11289f42009-09-09 15:08:12 +00006415
Douglas Gregora16548e2009-08-11 05:31:07 +00006416template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006417ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006418TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6419 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006420}
Mike Stump11289f42009-09-09 15:08:12 +00006421
Douglas Gregora16548e2009-08-11 05:31:07 +00006422template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006423ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006424TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6425 // Transform the callee.
6426 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6427 if (Callee.isInvalid())
6428 return ExprError();
6429
6430 // Transform exec config.
6431 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6432 if (EC.isInvalid())
6433 return ExprError();
6434
6435 // Transform arguments.
6436 bool ArgChanged = false;
6437 ASTOwningVector<Expr*> Args(SemaRef);
6438 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6439 &ArgChanged))
6440 return ExprError();
6441
6442 if (!getDerived().AlwaysRebuild() &&
6443 Callee.get() == E->getCallee() &&
6444 !ArgChanged)
6445 return SemaRef.Owned(E);
6446
6447 // FIXME: Wrong source location information for the '('.
6448 SourceLocation FakeLParenLoc
6449 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6450 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6451 move_arg(Args),
6452 E->getRParenLoc(), EC.get());
6453}
6454
6455template<typename Derived>
6456ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006457TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006458 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6459 if (!Type)
6460 return ExprError();
6461
John McCalldadc5752010-08-24 06:29:42 +00006462 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006463 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006464 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006465 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006466
Douglas Gregora16548e2009-08-11 05:31:07 +00006467 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006468 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006469 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006470 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006471
Douglas Gregora16548e2009-08-11 05:31:07 +00006472 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006473 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006474 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6475 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6476 SourceLocation FakeRParenLoc
6477 = SemaRef.PP.getLocForEndOfToken(
6478 E->getSubExpr()->getSourceRange().getEnd());
6479 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006480 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006481 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006482 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006483 FakeRAngleLoc,
6484 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006485 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006486 FakeRParenLoc);
6487}
Mike Stump11289f42009-09-09 15:08:12 +00006488
Douglas Gregora16548e2009-08-11 05:31:07 +00006489template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006490ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006491TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6492 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006493}
Mike Stump11289f42009-09-09 15:08:12 +00006494
6495template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006496ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006497TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6498 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006499}
6500
Douglas Gregora16548e2009-08-11 05:31:07 +00006501template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006502ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006503TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006504 CXXReinterpretCastExpr *E) {
6505 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006506}
Mike Stump11289f42009-09-09 15:08:12 +00006507
Douglas Gregora16548e2009-08-11 05:31:07 +00006508template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006509ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006510TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6511 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006512}
Mike Stump11289f42009-09-09 15:08:12 +00006513
Douglas Gregora16548e2009-08-11 05:31:07 +00006514template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006515ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006516TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006517 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006518 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6519 if (!Type)
6520 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006521
John McCalldadc5752010-08-24 06:29:42 +00006522 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006523 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006524 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006525 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006526
Douglas Gregora16548e2009-08-11 05:31:07 +00006527 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006528 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006529 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006530 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006531
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006532 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006533 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006534 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006535 E->getRParenLoc());
6536}
Mike Stump11289f42009-09-09 15:08:12 +00006537
Douglas Gregora16548e2009-08-11 05:31:07 +00006538template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006539ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006540TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006541 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006542 TypeSourceInfo *TInfo
6543 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6544 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006545 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006546
Douglas Gregora16548e2009-08-11 05:31:07 +00006547 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006548 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006549 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006550
Douglas Gregor9da64192010-04-26 22:37:10 +00006551 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6552 E->getLocStart(),
6553 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006554 E->getLocEnd());
6555 }
Mike Stump11289f42009-09-09 15:08:12 +00006556
Douglas Gregora16548e2009-08-11 05:31:07 +00006557 // We don't know whether the expression is potentially evaluated until
6558 // after we perform semantic analysis, so the expression is potentially
6559 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006560 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006561 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006562
John McCalldadc5752010-08-24 06:29:42 +00006563 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006564 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006565 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006566
Douglas Gregora16548e2009-08-11 05:31:07 +00006567 if (!getDerived().AlwaysRebuild() &&
6568 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006569 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006570
Douglas Gregor9da64192010-04-26 22:37:10 +00006571 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6572 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006573 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006574 E->getLocEnd());
6575}
6576
6577template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006578ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006579TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6580 if (E->isTypeOperand()) {
6581 TypeSourceInfo *TInfo
6582 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6583 if (!TInfo)
6584 return ExprError();
6585
6586 if (!getDerived().AlwaysRebuild() &&
6587 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006588 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006589
Douglas Gregor69735112011-03-06 17:40:41 +00006590 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00006591 E->getLocStart(),
6592 TInfo,
6593 E->getLocEnd());
6594 }
6595
6596 // We don't know whether the expression is potentially evaluated until
6597 // after we perform semantic analysis, so the expression is potentially
6598 // potentially evaluated.
6599 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6600
6601 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6602 if (SubExpr.isInvalid())
6603 return ExprError();
6604
6605 if (!getDerived().AlwaysRebuild() &&
6606 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006607 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006608
6609 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6610 E->getLocStart(),
6611 SubExpr.get(),
6612 E->getLocEnd());
6613}
6614
6615template<typename Derived>
6616ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006617TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006618 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006619}
Mike Stump11289f42009-09-09 15:08:12 +00006620
Douglas Gregora16548e2009-08-11 05:31:07 +00006621template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006622ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006623TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006624 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006625 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006626}
Mike Stump11289f42009-09-09 15:08:12 +00006627
Douglas Gregora16548e2009-08-11 05:31:07 +00006628template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006629ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006630TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006631 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6632 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6633 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006634
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006635 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006636 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006637
Douglas Gregorb15af892010-01-07 23:12:05 +00006638 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006639}
Mike Stump11289f42009-09-09 15:08:12 +00006640
Douglas Gregora16548e2009-08-11 05:31:07 +00006641template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006642ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006643TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006644 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006645 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006646 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006647
Douglas Gregora16548e2009-08-11 05:31:07 +00006648 if (!getDerived().AlwaysRebuild() &&
6649 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006650 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006651
John McCallb268a282010-08-23 23:25:46 +00006652 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006653}
Mike Stump11289f42009-09-09 15:08:12 +00006654
Douglas Gregora16548e2009-08-11 05:31:07 +00006655template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006656ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006657TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006658 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006659 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6660 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006661 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006662 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006663
Chandler Carruth794da4c2010-02-08 06:42:49 +00006664 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006665 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006666 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006667
Douglas Gregor033f6752009-12-23 23:03:06 +00006668 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006669}
Mike Stump11289f42009-09-09 15:08:12 +00006670
Douglas Gregora16548e2009-08-11 05:31:07 +00006671template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006672ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006673TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6674 CXXScalarValueInitExpr *E) {
6675 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6676 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006677 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006678
Douglas Gregora16548e2009-08-11 05:31:07 +00006679 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006680 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006681 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006682
Douglas Gregor2b88c112010-09-08 00:15:04 +00006683 return getDerived().RebuildCXXScalarValueInitExpr(T,
6684 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006685 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006686}
Mike Stump11289f42009-09-09 15:08:12 +00006687
Douglas Gregora16548e2009-08-11 05:31:07 +00006688template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006689ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006690TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006691 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006692 TypeSourceInfo *AllocTypeInfo
6693 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6694 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006695 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006696
Douglas Gregora16548e2009-08-11 05:31:07 +00006697 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006698 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006699 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006700 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006701
Douglas Gregora16548e2009-08-11 05:31:07 +00006702 // Transform the placement arguments (if any).
6703 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006704 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006705 if (getDerived().TransformExprs(E->getPlacementArgs(),
6706 E->getNumPlacementArgs(), true,
6707 PlacementArgs, &ArgumentChanged))
6708 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006709
Douglas Gregorebe10102009-08-20 07:17:43 +00006710 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006711 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006712 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6713 ConstructorArgs, &ArgumentChanged))
6714 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006715
Douglas Gregord2d9da02010-02-26 00:38:10 +00006716 // Transform constructor, new operator, and delete operator.
6717 CXXConstructorDecl *Constructor = 0;
6718 if (E->getConstructor()) {
6719 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006720 getDerived().TransformDecl(E->getLocStart(),
6721 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006722 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006723 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006724 }
6725
6726 FunctionDecl *OperatorNew = 0;
6727 if (E->getOperatorNew()) {
6728 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006729 getDerived().TransformDecl(E->getLocStart(),
6730 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006731 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006732 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006733 }
6734
6735 FunctionDecl *OperatorDelete = 0;
6736 if (E->getOperatorDelete()) {
6737 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006738 getDerived().TransformDecl(E->getLocStart(),
6739 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006740 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006741 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006742 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006743
Douglas Gregora16548e2009-08-11 05:31:07 +00006744 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006745 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006746 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006747 Constructor == E->getConstructor() &&
6748 OperatorNew == E->getOperatorNew() &&
6749 OperatorDelete == E->getOperatorDelete() &&
6750 !ArgumentChanged) {
6751 // Mark any declarations we need as referenced.
6752 // FIXME: instantiation-specific.
6753 if (Constructor)
6754 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6755 if (OperatorNew)
6756 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6757 if (OperatorDelete)
6758 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006759 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006760 }
Mike Stump11289f42009-09-09 15:08:12 +00006761
Douglas Gregor0744ef62010-09-07 21:49:58 +00006762 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006763 if (!ArraySize.get()) {
6764 // If no array size was specified, but the new expression was
6765 // instantiated with an array type (e.g., "new T" where T is
6766 // instantiated with "int[4]"), extract the outer bound from the
6767 // array type as our array size. We do this with constant and
6768 // dependently-sized array types.
6769 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6770 if (!ArrayT) {
6771 // Do nothing
6772 } else if (const ConstantArrayType *ConsArrayT
6773 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006774 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006775 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6776 ConsArrayT->getSize(),
6777 SemaRef.Context.getSizeType(),
6778 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006779 AllocType = ConsArrayT->getElementType();
6780 } else if (const DependentSizedArrayType *DepArrayT
6781 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6782 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006783 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006784 AllocType = DepArrayT->getElementType();
6785 }
6786 }
6787 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006788
Douglas Gregora16548e2009-08-11 05:31:07 +00006789 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6790 E->isGlobalNew(),
6791 /*FIXME:*/E->getLocStart(),
6792 move_arg(PlacementArgs),
6793 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006794 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006795 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006796 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006797 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006798 /*FIXME:*/E->getLocStart(),
6799 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006800 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006801}
Mike Stump11289f42009-09-09 15:08:12 +00006802
Douglas Gregora16548e2009-08-11 05:31:07 +00006803template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006804ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006805TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006806 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006807 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006808 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006809
Douglas Gregord2d9da02010-02-26 00:38:10 +00006810 // Transform the delete operator, if known.
6811 FunctionDecl *OperatorDelete = 0;
6812 if (E->getOperatorDelete()) {
6813 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006814 getDerived().TransformDecl(E->getLocStart(),
6815 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006816 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006817 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006818 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006819
Douglas Gregora16548e2009-08-11 05:31:07 +00006820 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006821 Operand.get() == E->getArgument() &&
6822 OperatorDelete == E->getOperatorDelete()) {
6823 // Mark any declarations we need as referenced.
6824 // FIXME: instantiation-specific.
6825 if (OperatorDelete)
6826 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006827
6828 if (!E->getArgument()->isTypeDependent()) {
6829 QualType Destroyed = SemaRef.Context.getBaseElementType(
6830 E->getDestroyedType());
6831 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6832 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6833 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6834 SemaRef.LookupDestructor(Record));
6835 }
6836 }
6837
John McCallc3007a22010-10-26 07:05:15 +00006838 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006839 }
Mike Stump11289f42009-09-09 15:08:12 +00006840
Douglas Gregora16548e2009-08-11 05:31:07 +00006841 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6842 E->isGlobalDelete(),
6843 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006844 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006845}
Mike Stump11289f42009-09-09 15:08:12 +00006846
Douglas Gregora16548e2009-08-11 05:31:07 +00006847template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006848ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006849TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006850 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006851 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006852 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006853 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006854
John McCallba7bf592010-08-24 05:47:05 +00006855 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006856 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006857 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006858 E->getOperatorLoc(),
6859 E->isArrow()? tok::arrow : tok::period,
6860 ObjectTypePtr,
6861 MayBePseudoDestructor);
6862 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006863 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006864
John McCallba7bf592010-08-24 05:47:05 +00006865 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00006866 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6867 if (QualifierLoc) {
6868 QualifierLoc
6869 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6870 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00006871 return ExprError();
6872 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00006873 CXXScopeSpec SS;
6874 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00006875
Douglas Gregor678f90d2010-02-25 01:56:36 +00006876 PseudoDestructorTypeStorage Destroyed;
6877 if (E->getDestroyedTypeInfo()) {
6878 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006879 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00006880 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00006881 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006882 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006883 Destroyed = DestroyedTypeInfo;
6884 } else if (ObjectType->isDependentType()) {
6885 // We aren't likely to be able to resolve the identifier down to a type
6886 // now anyway, so just retain the identifier.
6887 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6888 E->getDestroyedTypeLoc());
6889 } else {
6890 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00006891 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006892 *E->getDestroyedTypeIdentifier(),
6893 E->getDestroyedTypeLoc(),
6894 /*Scope=*/0,
6895 SS, ObjectTypePtr,
6896 false);
6897 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006898 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006899
Douglas Gregor678f90d2010-02-25 01:56:36 +00006900 Destroyed
6901 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6902 E->getDestroyedTypeLoc());
6903 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006904
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006905 TypeSourceInfo *ScopeTypeInfo = 0;
6906 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006907 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006908 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006909 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006910 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006911
John McCallb268a282010-08-23 23:25:46 +00006912 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006913 E->getOperatorLoc(),
6914 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006915 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006916 ScopeTypeInfo,
6917 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006918 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006919 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006920}
Mike Stump11289f42009-09-09 15:08:12 +00006921
Douglas Gregorad8a3362009-09-04 17:36:40 +00006922template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006923ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006924TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006925 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006926 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6927 Sema::LookupOrdinaryName);
6928
6929 // Transform all the decls.
6930 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6931 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006932 NamedDecl *InstD = static_cast<NamedDecl*>(
6933 getDerived().TransformDecl(Old->getNameLoc(),
6934 *I));
John McCall84d87672009-12-10 09:41:52 +00006935 if (!InstD) {
6936 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6937 // This can happen because of dependent hiding.
6938 if (isa<UsingShadowDecl>(*I))
6939 continue;
6940 else
John McCallfaf5fb42010-08-26 23:41:50 +00006941 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006942 }
John McCalle66edc12009-11-24 19:00:30 +00006943
6944 // Expand using declarations.
6945 if (isa<UsingDecl>(InstD)) {
6946 UsingDecl *UD = cast<UsingDecl>(InstD);
6947 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6948 E = UD->shadow_end(); I != E; ++I)
6949 R.addDecl(*I);
6950 continue;
6951 }
6952
6953 R.addDecl(InstD);
6954 }
6955
6956 // Resolve a kind, but don't do any further analysis. If it's
6957 // ambiguous, the callee needs to deal with it.
6958 R.resolveKind();
6959
6960 // Rebuild the nested-name qualifier, if present.
6961 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00006962 if (Old->getQualifierLoc()) {
6963 NestedNameSpecifierLoc QualifierLoc
6964 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
6965 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006966 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006967
Douglas Gregor0da1d432011-02-28 20:01:57 +00006968 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006969 }
6970
Douglas Gregor9262f472010-04-27 18:19:34 +00006971 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006972 CXXRecordDecl *NamingClass
6973 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6974 Old->getNameLoc(),
6975 Old->getNamingClass()));
6976 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006977 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006978
Douglas Gregorda7be082010-04-27 16:10:10 +00006979 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006980 }
6981
6982 // If we have no template arguments, it's a normal declaration name.
6983 if (!Old->hasExplicitTemplateArgs())
6984 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6985
6986 // If we have template arguments, rebuild them, then rebuild the
6987 // templateid expression.
6988 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006989 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6990 Old->getNumTemplateArgs(),
6991 TransArgs))
6992 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006993
6994 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6995 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006996}
Mike Stump11289f42009-09-09 15:08:12 +00006997
Douglas Gregora16548e2009-08-11 05:31:07 +00006998template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006999ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007000TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00007001 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7002 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007003 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007004
Douglas Gregora16548e2009-08-11 05:31:07 +00007005 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00007006 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007007 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007008
Mike Stump11289f42009-09-09 15:08:12 +00007009 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007010 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007011 T,
7012 E->getLocEnd());
7013}
Mike Stump11289f42009-09-09 15:08:12 +00007014
Douglas Gregora16548e2009-08-11 05:31:07 +00007015template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007016ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00007017TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7018 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7019 if (!LhsT)
7020 return ExprError();
7021
7022 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7023 if (!RhsT)
7024 return ExprError();
7025
7026 if (!getDerived().AlwaysRebuild() &&
7027 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7028 return SemaRef.Owned(E);
7029
7030 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7031 E->getLocStart(),
7032 LhsT, RhsT,
7033 E->getLocEnd());
7034}
7035
7036template<typename Derived>
7037ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00007038TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7039 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7040 if (!T)
7041 return ExprError();
7042
7043 if (!getDerived().AlwaysRebuild() &&
7044 T == E->getQueriedTypeSourceInfo())
7045 return SemaRef.Owned(E);
7046
7047 ExprResult SubExpr;
7048 {
7049 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7050 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7051 if (SubExpr.isInvalid())
7052 return ExprError();
7053
7054 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7055 return SemaRef.Owned(E);
7056 }
7057
7058 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7059 E->getLocStart(),
7060 T,
7061 SubExpr.get(),
7062 E->getLocEnd());
7063}
7064
7065template<typename Derived>
7066ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00007067TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7068 ExprResult SubExpr;
7069 {
7070 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7071 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7072 if (SubExpr.isInvalid())
7073 return ExprError();
7074
7075 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7076 return SemaRef.Owned(E);
7077 }
7078
7079 return getDerived().RebuildExpressionTrait(
7080 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7081}
7082
7083template<typename Derived>
7084ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007085TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007086 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007087 NestedNameSpecifierLoc QualifierLoc
7088 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7089 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007090 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007091
John McCall31f82722010-11-12 08:19:04 +00007092 // TODO: If this is a conversion-function-id, verify that the
7093 // destination type name (if present) resolves the same way after
7094 // instantiation as it did in the local scope.
7095
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007096 DeclarationNameInfo NameInfo
7097 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7098 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007099 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007100
John McCalle66edc12009-11-24 19:00:30 +00007101 if (!E->hasExplicitTemplateArgs()) {
7102 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007103 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007104 // Note: it is sufficient to compare the Name component of NameInfo:
7105 // if name has not changed, DNLoc has not changed either.
7106 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00007107 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007108
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007109 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007110 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007111 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00007112 }
John McCall6b51f282009-11-23 01:53:49 +00007113
7114 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007115 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7116 E->getNumTemplateArgs(),
7117 TransArgs))
7118 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007119
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007120 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007121 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007122 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007123}
7124
7125template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007126ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007127TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00007128 // CXXConstructExprs are always implicit, so when we have a
7129 // 1-argument construction we just transform that argument.
7130 if (E->getNumArgs() == 1 ||
7131 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7132 return getDerived().TransformExpr(E->getArg(0));
7133
Douglas Gregora16548e2009-08-11 05:31:07 +00007134 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7135
7136 QualType T = getDerived().TransformType(E->getType());
7137 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007138 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007139
7140 CXXConstructorDecl *Constructor
7141 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007142 getDerived().TransformDecl(E->getLocStart(),
7143 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007144 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007145 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007146
Douglas Gregora16548e2009-08-11 05:31:07 +00007147 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007148 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007149 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7150 &ArgumentChanged))
7151 return ExprError();
7152
Douglas Gregora16548e2009-08-11 05:31:07 +00007153 if (!getDerived().AlwaysRebuild() &&
7154 T == E->getType() &&
7155 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00007156 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00007157 // Mark the constructor as referenced.
7158 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00007159 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007160 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00007161 }
Mike Stump11289f42009-09-09 15:08:12 +00007162
Douglas Gregordb121ba2009-12-14 16:27:04 +00007163 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7164 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00007165 move_arg(Args),
7166 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00007167 E->getConstructionKind(),
7168 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007169}
Mike Stump11289f42009-09-09 15:08:12 +00007170
Douglas Gregora16548e2009-08-11 05:31:07 +00007171/// \brief Transform a C++ temporary-binding expression.
7172///
Douglas Gregor363b1512009-12-24 18:51:59 +00007173/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7174/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007175template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007176ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007177TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007178 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007179}
Mike Stump11289f42009-09-09 15:08:12 +00007180
John McCall5d413782010-12-06 08:20:24 +00007181/// \brief Transform a C++ expression that contains cleanups that should
7182/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00007183///
John McCall5d413782010-12-06 08:20:24 +00007184/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00007185/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007186template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007187ExprResult
John McCall5d413782010-12-06 08:20:24 +00007188TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007189 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007190}
Mike Stump11289f42009-09-09 15:08:12 +00007191
Douglas Gregora16548e2009-08-11 05:31:07 +00007192template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007193ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007194TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00007195 CXXTemporaryObjectExpr *E) {
7196 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7197 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007198 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007199
Douglas Gregora16548e2009-08-11 05:31:07 +00007200 CXXConstructorDecl *Constructor
7201 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00007202 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007203 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007204 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007205 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007206
Douglas Gregora16548e2009-08-11 05:31:07 +00007207 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007208 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00007209 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00007210 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7211 &ArgumentChanged))
7212 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007213
Douglas Gregora16548e2009-08-11 05:31:07 +00007214 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007215 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007216 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007217 !ArgumentChanged) {
7218 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00007219 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007220 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007221 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00007222
7223 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7224 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007225 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007226 E->getLocEnd());
7227}
Mike Stump11289f42009-09-09 15:08:12 +00007228
Douglas Gregora16548e2009-08-11 05:31:07 +00007229template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007230ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007231TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007232 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00007233 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7234 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007235 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007236
Douglas Gregora16548e2009-08-11 05:31:07 +00007237 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007238 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007239 Args.reserve(E->arg_size());
7240 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7241 &ArgumentChanged))
7242 return ExprError();
7243
Douglas Gregora16548e2009-08-11 05:31:07 +00007244 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007245 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007246 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007247 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007248
Douglas Gregora16548e2009-08-11 05:31:07 +00007249 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00007250 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00007251 E->getLParenLoc(),
7252 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007253 E->getRParenLoc());
7254}
Mike Stump11289f42009-09-09 15:08:12 +00007255
Douglas Gregora16548e2009-08-11 05:31:07 +00007256template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007257ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007258TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007259 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007260 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007261 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007262 Expr *OldBase;
7263 QualType BaseType;
7264 QualType ObjectType;
7265 if (!E->isImplicitAccess()) {
7266 OldBase = E->getBase();
7267 Base = getDerived().TransformExpr(OldBase);
7268 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007269 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007270
John McCall2d74de92009-12-01 22:10:20 +00007271 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00007272 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00007273 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007274 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007275 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007276 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00007277 ObjectTy,
7278 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00007279 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007280 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007281
John McCallba7bf592010-08-24 05:47:05 +00007282 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00007283 BaseType = ((Expr*) Base.get())->getType();
7284 } else {
7285 OldBase = 0;
7286 BaseType = getDerived().TransformType(E->getBaseType());
7287 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7288 }
Mike Stump11289f42009-09-09 15:08:12 +00007289
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007290 // Transform the first part of the nested-name-specifier that qualifies
7291 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007292 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007293 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00007294 E->getFirstQualifierFoundInScope(),
7295 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00007296
Douglas Gregore16af532011-02-28 18:50:33 +00007297 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007298 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00007299 QualifierLoc
7300 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7301 ObjectType,
7302 FirstQualifierInScope);
7303 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007304 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007305 }
Mike Stump11289f42009-09-09 15:08:12 +00007306
John McCall31f82722010-11-12 08:19:04 +00007307 // TODO: If this is a conversion-function-id, verify that the
7308 // destination type name (if present) resolves the same way after
7309 // instantiation as it did in the local scope.
7310
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007311 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007312 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007313 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007314 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007315
John McCall2d74de92009-12-01 22:10:20 +00007316 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007317 // This is a reference to a member without an explicitly-specified
7318 // template argument list. Optimize for this common case.
7319 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007320 Base.get() == OldBase &&
7321 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007322 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007323 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007324 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007325 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007326
John McCallb268a282010-08-23 23:25:46 +00007327 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007328 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007329 E->isArrow(),
7330 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007331 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007332 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007333 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007334 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007335 }
7336
John McCall6b51f282009-11-23 01:53:49 +00007337 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007338 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7339 E->getNumTemplateArgs(),
7340 TransArgs))
7341 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007342
John McCallb268a282010-08-23 23:25:46 +00007343 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007344 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007345 E->isArrow(),
7346 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007347 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007348 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007349 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007350 &TransArgs);
7351}
7352
7353template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007354ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007355TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007356 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007357 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007358 QualType BaseType;
7359 if (!Old->isImplicitAccess()) {
7360 Base = getDerived().TransformExpr(Old->getBase());
7361 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007362 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007363 BaseType = ((Expr*) Base.get())->getType();
7364 } else {
7365 BaseType = getDerived().TransformType(Old->getBaseType());
7366 }
John McCall10eae182009-11-30 22:42:35 +00007367
Douglas Gregor0da1d432011-02-28 20:01:57 +00007368 NestedNameSpecifierLoc QualifierLoc;
7369 if (Old->getQualifierLoc()) {
7370 QualifierLoc
7371 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7372 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007373 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007374 }
7375
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007376 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007377 Sema::LookupOrdinaryName);
7378
7379 // Transform all the decls.
7380 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7381 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007382 NamedDecl *InstD = static_cast<NamedDecl*>(
7383 getDerived().TransformDecl(Old->getMemberLoc(),
7384 *I));
John McCall84d87672009-12-10 09:41:52 +00007385 if (!InstD) {
7386 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7387 // This can happen because of dependent hiding.
7388 if (isa<UsingShadowDecl>(*I))
7389 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007390 else {
7391 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007392 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007393 }
John McCall84d87672009-12-10 09:41:52 +00007394 }
John McCall10eae182009-11-30 22:42:35 +00007395
7396 // Expand using declarations.
7397 if (isa<UsingDecl>(InstD)) {
7398 UsingDecl *UD = cast<UsingDecl>(InstD);
7399 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7400 E = UD->shadow_end(); I != E; ++I)
7401 R.addDecl(*I);
7402 continue;
7403 }
7404
7405 R.addDecl(InstD);
7406 }
7407
7408 R.resolveKind();
7409
Douglas Gregor9262f472010-04-27 18:19:34 +00007410 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007411 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007412 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007413 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007414 Old->getMemberLoc(),
7415 Old->getNamingClass()));
7416 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007417 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007418
Douglas Gregorda7be082010-04-27 16:10:10 +00007419 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007420 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007421
John McCall10eae182009-11-30 22:42:35 +00007422 TemplateArgumentListInfo TransArgs;
7423 if (Old->hasExplicitTemplateArgs()) {
7424 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7425 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007426 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7427 Old->getNumTemplateArgs(),
7428 TransArgs))
7429 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007430 }
John McCall38836f02010-01-15 08:34:02 +00007431
7432 // FIXME: to do this check properly, we will need to preserve the
7433 // first-qualifier-in-scope here, just in case we had a dependent
7434 // base (and therefore couldn't do the check) and a
7435 // nested-name-qualifier (and therefore could do the lookup).
7436 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007437
John McCallb268a282010-08-23 23:25:46 +00007438 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007439 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007440 Old->getOperatorLoc(),
7441 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007442 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007443 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007444 R,
7445 (Old->hasExplicitTemplateArgs()
7446 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007447}
7448
7449template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007450ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007451TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7452 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7453 if (SubExpr.isInvalid())
7454 return ExprError();
7455
7456 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007457 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007458
7459 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7460}
7461
7462template<typename Derived>
7463ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007464TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007465 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7466 if (Pattern.isInvalid())
7467 return ExprError();
7468
7469 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7470 return SemaRef.Owned(E);
7471
Douglas Gregorb8840002011-01-14 21:20:45 +00007472 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7473 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007474}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007475
7476template<typename Derived>
7477ExprResult
7478TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7479 // If E is not value-dependent, then nothing will change when we transform it.
7480 // Note: This is an instantiation-centric view.
7481 if (!E->isValueDependent())
7482 return SemaRef.Owned(E);
7483
7484 // Note: None of the implementations of TryExpandParameterPacks can ever
7485 // produce a diagnostic when given only a single unexpanded parameter pack,
7486 // so
7487 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7488 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007489 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007490 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007491 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7492 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007493 ShouldExpand, RetainExpansion,
7494 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007495 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007496
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007497 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007498 return SemaRef.Owned(E);
7499
7500 // We now know the length of the parameter pack, so build a new expression
7501 // that stores that length.
7502 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7503 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007504 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007505}
7506
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007507template<typename Derived>
7508ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007509TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7510 SubstNonTypeTemplateParmPackExpr *E) {
7511 // Default behavior is to do nothing with this transformation.
7512 return SemaRef.Owned(E);
7513}
7514
7515template<typename Derived>
7516ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007517TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007518 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007519}
7520
Mike Stump11289f42009-09-09 15:08:12 +00007521template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007522ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007523TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007524 TypeSourceInfo *EncodedTypeInfo
7525 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7526 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007527 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007528
Douglas Gregora16548e2009-08-11 05:31:07 +00007529 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007530 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007531 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007532
7533 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007534 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007535 E->getRParenLoc());
7536}
Mike Stump11289f42009-09-09 15:08:12 +00007537
Douglas Gregora16548e2009-08-11 05:31:07 +00007538template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007539ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007540TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007541 // Transform arguments.
7542 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007543 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007544 Args.reserve(E->getNumArgs());
7545 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7546 &ArgChanged))
7547 return ExprError();
7548
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007549 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7550 // Class message: transform the receiver type.
7551 TypeSourceInfo *ReceiverTypeInfo
7552 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7553 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007554 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007555
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007556 // If nothing changed, just retain the existing message send.
7557 if (!getDerived().AlwaysRebuild() &&
7558 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007559 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007560
7561 // Build a new class message send.
7562 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7563 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007564 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007565 E->getMethodDecl(),
7566 E->getLeftLoc(),
7567 move_arg(Args),
7568 E->getRightLoc());
7569 }
7570
7571 // Instance message: transform the receiver
7572 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7573 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007574 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007575 = getDerived().TransformExpr(E->getInstanceReceiver());
7576 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007577 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007578
7579 // If nothing changed, just retain the existing message send.
7580 if (!getDerived().AlwaysRebuild() &&
7581 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007582 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007583
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007584 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007585 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007586 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007587 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007588 E->getMethodDecl(),
7589 E->getLeftLoc(),
7590 move_arg(Args),
7591 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007592}
7593
Mike Stump11289f42009-09-09 15:08:12 +00007594template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007595ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007596TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007597 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007598}
7599
Mike Stump11289f42009-09-09 15:08:12 +00007600template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007601ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007602TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007603 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007604}
7605
Mike Stump11289f42009-09-09 15:08:12 +00007606template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007607ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007608TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007609 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007610 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007611 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007612 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007613
7614 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007615
Douglas Gregord51d90d2010-04-26 20:11:03 +00007616 // If nothing changed, just retain the existing expression.
7617 if (!getDerived().AlwaysRebuild() &&
7618 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007619 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007620
John McCallb268a282010-08-23 23:25:46 +00007621 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007622 E->getLocation(),
7623 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007624}
7625
Mike Stump11289f42009-09-09 15:08:12 +00007626template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007627ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007628TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007629 // 'super' and types never change. Property never changes. Just
7630 // retain the existing expression.
7631 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007632 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007633
Douglas Gregor9faee212010-04-26 20:47:02 +00007634 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007635 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007636 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007637 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007638
Douglas Gregor9faee212010-04-26 20:47:02 +00007639 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007640
Douglas Gregor9faee212010-04-26 20:47:02 +00007641 // If nothing changed, just retain the existing expression.
7642 if (!getDerived().AlwaysRebuild() &&
7643 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007644 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007645
John McCallb7bd14f2010-12-02 01:19:52 +00007646 if (E->isExplicitProperty())
7647 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7648 E->getExplicitProperty(),
7649 E->getLocation());
7650
7651 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7652 E->getType(),
7653 E->getImplicitPropertyGetter(),
7654 E->getImplicitPropertySetter(),
7655 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007656}
7657
Mike Stump11289f42009-09-09 15:08:12 +00007658template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007659ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007660TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007661 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007662 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007663 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007664 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007665
Douglas Gregord51d90d2010-04-26 20:11:03 +00007666 // If nothing changed, just retain the existing expression.
7667 if (!getDerived().AlwaysRebuild() &&
7668 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007669 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007670
John McCallb268a282010-08-23 23:25:46 +00007671 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007672 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007673}
7674
Mike Stump11289f42009-09-09 15:08:12 +00007675template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007676ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007677TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007678 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007679 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007680 SubExprs.reserve(E->getNumSubExprs());
7681 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7682 SubExprs, &ArgumentChanged))
7683 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007684
Douglas Gregora16548e2009-08-11 05:31:07 +00007685 if (!getDerived().AlwaysRebuild() &&
7686 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007687 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007688
Douglas Gregora16548e2009-08-11 05:31:07 +00007689 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7690 move_arg(SubExprs),
7691 E->getRParenLoc());
7692}
7693
Mike Stump11289f42009-09-09 15:08:12 +00007694template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007695ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007696TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007697 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007698
John McCall490112f2011-02-04 18:33:18 +00007699 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7700 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7701
7702 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7703 llvm::SmallVector<ParmVarDecl*, 4> params;
7704 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007705
7706 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007707 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7708 oldBlock->param_begin(),
7709 oldBlock->param_size(),
7710 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007711 return true;
John McCall490112f2011-02-04 18:33:18 +00007712
7713 const FunctionType *exprFunctionType = E->getFunctionType();
7714 QualType exprResultType = exprFunctionType->getResultType();
7715 if (!exprResultType.isNull()) {
7716 if (!exprResultType->isDependentType())
7717 blockScope->ReturnType = exprResultType;
7718 else if (exprResultType != getSema().Context.DependentTy)
7719 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007720 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007721
7722 // If the return type has not been determined yet, leave it as a dependent
7723 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007724 if (blockScope->ReturnType.isNull())
7725 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007726
7727 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007728 if (blockScope->ReturnType->isObjCObjectType()) {
7729 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007730 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007731 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007732 return ExprError();
7733 }
John McCall3882ace2011-01-05 12:14:39 +00007734
John McCall490112f2011-02-04 18:33:18 +00007735 QualType functionType = getDerived().RebuildFunctionProtoType(
7736 blockScope->ReturnType,
7737 paramTypes.data(),
7738 paramTypes.size(),
7739 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007740 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007741 exprFunctionType->getExtInfo());
7742 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007743
7744 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007745 if (!params.empty())
7746 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007747
7748 // If the return type wasn't explicitly set, it will have been marked as a
7749 // dependent type (DependentTy); clear out the return type setting so
7750 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007751 if (blockScope->ReturnType == getSema().Context.DependentTy)
7752 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007753
John McCall3882ace2011-01-05 12:14:39 +00007754 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007755 StmtResult body = getDerived().TransformStmt(E->getBody());
7756 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007757 return ExprError();
7758
John McCall490112f2011-02-04 18:33:18 +00007759#ifndef NDEBUG
7760 // In builds with assertions, make sure that we captured everything we
7761 // captured before.
7762
7763 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7764
7765 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7766 e = oldBlock->capture_end(); i != e; ++i) {
John McCall351762c2011-02-07 10:33:21 +00007767 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007768
7769 // Ignore parameter packs.
7770 if (isa<ParmVarDecl>(oldCapture) &&
7771 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7772 continue;
7773
7774 VarDecl *newCapture =
7775 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7776 oldCapture));
John McCall351762c2011-02-07 10:33:21 +00007777 assert(blockScope->CaptureMap.count(newCapture));
John McCall490112f2011-02-04 18:33:18 +00007778 }
7779#endif
7780
7781 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7782 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007783}
7784
Mike Stump11289f42009-09-09 15:08:12 +00007785template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007786ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007787TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007788 ValueDecl *ND
7789 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7790 E->getDecl()));
7791 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007792 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007793
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007794 if (!getDerived().AlwaysRebuild() &&
7795 ND == E->getDecl()) {
7796 // Mark it referenced in the new context regardless.
7797 // FIXME: this is a bit instantiation-specific.
7798 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7799
John McCallc3007a22010-10-26 07:05:15 +00007800 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007801 }
7802
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007803 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00007804 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007805 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007806}
Mike Stump11289f42009-09-09 15:08:12 +00007807
Douglas Gregora16548e2009-08-11 05:31:07 +00007808//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007809// Type reconstruction
7810//===----------------------------------------------------------------------===//
7811
Mike Stump11289f42009-09-09 15:08:12 +00007812template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007813QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7814 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007815 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007816 getDerived().getBaseEntity());
7817}
7818
Mike Stump11289f42009-09-09 15:08:12 +00007819template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007820QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7821 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007822 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007823 getDerived().getBaseEntity());
7824}
7825
Mike Stump11289f42009-09-09 15:08:12 +00007826template<typename Derived>
7827QualType
John McCall70dd5f62009-10-30 00:06:24 +00007828TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7829 bool WrittenAsLValue,
7830 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007831 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007832 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007833}
7834
7835template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007836QualType
John McCall70dd5f62009-10-30 00:06:24 +00007837TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7838 QualType ClassType,
7839 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007840 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007841 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007842}
7843
7844template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007845QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007846TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7847 ArrayType::ArraySizeModifier SizeMod,
7848 const llvm::APInt *Size,
7849 Expr *SizeExpr,
7850 unsigned IndexTypeQuals,
7851 SourceRange BracketsRange) {
7852 if (SizeExpr || !Size)
7853 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7854 IndexTypeQuals, BracketsRange,
7855 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007856
7857 QualType Types[] = {
7858 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7859 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7860 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007861 };
7862 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7863 QualType SizeType;
7864 for (unsigned I = 0; I != NumTypes; ++I)
7865 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7866 SizeType = Types[I];
7867 break;
7868 }
Mike Stump11289f42009-09-09 15:08:12 +00007869
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007870 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7871 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007872 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007873 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007874 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007875}
Mike Stump11289f42009-09-09 15:08:12 +00007876
Douglas Gregord6ff3322009-08-04 16:50:30 +00007877template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007878QualType
7879TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007880 ArrayType::ArraySizeModifier SizeMod,
7881 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007882 unsigned IndexTypeQuals,
7883 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007884 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007885 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007886}
7887
7888template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007889QualType
Mike Stump11289f42009-09-09 15:08:12 +00007890TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007891 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007892 unsigned IndexTypeQuals,
7893 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007894 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007895 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007896}
Mike Stump11289f42009-09-09 15:08:12 +00007897
Douglas Gregord6ff3322009-08-04 16:50:30 +00007898template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007899QualType
7900TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007901 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007902 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007903 unsigned IndexTypeQuals,
7904 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007905 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007906 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007907 IndexTypeQuals, BracketsRange);
7908}
7909
7910template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007911QualType
7912TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007913 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007914 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007915 unsigned IndexTypeQuals,
7916 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007917 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007918 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007919 IndexTypeQuals, BracketsRange);
7920}
7921
7922template<typename Derived>
7923QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007924 unsigned NumElements,
7925 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007926 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007927 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007928}
Mike Stump11289f42009-09-09 15:08:12 +00007929
Douglas Gregord6ff3322009-08-04 16:50:30 +00007930template<typename Derived>
7931QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7932 unsigned NumElements,
7933 SourceLocation AttributeLoc) {
7934 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7935 NumElements, true);
7936 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007937 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7938 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007939 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007940}
Mike Stump11289f42009-09-09 15:08:12 +00007941
Douglas Gregord6ff3322009-08-04 16:50:30 +00007942template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007943QualType
7944TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007945 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007946 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007947 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007948}
Mike Stump11289f42009-09-09 15:08:12 +00007949
Douglas Gregord6ff3322009-08-04 16:50:30 +00007950template<typename Derived>
7951QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007952 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007953 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007954 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007955 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007956 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00007957 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007958 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007959 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007960 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007961 getDerived().getBaseEntity(),
7962 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007963}
Mike Stump11289f42009-09-09 15:08:12 +00007964
Douglas Gregord6ff3322009-08-04 16:50:30 +00007965template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007966QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7967 return SemaRef.Context.getFunctionNoProtoType(T);
7968}
7969
7970template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007971QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7972 assert(D && "no decl found");
7973 if (D->isInvalidDecl()) return QualType();
7974
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007975 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007976 TypeDecl *Ty;
7977 if (isa<UsingDecl>(D)) {
7978 UsingDecl *Using = cast<UsingDecl>(D);
7979 assert(Using->isTypeName() &&
7980 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7981
7982 // A valid resolved using typename decl points to exactly one type decl.
7983 assert(++Using->shadow_begin() == Using->shadow_end());
7984 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007985
John McCallb96ec562009-12-04 22:46:56 +00007986 } else {
7987 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7988 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7989 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7990 }
7991
7992 return SemaRef.Context.getTypeDeclType(Ty);
7993}
7994
7995template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007996QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7997 SourceLocation Loc) {
7998 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007999}
8000
8001template<typename Derived>
8002QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8003 return SemaRef.Context.getTypeOfType(Underlying);
8004}
8005
8006template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008007QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8008 SourceLocation Loc) {
8009 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008010}
8011
8012template<typename Derived>
8013QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00008014 TemplateName Template,
8015 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00008016 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00008017 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008018}
Mike Stump11289f42009-09-09 15:08:12 +00008019
Douglas Gregor1135c352009-08-06 05:28:30 +00008020template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008021TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008022TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008023 bool TemplateKW,
8024 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008025 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008026 Template);
8027}
8028
8029template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008030TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008031TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8032 const IdentifierInfo &Name,
8033 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00008034 QualType ObjectType,
8035 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008036 UnqualifiedId TemplateName;
8037 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00008038 Sema::TemplateTy Template;
8039 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008040 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008041 SS,
Douglas Gregor9db53502011-03-02 18:07:45 +00008042 TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00008043 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008044 /*EnteringContext=*/false,
8045 Template);
John McCall31f82722010-11-12 08:19:04 +00008046 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00008047}
Mike Stump11289f42009-09-09 15:08:12 +00008048
Douglas Gregora16548e2009-08-11 05:31:07 +00008049template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00008050TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008051TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008052 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00008053 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008054 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00008055 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00008056 // FIXME: Bogus location information.
8057 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8058 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00008059 Sema::TemplateTy Template;
8060 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008061 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008062 SS,
8063 Name,
John McCallba7bf592010-08-24 05:47:05 +00008064 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008065 /*EnteringContext=*/false,
8066 Template);
8067 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00008068}
Alexis Hunta8136cc2010-05-05 15:23:54 +00008069
Douglas Gregor71395fa2009-11-04 00:56:37 +00008070template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008071ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008072TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8073 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008074 Expr *OrigCallee,
8075 Expr *First,
8076 Expr *Second) {
8077 Expr *Callee = OrigCallee->IgnoreParenCasts();
8078 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00008079
Douglas Gregora16548e2009-08-11 05:31:07 +00008080 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00008081 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00008082 if (!First->getType()->isOverloadableType() &&
8083 !Second->getType()->isOverloadableType())
8084 return getSema().CreateBuiltinArraySubscriptExpr(First,
8085 Callee->getLocStart(),
8086 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00008087 } else if (Op == OO_Arrow) {
8088 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00008089 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8090 } else if (Second == 0 || isPostIncDec) {
8091 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008092 // The argument is not of overloadable type, so try to create a
8093 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00008094 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008095 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00008096
John McCallb268a282010-08-23 23:25:46 +00008097 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008098 }
8099 } else {
John McCallb268a282010-08-23 23:25:46 +00008100 if (!First->getType()->isOverloadableType() &&
8101 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008102 // Neither of the arguments is an overloadable type, so try to
8103 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00008104 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008105 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00008106 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00008107 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008108 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008109
Douglas Gregora16548e2009-08-11 05:31:07 +00008110 return move(Result);
8111 }
8112 }
Mike Stump11289f42009-09-09 15:08:12 +00008113
8114 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00008115 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00008116 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00008117
John McCallb268a282010-08-23 23:25:46 +00008118 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00008119 assert(ULE->requiresADL());
8120
8121 // FIXME: Do we have to check
8122 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00008123 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00008124 } else {
John McCallb268a282010-08-23 23:25:46 +00008125 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00008126 }
Mike Stump11289f42009-09-09 15:08:12 +00008127
Douglas Gregora16548e2009-08-11 05:31:07 +00008128 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00008129 Expr *Args[2] = { First, Second };
8130 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00008131
Douglas Gregora16548e2009-08-11 05:31:07 +00008132 // Create the overloaded operator invocation for unary operators.
8133 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00008134 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008135 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00008136 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008137 }
Mike Stump11289f42009-09-09 15:08:12 +00008138
Sebastian Redladba46e2009-10-29 20:17:01 +00008139 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00008140 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00008141 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008142 First,
8143 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00008144
Douglas Gregora16548e2009-08-11 05:31:07 +00008145 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00008146 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008147 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00008148 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8149 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008150 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008151
Mike Stump11289f42009-09-09 15:08:12 +00008152 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00008153}
Mike Stump11289f42009-09-09 15:08:12 +00008154
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008155template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008156ExprResult
John McCallb268a282010-08-23 23:25:46 +00008157TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008158 SourceLocation OperatorLoc,
8159 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00008160 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008161 TypeSourceInfo *ScopeType,
8162 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008163 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008164 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00008165 QualType BaseType = Base->getType();
8166 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008167 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00008168 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00008169 !BaseType->getAs<PointerType>()->getPointeeType()
8170 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008171 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00008172 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008173 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008174 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008175 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008176 /*FIXME?*/true);
8177 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008178
Douglas Gregor678f90d2010-02-25 01:56:36 +00008179 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008180 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8181 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8182 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8183 NameInfo.setNamedTypeInfo(DestroyedType);
8184
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008185 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008186
John McCallb268a282010-08-23 23:25:46 +00008187 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008188 OperatorLoc, isArrow,
8189 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008190 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008191 /*TemplateArgs*/ 0);
8192}
8193
Douglas Gregord6ff3322009-08-04 16:50:30 +00008194} // end namespace clang
8195
8196#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H