FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Extract type parameter types (and update dbscheme) · github/codeql-go@3952b1c · GitHub

This repository was archived by the owner on Jan 5, 2023. It is now read-only.
/ codeql-go Public archive

Commit 3952b1c

Browse files
authored andcommitted
Extract type parameter types (and update dbscheme)
1 parent f7dcb11 commit 3952b1c

3 files changed

Lines changed: 34 additions & 13 deletions

File tree

‎extractor/dbscheme/tables.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,9 @@ var BasicTypes = map[gotypes.BasicKind]*BranchType{
790790
// CompositeType is the type of all composite (that is, non-basic) types
791791
var CompositeType = NewUnionType("@compositetype")
792792

793+
// TypeParamType is the type of type parameter types
794+
var TypeParamType = TypeKind.NewBranch("@typeparamtype", CompositeType)
795+
793796
// ElementContainerType is the type of types that have elements, such as arrays
794797
// and channels
795798
var ElementContainerType = NewUnionType("@containertype", CompositeType)
@@ -1171,3 +1174,9 @@ var HasEllipsisTable = NewTable("has_ellipsis",
11711174
var VariadicTable = NewTable("variadic",
11721175
EntityColumn(SignatureType, "id"),
11731176
)
1177+
1178+
var TypeParamTable = NewTable("typeparam",
1179+
EntityColumn(TypeParamType, "tp").Unique(),
1180+
StringColumn("name"),
1181+
EntityColumn(CompositeType, "bound"),
1182+
)

‎extractor/extractor.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,9 @@ func extractType(tw *trap.Writer, tp types.Type) trap.Label {
14641464
dbscheme.MethodHostsTable.Emit(tw, methlbl, lbl)
14651465
}
14661466
}
1467+
case *types.TypeParam:
1468+
kind = dbscheme.TypeParamType.Index()
1469+
dbscheme.TypeParamTable.Emit(tw, lbl, tp.Obj().Name(), extractType(tw, tp.Constraint()))
14671470
default:
14681471
log.Fatalf("unexpected type %T", tp)
14691472
}
@@ -1578,6 +1581,11 @@ func getTypeLabel(tw *trap.Writer, tp types.Type) (trap.Label, bool) {
15781581
extractObject(tw, origintp.Obj(), entitylbl)
15791582
}
15801583
lbl = tw.Labeler.GlobalID(fmt.Sprintf("{%s};namedtype", entitylbl))
1584+
case *types.TypeParam:
1585+
constraint := extractType(tw, tp.Constraint())
1586+
lbl = tw.Labeler.GlobalID(fmt.Sprintf("{%s},{%s};typeparamtype", tp.Obj().Name(), constraint))
1587+
default:
1588+
log.Fatalf("(getTypeLabel) unexpected type %T", tp)
15811589
}
15821590
tw.Labeler.TypeLabels[tp] = lbl
15831591
}

‎ql/lib/go.dbscheme‎

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ has_ellipsis(int id: @callorconversionexpr ref);
225225

226226
variadic(int id: @signaturetype ref);
227227

228+
typeparam(unique int tp: @typeparamtype ref, string name: string ref, int bound: @compositetype ref);
229+
228230
@container = @file | @folder;
229231

230232
@locatable = @xmllocatable | @node | @localscope;
@@ -476,18 +478,19 @@ case @type.kind of
476478
| 23 = @complexliteraltype
477479
| 24 = @stringliteraltype
478480
| 25 = @nilliteraltype
479-
| 26 = @arraytype
480-
| 27 = @slicetype
481-
| 28 = @structtype
482-
| 29 = @pointertype
483-
| 30 = @interfacetype
484-
| 31 = @tupletype
485-
| 32 = @signaturetype
486-
| 33 = @maptype
487-
| 34 = @sendchantype
488-
| 35 = @recvchantype
489-
| 36 = @sendrcvchantype
490-
| 37 = @namedtype;
481+
| 26 = @typeparamtype
482+
| 27 = @arraytype
483+
| 28 = @slicetype
484+
| 29 = @structtype
485+
| 30 = @pointertype
486+
| 31 = @interfacetype
487+
| 32 = @tupletype
488+
| 33 = @signaturetype
489+
| 34 = @maptype
490+
| 35 = @sendchantype
491+
| 36 = @recvchantype
492+
| 37 = @sendrcvchantype
493+
| 38 = @namedtype;
491494

492495
@basictype = @booltype | @numerictype | @stringtype | @literaltype | @invalidtype | @unsafepointertype;
493496

@@ -510,7 +513,8 @@ case @type.kind of
510513
@literaltype = @boolliteraltype | @intliteraltype | @runeliteraltype | @floatliteraltype | @complexliteraltype
511514
| @stringliteraltype | @nilliteraltype;
512515

513-
@compositetype = @containertype | @structtype | @pointertype | @interfacetype | @tupletype | @signaturetype | @namedtype;
516+
@compositetype = @typeparamtype | @containertype | @structtype | @pointertype | @interfacetype | @tupletype
517+
| @signaturetype | @namedtype;
514518

515519
@containertype = @arraytype | @slicetype | @maptype | @chantype;
516520

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL