Documentation
¶
Overview ¶
This file is used to convert ast from "github.com/goplus/llcppg/ast" to "go/ast"
This file is used to convert type from ast type to types.Type
Index ¶
- Constants
- Variables
- func IsDepStd(pkgPath string) (string, bool)
- func ModInit(deps []string, outputDir string, modulePath string) error
- func NewFuncDocComments(funcName string, goFuncName string) *goast.CommentGroup
- func NewTypecDocComments() *goast.CommentGroup
- type BuiltinTypeMap
- type Config
- type ConstGroup
- type ConvertComment
- type ConvertCommentGroup
- type Converter
- type ExprWrap
- type GoFuncSpec
- type HeaderFile
- type Incomplete
- type IncompleteTypes
- type Module
- type Package
- func (p *Package) CollectNameMapping(originName, newName string)
- func (p *Package) DeclName(name string, toCamel bool) (pubName string, changed bool, err error)
- func (p *Package) GetGenPackage() *gogen.Package
- func (p *Package) GetOutputDir() string
- func (p *Package) LookupSymbol(mangleName config.MangleNameType) (*GoFuncSpec, error)
- func (p *Package) NewConstGroup() *ConstGroup
- func (p *Package) NewEnumTypeDecl(enumTypeDecl *ast.EnumTypeDecl) error
- func (p *Package) NewFuncDecl(funcDecl *ast.FuncDecl) error
- func (p *Package) NewMacro(macro *ast.Macro) error
- func (p *Package) NewTypeDecl(typeDecl *ast.TypeDecl) error
- func (p *Package) NewTypedefDecl(typedefDecl *ast.TypedefDecl) error
- func (p *Package) NewTypedefs(name string, typ types.Type) *gogen.TypeDecl
- func (p *Package) SetCurFile(hfile *HeaderFile)
- func (p *Package) ToSigSignature(recv *types.Var, funcDecl *ast.FuncDecl) (*types.Signature, error)
- func (p *Package) ToType(expr ast.Expr) (types.Type, error)
- func (p *Package) Write(headerFile string) error
- func (p *Package) WriteAutogenFile() error
- func (p *Package) WriteLinkFile() (string, error)
- func (p *Package) WritePkgFiles() error
- func (p *Package) WritePubFile() error
- func (p *Package) WriteToBuffer(genFName string) (*bytes.Buffer, error)
- type PackageConfig
- type PkgBase
- type PkgDepLoader
- func (pm *PkgDepLoader) Import(pkgPath string) (*PkgInfo, error)
- func (pm *PkgDepLoader) Imports(pkgPaths []string) (pkgs []*PkgInfo, err error)
- func (pm *PkgDepLoader) InitDeps(p *PkgInfo) error
- func (pm *PkgDepLoader) LoadDeps(p *PkgInfo) ([]*PkgInfo, error)
- func (pm *PkgDepLoader) RegisterDep(dep *PkgInfo)
- func (pm *PkgDepLoader) RegisterDeps(p *PkgInfo)
- type PkgInfo
- type ThirdTypeLoc
- type TypeContext
- type TypeConv
Constants ¶
const (
TYPEC = "// llgo:type C"
)
Variables ¶
var (
ErrTypeConv = errors.New("error convert type")
)
Functions ¶
func NewFuncDocComments ¶
func NewFuncDocComments(funcName string, goFuncName string) *goast.CommentGroup
func NewTypecDocComments ¶
func NewTypecDocComments() *goast.CommentGroup
Types ¶
type BuiltinTypeMap ¶
type BuiltinTypeMap struct {
// contains filtered or unexported fields
}
func NewBuiltinTypeMap ¶
func NewBuiltinTypeMap(pkgPath, name string, conf *gogen.Config) *BuiltinTypeMap
func NewBuiltinTypeMapWithPkgRefS ¶
func NewBuiltinTypeMapWithPkgRefS(pkgs ...gogen.PkgRef) *BuiltinTypeMap
func (*BuiltinTypeMap) FindBuiltinType ¶
func (p *BuiltinTypeMap) FindBuiltinType(builtinType ast.BuiltinType) (types.Type, error)
func (*BuiltinTypeMap) IsVoidType ¶
func (p *BuiltinTypeMap) IsVoidType(typ types.Type) bool
type ConstGroup ¶
type ConstGroup struct {
// contains filtered or unexported fields
}
func NewConstGroup ¶
func NewConstGroup(pkg *gogen.Package, scope *types.Scope) *ConstGroup
type ConvertComment ¶
func Comment ¶
func Comment(doc *ast.Comment) *ConvertComment
type ConvertCommentGroup ¶
type ConvertCommentGroup struct {
*goast.CommentGroup
}
func CommentGroup ¶
func CommentGroup(doc *ast.CommentGroup) *ConvertCommentGroup
func (*ConvertCommentGroup) AddComment ¶
func (p *ConvertCommentGroup) AddComment(comment *goast.Comment) error
func (*ConvertCommentGroup) AddCommentGroup ¶
func (p *ConvertCommentGroup) AddCommentGroup(doc *goast.CommentGroup)
type Converter ¶
func NewConverter ¶
type GoFuncSpec ¶
type GoFuncSpec struct {
GoSymbName string // original full name from input
FnName string // function name without receiver
IsMethod bool // if the function is a method
RecvName string // receiver name
PtrRecv bool // if the receiver is a pointer
}
GoFuncSpec parses and stores components of a Go function name Input examples from llcppg.symb.json's "go" field: 1. Simple function: "AddPatchToArray" 2. Method with pointer receiver: "(*Sqlite3Stmt).Sqlite3BindParameterIndex" 3. Method with value receiver: "CJSONBool.CJSONCreateBool"
func NewGoFuncSpec ¶
func NewGoFuncSpec(name string) *GoFuncSpec
- "AddPatchToArray" -> {goSymbolName: "AddPatchToArray", funcName: "AddPatchToArray"} - "(*Sqlite3Stmt).Sqlite3BindParameterIndex" -> {goSymbolName: "...", recvName: "Sqlite3Stmt", funcName: "Sqlite3BindParameterIndex", ptrRecv: true} - "CJSONBool.CJSONCreateBool" -> {goSymbolName: "...", recvName: "CJSONBool", funcName: "CJSONCreateBool", ptrRecv: false}
func (*GoFuncSpec) IsIgnore ¶ added in v0.2.1
func (g *GoFuncSpec) IsIgnore() bool
type HeaderFile ¶
func NewHeaderFile ¶
func NewHeaderFile(file string, fileType llcppg.FileType) *HeaderFile
func (*HeaderFile) InCurPkg ¶
func (p *HeaderFile) InCurPkg() bool
func (*HeaderFile) ToGoFileName ¶
func (p *HeaderFile) ToGoFileName(pkgName string) string
Note:third hfile should not set to gogen.Package
type Incomplete ¶
type Incomplete struct {
// contains filtered or unexported fields
}
type IncompleteTypes ¶
type IncompleteTypes struct {
// contains filtered or unexported fields
}
func NewIncompleteTypes ¶
func NewIncompleteTypes() *IncompleteTypes
func (*IncompleteTypes) Add ¶
func (it *IncompleteTypes) Add(inc *Incomplete)
func (*IncompleteTypes) Clear ¶
func (it *IncompleteTypes) Clear()
func (*IncompleteTypes) Complete ¶
func (it *IncompleteTypes) Complete(cname string)
func (*IncompleteTypes) IterateIncomplete ¶
func (it *IncompleteTypes) IterateIncomplete(fn func(*Incomplete) error) error
func (*IncompleteTypes) Lookup ¶
func (it *IncompleteTypes) Lookup(cname string) (*Incomplete, bool)
type Package ¶
type Package struct {
*PkgInfo
// contains filtered or unexported fields
}
In Processing Package
func NewPackage ¶
func NewPackage(config *PackageConfig) *Package
When creating a new package for conversion, a Go file named after the package is generated by default. If SetCurFile is not called, all type conversions will be written to this default Go file.
func (*Package) CollectNameMapping ¶
Collect the name mapping between origin name and pubname if in current package, it will be collected in public symbol table
func (*Package) GetGenPackage ¶
func (*Package) GetOutputDir ¶
func (*Package) LookupSymbol ¶
func (p *Package) LookupSymbol(mangleName config.MangleNameType) (*GoFuncSpec, error)
func (*Package) NewConstGroup ¶
func (p *Package) NewConstGroup() *ConstGroup
func (*Package) NewEnumTypeDecl ¶
func (p *Package) NewEnumTypeDecl(enumTypeDecl *ast.EnumTypeDecl) error
func (*Package) NewTypeDecl ¶
NewTypeDecl converts C/C++ type declarations to Go. Besides regular type declarations, it also supports: - Forward declarations: Pre-registers incomplete types for later definition - Self-referential types: Handles types that reference themselves (like linked lists)
func (*Package) NewTypedefDecl ¶
func (p *Package) NewTypedefDecl(typedefDecl *ast.TypedefDecl) error
func (*Package) NewTypedefs ¶
func (*Package) SetCurFile ¶
func (p *Package) SetCurFile(hfile *HeaderFile)
func (*Package) ToSigSignature ¶
func (*Package) Write ¶
Write generates a Go file based on the package content. The output file will be generated in a subdirectory named after the package within the outputDir. If outputDir is not provided, the current directory will be used. The header file name is the go file name.
Files that are already processed in dependent packages will not be output.
func (*Package) WriteAutogenFile ¶
func (*Package) WriteLinkFile ¶
func (*Package) WritePkgFiles ¶
WritePkgFiles writes all converted header files to Go files. Calls deferTypeBuild() first to complete all incomplete type definitions, because some types may be implemented across multiple files.
func (*Package) WritePubFile ¶
type PackageConfig ¶
type PkgDepLoader ¶
type PkgDepLoader struct {
// contains filtered or unexported fields
}
func NewPkgDepLoader ¶
func NewPkgDepLoader(mod *gopmod.Module, pkg *gogen.Package) *PkgDepLoader
func (*PkgDepLoader) Imports ¶
func (pm *PkgDepLoader) Imports(pkgPaths []string) (pkgs []*PkgInfo, err error)
func (*PkgDepLoader) InitDeps ¶
func (pm *PkgDepLoader) InitDeps(p *PkgInfo) error
func (*PkgDepLoader) LoadDeps ¶
func (pm *PkgDepLoader) LoadDeps(p *PkgInfo) ([]*PkgInfo, error)
LoadDeps loads direct dependencies of the current package and recursively loads their dependencies, to get the complete dependency.
func (*PkgDepLoader) RegisterDep ¶
func (pm *PkgDepLoader) RegisterDep(dep *PkgInfo)
func (*PkgDepLoader) RegisterDeps ¶
func (pm *PkgDepLoader) RegisterDeps(p *PkgInfo)
RegisterDeps registers types from dependent packages into the current conversion project's scope
type ThirdTypeLoc ¶
type ThirdTypeLoc struct {
// contains filtered or unexported fields
}
func NewThirdTypeLoc ¶
func NewThirdTypeLoc() *ThirdTypeLoc
type TypeContext ¶
type TypeContext int
const ( Normal TypeContext = iota Param // In function parameter context Record // In record field context )
type TypeConv ¶
type TypeConv struct {
// contains filtered or unexported fields
}