syms

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: BSD-3-Clause Imports: 22 Imported by: 3

Documentation

Overview

Package syms defines the symbols and their properties that are accumulated from a parsed file, and are then used for e.g., completion lookup, etc.

We looked at several different standards for formats, types, etc:

LSP: https://microsoft.github.io/language-server-protocol/specification useful to enable parse to act as an LSP server at some point. additional symbol kinds: https://github.com/Microsoft/language-server-protocol/issues/344

See also: github.com/sourcegraph/sourcegraph and specifically: /cmd/frontend/graphqlbackend/search_symbols.go it seems to use https://github.com/universal-ctags/ctags for the raw data..

Other relevant guidance comes from the go compiler system which is used extensively in github.com/mdemsky/gocode for example. In particular: go/types/scope.go type.go, and package.go contain the relevant data structures for how information is organized for compiled go packages, which have all this data cached and avail to be imported via the go/importer which returns a go/types/Package which in turn contains Scope's which in turn contain Objects that define the elements of the compiled language.

Index

Constants

This section is empty.

Variables

View Source
var CatMap map[Kinds]Kinds

CatMap is the map into the category level for each kind

Categories

View Source
var Sub2CatMap map[Kinds]Kinds

Sub2CatMap is the map into the sub2-category level for each kind

Sub2-Categories

View Source
var SubCatMap map[Kinds]Kinds

SubCatMap is the map into the sub-category level for each kind

Sub-Categories

Functions

func AddCompleteSyms

func AddCompleteSyms(sym SymMap, scope string, md *complete.Matches)

AddCompleteSyms adds given symbols as matches in the given match data Scope is e.g., type name (label only)

func AddCompleteSymsPrefix

func AddCompleteSymsPrefix(sym SymMap, scope, seed string, md *complete.Matches)

AddCompleteSymsPrefix adds subset of symbols that match seed prefix to given match data

func AddCompleteTypeNames

func AddCompleteTypeNames(typ *Type, scope, seed string, md *complete.Matches)

AddCompleteTypeNames adds names from given type as matches in the given match data Scope is e.g., type name (label only), and seed is prefix filter for names

func CacheFilename

func CacheFilename(lang fileinfo.Known, filename string) (string, error)

CacheFilename returns the filename to use for cache file for given filename

func GoRelPath

func GoRelPath(filename string) (string, error)

GoRelPath returns the GOPATH or GOROOT relative path for given filename

func InitCatMap

func InitCatMap()

InitCatMap initializes the CatMap

func InitSub2CatMap

func InitSub2CatMap()

InitSub2CatMap initializes the SubCatMap

func InitSubCatMap

func InitSubCatMap()

InitSubCatMap initializes the SubCatMap

func ParseCacheDir

func ParseCacheDir(lang fileinfo.Known) (string, error)

ParseCacheDir returns the parse cache directory for given language, and ensures that it exists.

func SaveSymCache

func SaveSymCache(sy *Symbol, lang fileinfo.Known, filename string) error

SaveSymCache saves cache of symbols starting with given symbol (typically a package, module, library), which is at given filename

func SaveSymDoc

func SaveSymDoc(sy *Symbol, lang fileinfo.Known, filename string) error

SaveSymDoc saves doc file of syms -- for double-checking contents etc

Types

type Kinds

type Kinds int32 //enums:enum

Kinds is a complete set of basic type categories and sub(sub..) categories -- these describe builtin types -- user-defined types must be some combination / version of these builtin types.

See: https://en.wikipedia.org/wiki/List_of_data_structures

