ir

package
v1.3.148 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package ir extracts control flow decisions from Go AST.

Package ir extracts control flow decisions from Go AST. It builds the intermediate representation consumed by the eval layer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildDecisions

func BuildDecisions(fset *token.FileSet, body *ast.BlockStmt) (decisions []model.Decision)

BuildDecisions extracts all control flow decisions from a function body. Each decision has outcomes with statement counts (DirectStatements from the immediate block, ReachableEstimate from the full subtree).

Params:

  • fset: token file set for position info
  • body: function body to analyze

Returns:

  • decisions: extracted decisions

func ExtractCondition

func ExtractCondition(expr ast.Expr) (text string)

ExtractCondition returns a human-readable textual representation of an AST expression. Used for decision labels and diagnostic messages.

Params:

  • expr: AST expression

Returns:

  • text: textual representation

Types

type ParamConstraint

type ParamConstraint struct {
	// Name is the parameter or variable name.
	Name string
	// Type is the Go type (nil if unavailable).
	Type types.Type
	// Operator is the comparison operator (">", "==", "!=", "len", etc.).
	Operator string
	// Value is the textual comparison value ("0", "nil", `""`).
	Value string
}

ParamConstraint describes a constraint on a function parameter derived from a branch condition.

func ExtractParams

func ExtractParams(expr ast.Expr, info *types.Info) (constraints []ParamConstraint)

ExtractParams identifies parameter constraints from a condition expression. Only extracts simple binary comparisons (x > 0, err != nil, ok == true).

Params:

  • expr: condition expression
  • info: type information (can be nil for untyped analysis)

Returns:

  • constraints: extracted constraints

Jump to

Keyboard shortcuts

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