parser

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2022 License: MIT Imports: 12 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Universe = NewScope()
View Source
var UniverseScope = ast.NewScope(nil)

Functions

func ExprToString

func ExprToString(expr ast.Expr) string

func GetTypeStars

func GetTypeStars(t Type) int

func InspectUnderlyingStruct

func InspectUnderlyingStruct(t Type, inspect func(*Field) bool) bool

func IsAtomicType

func IsAtomicType(t Type) bool

func IsErrorType

func IsErrorType(t Type) bool

func NotNilPointerValue

func NotNilPointerValue(t *PointerType, file *File) ast.Expr

func ParseExpr

func ParseExpr(x string) (ast.Expr, error)

func ResolveUnknownField

func ResolveUnknownField(field *Field)

func TypeAssignable

func TypeAssignable(target, source Type) bool

func TypeEqual

func TypeEqual(a, b Type) bool

func TypeEqualAsReceiver

func TypeEqualAsReceiver(t1 Type, t2 Type) bool

func TypeExprInFile

func TypeExprInFile(t Type, file *File) ast.Expr

func TypeInitValue

func TypeInitValue(t Type, file *File) ast.Expr

func TypeIsUnknown

func TypeIsUnknown(t Type) bool

func TypeZeroValue

func TypeZeroValue(t Type, file *File) ast.Expr

func WalkFile

func WalkFile(file *File, walker DeclWalker)

func WalkPackage

func WalkPackage(pkg *Package, walker DeclWalker)

Types

type ArrayType

type ArrayType struct {
	Element Type
	Slices  int
	Len     int
	// contains filtered or unexported fields
}

func (*ArrayType) AssignableTo

func (t *ArrayType) AssignableTo(tt Type) bool

func (*ArrayType) Copy

func (t *ArrayType) Copy() Type

func (*ArrayType) DefaultValue

func (t *ArrayType) DefaultValue() ast.Expr

func (*ArrayType) EqualTo

func (t *ArrayType) EqualTo(tt Type) bool

func (*ArrayType) File

func (t *ArrayType) File() *File

func (*ArrayType) LenExpr

func (t *ArrayType) LenExpr() ast.Expr

func (*ArrayType) Name

func (t *ArrayType) Name() string

func (*ArrayType) Package

func (t *ArrayType) Package() *Package

func (*ArrayType) String

func (t *ArrayType) String() string

func (*ArrayType) Underlying

func (t *ArrayType) Underlying() Type

type BasicType

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

Define: basicType: for golang pre defeined type

func (*BasicType) AssignableTo

func (t *BasicType) AssignableTo(Type) bool

func (*BasicType) Copy

func (t *BasicType) Copy() Type

func (*BasicType) DefaultValue

func (t *BasicType) DefaultValue() ast.Expr

func (*BasicType) EqualTo

func (t *BasicType) EqualTo(tt Type) bool

func (*BasicType) File

func (t *BasicType) File() *File

func (*BasicType) Name

func (t *BasicType) Name() string

func (*BasicType) Package

func (t *BasicType) Package() *Package

func (*BasicType) String

func (t *BasicType) String() string

func (*BasicType) Underlying

func (t *BasicType) Underlying() Type

type DeclFinder

type DeclFinder interface {
	Find(ast.Decl) *DeclNode
	WithName(name string) DeclFinder
}

func NewFuncDeclFinder

func NewFuncDeclFinder(recvName string) DeclFinder

func NewGenDeclFinder

func NewGenDeclFinder(tok token.Token) DeclFinder

func NewInterfaceTypeFinder

func NewInterfaceTypeFinder() DeclFinder

func NewStructTypeFinder

func NewStructTypeFinder() DeclFinder

func NewTypeSpecFinder

func NewTypeSpecFinder() DeclFinder

func NewValueSpecFinder

func NewValueSpecFinder() DeclFinder

type DeclNode

type DeclNode struct {
	Name  *ast.Ident
	Node  ast.Node
	Alias ast.Expr

	PreNode *DeclNode
	File    *File
}