const (
	// Unknown is the nil kind -- kinds should be known in general..
	Unknown Kinds = iota

	// Category: Primitive, in the strict sense of low-level, atomic, small, fixed size
	Primitive

	// SubCat: Numeric
	Numeric

	// Sub2Cat: Integer
	Integer

	// Sub3Cat: Signed -- track this using properties in types, not using Sub3 level
	Signed
	Int
	Int8
	Int16
	Int32
	Int64

	// Sub3Cat: Unsigned
	Unsigned
	Uint
	Uint8
	Uint16
	Uint32
	Uint64
	Uintptr // generic raw pointer data value -- see also Ptr, Ref for more semantic cases

	// Sub3Cat: Ptr, Ref etc -- in Numeric, Integer even though in some languages
	// pointer arithmetic might not be allowed, for some cases, etc
	Ptr       // pointer -- element is what we point to (kind of a composite type)
	Ref       // reference -- element is what we refer to
	UnsafePtr // for case where these are distinguished from Ptr (Go) -- similar to Uintptr

	// Sub2Cat: Fixed point -- could be under integer, but..
	Fixed
	Fixed26_6
	Fixed16_6
	Fixed0_32

	// Sub2Cat: Floating point
	Float
	Float16
	Float32
	Float64

	// Sub3Cat: Complex -- under floating point
	Complex
	Complex64
	Complex128

	// SubCat: Bool
	Bool

	// Category: Composite -- types composed of above primitive types
	Composite

	// SubCat: Tuple -- a fixed length 1d collection of elements that can be of any type
	// Type.Els required for each element
	Tuple
	Range // a special kind of tuple for Python ranges

	// SubCat: Array -- a fixed length 1d collection of same-type elements
	// Type.Els has one element for type
	Array

	// SubCat: List -- a variable-length 1d collection of same-type elements
	// This is Slice for Go
	// Type.Els has one element for type
	List
	String // List of some type of char rep -- Type.Els is type, as all Lists

	// SubCat: Matrix -- a twod collection of same-type elements
	// has two Size values, one for each dimension
	Matrix

	// SubCat: Tensor -- an n-dimensional collection of same-type elements
	// first element of Size is number of dimensions, rest are dimensions
	Tensor

	// SubCat: Map -- an associative array / hash map / dictionary
	// Type.Els first el is key, second is type
	Map

	// SubCat: Set -- typically a degenerate form of hash map with no value
	Set
	FrozenSet // python's frozen set of fixed values

	// SubCat: Struct -- like a tuple but with specific semantics in most languages
	// Type.Els are the fields, and if there is an inheritance relationship these
	// are put first with relevant identifiers -- in Go these are unnamed fields
	Struct
	Class
	Object

	// Chan: a channel (Go Specific)
	Chan

	// Category: Function -- types that are functions
	// Type.Els are the params and return values in order, with Size[0] being number
	// of params and Size[1] number of returns
	Function

	// SubCat: Func -- a standalone function
	Func

	// SubCat: Method -- a function with a specific receiver (e.g., on a Class in C++,
	// or on any type in Go).
	// First Type.Els is receiver param -- included in Size[0]
	Method

	// SubCat: Interface -- an abstract definition of a set of methods (in Go)
	// Type.Els are the Methods with the receiver type missing or Unknown
	Interface
)

The list of Kinds

const KindsN Kinds = 51

KindsN is the highest valid value for type Kinds, plus one.

func KindsValues

func KindsValues() []Kinds

KindsValues returns all possible values for the type Kinds.

func (Kinds) Cat

func (tk Kinds) Cat() Kinds

Cat returns the category that a given kind lives in, using CatMap

func (Kinds) Desc

func (i Kinds) Desc() string

Desc returns the description of the Kinds value.

func (Kinds) InCat

func (tk Kinds) InCat(other Kinds) bool

func (Kinds) InSub2Cat

func (tk Kinds) InSub2Cat(other Kinds) bool

func (Kinds) InSubCat

func (tk Kinds) InSubCat(other Kinds) bool

func (Kinds) Int64

func (i Kinds) Int64() int64

Int64 returns the Kinds value as an int64.

func (Kinds) IsCat

func (tk Kinds) IsCat() bool

IsCat returns true if this is a category-level kind

