boosd

package
v0.0.0-...-890eb65 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2015 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Raw         = iota // leave error list unchanged
	Sorted             // sort error list by file, line, and column number
	NoMultiples        // sort error list and leave only the first error per line
)

These constants control the construction of the ErrorList returned by GetErrors.

View Source
const FN_CALL = 57357
View Source
const UMINUS = 57356
View Source
const YIDENT = 57353
View Source
const YIMPORT = 57346
View Source
const YINTERFACE = 57351
View Source
const YKIND = 57347
View Source
const YKIND_DECL = 57348
View Source
const YLITERAL = 57354
View Source
const YMODEL = 57352
View Source
const YNUMBER = 57355
View Source
const YPACKAGE = 57349
View Source
const YSPECIALIZES = 57350

Variables

This section is empty.

Functions

func GenGo

func GenGo(f *File) (*ast.File, error)

func Inspect

func Inspect(node Node, f func(Node) bool)

Inspect traverses an AST in depth-first order: It starts by calling f(node); node must not be nil. If f returns true, Inspect invokes f for all the non-nil children of node, recursively.

func PassScopeChain

func PassScopeChain(f *File)

func PrintError

func PrintError(w io.Writer, err error)

PrintError is a utility function that prints a list of errors to w, one error per line, if the err parameter is an ErrorList. Otherwise it prints the err string.

func Walk

func Walk(v Visitor, node Node)

Walk traverses an AST in depth-first order: It starts by calling v.Visit(node); node must not be nil. If the visitor w returned by v.Visit(node) is not nil, Walk is invoked recursively with visitor w for each of the non-nil children of node, followed by a call of w.Visit(nil).

Types

type AssignStmt

type AssignStmt struct {
	Lhs    *VarDecl
	TokPos token.Pos   // position of Tok
	Tok    token.Token // assignment token, DEFINE
	Rhs    Expr
}

An AssignStmt node represents an assignment or a short variable declaration.

func (*AssignStmt) End

func (s *AssignStmt) End() token.Pos

func (*AssignStmt) Name

func (s *AssignStmt) Name() string

func (*AssignStmt) Pos

func (s *AssignStmt) Pos() token.Pos

type BadDecl

type BadDecl struct {
	From, To token.Pos // position range of bad declaration
}

A BadDecl node is a placeholder for declarations containing syntax errors for which no correct declaration nodes can be created.

func (*BadDecl) End

func (d *BadDecl) End() token.Pos

func (*BadDecl) Pos

func (d *BadDecl) Pos() token.Pos

Pos and End implementations for declaration nodes.

type BadExpr

type BadExpr struct {
	From, To token.Pos // position range of bad expression
}

A BadExpr node is a placeholder for expressions containing syntax errors for which no correct expression nodes can be created.

func (*BadExpr) End

func (x *BadExpr) End() token.Pos

func (*BadExpr) Pos

func (x *BadExpr) Pos() token.Pos

type BadStmt

type BadStmt struct {
	From, To token.Pos // position range of bad statement
}

A BadStmt node is a placeholder for statements containing syntax errors for which no correct statement nodes can be created.

func (*BadStmt) End

func (s *BadStmt) End() token.Pos

func (*BadStmt) Pos

func (s *BadStmt) Pos() token.Pos

Pos and End implementations for statement nodes.

type BasicLit

type BasicLit struct {
	ValuePos token.Pos   // literal position
	Kind     token.Token // token.INT, token.FLOAT, token.IMAG, token.CHAR, or token.STRING
	Value    string      // literal string; e.g. 42, 0x7f, 3.14, 1e-9, 2.4i, 'a', '\x7f', "foo" or `\m\n\o`
}

A BasicLit node represents a literal of basic type.

func (*BasicLit) End

func (x *BasicLit) End() token.Pos

func (*BasicLit) Pos

func (x *BasicLit) Pos() token.Pos

func (*BasicLit) String

func (bl *BasicLit) String() string

type BinaryExpr

type BinaryExpr struct {
	X     Expr        // left operand
	OpPos token.Pos   // position of Op
	Op    token.Token // operator
	Y     Expr        // right operand
}

A BinaryExpr node represents a binary expression.

