Extract type parameter types (and update dbscheme)

This commit is contained in:
Owen Mansel-Chan
2022-01-27 14:57:52 +00:00
committed by Chris Smowton
parent f7dcb11816
commit 3952b1c07a
3 changed files with 34 additions and 13 deletions

View File

@@ -790,6 +790,9 @@ var BasicTypes = map[gotypes.BasicKind]*BranchType{
// CompositeType is the type of all composite (that is, non-basic) types
var CompositeType = NewUnionType("@compositetype")
// TypeParamType is the type of type parameter types
var TypeParamType = TypeKind.NewBranch("@typeparamtype", CompositeType)
// ElementContainerType is the type of types that have elements, such as arrays
// and channels
var ElementContainerType = NewUnionType("@containertype", CompositeType)
@@ -1171,3 +1174,9 @@ var HasEllipsisTable = NewTable("has_ellipsis",
var VariadicTable = NewTable("variadic",
EntityColumn(SignatureType, "id"),
)
var TypeParamTable = NewTable("typeparam",
EntityColumn(TypeParamType, "tp").Unique(),
StringColumn("name"),
EntityColumn(CompositeType, "bound"),
)

View File

@@ -1464,6 +1464,9 @@ func extractType(tw *trap.Writer, tp types.Type) trap.Label {
dbscheme.MethodHostsTable.Emit(tw, methlbl, lbl)
}
}
case *types.TypeParam:
kind = dbscheme.TypeParamType.Index()
dbscheme.TypeParamTable.Emit(tw, lbl, tp.Obj().Name(), extractType(tw, tp.Constraint()))
default:
log.Fatalf("unexpected type %T", tp)
}
@@ -1578,6 +1581,11 @@ func getTypeLabel(tw *trap.Writer, tp types.Type) (trap.Label, bool) {
extractObject(tw, origintp.Obj(), entitylbl)
}
lbl = tw.Labeler.GlobalID(fmt.Sprintf("{%s};namedtype", entitylbl))
case *types.TypeParam:
constraint := extractType(tw, tp.Constraint())
lbl = tw.Labeler.GlobalID(fmt.Sprintf("{%s},{%s};typeparamtype", tp.Obj().Name(), constraint))
default:
log.Fatalf("(getTypeLabel) unexpected type %T", tp)
}
tw.Labeler.TypeLabels[tp] = lbl
}

View File

@@ -225,6 +225,8 @@ has_ellipsis(int id: @callorconversionexpr ref);
variadic(int id: @signaturetype ref);
typeparam(unique int tp: @typeparamtype ref, string name: string ref, int bound: @compositetype ref);
@container = @file | @folder;
@locatable = @xmllocatable | @node | @localscope;
@@ -476,18 +478,19 @@ case @type.kind of
| 23 = @complexliteraltype
| 24 = @stringliteraltype
| 25 = @nilliteraltype
| 26 = @arraytype
| 27 = @slicetype
| 28 = @structtype
| 29 = @pointertype
| 30 = @interfacetype
| 31 = @tupletype
| 32 = @signaturetype
| 33 = @maptype
| 34 = @sendchantype
| 35 = @recvchantype
| 36 = @sendrcvchantype
| 37 = @namedtype;
| 26 = @typeparamtype
| 27 = @arraytype
| 28 = @slicetype
| 29 = @structtype
| 30 = @pointertype
| 31 = @interfacetype
| 32 = @tupletype
| 33 = @signaturetype
| 34 = @maptype
| 35 = @sendchantype
| 36 = @recvchantype
| 37 = @sendrcvchantype
| 38 = @namedtype;
@basictype = @booltype | @numerictype | @stringtype | @literaltype | @invalidtype | @unsafepointertype;
@@ -510,7 +513,8 @@ case @type.kind of
@literaltype = @boolliteraltype | @intliteraltype | @runeliteraltype | @floatliteraltype | @complexliteraltype
| @stringliteraltype | @nilliteraltype;
@compositetype = @containertype | @structtype | @pointertype | @interfacetype | @tupletype | @signaturetype | @namedtype;
@compositetype = @typeparamtype | @containertype | @structtype | @pointertype | @interfacetype | @tupletype
| @signaturetype | @namedtype;
@containertype = @arraytype | @slicetype | @maptype | @chantype;