func (*DeclNode) InFile

func (node *DeclNode) InFile(f *File) *DeclNode

func (*DeclNode) WithPre

func (node *DeclNode) WithPre(dn *DeclNode) *DeclNode

type DeclWalker

type DeclWalker interface {
	Walk(ast.Decl) bool
}

func NewFuncDeclWalker

func NewFuncDeclWalker(walk func(*ast.FuncDecl) bool) DeclWalker

func NewGenDeclWalker

func NewGenDeclWalker(tok token.Token, walk func(*ast.GenDecl) bool) DeclWalker

type Direction

type Direction int
const (
	D_Self Direction
	D_SkipPointer
	D_SkipBracket
	D_SpreadFields
	D_CallFunction //call function
	D_AddPointer
	D_AddBracket
	D_TypeConversion
)

type Field

type Field struct {
	Type
	Tag string
	// contains filtered or unexported fields
}

Define: Field

func NewField

func NewField(t Type, name string, tag string) *Field

func (*Field) Copy

func (t *Field) Copy() Type

func (*Field) FieldName

func (t *Field) FieldName() string

func (*Field) IsAnonymous

func (t *Field) IsAnonymous() bool

func (*Field) IsStruct

func (t *Field) IsStruct() bool

func (*Field) Name

func (t *Field) Name() string

func (*Field) SetName

func (t *Field) SetName(name string)

func (*Field) SetType

func (t *Field) SetType(tt Type)

func (*Field) String

func (t *Field) String() string

type File

type File struct {
	BelongTo *Package

	Name string
	File *ast.File
	// contains filtered or unexported fields
}

func (*File) AddImport

func (file *File) AddImport(name string, pkg *Package)

func (*File) DotImported

func (file *File) DotImported() []*Package

func (*File) FindAllDotImport

func (f *File) FindAllDotImport() (paths []string)

func (*File) FindDecl

func (file *File) FindDecl(expr ast.Expr, finder DeclFinder) *DeclNode

GenDecl FuncDecl

func (*File) FindImport

func (file *File) FindImport(name string) *Package

func (*File) FindImportNameByPath

func (file *File) FindImportNameByPath(path string) string

func (*File) FindImportPath

func (f *File) FindImportPath(name string) (path string, ok bool)

func (*File) ImportAllDots

func (f *File) ImportAllDots() []*Package

func (*File) LookupImport

func (file *File) LookupImport(name string) (*File, *ast.Object)

func (*File) LookupMethod

func (file *File) LookupMethod(name string) ([]*File, []*ast.FuncDecl)

method need lookup

func (*File) LookupName

func (file *File) LookupName(name string) (*File, *ast.Object)

func (*File) ReduceType

func (file *File) ReduceType(expr ast.Expr) Type

func (*File) ReduceTypeSrc

func (file *File) ReduceTypeSrc(src string) Type

type FuncDeclFinder

type FuncDeclFinder struct {
	Name     string
	Receiver string
}

func (*FuncDeclFinder) Find

func (finder *FuncDeclFinder) Find(decl ast.Decl) *DeclNode

func (*FuncDeclFinder) WithName

func (finder *FuncDeclFinder) WithName(name string) DeclFinder

type FuncDeclWalker

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

func (*FuncDeclWalker) Walk

func (walker *FuncDeclWalker) Walk(decl ast.Decl) bool

type FuncType

type FuncType struct {
	Receiver *Field
	Params   []*Field
	Results  []*Field
}

Define: FuncType

func (*FuncType) AssignableTo

func (t *FuncType) AssignableTo(Type) bool

func (*FuncType) Copy

func (t *FuncType) Copy() Type

func (*FuncType) DefaultValue

func (t *FuncType) DefaultValue() ast.Expr

func (*FuncType) EqualTo

func (t *FuncType) EqualTo(Type) bool

func (*FuncType) File

func (t *FuncType) File() *File

