Skip to content

Commit 7ed8206

Browse files
committed
Add type param decls to AST viewer hierarchy
1 parent b8ea840 commit 7ed8206

File tree

6 files changed

+57
-58
lines changed

6 files changed

+57
-58
lines changed

go/ql/lib/semmle/go/AST.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class AstNode extends @node, Locatable {
5555
kind = "commentgroup" and result = this.(File).getCommentGroup(i)
5656
or
5757
kind = "comment" and result = this.(CommentGroup).getComment(i)
58+
or
59+
kind = "typeparamdecl" and result = this.(TypeParamDeclParent).getTypeParameterDecl(i)
5860
}
5961

6062
/**

go/ql/test/library-tests/semmle/go/PrintAst/PrintAst.expected

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
other.go:
2-
# 8| [TypeParamDecl] type parameter declaration
3-
# 8| 0: [Ident, TypeName] int
4-
# 8| Type = int
5-
# 8| 1: [Ident, TypeName] U
6-
# 8| Type = U
7-
# 17| [TypeParamDecl] type parameter declaration
8-
# 17| 0: [TypeSetLiteralExpr] type set literal
9-
# 17| Type = ~string
10-
# 17| 0: [Ident, TypeName] string
11-
# 17| Type = string
12-
# 17| 1: [Ident, TypeName] T
13-
# 17| Type = T
141
go.mod:
152
# 0| [GoModFile] go.mod
163
# 1| 0: [GoModModuleLine] go.mod module line
@@ -652,6 +639,11 @@ other.go:
652639
# 11| Type = int
653640
# 11| 0: [Ident, VariableName] myNested
654641
# 11| Type = func() int
642+
# 8| 3: [TypeParamDecl] type parameter declaration
643+
# 8| 0: [Ident, TypeName] int
644+
# 8| Type = int
645+
# 8| 1: [Ident, TypeName] U
646+
# 8| Type = U
655647
# 15| 5: [VarDecl] variable declaration
656648
# 15| 0: [ValueSpec] value declaration specifier
657649
# 15| 0: [Ident, VariableName] x
@@ -669,6 +661,13 @@ other.go:
669661
# 17| Type = []T
670662
# 17| 0: [Ident, TypeName] T
671663
# 17| Type = T
664+
# 17| 2: [TypeParamDecl] type parameter declaration
665+
# 17| 0: [TypeSetLiteralExpr] type set literal
666+
# 17| Type = ~string
667+
# 17| 0: [Ident, TypeName] string
668+
# 17| Type = string
669+
# 17| 1: [Ident, TypeName] T
670+
# 17| Type = T
672671
# 19| 7: [MethodDecl] function declaration
673672
# 19| 0: [FunctionName, Ident] f
674673
# 19| Type = func()

go/ql/test/library-tests/semmle/go/PrintAst/PrintAstExcludeComments.expected

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
other.go:
2-
# 8| [TypeParamDecl] type parameter declaration
3-
# 8| 0: [Ident, TypeName] int
4-
# 8| Type = int
5-
# 8| 1: [Ident, TypeName] U
6-
# 8| Type = U
7-
# 17| [TypeParamDecl] type parameter declaration
8-
# 17| 0: [TypeSetLiteralExpr] type set literal
9-
# 17| Type = ~string
10-
# 17| 0: [Ident, TypeName] string
11-
# 17| Type = string
12-
# 17| 1: [Ident, TypeName] T
13-
# 17| Type = T
141
go.mod:
152
# 0| [GoModFile] go.mod
163
# 1| 0: [GoModModuleLine] go.mod module line
@@ -632,6 +619,11 @@ other.go:
632619
# 11| Type = int
633620
# 11| 0: [Ident, VariableName] myNested
634621
# 11| Type = func() int
622+
# 8| 3: [TypeParamDecl] type parameter declaration
623+
# 8| 0: [Ident, TypeName] int
624+
# 8| Type = int
625+
# 8| 1: [Ident, TypeName] U
626+
# 8| Type = U
635627
# 15| 5: [VarDecl] variable declaration
636628
# 15| 0: [ValueSpec] value declaration specifier
637629
# 15| 0: [Ident, VariableName] x
@@ -649,6 +641,13 @@ other.go:
649641
# 17| Type = []T
650642
# 17| 0: [Ident, TypeName] T
651643
# 17| Type = T
644+
# 17| 2: [TypeParamDecl] type parameter declaration
645+
# 17| 0: [TypeSetLiteralExpr] type set literal
646+
# 17| Type = ~string
647+
# 17| 0: [Ident, TypeName] string
648+
# 17| Type = string
649+
# 17| 1: [Ident, TypeName] T
650+
# 17| Type = T
652651
# 19| 7: [MethodDecl] function declaration
653652
# 19| 0: [FunctionName, Ident] f
654653
# 19| Type = func()

go/ql/test/library-tests/semmle/go/PrintAst/PrintAstNestedFunction.expected

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
other.go:
2-
# 8| [TypeParamDecl] type parameter declaration
3-
# 8| 0: [Ident, TypeName] int
4-
# 8| Type = int
5-
# 8| 1: [Ident, TypeName] U
6-
# 8| Type = U
7-
# 17| [TypeParamDecl] type parameter declaration
8-
# 17| 0: [TypeSetLiteralExpr] type set literal
9-
# 17| Type = ~string
10-
# 17| 0: [Ident, TypeName] string
11-
# 17| Type = string
12-
# 17| 1: [Ident, TypeName] T
13-
# 17| Type = T
141
go.mod:
152
# 0| [GoModFile] go.mod
163
# 1| 0: [GoModModuleLine] go.mod module line
@@ -69,6 +56,11 @@ other.go:
6956
# 11| Type = int
7057
# 11| 0: [Ident, VariableName] myNested
7158
# 11| Type = func() int
59+
# 8| 3: [TypeParamDecl] type parameter declaration
60+
# 8| 0: [Ident, TypeName] int
61+
# 8| Type = int
62+
# 8| 1: [Ident, TypeName] U
63+
# 8| Type = U
7264
# 15| 2: [VarDecl] variable declaration
7365
# 15| 0: [ValueSpec] value declaration specifier
7466
# 15| 0: [Ident, VariableName] x
@@ -86,3 +78,10 @@ other.go:
8678
# 17| Type = []T
8779
# 17| 0: [Ident, TypeName] T
8880
# 17| Type = T
81+
# 17| 2: [TypeParamDecl] type parameter declaration
82+
# 17| 0: [TypeSetLiteralExpr] type set literal
83+
# 17| Type = ~string
84+
# 17| 0: [Ident, TypeName] string
85+
# 17| Type = string
86+
# 17| 1: [Ident, TypeName] T
87+
# 17| Type = T

go/ql/test/library-tests/semmle/go/PrintAst/PrintAstRestrictFile.expected

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,4 @@
11
other.go:
2-
# 8| [TypeParamDecl] type parameter declaration
3-
# 8| 0: [Ident, TypeName] int
4-
# 8| Type = int
5-
# 8| 1: [Ident, TypeName] U
6-
# 8| Type = U
7-
# 17| [TypeParamDecl] type parameter declaration
8-
# 17| 0: [TypeSetLiteralExpr] type set literal
9-
# 17| Type = ~string
10-
# 17| 0: [Ident, TypeName] string
11-
# 17| Type = string
12-
# 17| 1: [Ident, TypeName] T
13-
# 17| Type = T
142
# 0| [GoFile] other.go
153
# 1| package: [Ident] main
164
# 3| 1: [FuncDecl] function declaration
@@ -53,6 +41,11 @@ other.go:
5341
# 11| Type = int
5442
# 11| 0: [Ident, VariableName] myNested
5543
# 11| Type = func() int
44+
# 8| 3: [TypeParamDecl] type parameter declaration
45+
# 8| 0: [Ident, TypeName] int
46+
# 8| Type = int
47+
# 8| 1: [Ident, TypeName] U
48+
# 8| Type = U
5649
# 15| 5: [VarDecl] variable declaration
5750
# 15| 0: [ValueSpec] value declaration specifier
5851
# 15| 0: [Ident, VariableName] x
@@ -70,6 +63,13 @@ other.go:
7063
# 17| Type = []T
7164
# 17| 0: [Ident, TypeName] T
7265
# 17| Type = T
66+
# 17| 2: [TypeParamDecl] type parameter declaration
67+
# 17| 0: [TypeSetLiteralExpr] type set literal
68+
# 17| Type = ~string
69+
# 17| 0: [Ident, TypeName] string
70+
# 17| Type = string
71+
# 17| 1: [Ident, TypeName] T
72+
# 17| Type = T
7373
# 19| 7: [MethodDecl] function declaration
7474
# 19| 0: [FunctionName, Ident] f
7575
# 19| Type = func()

go/ql/test/library-tests/semmle/go/PrintAst/PrintAstRestrictFunction.expected

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@ other.go:
44
# 8| Type = int
55
# 8| 1: [Ident, TypeName] U
66
# 8| Type = U
7-
# 17| [TypeParamDecl] type parameter declaration
8-
# 17| 0: [TypeSetLiteralExpr] type set literal
9-
# 17| Type = ~string
10-
# 17| 0: [Ident, TypeName] string
11-
# 17| Type = string
12-
# 17| 1: [Ident, TypeName] T
13-
# 17| Type = T
147
go.mod:
158
# 0| [GoModFile] go.mod
169
# 1| 0: [GoModModuleLine] go.mod module line
@@ -66,3 +59,10 @@ other.go:
6659
# 17| Type = []T
6760
# 17| 0: [Ident, TypeName] T
6861
# 17| Type = T
62+
# 17| 2: [TypeParamDecl] type parameter declaration
63+
# 17| 0: [TypeSetLiteralExpr] type set literal
64+
# 17| Type = ~string
65+
# 17| 0: [Ident, TypeName] string
66+
# 17| Type = string
67+
# 17| 1: [Ident, TypeName] T
68+
# 17| Type = T

0 commit comments

Comments
 (0)