codegen

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AutoGeneratedMark = "// Code generated by DarwinKit. DO NOT EDIT.\n"

Functions

func Create

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

Types

type AliasInfo

type AliasInfo struct {
	typing.AliasType
	Description string
	DocURL      string
	Values      []*EnumValue
}

AliasInfo enum type and values

func (*AliasInfo) IsString

func (e *AliasInfo) IsString() bool

IsString return if is a string type Enum

type Class

type Class struct {
	Type                *typing.ClassType
	Super               *Class
	Properties          []*Property
	InstanceTypeMethods []*Method // methods that return instance type
	Methods             []*Method
	Description         string
	DocURL              string
	// 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 // I do NOT understand why this exists
	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 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     *modules.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      modules.Module
	PlatformDir 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
	Suffix       bool // GoName conflicts so add suffix to this method
	Variadic     bool
	Description  string
	DocURL       string
	Protocol     bool
	// contains filtered or unexported fields
}

Method is code generator for objective-c method

func (*Method) GoFuncDeclare

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

GoFuncDeclare generate go function declaration

func (*Method) GoFuncName

func (m *Method) GoFuncName() 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) HasProtocolParam

func (m *Method) HasProtocolParam() bool

func (*Method) NormalizeInstanceTypeMethod

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

NormalizeInstanceTypeMethod return new init method.

func (*Method) ProtocolGoFuncFieldType

func (m *Method) ProtocolGoFuncFieldType(currentModule *modules.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) ToProtocolParamAsObjectMethod

func (m *Method) ToProtocolParamAsObjectMethod() *Method

func (*Method) WriteGoCallCode

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

WriteGoCallCode generate go method code to call c wrapper code

func (*Method) WriteGoInterfaceCode

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

WriteGoInterfaceCode generate go interface method signature code

type ModuleWriter

type ModuleWriter struct {
	Module      modules.Module
	Description string
	DocURL      string
	PlatformDir string
	Protocols   []*typing.ProtocolType
	EnumAliases []*AliasInfo
	FuncAliases []*AliasInfo
}

ModuleWriter mantains module level auto-generated code source files

func (*ModuleWriter) WriteCode

func (m *ModuleWriter) WriteCode()

func (*ModuleWriter) WriteDocFile

func (m *ModuleWriter) WriteDocFile()

func (*ModuleWriter) WriteEnumAliases

func (m *ModuleWriter) WriteEnumAliases()

func (*ModuleWriter) WriteProtocolsImportCode

func (m *ModuleWriter) WriteProtocolsImportCode()

func (*ModuleWriter) WriteTypeAliases

func (m *ModuleWriter) WriteTypeAliases()

type Param

type Param struct {
	Name      string
	Type      typing.Type
	FieldName string // objc param field name(part of function name)
	Object    bool   // version of param generalized to IObject for protocols
	IsPtrPtr  bool
}

Param is code generator for objective-c method param

func (*Param) GoDeclare

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

Return Go parameter code

func (*Param) GoName

func (p *Param) GoName() (name 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
	SetterName    string
	Type          typing.Type
	ClassProperty bool
	Weak          bool
	Deprecated    bool
	Required      bool //for protocol
	Description   string
	DocURL        string
}

Property is code generator for objective-c property

func (*Property) String

func (p *Property) String() string

type Protocol

type Protocol struct {
	Type        *typing.ProtocolType
	Supers      []*Protocol
	Methods     []*Method
	Properties  []*Property
	Description string
	DocURL      string

	SkipInterface bool
	SkipWrapper   bool
	SkipDelegate  bool
	// 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