From 3952b1c07a8d684b5f134034e44df8ae951b11ca Mon Sep 17 00:00:00 2001 From: Owen Mansel-Chan Date: Thu, 27 Jan 2022 14:57:52 +0000 Subject: [PATCH] Extract type parameter types (and update dbscheme) --- extractor/dbscheme/tables.go | 9 +++++++++ extractor/extractor.go | 8 ++++++++ ql/lib/go.dbscheme | 30 +++++++++++++++++------------- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/extractor/dbscheme/tables.go b/extractor/dbscheme/tables.go index 1f7a31e988d..f934ca57bb5 100644 --- a/extractor/dbscheme/tables.go +++ b/extractor/dbscheme/tables.go @@ -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"), +) diff --git a/extractor/extractor.go b/extractor/extractor.go index a9964a79593..40ab6a8592d 100644 --- a/extractor/extractor.go +++ b/extractor/extractor.go @@ -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 } diff --git a/ql/lib/go.dbscheme b/ql/lib/go.dbscheme index 8f168c8af3f..e0ac0aab04f 100644 --- a/ql/lib/go.dbscheme +++ b/ql/lib/go.dbscheme @@ -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;