gen

package
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AutoGeneratedMark = "// auto-generated code, do not modify"

Functions

func Create

func Create(filename string) (*os.File, error)

Types

type Class

type Class struct {
	Type                *typing.ClassType
	Parent              *Class
	Properties          []*Property
	InstanceTypeMethods []*Method // methods that return instance type
	Methods             []*Method
	// contains filtered or unexported fields
}

Class is code generator for objc class

func (*Class) Copy

func (c *Class) Copy() CodeGen

Copy for copy fetcher cache value

func (*Class) GoImports

func (c *Class) GoImports() set.Set[string]

func (*Class) Init

func (c *Class) Init()

func (*Class) String

func (c *Class) String() string

func (*Class) WriteGoCode

func (c *Class) WriteGoCode(cw *CodeWriter)

type CodeGen

type CodeGen interface {
	Init()
	Copy() CodeGen
	GoImports() set.Set[string]
	WriteGoCode(cw *CodeWriter)
}

CodeGen is interface for Class/Protocol code Gen

type CodeWriter

type CodeWriter struct {
	Writer io.Writer

	IndentStr string
	// contains filtered or unexported fields
}

CodeWriter write code

func (*CodeWriter) Indent

func (c *CodeWriter) Indent()

Indent add more indent from now

func (*CodeWriter) UnIndent

func (c *CodeWriter) UnIndent()

UnIndent reduce indent from now

func (*CodeWriter) WriteLine

func (c *CodeWriter) WriteLine(line string)

WriteLine write one line code

func (*CodeWriter) WriteLineF

func (c *CodeWriter) WriteLineF(format string, values ...any)

WriteLine write one line code

func (*CodeWriter) WriteLines

func (c *CodeWriter) WriteLines(lines []string)

WriteLines write multi lines code

type EnumInfo

type EnumInfo struct {
	typing.AliasType
	Values []*EnumValue
}

EnumInfo enum type and values

func (*EnumInfo) IsString

func (e *EnumInfo) IsString() bool

IsString return if is a string type Enum

type EnumValue

type EnumValue struct {
	Name       string         // the objc enum name
	GoName     string         // the go name of enum
	Value      string         // the value(amd64 arch)
	Arm64Value string         // the value for arm64. if is empty, use Value
	Module     *typing.Module // the module enum value defined in
}

EnumValue the enum name and value

type FileWriter

type FileWriter struct {
	Name        string // usually the header file name, without .h
	Module      typing.Module
	CodeFileDir string
	// contains filtered or unexported fields
}

TypeWriter write codes for a go file

func (*FileWriter) Add

func (w *FileWriter) Add(types ...CodeGen)

func (*FileWriter) WriteCode

func (w *FileWriter) WriteCode()

type Method

type Method struct {
	Name         string // the first part of objc method name
	GoName       string
	Params       []*Param
	ReturnType   typing.Type
	ClassMethod  bool // true if is class method
	WeakProperty bool // if is a weak property setter
	Deprecated   bool // if has been deprecated
	Required     bool // If this method is required. only for protocol method.
	InitMethod   bool // method that return instancetype
	// contains filtered or unexported fields
}

Method is code generator for objective-c method

func (*Method) GoFuncDeclare

func (m *Method) GoFuncDeclare(currentModule *typing.Module, goTypeName string) string

GoFuncDeclare generate go function declaration

func (*Method) GoFuncName

func (m *Method) GoFuncName(goTypeName string) string

GoFuncName return go func name

func (*Method) GoImports

func (m *Method) GoImports() set.Set[string]

GoImports return all imports for go file

func (*Method) NormalizeInstanceTypeMethod

func (m *Method) NormalizeInstanceTypeMethod(returnType *typing.ClassType) *Method

NormalizeInstanceTypeMethod return new init method.

func (*Method) ProtocolGoFuncFieldType

func (m *Method) ProtocolGoFuncFieldType(currentModule *typing.Module) string

ProtocolGoFuncFieldType generate go function declaration for protocol struct impl field

func (*Method) ProtocolGoFuncName

func (m *Method) ProtocolGoFuncName() string

ProtocolGoFuncName return go protocol func name

func (*Method) Selector

func (m *Method) Selector() string

Selector return full Objc function name

func (*Method) String

func (m *Method) String() string

func (*Method) WriteGoCallCode

func (m *Method) WriteGoCallCode(currentModule *typing.Module, typeName string, cw *CodeWriter)

WriteGoCallCode generate go method code to call c wrapper code

func (*Method) WriteGoInterfaceCode

func (m *Method) WriteGoInterfaceCode(currentModule *typing.Module, classType *typing.ClassType, w *CodeWriter)

WriteGoInterfaceCode generate go interface method signature code

type ModuleWriter

type ModuleWriter struct {
	Module      typing.Module
	CodeFileDir string
	Protocols   []*typing.ProtocolType
	Aliases     []*EnumInfo
}

ModuleWriter mantains module level auto-generated code source files

func (*ModuleWriter) WriteAliasesCode

func (m *ModuleWriter) WriteAliasesCode()

func (*ModuleWriter) WriteCode

func (m *ModuleWriter) WriteCode()

func (*ModuleWriter) WriteProtocolsImportCode

func (m *ModuleWriter) WriteProtocolsImportCode()

type Param

type Param struct {
	Name      string
	Type      typing.Type
	FieldName string // objc param field name(part of function name)
}

Param is code generator for objective-c method param

func (*Param) GoDeclare

func (p *Param) GoDeclare(currentModule *typing.Module, receiveFromObjc bool) string

GoDeclare return go param declare code

func (*Param) GoName

func (p *Param) GoName() string

func (*Param) ObjcDeclare

func (p *Param) ObjcDeclare() string

func (*Param) String

func (p *Param) String() string

type Property

type Property struct {
	Name          string
	GoName        string
	ReadOnly      bool
	GetterName    string
	Type          typing.Type
	ClassProperty bool
	Weak          bool
	Deprecated    bool
	Required      bool //for protocol
}

Property is code generator for objective-c property

func (*Property) String

func (p *Property) String() string

type Protocol

type Protocol struct {
	Type       *typing.ProtocolType
	Parents    []*Protocol
	Methods    []*Method
	Properties []*Property
	// contains filtered or unexported fields
}

Protocol is code generator for objc protocol.

func (*Protocol) Copy

func (p *Protocol) Copy() CodeGen

Copy implements CodeGen

func (*Protocol) GoImports

func (p *Protocol) GoImports() set.Set[string]

func (*Protocol) Init

func (p *Protocol) Init()

func (*Protocol) String

func (p *Protocol) String() string

func (*Protocol) WriteGoCode

func (p *Protocol) WriteGoCode(w *CodeWriter)

Jump to

Keyboard shortcuts

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