func (*BinaryExpr) End

func (x *BinaryExpr) End() token.Pos

func (*BinaryExpr) Pos

func (x *BinaryExpr) Pos() token.Pos

func (*BinaryExpr) String

func (x *BinaryExpr) String() string

type BlockStmt

type BlockStmt struct {
	Lbrace token.Pos // position of "{"
	List   []Stmt
	Rbrace token.Pos // position of "}"
}

A BlockStmt node represents a braced statement list.

func (*BlockStmt) End

func (s *BlockStmt) End() token.Pos

func (*BlockStmt) Pos

func (s *BlockStmt) Pos() token.Pos

type CallExpr

type CallExpr struct {
	Fun    Expr      // function expression
	Lparen token.Pos // position of "("
	Args   []Expr    // function arguments; or nil
	Rparen token.Pos // position of ")"
}

A CallExpr node represents an expression followed by an argument list.

func (*CallExpr) End

func (x *CallExpr) End() token.Pos

func (*CallExpr) Pos

func (x *CallExpr) Pos() token.Pos

type Comment

type Comment struct {
	Slash token.Pos // position of "/" starting the comment
	Text  string    // comment text (excluding '\n' for //-style comments)
}

A Comment node represents a single //-style or /*-style comment.

func (*Comment) End

func (c *Comment) End() token.Pos

func (*Comment) Pos

func (c *Comment) Pos() token.Pos

type CommentGroup

type CommentGroup struct {
	List []*Comment // len(List) > 0
}

A CommentGroup represents a sequence of comments with no other tokens and no empty lines between.

func (*CommentGroup) End

func (g *CommentGroup) End() token.Pos

func (*CommentGroup) Pos

func (g *CommentGroup) Pos() token.Pos

type CompositeLit

type CompositeLit struct {
	Type   Expr      // literal type; or nil
	Lbrace token.Pos // position of "{"
	Elts   []Expr    // list of composite elements; or nil
	Rbrace token.Pos // position of "}"
}

A CompositeLit node represents a composite literal.

func (*CompositeLit) End

func (x *CompositeLit) End() token.Pos

func (*CompositeLit) Pos

func (x *CompositeLit) Pos() token.Pos

type Decl

type Decl interface {
	Node
	// contains filtered or unexported methods
}

All declaration nodes implement the Decl interface.

type DeclStmt

type DeclStmt struct {
	Decl *VarDecl
}

A DeclStmt node represents a declaration in a statement list.

func (*DeclStmt) End

func (s *DeclStmt) End() token.Pos

func (*DeclStmt) Name

func (s *DeclStmt) Name() string

func (*DeclStmt) Pos

func (s *DeclStmt) Pos() token.Pos

type EmptyStmt

type EmptyStmt struct {
	Semicolon token.Pos // position of preceding ";"
}

An EmptyStmt node represents an empty statement. The "position" of the empty statement is the position of the immediately preceding semicolon.

func (*EmptyStmt) End

func (s *EmptyStmt) End() token.Pos

func (*EmptyStmt) Pos

func (s *EmptyStmt) Pos() token.Pos

type Error

type Error struct {
	Pos token.Position
	Msg string
}

Within ErrorVector, an error is represented by an Error node. The position Pos, if valid, points to the beginning of the offending token, and the error condition is described by Msg.

func (*Error) Error

func (e *Error) Error() string

type ErrorHandler

type ErrorHandler interface {
	Error(pos token.Position, msg string)
}

An implementation of an ErrorHandler may be provided to the Scanner. If a syntax error is encountered and a handler was installed, Error is called with a position and an error message. The position points to the beginning of the offending token.

type ErrorList

type ErrorList []*Error

An ErrorList is a (possibly sorted) list of Errors.

func (ErrorList) Error

func (p ErrorList) Error() string

func (ErrorList) Len

func (p ErrorList) Len() int

ErrorList implements the sort Interface.

func (ErrorList) Less

func (p ErrorList) Less(i, j int) bool

func (ErrorList) Swap

func (p ErrorList) Swap(i, j int)

type ErrorVector

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

