Documentation
¶
Overview ¶
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 NewCommentGroup(comments ...*goast.Comment) *goast.CommentGroup
- func NewCommentGroupFromC(doc *ast.CommentGroup) *goast.CommentGroup
- func NewFuncDocComment(funcName string, goFuncName string) *goast.Comment
- func NewTypecDocComment() *goast.Comment
- func SetDebug(dbgFlags dbgFlags)
- func Sizeof(T types.Type) int64
- type BuiltinTypeMap
- type Config
- type ConstGroup
- type Converter
- type ExprWrap
- type GoFuncSpec
- type HeaderFile
- type Incomplete
- type IncompleteTypes
- type LitParseError
- type Module
- type NameMethod
- type Node
- type Package
- func (p *Package) CollectNameMapping(originName, newName string)
- func (p *Package) Config() *PackageConfig
- func (p *Package) GetGenPackage() *gogen.Package
- func (p *Package) GetOutputDir() string
- func (p *Package) GetUniqueName(node Node, nameMethod NameMethod) (pubName string, changed bool)
- func (p *Package) Lookup(name string) types.Object
- 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) RegisterNode(node Node, nameMethod NameMethod, ...) (pubName string, changed bool, exist bool, err error)
- 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 ProcessSymbol
- type ThirdTypeLoc
- type TypeContext
- type TypeConv
- type TypeDefinedError
Constants ¶
const ( DbgLog dbgFlags = 1 << iota DbgFlagAll = DbgLog )
const ( FuncDecl nodeKind = iota + 1 TypeDecl TypedefDecl EnumTypeDecl EnumItem Macro )
const (
TYPEC = "// llgo:type C"
)
Variables ¶
var (
ErrTypeConv = errors.New("error convert type")
)
Functions ¶
func NewCommentGroup ¶ added in v0.3.1
func NewCommentGroup(comments ...*goast.Comment) *goast.CommentGroup
func NewCommentGroupFromC ¶ added in v0.3.1
func NewCommentGroupFromC(doc *ast.CommentGroup) *goast.CommentGroup
func NewFuncDocComment ¶ added in v0.3.1
func NewTypecDocComment ¶ added in v0.3.1
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 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 LitParseError ¶ added in v0.3.1
type LitParseError struct {
// contains filtered or unexported fields
}
func NewLitParseError ¶ added in v0.3.1
func NewLitParseError(from any, to string) *LitParseError
func (*LitParseError) Error ¶ added in v0.3.1
func (p *LitParseError) Error() string
type NameMethod ¶ added in v0.3.1
type Package ¶
type Package struct {
*PkgInfo
// contains filtered or unexported fields
}
In Processing Package
func NewPackage ¶
func NewPackage(config *PackageConfig) (*Package, error)
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) Config ¶ added in v0.3.1
func (p *Package) Config() *PackageConfig
func (*Package) GetGenPackage ¶
func (*Package) GetOutputDir ¶
func (*Package) GetUniqueName ¶ added in v0.3.1
func (p *Package) GetUniqueName(node Node, nameMethod NameMethod) (pubName string, changed bool)
GetUniqueName generates a unique public name for a given node using the provided name transformation method. It ensures the generated name doesn't conflict with existing names by adding a numeric suffix if needed.
Parameters:
- node: The node containing the original name to be transformed
- nameMethod: Function used to transform the original name (e.g., declName, constName)
Returns:
- pubName: The generated unique public name
- changed: Whether the generated name differs from the original name
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) RegisterNode ¶ added in v0.3.1
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 ProcessSymbol ¶ added in v0.3.1
type ProcessSymbol struct {
// contains filtered or unexported fields
}
func NewProcessSymbol ¶ added in v0.3.1
func NewProcessSymbol() *ProcessSymbol
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
}
func (*TypeConv) RecordTypeToStruct ¶
func (*TypeConv) ToDefaultEnumType ¶
func (*TypeConv) ToSignature ¶
type TypeDefinedError ¶ added in v0.3.1
func NewTypeDefinedError ¶ added in v0.3.1
func NewTypeDefinedError(name, originName string) *TypeDefinedError
func (*TypeDefinedError) Error ¶ added in v0.3.1
func (p *TypeDefinedError) Error() string