astcodec

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package astcodec writes syntax trees to a pack stream and reads them back. Nodes form a table, grouped by type, and refer to each other by table index.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownNode = errors.New("astcodec: node of a type the codec does not know")

ErrUnknownNode reports a node of a type the codec does not know, which it refuses to encode rather than drop.

Functions

func Reachable

func Reachable(roots ...ast.Node) map[ast.Node]bool

Reachable is the set of nodes reachable from roots, roots included: what Encode would write for them.

Types

type Decoder

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

Decoder reads one node table: Allocate creates the nodes, Fill reads their fields, and Node may hand out addresses while Fill runs elsewhere.

func NewDecoder

func NewDecoder(r *pack.Reader) *Decoder

NewDecoder returns a Decoder reading from r.

func (*Decoder) Allocate

func (d *Decoder) Allocate()

Allocate reads the node counts, allocates every node in one block per type, and moves the reader past the table; the nodes' fields are zero until Fill.

func (*Decoder) Decode

func (d *Decoder) Decode()

Decode reads the node table Encode wrote: Allocate then Fill. Errors are left on the reader for the caller to check.

func (*Decoder) Err

func (d *Decoder) Err() error

Err reports the first malformation Allocate or Fill met, or nil.

func (*Decoder) Fill

func (d *Decoder) Fill()

Fill reads the fields of the nodes Allocate made. Its error is on Err.

func (*Decoder) Node

func (d *Decoder) Node(id uint64) (ast.Node, bool)

Node returns the node at a table index, and whether the index is in the table; 0 is nil. It is safe to call while Fill runs.

type Encoder

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

Encoder writes one node table.

func NewEncoder

func NewEncoder(w *pack.Writer) *Encoder

NewEncoder returns an Encoder writing to w.

func (*Encoder) Encode

func (e *Encoder) Encode(roots []ast.Node) error

Encode writes the table of every node reachable from roots: the count of each type, then a section holding the nodes' fields.

func (*Encoder) ID

func (e *Encoder) ID(n ast.Node) (uint64, bool)

ID returns the table index of an encoded node; nil is 0. It reports false for a node Encode did not reach.

Jump to

Keyboard shortcuts

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