ErrorVector implements the ErrorHandler interface. It maintains a list of errors which can be retrieved with GetErrorList and GetError. The zero value for an ErrorVector is an empty ErrorVector ready to use.

A common usage pattern is to embed an ErrorVector alongside a scanner in a data structure that uses the scanner. By passing a reference to an ErrorVector to the scanner's Init call, default error handling is obtained.

func (*ErrorVector) Error

func (h *ErrorVector) Error(pos token.Position, msg string)

ErrorVector implements the ErrorHandler interface.

func (*ErrorVector) ErrorCount

func (h *ErrorVector) ErrorCount() int

ErrorCount returns the number of errors collected.

func (*ErrorVector) GetError

func (h *ErrorVector) GetError(mode int) error

GetError is like GetErrorList, but it returns an error instead so that a nil result can be assigned to an error variable and remains nil.

func (*ErrorVector) GetErrorList

func (h *ErrorVector) GetErrorList(mode int) ErrorList

GetErrorList returns the list of errors collected by an ErrorVector. The construction of the ErrorList returned is controlled by the mode parameter. If there are no errors, the result is nil.

func (*ErrorVector) Reset

func (h *ErrorVector) Reset()

Reset resets an ErrorVector to no errors.

type Expr

type Expr interface {
	Node
	// contains filtered or unexported methods
}

All expression nodes implement the Expr interface.

type ExprStmt

type ExprStmt struct {
	X Expr // expression
}

An ExprStmt node represents a (stand-alone) expression in a statement list.

func (*ExprStmt) End

func (s *ExprStmt) End() token.Pos

func (*ExprStmt) Pos

func (s *ExprStmt) Pos() token.Pos

type Field

type Field struct {
	Doc     *CommentGroup // associated documentation; or nil
	Names   []*Ident      // field/method/parameter names; or nil if anonymous field
	Type    Expr          // field/method/parameter type
	Value   Expr          // field/method/parameter value
	Tag     *BasicLit     // field tag; or nil
	Comment *CommentGroup // line comments; or nil
}

A Field represents a Field declaration list in a struct type, a method list in an interface type, or a parameter/result declaration in a signature.

func (*Field) End

func (f *Field) End() token.Pos

func (*Field) Pos

func (f *Field) Pos() token.Pos

type FieldList

type FieldList struct {
	Opening token.Pos // position of opening parenthesis/brace, if any
	List    []*Field  // field list; or nil
	Closing token.Pos // position of closing parenthesis/brace, if any
}

A FieldList represents a list of Fields, enclosed by parentheses or braces.

func (*FieldList) End

func (f *FieldList) End() token.Pos

func (*FieldList) NumFields

func (f *FieldList) NumFields() int

NumFields returns the number of (named and anonymous fields) in a FieldList.

func (*FieldList) Pos

func (f *FieldList) Pos() token.Pos

type File

type File struct {
	Doc        *CommentGroup   // associated documentation; or nil
	Package    token.Pos       // position of "package" keyword
	Name       *Ident          // package name
	Decls      []Decl          // top-level declarations; or nil
	Scope      *Scope          // package scope (this file only)
	Imports    []*ImportSpec   // imports in this file
	Unresolved []*Ident        // unresolved identifiers in this file
	Comments   []*CommentGroup // list of all comments in the source file
	NErrors    int             // number of errors
}

A File node represents a Go source file.

The Comments list contains all comments in the source file in order of appearance, including the comments that are pointed to from other nodes via Doc and Comment fields.

func Parse

func Parse(f *token.File, str string) (*File, error)

func (*File) End

func (f *File) End() token.Pos

func (*File) GetModel

func (f *File) GetModel(name string) *ModelDecl

func (*File) Pos

func (f *File) Pos() token.Pos

type GenDecl

type GenDecl struct {
	Doc    *CommentGroup // associated documentation; or nil
	TokPos token.Pos     // position of Tok
	Tok    token.Token   // IMPORT, CONST, TYPE, VAR
	Lparen token.Pos     // position of '(', if any
	Specs  []Spec
	Rparen token.Pos // position of ')', if any
}

A GenDecl node (generic declaration node) represents an import, constant, type or variable declaration. A valid Lparen position (Lparen.Line > 0) indicates a parenthesized declaration.