func (Kinds) IsPrimitiveNonPtr

func (tk Kinds) IsPrimitiveNonPtr() bool

func (Kinds) IsPtr

func (tk Kinds) IsPtr() bool

func (Kinds) IsSub2Cat

func (tk Kinds) IsSub2Cat() bool

IsSub2Cat returns true if this is a sub2-category-level kind

func (Kinds) IsSubCat

func (tk Kinds) IsSubCat() bool

IsSubCat returns true if this is a sub-category-level kind

func (Kinds) MarshalText

func (i Kinds) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*Kinds) SetInt64

func (i *Kinds) SetInt64(in int64)

SetInt64 sets the Kinds value from an int64.

func (*Kinds) SetString

func (i *Kinds) SetString(s string) error

SetString sets the Kinds value from its string representation, and returns an error if the string is invalid.

func (Kinds) String

func (i Kinds) String() string

String returns the string representation of this Kinds value.

func (Kinds) Sub2Cat

func (tk Kinds) Sub2Cat() Kinds

Sub2Cat returns the sub2-category that a given kind lives in, using Sub2CatMap

func (Kinds) SubCat

func (tk Kinds) SubCat() Kinds

SubCat returns the sub-category that a given kind lives in, using SubCatMap

func (*Kinds) UnmarshalText

func (i *Kinds) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Kinds) Values

func (i Kinds) Values() []enums.Enum

Values returns all possible values for the type Kinds.

type SymMap

type SymMap map[string]*Symbol

SymMap is a map between symbol names and their full information. A given project will have a top-level SymMap and perhaps local maps for individual files, etc. Namespaces / packages can be created and elements added to them to create appropriate scoping structure etc. Note that we have to use pointers for symbols b/c otherwise it is very expensive to re-assign values all the time -- https://github.com/golang/go/issues/3117

func (*SymMap) Add

func (sm *SymMap) Add(sy *Symbol)

Add adds symbol to map

func (*SymMap) AddNew

func (sm *SymMap) AddNew(name string, kind token.Tokens, fname string, reg lexer.Reg) *Symbol

AddNew adds a new symbol to the map with the basic info

func (*SymMap) Alloc

func (sm *SymMap) Alloc()

Alloc ensures that map is made

func (*SymMap) ClearAST added in v0.2.3

func (sm *SymMap) ClearAST()

ClearAST sets the AST pointers to nil for all symbols. otherwise the AST memory is never freed and can get quite large.

func (*SymMap) CopyFrom

func (sm *SymMap) CopyFrom(src SymMap, srcIsNewer bool)

CopyFrom copies all the symbols from given source map into this one, including merging everything from common elements. Symbols with Type resolved are retained when there are duplicates. srcIsNewer means that the src map has the newer information to grab for updating the symbol region info during the merge.

func (*SymMap) FindContainsRegion

func (sm *SymMap) FindContainsRegion(fpath string, pos lexer.Pos, extraLns int, kind token.Tokens, matches *SymMap)

FindContainsRegion looks for given symbol kind that contains the given source file path (must be filepath.Abs file path) and position. Returns all instances found. Uses cat / subcat based token matching -- if you specify a category-level or subcategory level token, it will match everything in that group. if you specify kind = token.None then all tokens that contain region will be returned. extraLns are extra lines added to the symbol region for purposes of matching.

func (*SymMap) FindKind

func (sm *SymMap) FindKind(kind token.Tokens, matches *SymMap)

FindKind looks for given symbol kind within this map and any children on the map Returns all instances found. Uses cat / subcat based token matching -- if you specify a category-level or subcategory level token, it will match everything in that group

func (*SymMap) FindKindScoped

func (sm *SymMap) FindKindScoped(kind token.Tokens, matches *SymMap)

FindKindScoped looks for given symbol kind within this map and any children on the map that are of subcategory token.NameScope (i.e., namespace, module, package, library). Returns all instances found. Uses cat / subcat based token matching -- if you specify a category-level or subcategory level token, it will match everything in that group

