Skip to content

Commit

Permalink
Add type param decls to AST viewer hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-mc committed Oct 17, 2024
1 parent b8ea840 commit 7ed8206
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 58 deletions.
2 changes: 2 additions & 0 deletions go/ql/lib/semmle/go/AST.qll
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class AstNode extends @node, Locatable {
kind = "commentgroup" and result = this.(File).getCommentGroup(i)
or
kind = "comment" and result = this.(CommentGroup).getComment(i)
or
kind = "typeparamdecl" and result = this.(TypeParamDeclParent).getTypeParameterDecl(i)
}

/**
Expand Down
25 changes: 12 additions & 13 deletions go/ql/test/library-tests/semmle/go/PrintAst/PrintAst.expected
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
other.go:
# 8| [TypeParamDecl] type parameter declaration
# 8| 0: [Ident, TypeName] int
# 8| Type = int
# 8| 1: [Ident, TypeName] U
# 8| Type = U
# 17| [TypeParamDecl] type parameter declaration
# 17| 0: [TypeSetLiteralExpr] type set literal
# 17| Type = ~string
# 17| 0: [Ident, TypeName] string
# 17| Type = string
# 17| 1: [Ident, TypeName] T
# 17| Type = T
go.mod:
# 0| [GoModFile] go.mod
# 1| 0: [GoModModuleLine] go.mod module line
Expand Down Expand Up @@ -652,6 +639,11 @@ other.go:
# 11| Type = int
# 11| 0: [Ident, VariableName] myNested
# 11| Type = func() int
# 8| 3: [TypeParamDecl] type parameter declaration
# 8| 0: [Ident, TypeName] int
# 8| Type = int
# 8| 1: [Ident, TypeName] U
# 8| Type = U
# 15| 5: [VarDecl] variable declaration
# 15| 0: [ValueSpec] value declaration specifier
# 15| 0: [Ident, VariableName] x
Expand All @@ -669,6 +661,13 @@ other.go:
# 17| Type = []T
# 17| 0: [Ident, TypeName] T
# 17| Type = T
# 17| 2: [TypeParamDecl] type parameter declaration
# 17| 0: [TypeSetLiteralExpr] type set literal
# 17| Type = ~string
# 17| 0: [Ident, TypeName] string
# 17| Type = string
# 17| 1: [Ident, TypeName] T
# 17| Type = T
# 19| 7: [MethodDecl] function declaration
# 19| 0: [FunctionName, Ident] f
# 19| Type = func()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
other.go:
# 8| [TypeParamDecl] type parameter declaration
# 8| 0: [Ident, TypeName] int
# 8| Type = int
# 8| 1: [Ident, TypeName] U
# 8| Type = U
# 17| [TypeParamDecl] type parameter declaration
# 17| 0: [TypeSetLiteralExpr] type set literal
# 17| Type = ~string
# 17| 0: [Ident, TypeName] string
# 17| Type = string
# 17| 1: [Ident, TypeName] T
# 17| Type = T
go.mod:
# 0| [GoModFile] go.mod
# 1| 0: [GoModModuleLine] go.mod module line
Expand Down Expand Up @@ -632,6 +619,11 @@ other.go:
# 11| Type = int
# 11| 0: [Ident, VariableName] myNested
# 11| Type = func() int
# 8| 3: [TypeParamDecl] type parameter declaration
# 8| 0: [Ident, TypeName] int
# 8| Type = int
# 8| 1: [Ident, TypeName] U
# 8| Type = U
# 15| 5: [VarDecl] variable declaration
# 15| 0: [ValueSpec] value declaration specifier
# 15| 0: [Ident, VariableName] x
Expand All @@ -649,6 +641,13 @@ other.go:
# 17| Type = []T
# 17| 0: [Ident, TypeName] T
# 17| Type = T
# 17| 2: [TypeParamDecl] type parameter declaration
# 17| 0: [TypeSetLiteralExpr] type set literal
# 17| Type = ~string
# 17| 0: [Ident, TypeName] string
# 17| Type = string
# 17| 1: [Ident, TypeName] T
# 17| Type = T
# 19| 7: [MethodDecl] function declaration
# 19| 0: [FunctionName, Ident] f
# 19| Type = func()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
other.go:
# 8| [TypeParamDecl] type parameter declaration
# 8| 0: [Ident, TypeName] int
# 8| Type = int
# 8| 1: [Ident, TypeName] U
# 8| Type = U
# 17| [TypeParamDecl] type parameter declaration
# 17| 0: [TypeSetLiteralExpr] type set literal
# 17| Type = ~string
# 17| 0: [Ident, TypeName] string
# 17| Type = string
# 17| 1: [Ident, TypeName] T
# 17| Type = T
go.mod:
# 0| [GoModFile] go.mod
# 1| 0: [GoModModuleLine] go.mod module line
Expand Down Expand Up @@ -69,6 +56,11 @@ other.go:
# 11| Type = int
# 11| 0: [Ident, VariableName] myNested
# 11| Type = func() int
# 8| 3: [TypeParamDecl] type parameter declaration
# 8| 0: [Ident, TypeName] int
# 8| Type = int
# 8| 1: [Ident, TypeName] U
# 8| Type = U
# 15| 2: [VarDecl] variable declaration
# 15| 0: [ValueSpec] value declaration specifier
# 15| 0: [Ident, VariableName] x
Expand All @@ -86,3 +78,10 @@ other.go:
# 17| Type = []T
# 17| 0: [Ident, TypeName] T
# 17| Type = T
# 17| 2: [TypeParamDecl] type parameter declaration
# 17| 0: [TypeSetLiteralExpr] type set literal
# 17| Type = ~string
# 17| 0: [Ident, TypeName] string
# 17| Type = string
# 17| 1: [Ident, TypeName] T
# 17| Type = T
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
other.go:
# 8| [TypeParamDecl] type parameter declaration
# 8| 0: [Ident, TypeName] int
# 8| Type = int
# 8| 1: [Ident, TypeName] U
# 8| Type = U
# 17| [TypeParamDecl] type parameter declaration
# 17| 0: [TypeSetLiteralExpr] type set literal
# 17| Type = ~string
# 17| 0: [Ident, TypeName] string
# 17| Type = string
# 17| 1: [Ident, TypeName] T
# 17| Type = T
# 0| [GoFile] other.go
# 1| package: [Ident] main
# 3| 1: [FuncDecl] function declaration
Expand Down Expand Up @@ -53,6 +41,11 @@ other.go:
# 11| Type = int
# 11| 0: [Ident, VariableName] myNested
# 11| Type = func() int
# 8| 3: [TypeParamDecl] type parameter declaration
# 8| 0: [Ident, TypeName] int
# 8| Type = int
# 8| 1: [Ident, TypeName] U
# 8| Type = U
# 15| 5: [VarDecl] variable declaration
# 15| 0: [ValueSpec] value declaration specifier
# 15| 0: [Ident, VariableName] x
Expand All @@ -70,6 +63,13 @@ other.go:
# 17| Type = []T
# 17| 0: [Ident, TypeName] T
# 17| Type = T
# 17| 2: [TypeParamDecl] type parameter declaration
# 17| 0: [TypeSetLiteralExpr] type set literal
# 17| Type = ~string
# 17| 0: [Ident, TypeName] string
# 17| Type = string
# 17| 1: [Ident, TypeName] T
# 17| Type = T
# 19| 7: [MethodDecl] function declaration
# 19| 0: [FunctionName, Ident] f
# 19| Type = func()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ other.go:
# 8| Type = int
# 8| 1: [Ident, TypeName] U
# 8| Type = U
# 17| [TypeParamDecl] type parameter declaration
# 17| 0: [TypeSetLiteralExpr] type set literal
# 17| Type = ~string
# 17| 0: [Ident, TypeName] string
# 17| Type = string
# 17| 1: [Ident, TypeName] T
# 17| Type = T
go.mod:
# 0| [GoModFile] go.mod
# 1| 0: [GoModModuleLine] go.mod module line
Expand Down Expand Up @@ -66,3 +59,10 @@ other.go:
# 17| Type = []T
# 17| 0: [Ident, TypeName] T
# 17| Type = T
# 17| 2: [TypeParamDecl] type parameter declaration
# 17| 0: [TypeSetLiteralExpr] type set literal
# 17| Type = ~string
# 17| 0: [Ident, TypeName] string
# 17| Type = string
# 17| 1: [Ident, TypeName] T
# 17| Type = T

0 comments on commit 7ed8206

Please sign in to comment.