golang

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuiltinFuncs = []string{
	"append",
	"copy",
	"delete",
	"len",
	"cap",
	"make",
	"new",
	"complex",
	"real",
	"imag",
	"close",
	"panic",
	"recover",
}

BuiltinFuncs are functions builtin to the Go language

View Source
var BuiltinKeywords = []string{
	"break",
	"case",
	"chan",
	"const",
	"continue",
	"default",
	"defer",
	"else",
	"fallthrough",
	"for",
	"func",
	"go",
	"goto",
	"if",
	"import",
	"interface",
	"map",
	"package",
	"range",
	"return",
	"select",
	"struct",
	"switch",
	"type",
	"var",
}

BuiltinKeywords are keywords built into Go -- for, range, etc

View Source
var BuiltinMisc = []string{
	"true",
	"false",
}

BuiltinMisc are misc builtin items

View Source
var BuiltinPackages = []string{}/* 134 elements not displayed */

BuiltinPackages are the standard library packages

View Source
var BuiltinTypeKind = []syms.TypeKindSize{
	{"int", syms.Int, int(unsafe.Sizeof(int(0)))},
	{"int8", syms.Int8, 1},
	{"int16", syms.Int16, 2},
	{"int32", syms.Int32, 4},
	{"int64", syms.Int64, 8},

	{"uint", syms.Uint, int(unsafe.Sizeof(uint(0)))},
	{"uint8", syms.Uint8, 1},
	{"uint16", syms.Uint16, 2},
	{"uint32", syms.Uint32, 4},
	{"uint64", syms.Uint64, 8},
	{"uintptr", syms.Uintptr, 8},

	{"byte", syms.Uint8, 1},
	{"rune", syms.Int32, 4},

	{"float32", syms.Float32, 4},
	{"float64", syms.Float64, 8},

	{"complex64", syms.Complex64, 8},
	{"complex128", syms.Complex128, 16},

	{"bool", syms.Bool, 1},

	{"string", syms.String, 0},

	{"error", syms.Interface, 0},

	{"struct{}", syms.Struct, 0},
	{"interface{}", syms.Interface, 0},
}

BuiltinTypeKind are the type names and kinds for builtin Go primitive types (i.e., those with names)

View Source
var BuiltinTypes syms.TypeMap
View Source
var CompleteTrace = false
View Source
var ParseDirExcludes = []string{
	"/image/font/gofont/",
	"zerrors_",
	"unicode/tables.go",
	"filecat/mimetype.go",
	"/html/entity.go",
	"/draw/impl.go",
	"/truetype/hint.go",
	"/runtime/proc.go",
}

ParseDirExcludes are files to exclude in processing directories because they take a long time and aren't very useful (data files). Any file that contains one of these strings is excluded.

View Source
var TheGoLang = GoLang{}

TheGoLang is the instance variable providing support for the Go language

View Source
var TraceTypes = false
View Source
var TypeErr = "<err>"

TypeErr indicates is the type name we use to indicate that the type could not be inferred

View Source
var TypeInProcess = "<in-process>"

TypeInProcess indicates is the type name we use to indicate that the type is currently being processed -- prevents loops

View Source
var TypeToKindMap = map[string]syms.Kinds{
	"BasicType":     syms.Primitive,
	"TypeNm":        syms.Primitive,
	"QualType":      syms.Primitive,
	"PointerType":   syms.Primitive,
	"MapType":       syms.Composite,
	"SliceType":     syms.Composite,
	"ArrayType":     syms.Composite,
	"StructType":    syms.Composite,
	"InterfaceType": syms.Composite,
	"FuncType":      syms.Composite,
	"StringDbl":     syms.KindsN,
	"StringTicks":   syms.KindsN,
	"Rune":          syms.KindsN,
	"NumInteger":    syms.KindsN,
	"NumFloat":      syms.KindsN,
	"NumImag":       syms.KindsN,
}

TypeToKindMap maps Ast type names to syms.Kind basic categories for how we treat them for subsequent processing. Basically: Primitive or Composite

Functions

func InstallBuiltinTypes

func InstallBuiltinTypes()

InstallBuiltinTypes initializes the BuiltinTypes map

func IsQualifiedType

func IsQualifiedType(tnm string) bool