func (*SymMap) FindName

func (sm *SymMap) FindName(nm string) (*Symbol, bool)

FindName looks for given symbol name within this map and any children on the map

func (*SymMap) FindNamePrefix

func (sm *SymMap) FindNamePrefix(seed string, matches *SymMap)

FindNamePrefix looks for given symbol name prefix within this map adds to given matches map (which can be nil), for more efficient recursive use

func (*SymMap) FindNamePrefixRecursive

func (sm *SymMap) FindNamePrefixRecursive(seed string, matches *SymMap)

FindNamePrefixRecursive looks for given symbol name prefix within this map and any children on the map. adds to given matches map (which can be nil), for more efficient recursive use

func (*SymMap) FindNamePrefixScoped

func (sm *SymMap) FindNamePrefixScoped(seed string, matches *SymMap)

FindNamePrefixScoped looks for given symbol name prefix within this map and any children on the map that are of subcategory token.NameScope (i.e., namespace, module, package, library) adds to given matches map (which can be nil), for more efficient recursive use

func (*SymMap) FindNameScoped

func (sm *SymMap) FindNameScoped(nm string) (*Symbol, bool)

FindNameScoped looks for given symbol name within this map and any children on the map that are of subcategory token.NameScope (i.e., namespace, module, package, library)

func (*SymMap) First

func (sm *SymMap) First() *Symbol

First returns the first symbol in the map -- only sensible when there is just one such element

func (*SymMap) KindNames

func (sm *SymMap) KindNames(sorted bool) []string

KindNames returns a slice of the kind:names in this map, optionally sorted

func (*SymMap) Names

func (sm *SymMap) Names(sorted bool) []string

Names returns a slice of the names in this map, optionally sorted

func (*SymMap) OpenJSON

func (sm *SymMap) OpenJSON(filename string) error

OpenJSON opens from a JSON-formatted file.

func (*SymMap) Reset

func (sm *SymMap) Reset()

Reset resets the symbol map

func (*SymMap) SaveJSON

func (sm *SymMap) SaveJSON(filename string) error

SaveJSON saves to a JSON-formatted file.

func (*SymMap) Slice

func (sm *SymMap) Slice(sorted bool) []*Symbol

Slice returns a slice of the elements in the map, optionally sorted by name

func (*SymMap) WriteDoc

func (sm *SymMap) WriteDoc(out io.Writer, depth int)

WriteDoc writes basic doc info, sorted by kind and name

type SymNames

type SymNames map[token.Tokens]string

SymNames provides a map-list of symbol names, indexed by their token kinds. Used primarily for specifying Scopes

func (*SymNames) Clone

func (sn *SymNames) Clone() SymNames

Clone returns a clone copy of this map (nil if empty)

func (*SymNames) SubCat

func (sn *SymNames) SubCat(sc token.Tokens) (string, bool)

SubCat returns a scope with the given SubCat type, or false if not found

type SymStack

type SymStack []*Symbol

SymStack is a simple stack (slice) of symbols

func (*SymStack) ClearAST added in v0.2.3

func (ss *SymStack) ClearAST()

func (*SymStack) FindNameScoped

func (ss *SymStack) FindNameScoped(nm string) (*Symbol, bool)

FindNameScoped searches top-down in the stack for something with the given name in symbols that are of subcategory token.NameScope (i.e., namespace, module, package, library)

func (*SymStack) Pop

func (ss *SymStack) Pop() *Symbol

Pop takes symbol off the stack and returns it

func (*SymStack) Push

func (ss *SymStack) Push(sy *Symbol)

Push appends symbol to stack

func (*SymStack) PushNew

func (ss *SymStack) PushNew(name string, kind token.Tokens, fname string, reg lexer.Reg) *Symbol

PushNew adds a new symbol to the stack with the basic info

func (*SymStack) Reset