Relationship between Tok value and Specs element type:

token.IMPORT  *ImportSpec
token.CONST   *ValueSpec
token.TYPE    *TypeSpec
token.VAR     *ValueSpec

func (*GenDecl) End

func (d *GenDecl) End() token.Pos

func (*GenDecl) Pos

func (d *GenDecl) Pos() token.Pos

type Ident

type Ident struct {
	NamePos token.Pos // identifier position
	Name    string    // identifier name
	Obj     *Object   // denoted object; or nil
}

An Ident node represents an identifier.

func NewIdent

func NewIdent(name string) *Ident

NewIdent creates a new Ident without position. Useful for ASTs generated by code other than the Go parser.

func (*Ident) End

func (x *Ident) End() token.Pos

func (*Ident) Pos

func (x *Ident) Pos() token.Pos

func (Ident) String

func (i Ident) String() string

type ImportSpec

type ImportSpec struct {
	Doc     *CommentGroup // associated documentation; or nil
	Name    *Ident        // local package name (including "."); or nil
	Path    *BasicLit     // import path
	Comment *CommentGroup // line comments; or nil
	EndPos  token.Pos     // end of spec (overrides Path.Pos if nonzero)
}

An ImportSpec node represents a single package import.

func (*ImportSpec) End

func (s *ImportSpec) End() token.Pos

func (*ImportSpec) Pos

func (s *ImportSpec) Pos() token.Pos

Pos and End implementations for spec nodes.

type Importer

type Importer func(imports map[string]*Object, path string) (pkg *Object, err error)

An Importer resolves import paths to package Objects. The imports map records the packages already imported, indexed by package id (canonical import path). An Importer must determine the canonical import path and check the map to see if it is already present in the imports map. If so, the Importer can return the map entry. Otherwise, the Importer should load the package data for the given path into a new *Object (pkg), record pkg in the imports map, and then return pkg.

type IndexExpr

type IndexExpr struct {
	X      Expr      // expression
	Lbrack token.Pos // position of "["
	Index  Expr      // index expression
	Rbrack token.Pos // position of "]"
}

An IndexExpr node represents an expression followed by an index.

func (*IndexExpr) End

func (x *IndexExpr) End() token.Pos

func (*IndexExpr) Pos

func (x *IndexExpr) Pos() token.Pos

func (*IndexExpr) String

func (e *IndexExpr) String() string

type InterfaceDecl

type InterfaceDecl struct {
	Doc   *CommentGroup // associated documentation; or nil
	Name  *Ident        // function/method name
	Super *Ident        // function/method name
	Units *BasicLit     // position of Func keyword, parameters and results
	Body  *BlockStmt    // function body; or nil (forward declaration)
}

A InterfaceDecl node represents an interface declaration.

func (*InterfaceDecl) End

func (d *InterfaceDecl) End() token.Pos

func (*InterfaceDecl) Pos

func (d *InterfaceDecl) Pos() token.Pos

type InterfaceType

type InterfaceType struct {
	Interface  token.Pos  // position of "interface" keyword
	Methods    *FieldList // list of methods
	Incomplete bool       // true if (source) methods are missing in the Methods list
}

An InterfaceType node represents an interface type.

func (*InterfaceType) End

func (x *InterfaceType) End() token.Pos

func (*InterfaceType) Pos

func (x *InterfaceType) Pos() token.Pos

type KeyValueExpr

type KeyValueExpr struct {
	Key   Expr
	Colon token.Pos // position of ":"
	Value Expr
}

A KeyValueExpr node represents (key : value) pairs in composite literals.

func (*KeyValueExpr) End

func (x *KeyValueExpr) End() token.Pos

func (*KeyValueExpr) Pos

func (x *KeyValueExpr) Pos() token.Pos

type KindSpec

type KindSpec struct {
	Doc     *CommentGroup // associated documentation; or nil
	Names   []*Ident      // value names (len(Names) > 0)
	Type    Expr          // value type; or nil
	Values  []Expr        // initial values; or nil
	Comment *CommentGroup // line comments; or nil
}

A ValueSpec node represents a constant or variable declaration (ConstSpec or VarSpec production).

func (*KindSpec) End

