@@ -55,6 +55,38 @@ func (v funcCallVisitor) VisitFuncCall(f *ast.FuncCall) ast.VisitResult {
5555 return ast .VisitRecurse
5656}
5757
58+ type unaryExprVisitor func (* ast.UnaryExpr )
59+
60+ func (unaryExprVisitor ) Visitor () {}
61+ func (v unaryExprVisitor ) VisitUnaryExpr (c * ast.UnaryExpr ) ast.VisitResult {
62+ v (c )
63+ return ast .VisitRecurse
64+ }
65+
66+ type binaryExprVisitor func (* ast.BinaryExpr )
67+
68+ func (binaryExprVisitor ) Visitor () {}
69+ func (v binaryExprVisitor ) VisitBinaryExpr (c * ast.BinaryExpr ) ast.VisitResult {
70+ v (c )
71+ return ast .VisitRecurse
72+ }
73+
74+ type ternaryExprVisitor func (* ast.TernaryExpr )
75+
76+ func (ternaryExprVisitor ) Visitor () {}
77+ func (v ternaryExprVisitor ) VisitTernaryExpr (c * ast.TernaryExpr ) ast.VisitResult {
78+ v (c )
79+ return ast .VisitRecurse
80+ }
81+
82+ type castExprVisitor func (* ast.CastExpr )
83+
84+ func (castExprVisitor ) Visitor () {}
85+ func (v castExprVisitor ) VisitCastExpr (c * ast.CastExpr ) ast.VisitResult {
86+ v (c )
87+ return ast .VisitRecurse
88+ }
89+
5890var (
5991 duden_modules = make (map [string ]* ast.Module , 30 )
6092 duden_funcs = make (map [* ast.FuncDecl ]struct {}, 100 )
@@ -117,6 +149,17 @@ func TestStdlibCoverage(t *testing.T) {
117149
118150 const stdlib_testdata = "testdata/stdlib"
119151 called_functions := make (map [* ast.FuncDecl ]int , len (duden_funcs ))
152+ func_called := func (f * ast.FuncDecl ) {
153+ if _ , ok := duden_funcs [f ]; ! ok {
154+ return
155+ }
156+ if n , ok := called_functions [f ]; ok {
157+ called_functions [f ] = n + 1
158+ } else {
159+ called_functions [f ] = 1
160+ }
161+ }
162+
120163 err = filepath .WalkDir (stdlib_testdata , func (path string , d fs.DirEntry , err error ) error {
121164 if err != nil || ! d .IsDir () || path == stdlib_testdata {
122165 return nil
@@ -135,13 +178,30 @@ func TestStdlibCoverage(t *testing.T) {
135178 }
136179
137180 ast .VisitModule (module , funcCallVisitor (func (f * ast.FuncCall ) {
138- if _ , ok := duden_funcs [f .Func ]; ! ok {
139- return
181+ func_called (f .Func )
182+ }))
183+
184+ ast .VisitModule (module , unaryExprVisitor (func (c * ast.UnaryExpr ) {
185+ if c .OverloadedBy != nil {
186+ func_called (c .OverloadedBy .Decl )
140187 }
141- if n , ok := called_functions [f .Func ]; ok {
142- called_functions [f .Func ] = n + 1
143- } else {
144- called_functions [f .Func ] = 1
188+ }))
189+
190+ ast .VisitModule (module , binaryExprVisitor (func (c * ast.BinaryExpr ) {
191+ if c .OverloadedBy != nil {
192+ func_called (c .OverloadedBy .Decl )
193+ }
194+ }))
195+
196+ ast .VisitModule (module , ternaryExprVisitor (func (c * ast.TernaryExpr ) {
197+ if c .OverloadedBy != nil {
198+ func_called (c .OverloadedBy .Decl )
199+ }
200+ }))
201+
202+ ast .VisitModule (module , castExprVisitor (func (c * ast.CastExpr ) {
203+ if c .OverloadedBy != nil {
204+ func_called (c .OverloadedBy .Decl )
145205 }
146206 }))
147207
0 commit comments