func (ss *SymStack) Reset()

Reset resets the stack

func (*SymStack) Top

func (ss *SymStack) Top() *Symbol

Top returns the state at the top of the stack (could be nil)

type Symbol

type Symbol struct {

	// name of the symbol
	Name string

	// additional detail and specification of the symbol -- e.g. if a function, the signature of the function
	Detail string

	// lexical kind of symbol, using token.Tokens list
	Kind token.Tokens

	// Type name for this symbol -- if it is a type, this is its corresponding type representation -- if it is a variable then this is its type
	Type string

	// index for ordering children within a given scope, e.g., fields in a struct / class
	Index int

	// full filename / URI of source
	Filename string

	// region in source encompassing this item -- if = RegZero then this is a temp symbol and children are not added to it
	Region lexer.Reg

	// region that should be selected when activated, etc
	SelectReg lexer.Reg

	// relevant scoping / parent symbols, e.g., namespace, package, module, class, function, etc..
	Scopes SymNames

	// children of this symbol -- this includes e.g., methods and fields of classes / structs / types, and all elements within packages, etc
	Children SymMap

	// types defined within the scope of this symbol
	Types TypeMap

	// AST node that created this symbol -- only valid during parsing
	AST tree.Node `json:"-" xml:"-"`
}

Symbol contains the information for everything about a given symbol that is created by parsing, and can be looked up. It corresponds to the LSP DocumentSymbol structure, and the Go Object type.

func NewSymbol

func NewSymbol(name string, kind token.Tokens, fname string, reg lexer.Reg) *Symbol

NewSymbol returns a new symbol with the basic info filled in -- SelectReg defaults to Region

func OpenSymCache

func OpenSymCache(lang fileinfo.Known, filename string) (*Symbol, time.Time, error)

OpenSymCache opens cache of symbols into given symbol (typically a package, module, library), which is at given filename -- returns time stamp when cache was last saved

func (*Symbol) AddChild

func (sy *Symbol) AddChild(child *Symbol) bool

AddChild adds a child symbol, if this parent symbol is not temporary returns true if item name was added and NOT already on the map, and false if it was already or parent is temp. Always adds new symbol in any case. If parent symbol is of the NameType subcategory, then index of child is set to the size of this child map before adding.

func (*Symbol) AddScopesMap

func (sy *Symbol) AddScopesMap(sm SymMap, add bool)

AddScopesMap adds a given scope element(s) from map to this Symbol. if add is true, add this symbol to those scopes if they are not temporary.

func (*Symbol) AddScopesStack

func (sy *Symbol) AddScopesStack(ss SymStack) bool

AddScopesStack adds a given scope element(s) from stack to this Symbol. Adds this symbol as a child to the top of the scopes if it is not temporary -- returns true if so added.

func (*Symbol) AllocScopes

func (sy *Symbol) AllocScopes()

AllocScopes allocates scopes map if nil

func (*Symbol) ClearAST added in v0.2.3

func (sm *Symbol) ClearAST()

ClearAST sets the AST pointers to nil for all symbols in this one. otherwise the AST memory is never freed and can get quite large.

func (*Symbol) Clone

func (sy *Symbol) Clone() *Symbol

Clone returns a clone copy of this symbol. Does NOT copy the Children or Types -- caller can decide about that.

func (*Symbol) CopyFromScope

func (sy *Symbol) CopyFromScope(src *Symbol)

CopyFromScope copies the Children and Types from given other symbol for scopes (e.g., Go package), to merge with existing.

func (*Symbol) CopyFromSrc

func (sy *Symbol) CopyFromSrc(cp *Symbol)

CopyFromSrc copies all the source-related fields from other symbol (no Type, Types, or Children). AST is only copied if non-nil.

func (*Symbol) FindAnyChildren

func (sy *Symbol) FindAnyChildren(seed string, scope1, scope2 SymMap, kids *SymMap) bool

