golang

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: 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 *parse.Parser
}

GoLang implements the Lang interface for the Go language

func (*GoLang) ASTTypeName

func (gl *GoLang) ASTTypeName(tyast *parser.AST) string

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

func (*GoLang) AddImportToExts

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

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

func (*GoLang) AddImportsToExts

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

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

func (*GoLang) AddPathToExts

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

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

func (*GoLang) AddPathToSyms

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

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

func (*GoLang) AddPkgToExts

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

AddPkgToExts adds given package symbol, with children from package to parse.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 *parse.FileState, pkg *syms.Symbol) bool

AddPkgToSyms adds given package symbol, with children from package to parse.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) AutoBracket

func (gl *GoLang) AutoBracket(fs *parse.FileStates, bra rune, pos lexer.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 *parser.AST, scope token.Tokens) (start, last *parser.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 *parse.FileState, seed string, md *complete.Matches)

func (*GoLang) CompleteEdit

func (gl *GoLang) CompleteEdit(fss *parse.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 *parse.FileStates, str string, pos lexer.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 *parse.FileState, pkg *syms.Symbol, seed string, md *complete.Matches)

CompletePkgSyms matches all package symbols using seed

func (*GoLang) CompletePosScope

func (gl *GoLang) CompletePosScope(fs *parse.FileState, pos lexer.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 *parse.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 *parse.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 *parse.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 *parse.FileState, pkg *syms.Symbol, ast *parser.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) HighlightLine

func (gl *GoLang) HighlightLine(fss *parse.FileStates, line int, txt []rune) lexer.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 *parse.FileStates, src [][]rune, tags []lexer.Line, ln int, tabSz int) (pInd, delInd, pLn int, ichr indent.Character)

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 lexer.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 *parse.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 *parse.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 *parse.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 *parse.FileState, pkg *syms.Symbol, ty *syms.Type)

InitTypeFromAST initializes given type from ast

func (*GoLang) LexLine

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

func (*GoLang) Lookup

func (gl *GoLang) Lookup(fss *parse.FileStates, str string, pos lexer.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 *parse.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 *parse.FileState, pkg *syms.Symbol, ast *parser.AST, idx int) []string

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

func (*GoLang) ParamsFromAST

func (gl *GoLang) ParamsFromAST(fs *parse.FileState, pkg *syms.Symbol, pars *parser.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 *parse.FileState, path string, opts parse.LanguageDirOptions) *syms.Symbol

ParseDir is the interface call for parsing a directory

func (*GoLang) ParseDirImpl

func (gl *GoLang) ParseDirImpl(fs *parse.FileState, path string, opts parse.LanguageDirOptions) *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 *parse.FileStates, txt []byte)

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

func (*GoLang) ParseLine

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

func (*GoLang) Parser

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

func (*GoLang) PkgSyms

func (gl *GoLang) PkgSyms(fs *parse.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 *parse.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 *parse.FileState, pkg *syms.Symbol, rvals *parser.AST, fty *syms.Type)

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

func (*GoLang) StructInheritEls

func (gl *GoLang) StructInheritEls(fs *parse.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 *parse.FileState, pkg *syms.Symbol, ast *parser.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 *parse.FileState, pkg *syms.Symbol, ty *syms.Type, tyast *parser.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 *parse.FileState, pkg *syms.Symbol, ty *syms.Type, tyast *parser.AST) (*syms.Type, bool)

TypeFromASTComp handles composite type processing

func (*GoLang) TypeFromASTExpr

func (gl *GoLang) TypeFromASTExpr(fs *parse.FileState, origPkg, pkg *syms.Symbol, tyast, last *parser.AST) (*syms.Type, *parser.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 *parse.FileState, origPkg, pkg *syms.Symbol, tyast *parser.AST) (*syms.Type, *parser.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 *parse.FileState, pkg *syms.Symbol, ty *syms.Type, tyast *parser.AST) (*syms.Type, bool)

TypeFromASTLit gets type from literals

func (*GoLang) TypeFromASTName

func (gl *GoLang) TypeFromASTName(fs *parse.FileState, origPkg, pkg *syms.Symbol, tyast, last *parser.AST, conts syms.SymMap) (*syms.Type, *parser.AST, bool)

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

func (*GoLang) TypeFromASTPrim

func (gl *GoLang) TypeFromASTPrim(fs *parse.FileState, pkg *syms.Symbol, ty *syms.Type, tyast *parser.AST) (*syms.Type, bool)

TypeFromASTPrim handles primitive (non composite) type processing

func (*GoLang) TypeFromASTSym

func (gl *GoLang) TypeFromASTSym(fs *parse.FileState, origPkg, pkg *syms.Symbol, tyast, last *parser.AST, sym *syms.Symbol) (*syms.Type, *parser.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 *parse.FileState, origPkg, pkg *syms.Symbol, tyast, last *parser.AST, tnm string) (*syms.Type, *parser.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 *parse.FileState, origPkg, pkg *syms.Symbol, tyast, last *parser.AST, ftyp *syms.Type) (*syms.Type, *parser.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 *parse.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 *parse.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 *parse.FileState, path string, opts parse.LanguageDirOptions) *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