Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / honnef.co / go / tools@v0.0.1-2020.1.5 / functions / stub.go
1 package functions
2
3 import (
4         "honnef.co/go/tools/ir"
5 )
6
7 // IsStub reports whether a function is a stub. A function is
8 // considered a stub if it has no instructions or if all it does is
9 // return a constant value.
10 func IsStub(fn *ir.Function) bool {
11         for _, b := range fn.Blocks {
12                 for _, instr := range b.Instrs {
13                         switch instr.(type) {
14                         case *ir.Const:
15                                 // const naturally has no side-effects
16                         case *ir.Panic:
17                                 // panic is a stub if it only uses constants
18                         case *ir.Return:
19                                 // return is a stub if it only uses constants
20                         case *ir.DebugRef:
21                         case *ir.Jump:
22                                 // if there are no disallowed instructions, then we're
23                                 // only jumping to the exit block (or possibly
24                                 // somewhere else that's stubby?)
25                         default:
26                                 // all other instructions are assumed to do actual work
27                                 return false
28                         }
29                 }
30         }
31         return true
32 }