FindAnyChildren finds children of this symbol using either direct children if those are present, or the type name if present -- used for completion routines. Adds to kids map. scope1, scope2 are used for looking up type name. If seed is non-empty it is used as a prefix for filtering children names. Returns false if no children were found.

func (*Symbol) HasChildren

func (sy *Symbol) HasChildren() bool

HasChildren returns true if this symbol has children

func (*Symbol) IsTemp

func (sy *Symbol) IsTemp() bool

IsTemp returns true if this is temporary symbol that is used for scoping but is not otherwise permanently added to list of symbols. Indicated by Zero Region.

func (*Symbol) Label

func (sy *Symbol) Label() string

Label satisfies core.Labeler interface -- nicer presentation label

func (*Symbol) NonPtrTypeName

func (sy *Symbol) NonPtrTypeName() string

NonPtrTypeName returns the name of the type without any leading * or &

func (*Symbol) OpenJSON

func (sy *Symbol) OpenJSON(filename string) error

OpenJSON opens from a JSON-formatted file.

func (*Symbol) SaveJSON

func (sy *Symbol) SaveJSON(filename string) error

SaveJSON saves to a JSON-formatted file.

func (*Symbol) String

func (sy *Symbol) String() string

String satisfies fmt.Stringer interface

func (*Symbol) WriteDoc

func (sy *Symbol) WriteDoc(out io.Writer, depth int)

WriteDoc writes basic doc info

type Type

type Type struct {

	// name of the type -- can be the name of a field or the role for a type element
	Name string

	// kind of type -- overall nature of the type
	Kind Kinds

	// documentation about this type, extracted from code
	Desc string

	// set to true after type has been initialized during post-parse processing
	Initialized bool `edit:"-"`

	// elements of this type -- ordering and meaning varies depending on the Kind of type -- for Primitive types this is the parent type, for Composite types it describes the key elements of the type: Tuple = each element's type; Array = type of elements; Struct = each field, etc (see docs for each in Kinds)
	Els TypeEls

	// methods defined for this type
	Meths TypeMap

	// for primitive types, this is the number of bytes, for composite types, it is the number of elements, which can be multi-dimensional (e.g., for functions, number of params is (including receiver param for methods) and return vals is )
	Size []int

	// full filename / URI of source where type is defined (may be empty for auto types)
	Filename string

	// region in source encompassing this type
	Region lexer.Reg

	// relevant scoping / parent symbols, e.g., namespace, package, module, class, function, etc..
	Scopes SymNames

	// additional type properties, such as const, virtual, static -- these are just recorded textually and not systematized to keep things open-ended -- many of the most important properties can be inferred from the Kind property
	Properties map[string]any

	// AST node that corresponds to this type -- only valid during parsing
	AST tree.Node `json:"-" xml:"-"`
}

Type contains all the information about types. Types can be builtin or composed of builtin types. Each type can have one or more elements, e.g., fields for a struct or class, multiple values for a go function, or the two types for a map (key, value), etc..

func NewType

func NewType(name string, kind Kinds) *Type

NewType returns a new Type struct initialized with given name and kind

func (*Type) AddScopesStack

func (ty *Type) AddScopesStack(ss SymStack)

AddScopesStack adds a given scope element(s) from stack to this Type.

func (*Type) AllocScopes

func (ty *Type) AllocScopes()

AllocScopes allocates scopes map if nil

func (*Type) ArgString

func (ty *Type) ArgString() string

ArgString() returns string of args to function if it is a function type

func (*Type) ClearAST added in v0.2.3

func (ty *Type) ClearAST()

ClearAST sets the AST pointers to nil for all symbols in this one. otherwise the AST memory is never freed and can get quite large.

func (*Type) Clone

func (ty *Type) Clone() *Type

Clone returns a deep copy of this type, cloning / copying all sub-elements except the AST and Initialized

func (*Type) CopyFromSrc

func (ty *Type) CopyFromSrc(cp *Type)

