xc

package module
v0.0.0-...-45b0697 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2018 License: BSD-3-Clause Imports: 14 Imported by: 23 modules, 26 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.

README

github.com/cznic/xc has moved to modernc.org/xc (vcs).

Please update your import paths to modernc.org/xc.

This repo is now archived.

Documentation

Overview

Package xc provides cross language compiler support/utility stuff.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DB keeps parser/compiler data shared between stages. See also *MemDB
	// methods.
	DB = NewMemDB()

	// Dict collects unique []byte values using the global DB variable.
	// See also *Dictionary methods.
	Dict = NewDictionary()

	// FileSet represents a set of source files.
	FileSet = token.NewFileSet()

	// Files is a ready to use FileCentral.
	Files = NewFileCentral()

	// PrintHooks define default strutil.PrettyPrintHooks.
	PrintHooks = strutil.PrettyPrintHooks{
		reflect.TypeOf(lex.Char{}): func(f strutil.Formatter, v interface{}, prefix, suffix string) {
			c := v.(lex.Char)
			suffix = strings.Replace(suffix, "%", "%%", -1)
			f.Format("%s%v: %q"+suffix, prefix, FileSet.Position(c.Pos()), string(c.Rune))
		},
		reflect.TypeOf(token.Pos(0)): func(f strutil.Formatter, v interface{}, prefix, suffix string) {
			p := v.(token.Pos)
			suffix = strings.Replace(suffix, "%", "%%", -1)
			f.Format("%s%v"+suffix, prefix, FileSet.Position(p))
		},
		reflect.TypeOf(Val(0)): func(f strutil.Formatter, v interface{}, prefix, suffix string) {
			suffix = strings.Replace(suffix, "%", "%%", -1)
			f.Format("%s%s"+suffix, prefix, Dict.S(int(v.(Val))))
		},
	}
)

Functions

This section is empty.

Types

type Dictionary

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

Dictionary is a bijection of a set of byte slice values and their associated numeric identifiers. A zero length byte slice is guaranteed to have zero ID. Dictionary uses the global DB variable.

func NewDictionary

func NewDictionary() *Dictionary

NewDictionary returns a newly created *Dictionary.

func (*Dictionary) ID

func (d *Dictionary) ID(s []byte) int

ID returns the identifier associated with s. If len(s) is 0, ID returns zero.

func (*Dictionary) S

func (d *Dictionary) S(id int) []byte

S returns the byte slice associated with id.

NOTE: The result refers to the dictionary backing storage directly without copying and is thus strictly R/O.

func (*Dictionary) SID

func (d *Dictionary) SID(s string) int

SID is like ID but accepts a string instead of a byte slice.

type FileCentral

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

FileCentral provides centralized source file handling. Methods of FileCentral are synchonized; multiple goroutines may invoke them concurrently.

func NewFileCentral

func NewFileCentral() *FileCentral

NewFileCentral returns a newly created FileCentral.

func (*FileCentral) Map

func (f *FileCentral) Map(fn func(string, *Once) bool)

Map calls fn for every pair of path and its associated Once in f, in random order. f is locked through the execution of Map.

If fn returns false, the iteration of f is aborted.

func (*FileCentral) Once

func (f *FileCentral) Once(id string, set func() interface{}) *Once

Once returns the *Once associated with id, which must be an absolute path. If the value of the returned object needs to be set, Once starts the set function in a new goroutine to obtain the value. Once will panic is the set function returns nil.

type MemDB

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

MemDB stores data accessible using a numeric identifier.

func NewMemDB

func NewMemDB() *MemDB

NewMemDB returns a newly create *MemDB.

func (*MemDB) Bytes

func (d *MemDB) Bytes(id int) []byte

Bytes returns the byte slice associated with id. Passing id not obtained by PutBytes has undefined behavior. Bytes RLocks the DB to obtain the result.

NOTE: The result refers to the DB backing storage directly without copying and is thus strictly R/O.

func (*MemDB) Cap

func (d *MemDB) Cap() int

Cap reports the current DB capacity.

func (*MemDB) Len

func (d *MemDB) Len() int

Len reports the size of the DB used by data.

func (*MemDB) PutBytes

func (d *MemDB) PutBytes(b []byte) int

PutBytes stores b in the DB and returns its id. Zero length byte slices are guaranteed to return zero ID. PutBytes Locks the DB before updating it.

type Once

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

Once manages a single value instantiated only once.

func (*Once) Value

func (o *Once) Value() interface{}

Value returns the value of o. Value may block if o's value is not yet set.

type Report

type Report struct {
	// ErrLimit limits the number of calls to the error reporting methods.
	// After the limit is reached, all errors are reported using log.Print
	// and then log.Fatal() is called with a message about too many errors.
	// To disable error limit set ErrLimit to value less or equal zero.
	// Default value is 10.
	ErrLimit int

	// IgnoreErrors is a testing hook allowing to ignore errors.
	IgnoreErrors bool

	// PanicOnError is a testing hook allowing to fast fail by panicking on
	// first call to any of the error reporting methods.
	PanicOnError bool

	// TraceErrors enable printing errors to stderr as they come, which
	// means they may not be sorted. Intended for testing.
	TraceErrors bool
	// contains filtered or unexported fields
}

Report provides centralized error collecting. Methods of Report are synchonized; multiple goroutines may invoke them concurrently.

func NewReport

func NewReport() *Report

NewReport returns a newly created Report.

func (*Report) ClearErrors

func (c *Report) ClearErrors() error

ClearErrors clears any errors already reported to c and returnes them.

func (*Report) Err

func (c *Report) Err(pos token.Pos, format string, arg ...interface{})

Err reports an error at pos. goroutines.

func (*Report) ErrChar

func (c *Report) ErrChar(ch lex.Char, format string, arg ...interface{})

ErrChar reports an error for char ch. ErrChar is safe for concurrent use by multiple goroutines.

func (*Report) ErrPosition

func (c *Report) ErrPosition(position token.Position, format string, arg ...interface{})

ErrPosition reports an error at position.

func (*Report) ErrTok

func (c *Report) ErrTok(tok Token, format string, arg ...interface{})

ErrTok reports an error for token tok.

func (*Report) Errors

func (c *Report) Errors(sorted bool) error

Errors returns a go/scanner.ErrorList or nil if there were no errors reported so far by the Err* methods.

type Token

type Token struct {
	lex.Char     // Token rune and position.
	Val      int // ID of token value in the global Dict variable.
}

Token describes a token.

func (*Token) Position

func (t *Token) Position() token.Position

Position returns position of t.

func (Token) S

func (t Token) S() []byte

S returns a R/O value of t, ie. Dict.S(t.Val).

func (Token) String

func (t Token) String() string

String implements fmt.Stringer.

type Val

type Val int

Val represents an item of a Dict. It prettyPrints as a string Dict.S(theVal).

func (Val) String

func (v Val) String() string

String implements fmt.Stringer.

Jump to

Keyboard shortcuts

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