store

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2017 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package store provides interfaces for a key-value store. Keys are nameable objects, and Values have a unique representation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Const

type Const struct{ ssa.Const }

Const is a known constant.

It's used to track unique symbols of the same constant value.

func (Const) UniqName

func (c Const) UniqName() string

UniqueName of Const is its SSA Value name, e.g. 1:int

type IDClashError

type IDClashError struct {
	ID Value
}

IDClashError is the error returned if the unique ID of two objects clash.

func (IDClashError) Error

func (e IDClashError) Error() string

type Key

type Key interface {
	Name() string     // (Short) name of key.
	Pos() token.Pos   // Position in program.
	String() string   // Description of key.
	Type() types.Type // Underlying datatype.
}

Key is a nameable key for lookup in storage.

Key represents a variable where its name is unique in the scope. Key may be synthetic, in such case, the position should be set to NoPos to indicate that the Key does not originate from the program.

The string description of the key and the Position is primarily for debugging and locating source of the key. The underlying datatype is needed for compositional datatypes (struct, chan, map, etc.).

type Logger

type Logger interface {
	SetLog(io.Writer)
}

Logger is the logging interface for a storage.

type MockKey

type MockKey struct {
	Typ         types.Type
	SrcPos      token.Pos
	Description string // Description of the key, start with a verb to get a descriptive Name()
}

A MockKey is a placeholder for a Key. MockKey requires a type to be specified. A MockKey is a wrapper, and should not be modified after creation, so all methods takes a value receiver.

func (MockKey) Name

func (k MockKey) Name() string

func (MockKey) Pos

func (k MockKey) Pos() token.Pos

func (MockKey) String

func (k MockKey) String() string

func (MockKey) Type

func (k MockKey) Type() types.Type

type MockValue

type MockValue struct {
	SrcPos      token.Pos
	Description string // Description of the key
}

A MockValue is a placeholder for a Value.

This could mean the value comes from external (C), or is not instantiated in main body of program.

func (MockValue) UniqName

func (v MockValue) UniqName() string

type ObjUndefError

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

ObjUndefError is the error returned if accessing a non-existent object.

func (ObjUndefError) Error

func (e ObjUndefError) Error() string

type Pool

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

Pool is key-value store of ssa.Value to store instances.

Pool key has no particular significance, except that it has to be unique within the Pool. Always use AddValue() to add ssa.Value in the Pool, or use AddWrapped() to add a pre-wrapped ssa.Value in the Pool. A new unique key is generated for each call (multiple of the same value is allowed as long as they are added by different NewValue calls).

func (*Pool) AddValue

func (p *Pool) AddValue(v ssa.Value) Value

func (*Pool) AddWrapped

func (p *Pool) AddWrapped(v ValueWrapper) error

func (*Pool) Get

func (p *Pool) Get(v Value) (ssa.Value, error)

type Store

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

Store is a two-layer key-value storage for ssa.Value.

Effectively the storage is a map[Key]map[Value]ssa.Value, but the second layer is designed to be efficient for name substitution.

func Extend

func Extend(s *Store) *Store

Extend storage with new set of names, using the same backing storage.

func New

func New() *Store

func (*Store) Get

func (s *Store) Get(k Key) Value

Get retrieves the Value in storage give Key k, if k is not found returns a MockValue.

func (*Store) GetObj

func (s *Store) GetObj(k Key) ssa.Value

GetObj obtains the underlying ssa.Value in the actual object store.

func (*Store) Put

func (s *Store) Put(k Key, v Value)

Put inserts an existing value v with the new key k.

func (*Store) PutObj

func (s *Store) PutObj(k Key, v ssa.Value)

PutObj puts a new, fresh ssa.Value v to storage with key k. The new value can be referenced by a centrally generated unqiue ID.

func (*Store) PutUniq

func (s *Store) PutUniq(k Key, v ValueWrapper) error

PutUniq inserts an existing wrapped value v with the new key k.

func (*Store) SetLog

func (s *Store) SetLog(w io.Writer)

SetOutput sets debug output stream to w.

func (*Store) String

func (s *Store) String() string

type Unused

type Unused struct {
	MockKey
}

Unused is an annotated MockKey indicating the Key (local variable) is unused.

type Value

type Value interface {
	UniqName() string
}

A Value represents the (symbolic) value in a storage.

The value could be any symbolic/concrete representation of a variable instance, but is required to be unique so difference instances can be distinguished.

type ValueWrapper

type ValueWrapper interface {
	ssa.Value // Actual Value.
	Value     // Ensure uniqueness.
}

ValueWrapper is a Value that wraps an ssa.Value. It can be used as both key and value of the pool for convenience.

Directories

Path Synopsis
Package chans implements store.Value of type chan.
Package chans implements store.Value of type chan.
Package structs implements store.Value for composite struct type.
Package structs implements store.Value for composite struct type.

Jump to

Keyboard shortcuts

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