func (*FuncType) Name

func (*FuncType) Name() string

func (*FuncType) Package

func (t *FuncType) Package() *Package

func (*FuncType) String

func (t *FuncType) String() string

func (*FuncType) Underlying

func (t *FuncType) Underlying() Type

type GenDeclFinder

type GenDeclFinder struct {
	Tok token.Token
}

func (*GenDeclFinder) Find

func (finder *GenDeclFinder) Find(decl ast.Decl) *DeclNode

func (*GenDeclFinder) WithName

func (finder *GenDeclFinder) WithName(name string) DeclFinder

type GenDeclWalker

type GenDeclWalker struct {
	Tok token.Token
	// contains filtered or unexported fields
}

func (*GenDeclWalker) Walk

func (walker *GenDeclWalker) Walk(decl ast.Decl) bool

type InterfaceType

type InterfaceType struct {
	Methods []*Field
}

Define: InterfaceType

func (*InterfaceType) AssignableTo

func (t *InterfaceType) AssignableTo(tt Type) bool

func (*InterfaceType) Copy

func (t *InterfaceType) Copy() Type

func (*InterfaceType) DefaultValue

func (t *InterfaceType) DefaultValue() ast.Expr

func (*InterfaceType) EqualTo

func (t *InterfaceType) EqualTo(tt Type) bool

func (*InterfaceType) File

func (t *InterfaceType) File() *File

func (*InterfaceType) GetFuncByName

func (t *InterfaceType) GetFuncByName(name string) Type

func (*InterfaceType) Name

func (t *InterfaceType) Name() string

func (*InterfaceType) Package

func (t *InterfaceType) Package() *Package

func (*InterfaceType) String

func (t *InterfaceType) String() string

func (*InterfaceType) Underlying

func (t *InterfaceType) Underlying() Type

type InterfaceTypeFinder

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

func (*InterfaceTypeFinder) Find

func (finder *InterfaceTypeFinder) Find(decl ast.Decl) *DeclNode

func (*InterfaceTypeFinder) WithName

func (finder *InterfaceTypeFinder) WithName(name string) DeclFinder

type OldFuncType

type OldFuncType struct {
	Expr        ast.Expr
	Package     *Package
	Name        *ast.Ident
	OldFuncType *ast.FuncType
	Signature   string
}

func NewOldFuncType

func NewOldFuncType(name string) *OldFuncType

func (*OldFuncType) CopyAstOldFuncType

func (ft *OldFuncType) CopyAstOldFuncType() *ast.FuncType

func (*OldFuncType) CopyAstOldFuncTypeToPackage

func (ft *OldFuncType) CopyAstOldFuncTypeToPackage(pkg *Package) *ast.FuncType

func (*OldFuncType) Fill

func (ft *OldFuncType) Fill(node *DeclNode)

type OldInterface

type OldInterface struct {
	OldFuncTypes []*OldFuncType
}

func NewOldInterface

func NewOldInterface() *OldInterface

func (*OldInterface) Fill

func (i *OldInterface) Fill(node *DeclNode)

func (*OldInterface) GetFuncByName

func (i *OldInterface) GetFuncByName(name string) *OldFuncType

type Package

type Package struct {
	Scope         *Scope
	Name          string
	Dir           string
	Path          string
	CanonicalPath string
	PackageName   string
	Files         []*File
	// contains filtered or unexported fields
}

func NewPackage

func NewPackage(p *Parser, name string, dir string, path string, files []*File) *Package

func (*Package) EqualTo

func (pkg *Package) EqualTo(np *Package) bool

func (*Package) FindDecl

func (pkg *Package) FindDecl(name string, finder DeclFinder) *DeclNode

FindDecl

func (*Package) FindFuncDecl

func (pkg *Package) FindFuncDecl(name string) *DeclNode

findFuncDecl

func (*Package) GetFile

func (pkg *Package) GetFile(name string) *File

func (*Package) InsertFile

func (pkg *Package) InsertFile(file *File, index int)