CopyFromSrc copies source-level data from given other type

func (*Type) NonPtrType

func (ty *Type) NonPtrType() string

NonPtrType returns the non-pointer name of this type, if it is a pointer type otherwise just returns Name

func (*Type) ReturnString

func (ty *Type) ReturnString() string

ReturnString() returns string of return vals of function if it is a function type

func (*Type) String

func (ty *Type) String() string

String() satisfies the fmt.Stringer interface

func (*Type) WriteDoc

func (ty *Type) WriteDoc(out io.Writer, depth int)

WriteDoc writes basic doc info

type TypeEl

type TypeEl struct {

	// element name -- e.g., field name for struct, or functional name for other types
	Name string

	// type name -- looked up on relevant lists -- includes scoping / package / namespace name as appropriate
	Type string
}

TypeEl is a type element -- has a name (local to the type, e.g., field name) and a type name that can be looked up in a master list of types

func (*TypeEl) Clone

func (tel *TypeEl) Clone() *TypeEl

Clone() returns a copy of this el

func (*TypeEl) String

func (tel *TypeEl) String() string

String() satisfies the fmt.Stringer interface

type TypeEls

type TypeEls []TypeEl

TypeEls are the type elements for types

func (*TypeEls) Add

func (te *TypeEls) Add(nm, typ string)

Add adds a new type element

func (*TypeEls) ByName

func (te *TypeEls) ByName(nm string) *TypeEl

ByName returns type el with given name, nil if not there

func (*TypeEls) ByType

func (te *TypeEls) ByType(typ string) *TypeEl

ByType returns type el with given type, nil if not there

func (*TypeEls) CopyFrom

func (te *TypeEls) CopyFrom(cp TypeEls)

CopyFrom copies from another list

func (*TypeEls) String

func (te *TypeEls) String() string

String() satisfies the fmt.Stringer interface

func (*TypeEls) StringRange

func (te *TypeEls) StringRange(st, n int) string

StringRange() returns a string rep of range of items

type TypeKindSize

type TypeKindSize struct {
	Name string
	Kind Kinds
	Size int
}

TypeKindSize is used for initialization of builtin typemaps

type TypeMap

type TypeMap map[string]*Type

TypeMap is a map of types for quick looking up by name

func (*TypeMap) Add

func (tm *TypeMap) Add(ty *Type)

Add adds a type to the map, handling allocation for nil maps

func (*TypeMap) Alloc

func (tm *TypeMap) Alloc()

Alloc ensures that map is made

func (*TypeMap) ClearAST added in v0.2.3

func (tm *TypeMap) ClearAST()

ClearAST sets the AST pointers to nil for all symbols. otherwise the AST memory is never freed and can get quite large.

func (*TypeMap) Clone

func (tm *TypeMap) Clone() TypeMap

Clone returns deep copy of this type map -- types are Clone() copies. returns nil if this map is empty

func (*TypeMap) CopyFrom

func (tm *TypeMap) CopyFrom(src TypeMap, srcIsNewer bool)

CopyFrom copies all the types from given source map into this one. Types that have Kind != Unknown are retained over unknown ones. srcIsNewer means that the src type is newer and should be used for other data like source

func (*TypeMap) KindNames

func (tm *TypeMap) KindNames(sorted bool) []string

KindNames returns a slice of the kind:names in this map, optionally sorted

func (*TypeMap) Names

func (tm *TypeMap) Names(sorted bool) []string

Names returns a slice of the names in this map, optionally sorted

func (*TypeMap) PrintUnknowns

func (tm *TypeMap) PrintUnknowns()

PrintUnknowns prints all the types that have a Kind = Unknown indicates an error in type resolution

func (*TypeMap) WriteDoc

func (tm *TypeMap) WriteDoc(out io.Writer, depth int)

WriteDoc writes basic doc info, sorted by kind and name

Jump to

Keyboard shortcuts

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