File: stub.go

package info (click to toggle)
golang-honnef-go-tools 2023.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,784 kB
  • sloc: sh: 132; xml: 48; lisp: 30; makefile: 10; javascript: 1
file content (32 lines) | stat: -rw-r--r-- 845 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package irutil

import (
	"honnef.co/go/tools/go/ir"
)

// IsStub reports whether a function is a stub. A function is
// considered a stub if it has no instructions or if all it does is
// return a constant value.
func IsStub(fn *ir.Function) bool {
	for _, b := range fn.Blocks {
		for _, instr := range b.Instrs {
			switch instr.(type) {
			case *ir.Const:
				// const naturally has no side-effects
			case *ir.Panic:
				// panic is a stub if it only uses constants
			case *ir.Return:
				// return is a stub if it only uses constants
			case *ir.DebugRef:
			case *ir.Jump:
				// if there are no disallowed instructions, then we're
				// only jumping to the exit block (or possibly
				// somewhere else that's stubby?)
			default:
				// all other instructions are assumed to do actual work
				return false
			}
		}
	}
	return true
}