trap

package
v1.27.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2021 License: MIT Imports: 12 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Label

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

Label represents a label

var InvalidLabel Label

InvalidLabel represents an uninitialized or otherwise invalid label

func (*Label) String

func (lbl *Label) String() string

type Labeler

type Labeler struct {
	TypeLabels map[types.Type]Label // labels associated with types
	// contains filtered or unexported fields
}

Labeler is used to represent labels for a file. It is used to write associate objects with labels.

func (*Labeler) FieldID

func (l *Labeler) FieldID(field *types.Var, idx int, structlbl Label) (Label, bool)

FieldID associates a label with the given field and returns it, together with a flag indicating whether the field already had a label associated with it; the field must belong to `structlbl`, since that label is used to construct the label of the field. When the field name is the blank identifier `_`, `idx` is used to generate a unique name.

func (*Labeler) FileLabel

func (l *Labeler) FileLabel() Label

FileLabel returns the label for the file with which the trap writer is associated

func (*Labeler) FreshID

func (l *Labeler) FreshID() Label

FreshID creates a fresh label and returns it

func (*Labeler) GlobalID

func (l *Labeler) GlobalID(key string) Label

GlobalID associates a label with the given `key` and returns it

func (*Labeler) LocalID

func (l *Labeler) LocalID(nd interface{}) Label

LocalID associates a label with the given AST node `nd` and returns it

func (*Labeler) LookupObjectID

func (l *Labeler) LookupObjectID(object types.Object, typelbl Label) (Label, bool)

LookupObjectID looks up the label associated with the given object and returns it; if the object does not have a label yet, it tries to construct one based on its scope and/or name, and otherwise returns InvalidLabel

func (*Labeler) MethodID

func (l *Labeler) MethodID(method types.Object, recvlbl Label) (Label, bool)

MethodID associates a label with the given method and returns it, together with a flag indicating whether the method already had a label associated with it; the method must belong to `recvlbl`, since that label is used to construct the label of the method

func (*Labeler) ReceiverObjectID

func (l *Labeler) ReceiverObjectID(object types.Object, methlbl Label) (Label, bool)

ReceiverObjectID associates a label with the given object and returns it, together with a flag indicating whether the object already had a label associated with it; the object must be the receiver of `methlbl`, since that label is used to construct the label of the object

func (*Labeler) ScopeID

func (l *Labeler) ScopeID(scope *types.Scope, pkg *types.Package) Label

ScopeID associates a label with the given scope and returns it

func (*Labeler) ScopedObjectID

func (l *Labeler) ScopedObjectID(object types.Object, typelbl Label) (Label, bool)

ScopedObjectID associates a label with the given object and returns it, together with a flag indicating whether the object already had a label associated with it; the object must have a scope, since the scope's label is used to construct the label of the object.

There is a special case for variables that are method receivers. When this is detected, we must construct a special label, as the variable can be reached from several files via the method. As the type label is required to construct the receiver object id, it is also required here.

type Writer

type Writer struct {
	Labeler *Labeler

	Package *packages.Package
	// contains filtered or unexported fields
}

A Writer provides methods for writing data to a TRAP file

func NewWriter

func NewWriter(path string, pkg *packages.Package) (*Writer, error)

NewWriter creates a TRAP file for the given path and returns a writer for writing to it

func (*Writer) Close

func (tw *Writer) Close() error

Close the underlying file writer

func (*Writer) Emit

func (tw *Writer) Emit(table string, values []interface{}) error

Emit writes out a tuple of values for the given `table`

func (*Writer) ForEachObject

func (tw *Writer) ForEachObject(cb func(*Writer, types.Object, Label))

ForEachObject iterates over all objects labeled by this labeler, and invokes the provided callback with a writer for the trap file, the object, and its label.

Jump to

Keyboard shortcuts

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