Documentation
¶
Index ¶
- Constants
- func Append[T comparable](ids []T, id T) []T
- func ModPathName(mod ModPath) string
- type Dependency
- type File
- type FileLine
- type Function
- type Identity
- type Import
- type Language
- type ModPath
- type Module
- type Node
- func (n Node) CompressData() *string
- func (n Node) Content() string
- func (n Node) FileLine() FileLine
- func (n Node) GetDependency(id Identity) *Relation
- func (n Node) IsExported() bool
- func (n Node) Module() *Module
- func (n Node) SetCompressData(data string) bool
- func (n Node) SetContent(content string) bool
- func (n Node) SetFileLine(file FileLine)
- func (n Node) SetIsExported(isExported bool)
- func (n Node) SetIsMethod(isMethod bool)
- func (n Node) Signature() string
- type NodeGraph
- type NodeType
- type Package
- type Parser
- type PkgPath
- type Receiver
- type Relation
- type RelationKind
- type Repository
- func (r *Repository) AddRelation(node *Node, dep Identity, depFl FileLine, kinds ...RelationKind)
- func (r *Repository) AllNodesSetRepo()
- func (r *Repository) BuildGraph() error
- func (p Repository) GetFile(fp string) (*File, *Module)
- func (r Repository) GetFileNodes(path string) []*Node
- func (p Repository) GetFunction(id Identity) *Function
- func (r *Repository) GetModule(mod ModPath) *Module
- func (r *Repository) GetNode(id Identity) *Node
- func (r *Repository) GetPackage(mod ModPath, pkg PkgPath) *Package
- func (p Repository) GetType(id Identity) *Type
- func (p *Repository) GetVar(id Identity) *Var
- func (r Repository) ID() string
- func (r Repository) InternalModules() []*Module
- func (p *Repository) SetFunction(id Identity, f *Function) *Function
- func (p *Repository) SetModule(path string, mod *Module)
- func (r *Repository) SetNode(id Identity, typ NodeType) *Node
- func (p *Repository) SetType(id Identity, f *Type) *Type
- func (p *Repository) SetVar(id Identity, v *Var) *Var
- type Type
- type TypeKind
- type Var
- type Writer
Constants ¶
View Source
const Version = "v0.1.3"
Variables ¶
This section is empty.
Functions ¶
func Append ¶
func Append[T comparable](ids []T, id T) []T
func ModPathName ¶
Types ¶
type Dependency ¶
func InsertDependency ¶
func InsertDependency(ids []Dependency, id Dependency) []Dependency
func NewDependency ¶
func NewDependency(id Identity, fl FileLine) Dependency
func (Dependency) Id ¶
func (d Dependency) Id() Identity
type File ¶
type FileLine ¶
type FileLine struct { File string // NOTICE: start line. line number start from 1 Line int // start offset in file StartOffset int // end offset in file EndOffset int }
FileLine represents a filename and line number
type Function ¶
type Function struct { Exported bool IsMethod bool // If the function is a method IsInterfaceMethod bool // If is a empty interface method stub Identity // unique identity in a repo FileLine Content string // Content of the function, including functiion signature and body Signature string `json:",omitempty"` Receiver *Receiver `json:",omitempty"` // Method receiver Params []Dependency `json:",omitempty"` // function parameters, key is the parameter name Results []Dependency `json:",omitempty"` // function results, key is the result name or type name // call to in-the-project functions, key is {{pkgAlias.funcName}} or {{funcName}} FunctionCalls []Dependency `json:",omitempty"` // call to internal methods, // NOTICE: method name may be duplicated, so we collect according to the SEQUENCE of APPEARANCE MethodCalls []Dependency `json:",omitempty"` Types []Dependency `json:",omitempty"` // types used in the function GlobalVars []Dependency `json:",omitempty"` // global vars used in the function // func llm compress result CompressData *string `json:"compress_data,omitempty"` }
Function holds the information about a function
type Identity ¶
type Identity struct { // module id, must be unique within a repo ModPath `json:"ModPath" jsonschema:"description=the compiling module of the ast node, the format is {ModName} or {ModName}@{Version}"` // path id, must be unique within a module PkgPath `json:"PkgPath" jsonschema:"description=the namespace of the ast node"` // symbol id , must be unique within a package Name string `` /* 180-byte string literal not displayed */ }
Identity is the universal-unique for an ast node.
func NewIdentity ¶
func NewIdentityFromString ¶
type Module ¶
type Module struct { Language Language Version string Name string // go module name Dir string // relative path to repo Packages map[PkgPath]*Package // pkage import path => Package Dependencies map[string]string `json:",omitempty"` // module name => module_path@version Files map[string]*File `json:",omitempty"` // relative path => file info CompressData *string `json:"compress_data,omitempty"` // module compress info }
func (Module) GetPkgFiles ¶
func (Module) IsExternal ¶
type Node ¶
type Node struct { // unique identity of the node Identity // Node Type, must be one of FUNC, TYPE, VAR Type NodeType // other nodes that depends on this node Dependencies []Relation `json:",omitempty"` // other nodes that references this node References []Relation `json:",omitempty"` // other nodes this node implements Implements []Relation `json:",omitempty"` // other nodes this node inherits Inherits []Relation `json:",omitempty"` // other nodes in the same definition group Groups []Relation `json:",omitempty"` // the repo that this node belongs to Repo *Repository `json:"-"` }
an Entity in a language
func (Node) CompressData ¶
func (Node) GetDependency ¶
func (Node) IsExported ¶
func (Node) SetCompressData ¶
func (Node) SetContent ¶
func (Node) SetFileLine ¶
func (Node) SetIsExported ¶
func (Node) SetIsMethod ¶
type NodeType ¶
type NodeType int
Node Type
func NewNodeType ¶
func (NodeType) MarshalJSON ¶
func (*NodeType) UnmarshalJSON ¶
type Package ¶
type Package struct { IsMain bool IsTest bool PkgPath Functions map[string]*Function // Function name (may be {{func}} or {{struct.method}}) => Function Types map[string]*Type // type name => type define Vars map[string]*Var // var name => var define CompressData *string `json:"compress_data,omitempty"` // package compress info }
Package
func NewPackage ¶
type Parser ¶
type Parser interface { ParseRepo() (Repository, error) ParseNode(pkgPath string, name string) (Repository, error) ParsePackage(pkgPath PkgPath) (Repository, error) }
type PkgPath ¶
type PkgPath = string
PkgPath is the import path of a package, it is either absolute path or url
type Relation ¶
type Relation struct { // Kind of the relation Kind RelationKind // target node Identity // start line-offset of the target token related to the current node's codes Line int `json:",omitempty"` // information about this relation Desc *string `json:",omitempty"` // related codes representing this relation, comming from current node's codes Codes *string `json:",omitempty"` }
Relation between two nodes
func InsertRelation ¶
type RelationKind ¶
type RelationKind string
RelationKind
const ( // DEPENDENCY: the target node is a dependency of the current node DEPENDENCY RelationKind = "Dependency" // IMPLEMENT: the target node is implemented by the current node IMPLEMENT RelationKind = "Implement" // INHERIT: the target node is inherited by the current node INHERIT RelationKind = "Inherit" // GROUPT: the target is in same definition group of nodes, like `const(a=1,b=2)` GROUP RelationKind = "Group" )
type Repository ¶
type Repository struct { ASTVersion string Name string `json:"id"` // module name Path string // repo path Modules map[string]*Module // module name => module Graph NodeGraph // node id => node }
Repository
func LoadRepo ¶
func LoadRepo(path string) (*Repository, error)
func NewRepository ¶
func NewRepository(name string) Repository
NOTICE: Repository.Path is set as name by default, if th name isn't a path, set path somewhere
func (*Repository) AddRelation ¶
func (r *Repository) AddRelation(node *Node, dep Identity, depFl FileLine, kinds ...RelationKind)
func (*Repository) AllNodesSetRepo ¶
func (r *Repository) AllNodesSetRepo()
func (*Repository) BuildGraph ¶
func (r *Repository) BuildGraph() error
func (Repository) GetFileNodes ¶
func (r Repository) GetFileNodes(path string) []*Node
func (Repository) GetFunction ¶
func (p Repository) GetFunction(id Identity) *Function
GetFunction the function identified by id. if id indicates a method, it will try traceinto inlined sub structs to get the named method
func (*Repository) GetModule ¶
func (r *Repository) GetModule(mod ModPath) *Module
func (*Repository) GetNode ¶
func (r *Repository) GetNode(id Identity) *Node
func (*Repository) GetPackage ¶
func (r *Repository) GetPackage(mod ModPath, pkg PkgPath) *Package
func (Repository) GetType ¶
func (p Repository) GetType(id Identity) *Type
func (*Repository) GetVar ¶
func (p *Repository) GetVar(id Identity) *Var
func (Repository) ID ¶
func (r Repository) ID() string
func (Repository) InternalModules ¶
func (r Repository) InternalModules() []*Module
func (*Repository) SetFunction ¶
func (p *Repository) SetFunction(id Identity, f *Function) *Function
func (*Repository) SetModule ¶
func (p *Repository) SetModule(path string, mod *Module)
type Type ¶
type Type struct { Exported bool // if the struct is exported TypeKind TypeKind // type Kind: Struct / Interface / Typedef Identity // unique id in a repo FileLine Content string // struct declaration content // field type, type name => type id SubStruct []Dependency `json:",omitempty"` // inherit field type InlineStruct []Dependency `json:",omitempty"` // methods defined on the Struct, not including inlined type's method Methods map[string]Identity `json:",omitempty"` // Implemented interfaces Implements []Identity `json:",omitempty"` CompressData *string `json:"compress_data,omitempty"` // struct llm compress result }
Type holds the information about a struct
type Var ¶
type Var struct { IsExported bool IsConst bool IsPointer bool // if its Type is a pointer type Identity FileLine Type *Identity `json:",omitempty"` Content string Dependencies []Dependency `json:",omitempty"` // Groups means the var is a group of vars, like Enum in Go Groups []Identity `json:",omitempty"` CompressData *string `json:"compress_data,omitempty"` }
type Writer ¶
type Writer interface { // write a module onto Options.OutDir. WriteModule(repo *Repository, modPath string, outDir string) error // CreateFile will create a file bytes with the given file info. CreateFile(fi *File, mod *Module) ([]byte, error) // SplitImportsAndCodes will split the imports and codes from the src. // the src has only codes, just return the src. SplitImportsAndCodes(src string) (codes string, imports []Import, err error) // IdToImport converts the identity to import. IdToImport(id Identity) (Import, error) // PatchImports patches the imports into file content PatchImports(impts []Import, file []byte) ([]byte, error) }
Click to show internal directories.
Click to hide internal directories.