func (*Package) ReduceType

func (pkg *Package) ReduceType(expr ast.Expr) (*File, Type)

type Parser

type Parser struct {
	FileSet       *token.FileSet
	Scope         *ast.Scope
	ImportContext build.Context
	Scopes        map[string]*Scope
}

func NewParser

func NewParser() *Parser

func (*Parser) AddScope

func (p *Parser) AddScope(canonicalPath string, scope *Scope)

func (*Parser) ImportPackage

func (p *Parser) ImportPackage(name string, path string, srcDir string) *Package

func (*Parser) ImportScope

func (p *Parser) ImportScope(path string, dir string) (canonicalPath string, scope *Scope)

func (*Parser) InsertFileToPackage

func (p *Parser) InsertFileToPackage(pkg *Package, file *File, index int)

func (*Parser) ParseFileContent

func (p *Parser) ParseFileContent(name string, content interface{}) *File

func (*Parser) ParsePackage

func (p *Parser) ParsePackage(path string, directory string, names []string) *Package

parsePackage analyzes the single package constructed from the named files.

func (*Parser) ParsePackageDir

func (p *Parser) ParsePackageDir(directory string) *Package

func (*Parser) ParsePackageFiles

func (p *Parser) ParsePackageFiles(names []string) *Package

parsePackageFiles parses the package occupying the named files.

func (*Parser) PrintNode

func (p *Parser) PrintNode(node ast.Node)

type PointerType

type PointerType struct {
	Base  Type
	Stars int
}

Define: PointerType

func (*PointerType) AssignableTo

func (t *PointerType) AssignableTo(tt Type) bool

func (*PointerType) BaseType

func (t *PointerType) BaseType() Type

func (*PointerType) Copy

func (t *PointerType) Copy() Type

func (*PointerType) DefaultValue

func (t *PointerType) DefaultValue() ast.Expr

func (*PointerType) EqualTo

func (t *PointerType) EqualTo(tt Type) bool

func (*PointerType) File

func (t *PointerType) File() *File

func (*PointerType) Name

func (t *PointerType) Name() string

func (*PointerType) Package

func (t *PointerType) Package() *Package

func (*PointerType) String

func (t *PointerType) String() string

func (*PointerType) Underlying

func (t *PointerType) Underlying() Type

type Scope

type Scope struct {
	Objects map[string]Type
}

func NewScope

func NewScope() *Scope

func (*Scope) DeclType

func (s *Scope) DeclType(name string, t Type)

func (*Scope) Lookup

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

type StructType

type StructType struct {
	Fields []*Field
}

Define: StructType

func (*StructType) AssignableTo

func (t *StructType) AssignableTo(tt Type) bool

func (*StructType) Copy

func (t *StructType) Copy() Type

func (*StructType) DefaultValue

func (t *StructType) DefaultValue() ast.Expr

func (*StructType) EqualTo

func (t *StructType) EqualTo(tt Type) bool

func (*StructType) File

func (t *StructType) File() *File

func (*StructType) Name

func (t *StructType) Name() string
func (t *StructType) PackageName() string {
	return ""
}

func (*StructType) Package

func (t *StructType) Package() *Package

func (*StructType) String

func (t *StructType) String() string

func (*StructType) Underlying

func (t *StructType) Underlying() Type

type StructTypeFinder

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

func (*StructTypeFinder) Find

func (finder *StructTypeFinder) Find(decl ast.Decl) *DeclNode

func (*StructTypeFinder) WithName

func (finder *StructTypeFinder) WithName(name string) DeclFinder

type TPath

type TPath struct {
	Source Type
	Target Type
	D      Direction
	Arg    interface{}
	// contains filtered or unexported fields
}

func NewTPath

func NewTPath(src Type, dst Type) *TPath

func TypeToType

func TypeToType(a Type, b Type, knowns []*TPath) ([]*TPath, bool)

a to b

func (*TPath) ConflictWith