func (s *KindSpec) End() token.Pos

func (*KindSpec) Pos

func (s *KindSpec) Pos() token.Pos

type ModelDecl

type ModelDecl struct {
	Objects *Scope        // all declared variables
	Doc     *CommentGroup // associated documentation; or nil
	Recv    *FieldList    // receiver (methods); or nil (functions)
	Name    *Ident        // function/method name
	Super   *Ident        // function/method name
	Units   *BasicLit     // position of Func keyword, parameters and results
	Body    *BlockStmt    // function body; or nil (forward declaration)
	Virtual bool          // if the model has decls which require initialization
	Errors  int           // number of errors, such as unresolvable refs
}

A ModelDecl node represents a model declaration.

func (*ModelDecl) End

func (d *ModelDecl) End() token.Pos

func (*ModelDecl) Pos

func (d *ModelDecl) Pos() token.Pos

type ModelType

type ModelType struct {
	Model      token.Pos  // position of "struct" keyword
	Fields     *FieldList // list of field declarations
	Incomplete bool       // true if (source) fields are missing in the Fields list
}

A ModelType node represents a model type.

func (*ModelType) End

func (x *ModelType) End() token.Pos

func (*ModelType) Pos

func (x *ModelType) Pos() token.Pos

type Node

type Node interface {
	Pos() token.Pos // position of first character belonging to the node
	End() token.Pos // position of first character immediately after the node
}

All node types implement the Node interface.

type ObjKind

type ObjKind int

ObKind describes what an object represents.

const (
	Bad ObjKind = iota // for error handling
	Pkg                // package
	Con                // constant
	Typ                // type
	Var                // variable
	Fun                // function or method
	Lbl                // label
	Mdl                // model
)

The list of possible Object kinds.

func (ObjKind) String

func (kind ObjKind) String() string

type Object

type Object struct {
	Kind ObjKind
	Name string      // declared name
	Decl interface{} // corresponding Field, XxxSpec, FuncDecl, or LabeledStmt; or nil
	Data interface{} // object-specific data; or nil
	Type interface{} // place holder for type information; may be nil
}

An Object describes a named language entity such as a package, constant, type, variable, function (incl. methods), or label.

The Data fields contains object-specific data:

Kind    Data type    Data value
Pkg	*Scope       package scope
Con     int          iota for the respective declaration
Con     != nil       constant value

func NewObj

func NewObj(kind ObjKind, name string) *Object

NewObj creates a new object of a given kind and name.

func (*Object) Pos

func (obj *Object) Pos() token.Pos

Pos computes the source position of the declaration of an object name. The result may be an invalid position if it cannot be computed (obj.Decl may be nil or not correct).

type ObjectKind

type ObjectKind int
const (
	ObjModel ObjectKind = iota
	ObjInterface
	ObjKynd
	ObjFlow
	ObjStock
	ObjTime
	ObjAux
	ObjString
)

type Package

type Package struct {
	Name    string             // package name
	Scope   *Scope             // package scope across all files
	Imports map[string]*Object // map of package id -> package object
	Files   map[string]*File   // Go source files by filename
}

A Package node represents a set of source files collectively building a Go package.

func NewPackage

func NewPackage(fset *token.FileSet, files map[string]*File, importer Importer, universe *Scope) (*Package, error)

NewPackage creates a new Package node from a set of File nodes. It resolves unresolved identifiers across files and updates each file's Unresolved list accordingly. If a non-nil importer and universe scope are provided, they are used to resolve identifiers not declared in any of the package files. Any remaining unresolved identifiers are reported as undeclared. If the files belong to different packages, one package name is selected and files with different package names are reported and then ignored. The result is a package node and a scanner.ErrorList if there were errors.

func (*Package) End

func (p *Package) End() token.Pos

func (*Package) Pos

func (p *Package) Pos() token.Pos

type PairExpr

type PairExpr struct {
	X Expr // left operand
	Y Expr // right operand
}

A PairExpr node represents a pair in a table expression.

func (*PairExpr) End

func (x *PairExpr) End() token.Pos

func (*PairExpr) Pos

func (x *PairExpr) Pos() token.Pos

type ParenExpr

