Debian Codegraph @

tools/antithesis-go-instrumentor/scanners/coverage/instrumentor/node_stack.go

raw
1 package instrumentor
2
3 import (
4 "go/ast"
5 )
6
7 type Stack []ast.Node
8
9 // IsEmpty: check if stack is empty
10 func (s *Stack) IsEmpty() bool {
11 return len(*s) == 0
12 }
13
14 // Push a new integer onto the stack
15 func (s *Stack) Push(x ast.Node) {
16 *s = append(*s, x)
17 }
18
19 // Pop: remove and return top element of stack, return false if stack is empty
20 func (s *Stack) Pop() (ast.Node, bool) {
21 if s.IsEmpty() {
22 return nil, false
23 }
24
25 i := len(*s) - 1
26 x := (*s)[i]
27 *s = (*s)[:i]
28
29 return x, true
30 }
31
32 // Peek: return top element of stack, return false if stack is empty
33 func (s *Stack) Peek() (ast.Node, bool) {
34 if s.IsEmpty() {
35 return nil, false
36 }
37
38 i := len(*s) - 1
39 x := (*s)[i]
40
41 return x, true
42 }