func (tp *TPath) ConflictWith(ot *TPath) bool

func (*TPath) Copy

func (tp *TPath) Copy() *TPath

func (*TPath) String

func (tp *TPath) String() string

func (*TPath) WithArg

func (tp *TPath) WithArg(arg interface{}) *TPath

func (*TPath) WithDirection

func (tp *TPath) WithDirection(d Direction) *TPath

func (*TPath) WithFunction

func (tp *TPath) WithFunction(funcType Type) *TPath

func (*TPath) WithTypeConversion

func (tp *TPath) WithTypeConversion(t Type) *TPath

type Type

type Type interface {
	Copy() Type

	File() *File
	Package() *Package
	Name() string

	AssignableTo(Type) bool
	EqualTo(Type) bool

	Underlying() Type
	String() string
}

func ErrorType

func ErrorType() Type

func GetInterfaceFuncByName

func GetInterfaceFuncByName(t Type, name string) Type

func MapType

func MapType(key Type, val Type) Type

func NewBasicType

func NewBasicType(name string) Type

func NewType

func NewType(name string) Type

func ParseType

func ParseType(node ast.Node) Type

func ParseTypeString

func ParseTypeString(str string) Type

func TypeSkipBracket

func TypeSkipBracket(t Type, n int) Type

func TypeSkipPointer

func TypeSkipPointer(t Type, n int) Type

func TypeWithArray

func TypeWithArray(t Type, len int) Type

func TypeWithExpr

func TypeWithExpr(t Type, expr ast.Expr) Type

func TypeWithFile

func TypeWithFile(t Type, file *File) Type

func TypeWithName

func TypeWithName(underlying Type, name string) Type

func TypeWithPointer

func TypeWithPointer(t Type) Type

func TypeWithSlice

func TypeWithSlice(t Type) Type

func TypeWrapStruct

func TypeWrapStruct(t Type, name string) Type

type TypeSpecFinder

type TypeSpecFinder struct {
	Name string
	// contains filtered or unexported fields
}

func (*TypeSpecFinder) Find

func (finder *TypeSpecFinder) Find(decl ast.Decl) *DeclNode

func (*TypeSpecFinder) WithName

func (finder *TypeSpecFinder) WithName(name string) DeclFinder

type UnknownType

type UnknownType struct {
	Parent Type
	// contains filtered or unexported fields
}

Define wrapper: UnknownType

func NewUnknownType

func NewUnknownType(file *File, expr ast.Expr) *UnknownType

func TypeHasUnknown

func TypeHasUnknown(t Type) (*UnknownType, bool)

func (*UnknownType) AssignableTo

func (t *UnknownType) AssignableTo(Type) bool

func (*UnknownType) Copy

func (t *UnknownType) Copy() Type

func (*UnknownType) DefaultValue

func (t *UnknownType) DefaultValue() ast.Expr

func (*UnknownType) EqualTo

func (t *UnknownType) EqualTo(Type) bool

func (*UnknownType) File

func (t *UnknownType) File() *File

func (*UnknownType) Name

func (t *UnknownType) Name() string

func (*UnknownType) Package

func (t *UnknownType) Package() *Package

func (*UnknownType) Reduce

func (unknown *UnknownType) Reduce(file *File) Type

func (*UnknownType) ResetParent

func (unknown *UnknownType) ResetParent(kn Type)

func (*UnknownType) String

func (t *UnknownType) String() string

func (*UnknownType) Underlying

func (t *UnknownType) Underlying() Type

func (*UnknownType) WithFile

func (t *UnknownType) WithFile(f *File) *UnknownType

type ValueSpecFinder

type ValueSpecFinder struct {
	Name string
	// contains filtered or unexported fields
}

func (*ValueSpecFinder) Find

func (finder *ValueSpecFinder) Find(decl ast.Decl) *DeclNode

func (*ValueSpecFinder) WithName

func (finder *ValueSpecFinder) WithName(name string) DeclFinder

Jump to

Keyboard shortcuts

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