graph

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package graph provides control-flow graph analysis.

It enables reachability analysis between source code positions and limitation to a forward-only flow to approximate code reading.

The original algorithm was written by Alan Donovan for golang.org/x/tools/go/cfg.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockInterval

type BlockInterval struct {
	Start, End token.Pos // The range of the block in the source file.
	Successors []int     // Indices of successor blocks in the intervals slice.
}

BlockInterval represents a range in the source file with successor block indices for control-flow analysis.

func BuildGraph

func BuildGraph(ctx context.Context, info *types.Info, recv *ast.FieldList, typ *ast.FuncType, body *ast.BlockStmt, forwardOnly bool) []BlockInterval

BuildGraph constructs control-flow graph intervals for the given function body.

func (BlockInterval) Compare

func (bi BlockInterval) Compare(p token.Pos) int

Compare returns whether the position p is within the interval, before or after.

type LabelTarget

type LabelTarget struct {
	// contains filtered or unexported fields
}

LabelTarget represents the control flow targets for a labeled statement. A label can be the target of break, continue, or goto statements.

func NewLabelTarget

func NewLabelTarget(body *block.Block) *LabelTarget

NewLabelTarget creates a new label target with the given body source range. The break and continue targets are set later based on the statement type.

func (*LabelTarget) Body

func (l *LabelTarget) Body() *block.Block

Body returns the source range of the labeled statement itself.

func (*LabelTarget) BranchTarget

func (l *LabelTarget) BranchTarget(tok token.Token) *block.Block

BranchTarget returns the block that a branch statement should jump to based on the branch token type (BREAK, CONTINUE, or GOTO).

func (*LabelTarget) SetBreak

func (l *LabelTarget) SetBreak(b *block.Block)

SetBreak sets the break target block for the labeled statement.

func (*LabelTarget) SetContinue

func (l *LabelTarget) SetContinue(c *block.Block)

SetContinue sets the continue target block for the labeled statement.

Jump to

Keyboard shortcuts

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