branch

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const PreserveScope = "preserveScope"

Variables

View Source
var DeviatingFuncs = map[Call]BranchKind{
	{"os", "Exit"}:     Exit,
	{"log", "Fatal"}:   Exit,
	{"log", "Fatalf"}:  Exit,
	{"log", "Fatalln"}: Exit,
	{"", "panic"}:      Panic,
	{"log", "Panic"}:   Panic,
	{"log", "Panicf"}:  Panic,
	{"log", "Panicln"}: Panic,
}

DeviatingFuncs lists known control flow deviating function calls.

Functions

This section is empty.

Types

type Args

type Args struct {
	PreserveScope bool
}

Args contains arguments common to early-return.

type Branch

type Branch struct {
	Call
	BranchKind
	HasDecls bool
}

Branch stores the branch's information within an if-else statement.

func BlockBranch

func BlockBranch(block *ast.BlockStmt) Branch

func StmtBranch

func StmtBranch(stmt ast.Stmt) Branch

type BranchKind

type BranchKind int
const (
	Empty BranchKind = iota

	// Return branches return from the current function
	Return

	// Continue branches continue a surrounding `for` loop
	Continue

	// Break branches break out of a surrounding `for` loop
	Break

	// Goto branches jump to a label
	Goto

	// Panic panics the current program
	Panic

	// Exit exits the current program
	Exit

	// Regular branches not categorized as any of the above
	Regular
)

func (BranchKind) Branch

func (k BranchKind) Branch() Branch

func (BranchKind) Deviates

func (k BranchKind) Deviates() bool

func (BranchKind) IsEmpty

func (k BranchKind) IsEmpty() bool

func (BranchKind) Returns

func (k BranchKind) Returns() bool

func (BranchKind) String

func (k BranchKind) String() string

type Call

type Call struct {
	Pkg  string // package name
	Name string // function name
}

func ExprCall

func ExprCall(expr *ast.ExprStmt) (Call, bool)

ExprCall gets the call of an ExprStmt.

type Chain

type Chain struct {
	If                   Branch
	Else                 Branch
	HasInitializer       bool
	HasPriorNonDeviating bool
	AtBlockEnd           bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL