@@ -497,9 +497,7 @@ class alignas(8) Expr {
497
497
bool isImplicit () const {
498
498
return Bits.Expr .Implicit ;
499
499
}
500
- void setImplicit (bool Implicit = true ) {
501
- Bits.Expr .Implicit = Implicit;
502
- }
500
+ void setImplicit (bool Implicit = true );
503
501
504
502
// / Retrieves the declaration that is being referenced by this
505
503
// / expression, if any.
@@ -1333,40 +1331,63 @@ class SuperRefExpr : public Expr {
1333
1331
}
1334
1332
};
1335
1333
1336
- // / A reference to a type in expression context, spelled out as a TypeLoc .
1334
+ // / A reference to a type in expression context.
1337
1335
// /
1338
- // / The type of this expression is always \c MetaTypeType .
1336
+ // / The type of this expression is always \c MetatypeType .
1339
1337
class TypeExpr : public Expr {
1340
- TypeLoc Info;
1341
- TypeExpr (Type Ty);
1338
+ TypeRepr *Repr;
1342
1339
public:
1343
- // Create a TypeExpr with location information.
1344
- TypeExpr (TypeLoc Ty);
1345
-
1346
- // The type of a TypeExpr is always a metatype type. Return the instance
1347
- // type, ErrorType if an error, or null if not set yet.
1348
- Type getInstanceType (llvm::function_ref<bool (const Expr *)> hasType =
1349
- [](const Expr *E) -> bool { return !!E->getType (); },
1350
- llvm::function_ref<Type(const Expr *)> getType =
1351
- [](const Expr *E) -> Type {
1352
- return E->getType ();
1353
- }) const ;
1340
+ // / Create a \c TypeExpr from a parsed \c TypeRepr.
1341
+ TypeExpr (TypeRepr *Ty);
1354
1342
1355
- // Create an implicit TypeExpr, which has no location information.
1356
- static TypeExpr *createImplicit (Type Ty, ASTContext &C) {
1357
- return new (C) TypeExpr (Ty);
1358
- }
1343
+ // / Retrieves the corresponding instance type of the type referenced by this
1344
+ // / expression.
1345
+ // /
1346
+ // / If this node has no type, the resulting instance type is also the
1347
+ // / null \c Type(). If the type of this node is not a \c MetatypeType, the
1348
+ // / resulting instance type is \c ErrorType.
1349
+ Type getInstanceType () const ;
1359
1350
1360
- // Create an implicit TypeExpr, with location information even though it
1361
- // shouldn't have one. This is presently used to work around other location
1362
- // processing bugs. If you have an implicit location, use createImplicit.
1351
+ public:
1352
+ // / Create an implicit \c TypeExpr.
1353
+ // /
1354
+ // / The given type is required to be non-null and must be not be
1355
+ // / a \c MetatypeType as this function will wrap the given type in one.
1356
+ // /
1357
+ // / FIXME: This behavior is bizarre.
1358
+ static TypeExpr *createImplicit (Type Ty, ASTContext &C);
1359
+
1360
+ // / Create an implicit \c TypeExpr that has artificial
1361
+ // / location information attached.
1362
+ // /
1363
+ // / The given type is required to be non-null and must be not be
1364
+ // / a \c MetatypeType as this function will wrap the given type in one.
1365
+ // /
1366
+ // / FIXME: This behavior is bizarre.
1367
+ // /
1368
+ // / Due to limitations in the modeling of certain AST elements, implicit
1369
+ // / \c TypeExpr nodes are often the only source of location information the
1370
+ // / expression checker has when it comes time to diagnose an error.
1363
1371
static TypeExpr *createImplicitHack (SourceLoc Loc, Type Ty, ASTContext &C);
1364
1372
1365
-
1366
- // / Create a TypeExpr for a TypeDecl at the specified location.
1367
- static TypeExpr *createForDecl (DeclNameLoc Loc, TypeDecl *D,
1368
- DeclContext *DC,
1369
- bool isImplicit);
1373
+ // / Create an implicit \c TypeExpr for a given \c TypeDecl at the specified location.
1374
+ // /
1375
+ // / The given type is required to be non-null and must be not be
1376
+ // / a \c MetatypeType as this function will wrap the given type in one.
1377
+ // /
1378
+ // / FIXME: This behavior is bizarre.
1379
+ // /
1380
+ // / Unlike the non-implicit case, the given location is not required to be
1381
+ // / valid.
1382
+ static TypeExpr *createImplicitForDecl (DeclNameLoc Loc, TypeDecl *D,
1383
+ DeclContext *DC, Type ty);
1384
+
1385
+ public:
1386
+ // / Create a \c TypeExpr for a given \c TypeDecl at the specified location.
1387
+ // /
1388
+ // / The given location must be valid. If it is not, you must use
1389
+ // / \c TypeExpr::createImplicitForDecl instead.
1390
+ static TypeExpr *createForDecl (DeclNameLoc Loc, TypeDecl *D, DeclContext *DC);
1370
1391
1371
1392
// / Create a TypeExpr for a member TypeDecl of the given parent TypeDecl.
1372
1393
static TypeExpr *createForMemberDecl (DeclNameLoc ParentNameLoc,
@@ -1389,13 +1410,11 @@ class TypeExpr : public Expr {
1389
1410
SourceRange AngleLocs,
1390
1411
ASTContext &C);
1391
1412
1392
- TypeLoc &getTypeLoc () { return Info; }
1393
- TypeLoc getTypeLoc () const { return Info; }
1394
- TypeRepr *getTypeRepr () const { return Info.getTypeRepr (); }
1413
+ TypeRepr *getTypeRepr () const { return Repr; }
1395
1414
// NOTE: TypeExpr::getType() returns the type of the expr node, which is the
1396
1415
// metatype of what is stored as an operand type.
1397
1416
1398
- SourceRange getSourceRange () const { return Info. getSourceRange (); }
1417
+ SourceRange getSourceRange () const ;
1399
1418
// TODO: optimize getStartLoc() and getEndLoc() when TypeLoc allows it.
1400
1419
1401
1420
static bool classof (const Expr *E) {
@@ -4490,8 +4509,7 @@ class ExplicitCastExpr : public Expr {
4490
4509
TypeLoc CastTy;
4491
4510
4492
4511
protected:
4493
- ExplicitCastExpr (ExprKind kind, Expr *sub, SourceLoc AsLoc, TypeLoc castTy,
4494
- Type resultTy)
4512
+ ExplicitCastExpr (ExprKind kind, Expr *sub, SourceLoc AsLoc, TypeLoc castTy)
4495
4513
: Expr(kind, /* Implicit=*/ false ), SubExpr(sub), AsLoc(AsLoc), CastTy(castTy)
4496
4514
{}
4497
4515
@@ -4547,8 +4565,8 @@ StringRef getCheckedCastKindName(CheckedCastKind kind);
4547
4565
class CheckedCastExpr : public ExplicitCastExpr {
4548
4566
public:
4549
4567
CheckedCastExpr (ExprKind kind,
4550
- Expr *sub, SourceLoc asLoc, TypeLoc castTy, Type resultTy )
4551
- : ExplicitCastExpr(kind, sub, asLoc, castTy, resultTy )
4568
+ Expr *sub, SourceLoc asLoc, TypeLoc castTy)
4569
+ : ExplicitCastExpr(kind, sub, asLoc, castTy)
4552
4570
{
4553
4571
Bits.CheckedCastExpr .CastKind = unsigned (CheckedCastKind::Unresolved);
4554
4572
}
@@ -4583,7 +4601,7 @@ class ForcedCheckedCastExpr : public CheckedCastExpr {
4583
4601
ForcedCheckedCastExpr (Expr *sub, SourceLoc asLoc, SourceLoc exclaimLoc,
4584
4602
TypeLoc type)
4585
4603
: CheckedCastExpr(ExprKind::ForcedCheckedCast,
4586
- sub, asLoc, type, type.getType() ),
4604
+ sub, asLoc, type),
4587
4605
ExclaimLoc (exclaimLoc)
4588
4606
{
4589
4607
}
@@ -4612,7 +4630,7 @@ class ConditionalCheckedCastExpr : public CheckedCastExpr {
4612
4630
ConditionalCheckedCastExpr (Expr *sub, SourceLoc asLoc, SourceLoc questionLoc,
4613
4631
TypeLoc type)
4614
4632
: CheckedCastExpr(ExprKind::ConditionalCheckedCast,
4615
- sub, asLoc, type, type.getType() ),
4633
+ sub, asLoc, type),
4616
4634
QuestionLoc (questionLoc)
4617
4635
{ }
4618
4636
@@ -4637,8 +4655,7 @@ class ConditionalCheckedCastExpr : public CheckedCastExpr {
4637
4655
class IsExpr : public CheckedCastExpr {
4638
4656
public:
4639
4657
IsExpr (Expr *sub, SourceLoc isLoc, TypeLoc type)
4640
- : CheckedCastExpr(ExprKind::Is,
4641
- sub, isLoc, type, Type())
4658
+ : CheckedCastExpr(ExprKind::Is, sub, isLoc, type)
4642
4659
{}
4643
4660
4644
4661
IsExpr (SourceLoc isLoc, TypeLoc type)
@@ -4661,7 +4678,7 @@ class CoerceExpr : public ExplicitCastExpr {
4661
4678
4662
4679
public:
4663
4680
CoerceExpr (Expr *sub, SourceLoc asLoc, TypeLoc type)
4664
- : ExplicitCastExpr(ExprKind::Coerce, sub, asLoc, type, type.getType() )
4681
+ : ExplicitCastExpr(ExprKind::Coerce, sub, asLoc, type)
4665
4682
{ }
4666
4683
4667
4684
CoerceExpr (SourceLoc asLoc, TypeLoc type)
@@ -4671,7 +4688,7 @@ class CoerceExpr : public ExplicitCastExpr {
4671
4688
private:
4672
4689
CoerceExpr (SourceRange initRange, Expr *literal, TypeLoc type)
4673
4690
: ExplicitCastExpr(ExprKind::Coerce, literal, initRange.Start,
4674
- type, type.getType() ), InitRangeEnd(initRange.End)
4691
+ type), InitRangeEnd(initRange.End)
4675
4692
{ setImplicit (); }
4676
4693
4677
4694
public:
0 commit comments