@@ -497,9 +497,7 @@ class alignas(8) Expr {
497497 bool isImplicit () const {
498498 return Bits.Expr .Implicit ;
499499 }
500- void setImplicit (bool Implicit = true ) {
501- Bits.Expr .Implicit = Implicit;
502- }
500+ void setImplicit (bool Implicit = true );
503501
504502 // / Retrieves the declaration that is being referenced by this
505503 // / expression, if any.
@@ -1333,40 +1331,63 @@ class SuperRefExpr : public Expr {
13331331 }
13341332};
13351333
1336- // / A reference to a type in expression context, spelled out as a TypeLoc .
1334+ // / A reference to a type in expression context.
13371335// /
1338- // / The type of this expression is always \c MetaTypeType .
1336+ // / The type of this expression is always \c MetatypeType .
13391337class TypeExpr : public Expr {
1340- TypeLoc Info;
1341- TypeExpr (Type Ty);
1338+ TypeRepr *Repr;
13421339public:
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);
13541342
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 ;
13591350
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.
13631371 static TypeExpr *createImplicitHack (SourceLoc Loc, Type Ty, ASTContext &C);
13641372
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);
13701391
13711392 // / Create a TypeExpr for a member TypeDecl of the given parent TypeDecl.
13721393 static TypeExpr *createForMemberDecl (DeclNameLoc ParentNameLoc,
@@ -1389,13 +1410,11 @@ class TypeExpr : public Expr {
13891410 SourceRange AngleLocs,
13901411 ASTContext &C);
13911412
1392- TypeLoc &getTypeLoc () { return Info; }
1393- TypeLoc getTypeLoc () const { return Info; }
1394- TypeRepr *getTypeRepr () const { return Info.getTypeRepr (); }
1413+ TypeRepr *getTypeRepr () const { return Repr; }
13951414 // NOTE: TypeExpr::getType() returns the type of the expr node, which is the
13961415 // metatype of what is stored as an operand type.
13971416
1398- SourceRange getSourceRange () const { return Info. getSourceRange (); }
1417+ SourceRange getSourceRange () const ;
13991418 // TODO: optimize getStartLoc() and getEndLoc() when TypeLoc allows it.
14001419
14011420 static bool classof (const Expr *E) {
@@ -4490,8 +4509,7 @@ class ExplicitCastExpr : public Expr {
44904509 TypeLoc CastTy;
44914510
44924511protected:
4493- ExplicitCastExpr (ExprKind kind, Expr *sub, SourceLoc AsLoc, TypeLoc castTy,
4494- Type resultTy)
4512+ ExplicitCastExpr (ExprKind kind, Expr *sub, SourceLoc AsLoc, TypeLoc castTy)
44954513 : Expr(kind, /* Implicit=*/ false ), SubExpr(sub), AsLoc(AsLoc), CastTy(castTy)
44964514 {}
44974515
@@ -4547,8 +4565,8 @@ StringRef getCheckedCastKindName(CheckedCastKind kind);
45474565class CheckedCastExpr : public ExplicitCastExpr {
45484566public:
45494567 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)
45524570 {
45534571 Bits.CheckedCastExpr .CastKind = unsigned (CheckedCastKind::Unresolved);
45544572 }
@@ -4583,7 +4601,7 @@ class ForcedCheckedCastExpr : public CheckedCastExpr {
45834601 ForcedCheckedCastExpr (Expr *sub, SourceLoc asLoc, SourceLoc exclaimLoc,
45844602 TypeLoc type)
45854603 : CheckedCastExpr(ExprKind::ForcedCheckedCast,
4586- sub, asLoc, type, type.getType() ),
4604+ sub, asLoc, type),
45874605 ExclaimLoc (exclaimLoc)
45884606 {
45894607 }
@@ -4612,7 +4630,7 @@ class ConditionalCheckedCastExpr : public CheckedCastExpr {
46124630 ConditionalCheckedCastExpr (Expr *sub, SourceLoc asLoc, SourceLoc questionLoc,
46134631 TypeLoc type)
46144632 : CheckedCastExpr(ExprKind::ConditionalCheckedCast,
4615- sub, asLoc, type, type.getType() ),
4633+ sub, asLoc, type),
46164634 QuestionLoc (questionLoc)
46174635 { }
46184636
@@ -4637,8 +4655,7 @@ class ConditionalCheckedCastExpr : public CheckedCastExpr {
46374655class IsExpr : public CheckedCastExpr {
46384656public:
46394657 IsExpr (Expr *sub, SourceLoc isLoc, TypeLoc type)
4640- : CheckedCastExpr(ExprKind::Is,
4641- sub, isLoc, type, Type())
4658+ : CheckedCastExpr(ExprKind::Is, sub, isLoc, type)
46424659 {}
46434660
46444661 IsExpr (SourceLoc isLoc, TypeLoc type)
@@ -4661,7 +4678,7 @@ class CoerceExpr : public ExplicitCastExpr {
46614678
46624679public:
46634680 CoerceExpr (Expr *sub, SourceLoc asLoc, TypeLoc type)
4664- : ExplicitCastExpr(ExprKind::Coerce, sub, asLoc, type, type.getType() )
4681+ : ExplicitCastExpr(ExprKind::Coerce, sub, asLoc, type)
46654682 { }
46664683
46674684 CoerceExpr (SourceLoc asLoc, TypeLoc type)
@@ -4671,7 +4688,7 @@ class CoerceExpr : public ExplicitCastExpr {
46714688private:
46724689 CoerceExpr (SourceRange initRange, Expr *literal, TypeLoc type)
46734690 : ExplicitCastExpr(ExprKind::Coerce, literal, initRange.Start,
4674- type, type.getType() ), InitRangeEnd(initRange.End)
4691+ type), InitRangeEnd(initRange.End)
46754692 { setImplicit (); }
46764693
46774694public:
0 commit comments