type ParenExpr struct {
	Lparen token.Pos // position of "("
	X      Expr      // parenthesized expression
	Rparen token.Pos // position of ")"
}

A ParenExpr node represents a parenthesized expression.

func (*ParenExpr) End

func (x *ParenExpr) End() token.Pos

func (*ParenExpr) Pos

func (x *ParenExpr) Pos() token.Pos

type RefExpr

type RefExpr struct {
	Ident // the variable name
}

a reference to a variable's value

type Scope

type Scope struct {
	Outer   *Scope
	Objects map[string]*Object
}

A Scope maintains the set of named language entities declared in the scope and a link to the immediately surrounding (outer) scope.

func NewScope

func NewScope(outer *Scope) *Scope

NewScope creates a new scope nested in the outer scope.

func (*Scope) Insert

func (s *Scope) Insert(obj *Object) (alt *Object)

Insert attempts to insert a named object obj into the scope s. If the scope already contains an object alt with the same name, Insert leaves the scope unchanged and returns alt. Otherwise it inserts obj and returns nil."

func (*Scope) Lookup

func (s *Scope) Lookup(name string) *Object

Lookup returns the object with the given name if it is found in scope s, otherwise it returns nil. Outer scopes are ignored.

func (*Scope) String

func (s *Scope) String() string

Debugging support

type SelectorExpr

type SelectorExpr struct {
	X   Expr   // expression
	Sel *Ident // field selector
}

A SelectorExpr node represents an expression followed by a selector.

func (*SelectorExpr) End

func (x *SelectorExpr) End() token.Pos

func (*SelectorExpr) Pos

func (x *SelectorExpr) Pos() token.Pos

type Spec

type Spec interface {
	Node
	// contains filtered or unexported methods
}

The Spec type stands for any of *ImportSpec, *ValueSpec, and *TypeSpec.

type Stmt

type Stmt interface {
	Node

	Name() string
	// contains filtered or unexported methods
}

All statement nodes implement the Stmt interface.

type TableExpr

type TableExpr struct {
	Lbrack token.Pos
	Pairs  []*PairExpr // function arguments; or nil
	Rbrack token.Pos
}

A CallExpr node represents an expression followed by an argument list.

func (*TableExpr) End

func (x *TableExpr) End() token.Pos

func (*TableExpr) Pos

func (x *TableExpr) Pos() token.Pos

type TableForwardExpr

type TableForwardExpr struct {
	Ys []*BasicLit
}

An expression is represented by a tree consisting of one or more of the following concrete expression nodes.

type UnaryExpr

type UnaryExpr struct {
	OpPos token.Pos   // position of Op
	Op    token.Token // operator
	X     Expr        // operand
}

A UnaryExpr node represents a unary expression. Unary "*" expressions are represented via StarExpr nodes.

func (*UnaryExpr) End

func (x *UnaryExpr) End() token.Pos

func (*UnaryExpr) Pos

func (x *UnaryExpr) Pos() token.Pos

type UnitExpr

type UnitExpr struct {
	X    Expr // the expression
	Unit Expr // the expression's units
}

An expression is represented by a tree consisting of one or more of the following concrete expression nodes.

func (*UnitExpr) End

func (x *UnitExpr) End() token.Pos

func (*UnitExpr) Pos

func (x *UnitExpr) Pos() token.Pos

func (*UnitExpr) String

func (x *UnitExpr) String() string

FIXME: this isn't correct

type VarDecl

type VarDecl struct {
	Doc   *CommentGroup // associated documentation; or nil
	Name  *Ident        // name of the variable
	Type  *Ident        // type (stock, flow) of the variable
	Units Expr          // name of the variable
}

A declaration is represented by one of the following declaration nodes.

func (*VarDecl) End

func (d *VarDecl) End() token.Pos

func (*VarDecl) Pos

func (d *VarDecl) Pos() token.Pos

type Visitor

type Visitor interface {
	Visit(node Node) (w Visitor)
}

A Visitor's Visit method is invoked for each node encountered by Walk. If the result visitor w is not nil, Walk visits each of the children of node with the visitor w, followed by a call of w.Visit(nil).

Jump to

Keyboard shortcuts

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