IsQualifiedType returns true if type is qualified by a package prefix is sensitive to [] or map[ prefix so it does NOT report as a qualified type in that case -- it is a compound local type defined in terms of a qualified type.

func PrefixType

func PrefixType(pfx, nm string) string

PrefixType returns the type name prefixed with given prefix -- keeps any package name as the outer scope.

func QualifyType

func QualifyType(pkgnm, tnm string) string

QualifyType returns the type name tnm qualified by pkgnm if it is non-empty and only if tnm is not a basic type name

func SplitType

func SplitType(nm string) (pkgnm, tnm string)

SplitType returns the package and type names from a potentially qualified type name -- if it is not qualified, package name is empty. is sensitive to [] prefix so it does NOT split in that case

func SymTypeNameForPkg

func SymTypeNameForPkg(ty *syms.Type, pkg *syms.Symbol) string

Types

type GoLang

type GoLang struct {
	Pr *pi.Parser
}

GoLang implements the Lang interface for the Go language

func (*GoLang) AddImportToExts

func (gl *GoLang) AddImportToExts(fs *pi.FileState, im string, lock bool)

AddImportToExts adds given import into pi.FileState.ExtSyms list assumed to be called as a separate goroutine

func (*GoLang) AddImportsToExts

func (gl *GoLang) AddImportsToExts(fss *pi.FileStates, pfs *pi.FileState, pkg *syms.Symbol)

AddImportsToExts adds imports from given package into pi.FileState.ExtSyms list imports are coded as NameLibrary symbols with names = import path

func (*GoLang) AddPathToExts

func (gl *GoLang) AddPathToExts(fs *pi.FileState, path string)

AddPathToExts adds given path into pi.FileState.ExtSyms list assumed to be called as a separate goroutine

func (*GoLang) AddPathToSyms

func (gl *GoLang) AddPathToSyms(fs *pi.FileState, path string)

AddPathToSyms adds given path into pi.FileState.Syms list Is called as a separate goroutine in ParseFile with WaitGp

func (*GoLang) AddPkgToExts

func (gl *GoLang) AddPkgToExts(fs *pi.FileState, pkg *syms.Symbol) bool

AddPkgToExts adds given package symbol, with children from package to pi.FileState.ExtSyms map -- merges with anything already there does NOT add imports -- that is an optional second step. Returns true if there was an existing entry for this package.

func (*GoLang) AddPkgToSyms

func (gl *GoLang) AddPkgToSyms(fs *pi.FileState, pkg *syms.Symbol) bool

AddPkgToSyms adds given package symbol, with children from package to pi.FileState.Syms map -- merges with anything already there does NOT add imports -- that is an optional second step. Returns true if there was an existing entry for this package.

func (*GoLang) AstTypeName

func (gl *GoLang) AstTypeName(tyast *parse.Ast) string

AstTypeName returns the effective type name from ast node dropping the "Lit" for example.

func (*GoLang) AutoBracket

func (gl *GoLang) AutoBracket(fs *pi.FileStates, bra rune, pos lex.Pos, curLn []rune) (match, newLine bool)

AutoBracket returns what to do when a user types a starting bracket character (bracket, brace, paren) while typing. pos = position where bra will be inserted, and curLn is the current line match = insert the matching ket, and newLine = insert a new line.

func (*GoLang) CompleteAstStart

func (gl *GoLang) CompleteAstStart(ast *parse.Ast, scope token.Tokens) (start, last *parse.Ast)

CompleteAstStart finds the best starting point in the given current-line Ast to start completion process, which walks back down from that starting point

func (*GoLang) CompleteBuiltins

func (gl *GoLang) CompleteBuiltins(fs *pi.FileState, seed string, md *complete.Matches)

func (*GoLang) CompleteEdit

func (gl *GoLang) CompleteEdit(fss *pi.FileStates, text string, cp int, comp complete.Completion, seed string) (ed complete.Edit)

CompleteEdit returns the completion edit data for integrating the selected completion into the source

func (*GoLang) CompleteLine

func (gl *GoLang) CompleteLine(fss *pi.FileStates, str string, pos lex.Pos) (md complete.Matches)

CompleteLine is the main api called by completion code in giv/complete.go

func (*GoLang) CompletePkgSyms

func (gl *GoLang) CompletePkgSyms(fs *pi.FileState, pkg *syms.Symbol, seed string, md *complete.Matches)

CompletePkgSyms matches all package symbols using seed

func (*GoLang) CompletePosScope

func (gl *GoLang) CompletePosScope(fs *pi.FileState, pos lex.Pos, fpath string, scopes *syms.SymMap) token.Tokens

CompletePosScope returns the scope for given position in given filename, and fills in the scoping symbol(s) in scMap

func (*GoLang) CompleteTypeName

func (gl *GoLang) CompleteTypeName(fs *pi.FileState, pkg *syms.Symbol, seed string, md *complete.Matches)

CompleteTypeName matches builtin and package type names to seed

func (*GoLang) DeleteExternalTypes

func (gl *GoLang) DeleteExternalTypes(sy *syms.Symbol)

DeleteExternalTypes deletes types from outside current package scope. These can be created during ResolveTypes but should be deleted before saving symbol type.

func (*GoLang) DeleteUnexported

func (gl *GoLang) DeleteUnexported(sy *syms.Symbol, pkgsc string)

DeleteUnexported deletes lower-case unexported items from map, and children of symbols on map

func (*GoLang) FindImportPkg

func (gl *GoLang) FindImportPkg(fs *pi.FileState, psyms syms.SymMap, nm string) (*syms.Symbol, bool)

FindImportPkg attempts to find an import package based on symbols in an existing package. For indirect loading of packages from other packages that we don't direct import.

func (*GoLang) FindTypeName

func (gl *GoLang) FindTypeName(tynm string, fs *pi.FileState, pkg *syms.Symbol) (*syms.Type, *syms.Symbol)

FindTypeName finds given type name in pkg and in broader context returns new package symbol if type name is in a different package else returns pkg arg.

func (*GoLang) FuncParams

func (gl *GoLang) FuncParams(fsym *syms.Symbol) []string

FuncParams returns the parameters of given function / method symbol, in proper order, name type for each param space separated in string

func (*GoLang) FuncTypeFromAst

func (gl *GoLang) FuncTypeFromAst(fs *pi.FileState, pkg *syms.Symbol, ast *parse.Ast, fty *syms.Type) *syms.Type

FuncTypeFromAst initializes a function type from ast -- type can either be anon or a named type -- if anon then the name is the full type signature without param names

func (*GoLang) HiLine

func (gl *GoLang) HiLine(fss *pi.FileStates, line int, txt []rune) lex.Line

func (*GoLang) ImportPathPkg

func (gl *GoLang) ImportPathPkg(im string) (path, base, pkg string)

ImportPathPkg returns the package (last dir) and base of import path from import path string -- removes any quotes around path first.

func (*GoLang) IndentLine

func (gl *GoLang) IndentLine(fs *pi.FileStates, src [][]rune, tags []lex.Line, ln int, tabSz int) (pInd, delInd, pLn int, ichr indent.Char)

IndentLine returns the indentation level for given line based on previous line's indentation level, and any delta change based on e.g., brackets starting or ending the previous or current line, or other language-specific keywords. See lex.BracketIndentLine for example. Indent level is in increments of tabSz for spaces, and tabs for tabs. Operates on rune source with markup lex tags per line.

func (*GoLang) InferEmptySymbolType

func (gl *GoLang) InferEmptySymbolType(sym *syms.Symbol, fs *pi.FileState, pkg *syms.Symbol) bool

InferEmptySymbolType ensures that any empty symbol type is resolved during processing of other type information -- returns true if was able to resolve

func (*GoLang) InferForRangeSymbolType

func (gl *GoLang) InferForRangeSymbolType(sy *syms.Symbol, fs *pi.FileState, pkg *syms.Symbol)

InferForRangeSymbolType infers the type of a ForRange expr gets the container type properly

func (*GoLang) InferSymbolType

func (gl *GoLang) InferSymbolType(sy *syms.Symbol, fs *pi.FileState, pkg *syms.Symbol, funInternal bool)

InferSymbolType infers the symbol types for given symbol and all of its children funInternal determines whether to include function-internal symbols (e.g., variables within function scope -- only for local files).

func (*GoLang) InitTypeFromAst

func (gl *GoLang) InitTypeFromAst(fs *pi.FileState, pkg *syms.Symbol, ty *syms.Type)

InitTypeFromAst initializes given type from ast

func (*GoLang) LexLine

func (gl *GoLang) LexLine(fs *pi.FileState, line int, txt []rune) lex.Line

func (*GoLang) Lookup

func (gl *GoLang) Lookup(fss *pi.FileStates, str string, pos lex.Pos) (ld complete.Lookup)

Lookup is the main api called by completion code in giv/complete.go to lookup item

func (*GoLang) LookupString

func (gl *GoLang) LookupString(fs *pi.FileState, pkg *syms.Symbol, scopes syms.SymMap, str string) (ld complete.Lookup)

LookupString attempts to lookup a string, which could be a type name, (with package qualifier), could be partial, etc

func (*GoLang) NamesFromAst

func (gl *GoLang) NamesFromAst(fs *pi.FileState, pkg *syms.Symbol, ast *parse.Ast, idx int) []string

NamesFromAst returns a slice of name(s) from namelist nodes

func (*GoLang) ParamsFromAst

func (gl *GoLang) ParamsFromAst(fs *pi.FileState, pkg *syms.Symbol, pars *parse.Ast, fty *syms.Type, name string)

ParamsFromAst sets params as Els for given function type (also for return types)

func (*GoLang) ParseDir

func (gl *GoLang) ParseDir(fs *pi.FileState, path string, opts pi.LangDirOpts) *syms.Symbol

ParseDir is the interface call for parsing a directory

func (*GoLang) ParseDirImpl

func (gl *GoLang) ParseDirImpl(fs *pi.FileState, path string, opts pi.LangDirOpts) *syms.Symbol

ParseDirImpl does the actual work of parsing a directory. Path is assumed to be a package import path or a local file name

func (*GoLang) ParseFile

func (gl *GoLang) ParseFile(fss *pi.FileStates, txt []byte)

ParseFile is the main point of entry for external calls into the parser

func (*GoLang) ParseLine

func (gl *GoLang) ParseLine(fs *pi.FileState, line int) *pi.FileState

func (*GoLang) Parser

func (gl *GoLang) Parser() *pi.Parser

func (*GoLang) PkgSyms

func (gl *GoLang) PkgSyms(fs *pi.FileState, psyms syms.SymMap, pnm string) (*syms.Symbol, bool)

PkgSyms attempts to find package symbols for given package name. Is also passed any current package symbol context in psyms which might be different from default filestate context.

func (*GoLang) ResolveTypes

func (gl *GoLang) ResolveTypes(fs *pi.FileState, pkg *syms.Symbol, funInternal bool)

ResolveTypes initializes all user-defined types from Ast data and then resolves types of symbols. The pkg must be a single package symbol i.e., the children there are all the elements of the package and the types are all the global types within the package. funInternal determines whether to include function-internal symbols (e.g., variables within function scope -- only for local files).

func (*GoLang) RvalsFromAst

func (gl *GoLang) RvalsFromAst(fs *pi.FileState, pkg *syms.Symbol, rvals *parse.Ast, fty *syms.Type)

RvalsFromAst sets return value(s) as Els for given function type

func (*GoLang) StructInheritEls

func (gl *GoLang) StructInheritEls(fs *pi.FileState, pkg *syms.Symbol, ty *syms.Type, etynm string)

StructInheritEls inherits struct fields and meths from given embedded type. Ensures that copied values are properly qualified if from another package.

func (*GoLang) SubTypeFromAst

func (gl *GoLang) SubTypeFromAst(fs *pi.FileState, pkg *syms.Symbol, ast *parse.Ast, idx int) (*syms.Type, bool)

SubTypeFromAst returns a subtype from child ast at given index, nil if failed

func (*GoLang) TypeFromAst

func (gl *GoLang) TypeFromAst(fs *pi.FileState, pkg *syms.Symbol, ty *syms.Type, tyast *parse.Ast) (*syms.Type, bool)

TypeFromAst returns type from Ast parse -- returns true if successful. This is used both for initialization of global types via TypesFromAst and also for online type processing in the course of tracking down other types while crawling the Ast. In the former case, ty is non-nil and the goal is to fill out the type information -- the ty will definitely have a name already. In the latter case, the ty will be nil, but the tyast node may have a Src name that will first be looked up to determine if a previously-processed type is already available. The tyast.Name is the parser categorization of the type (BasicType, StructType, etc).

func (*GoLang) TypeFromAstComp

func (gl *GoLang) TypeFromAstComp(fs *pi.FileState, pkg *syms.Symbol, ty *syms.Type, tyast *parse.Ast) (*syms.Type, bool)

TypeFromAstComp handles composite type processing

func (*GoLang) TypeFromAstExpr

func (gl *GoLang) TypeFromAstExpr(fs *pi.FileState, origPkg, pkg *syms.Symbol, tyast, last *parse.Ast) (*syms.Type, *parse.Ast, bool)

TypeFromAstExpr walks the ast expression to find the type. It returns the type, any Ast node that remained unprocessed at the end, and bool if found.

func (*GoLang) TypeFromAstExprStart

func (gl *GoLang) TypeFromAstExprStart(fs *pi.FileState, origPkg, pkg *syms.Symbol, tyast *parse.Ast) (*syms.Type, *parse.Ast, bool)

TypeFromAstExprStart starts walking the ast expression to find the type. This computes the last ast point as the stopping point for processing and then calls TypeFromAstExpr. It returns the type, any Ast node that remained unprocessed at the end, and bool if found.

func (*GoLang) TypeFromAstLit

func (gl *GoLang) TypeFromAstLit(fs *pi.FileState, pkg *syms.Symbol, ty *syms.Type, tyast *parse.Ast) (*syms.Type, bool)

TypeFromAstLit gets type from literals

func (*GoLang) TypeFromAstName

func (gl *GoLang) TypeFromAstName(fs *pi.FileState, origPkg, pkg *syms.Symbol, tyast, last *parse.Ast, conts syms.SymMap) (*syms.Type, *parse.Ast, bool)

TypeFromAstName gets type from a Name in a given context (conts)

func (*GoLang) TypeFromAstPrim

func (gl *GoLang) TypeFromAstPrim(fs *pi.FileState, pkg *syms.Symbol, ty *syms.Type, tyast *parse.Ast) (*syms.Type, bool)

TypeFromAstPrim handles primitive (non composite) type processing

func (*GoLang) TypeFromAstSym

func (gl *GoLang) TypeFromAstSym(fs *pi.FileState, origPkg, pkg *syms.Symbol, tyast, last *parse.Ast, sym *syms.Symbol) (*syms.Type, *parse.Ast, bool)

TypeFromAstSym attempts to get the type from given symbol as part of expression. It returns the type, any Ast node that remained unprocessed at the end, and bool if found.

func (*GoLang) TypeFromAstType

func (gl *GoLang) TypeFromAstType(fs *pi.FileState, origPkg, pkg *syms.Symbol, tyast, last *parse.Ast, tnm string) (*syms.Type, *parse.Ast, bool)

TypeFromAstType walks the ast expression to find the type, starting from current type name. It returns the type, any Ast node that remained unprocessed at the end, and bool if found.

func (*GoLang) TypeFromFuncCall

func (gl *GoLang) TypeFromFuncCall(fs *pi.FileState, origPkg, pkg *syms.Symbol, tyast, last *parse.Ast, ftyp *syms.Type) (*syms.Type, *parse.Ast, bool)

TypeFromAstFuncCall gets return type of function call as return value, and returns the sibling node to continue parsing in, skipping over everything in the function call

func (*GoLang) TypeMeths

func (gl *GoLang) TypeMeths(fs *pi.FileState, pkg *syms.Symbol, ty *syms.Type)

TypeMeths gathers method types from the type symbol's children

func (*GoLang) TypesFromAst

func (gl *GoLang) TypesFromAst(fs *pi.FileState, pkg *syms.Symbol)

TypesFromAst initializes the types from their Ast parse

type ParseDirLock

type ParseDirLock struct {

	// logical import path
	Path string

	Processing bool

	// mutex protecting processing of this path
	Mu sync.Mutex `json:"-" xml:"-"`
}

ParseDirLock provides a lock protecting parsing of a package directory

type ParseDirLocks

type ParseDirLocks struct {

	// map of paths with processing status
	Dirs map[string]*ParseDirLock

	// mutex protecting access to Dirs
	Mu sync.Mutex `json:"-" xml:"-"`
}

ParseDirLocks manages locking for parsing package directories

var TheParseDirs ParseDirLocks

TheParseDirs is the parse dirs locking manager

func (*ParseDirLocks) ParseDir

func (pd *ParseDirLocks) ParseDir(gl *GoLang, fs *pi.FileState, path string, opts pi.LangDirOpts) *syms.Symbol

ParseDir is how you call ParseDir on a given path in a secure way that is managed for multiple accesses. If dir is currently being parsed, then the mutex is locked and caller will wait until that is done -- at which point the next one should be able to load parsed symbols instead of parsing fresh. Once the symbols are returned, then the local FileState SymsMu lock must be used when integrating any external symbols back into another filestate. As long as all the symbol resolution etc is all happening outside of the external syms linking, then it does not need to be protected.

Jump to

Keyboard shortcuts

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