gen

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SignExtMethodMap = map[string]SignExtMethodID{
	"":        SignExtMethodDefault,
	"default": SignExtMethodDefault,
	"shift":   SignExtMethodShift,
	"arith":   SignExtMethodArith,
}

Functions

func MatchOption

func MatchOption(options *util.OrderedMap[string, *definition.Option], name string, value any) bool

Types

type ExprGeneratorImpl

type ExprGeneratorImpl interface {
	GenerateUnopExpr(expr *definition.UnopExpr) (string, error)
	GenerateBinopExpr(expr *definition.BinopExpr) (string, error)
	GenerateCastExpr(expr *definition.CastExpr) (string, error)
	GenerateConstantExpr(expr *definition.ConstantExpr) (string, error)
	GenerateTenaryExpr(expr *definition.TenaryExpr) (string, error)
	GenerateValueExpr(expr *definition.ValueExpr) (string, error)
	GenerateRawExpr(expr *definition.RawExpr) (string, error)
}

type GenCtx

type GenCtx struct {
	Units      []*definition.CompilationUnit
	GenOptions *GenOptions
	OutputPath string
}

func (*GenCtx) WriteFile

func (ctx *GenCtx) WriteFile(file string, text string) error

func (*GenCtx) WriteFileAbs

func (ctx *GenCtx) WriteFileAbs(path string, text string) error

func (*GenCtx) WritePackage

func (ctx *GenCtx) WritePackage(pkg *definition.Package, ext string, text string) error

type GenDispatcher

type GenDispatcher struct {
	GeneratorImpl
}

func NewGenDispatcher

func NewGenDispatcher(generatorImpl GeneratorImpl) *GenDispatcher

func (*GenDispatcher) AcceptExpr

func (d *GenDispatcher) AcceptExpr(expr definition.Expr, impl ...ExprGeneratorImpl) (string, error)

AcceptExpr(expr definition.Expr) (string, error) AcceptExpr(expr definition.Expr, impl ExprGeneratorImpl) (string, error)

func (*GenDispatcher) AcceptField

func (d *GenDispatcher) AcceptField(field definition.Field) (string, error)

func (*GenDispatcher) AcceptGenCtx

func (d *GenDispatcher) AcceptGenCtx(ctx *GenCtx) error

func (*GenDispatcher) AcceptMethod

func (d *GenDispatcher) AcceptMethod(method definition.Method) (string, error)

func (*GenDispatcher) AcceptMethodDecl

func (d *GenDispatcher) AcceptMethodDecl(method definition.Method) (string, error)

func (*GenDispatcher) AcceptType

func (d *GenDispatcher) AcceptType(type_ definition.Type) (string, error)

func (*GenDispatcher) AcceptTypeDefaultValue

func (d *GenDispatcher) AcceptTypeDefaultValue(type_ definition.Type) (string, error)

type GenExprDispatcher

type GenExprDispatcher struct {
	ExprGeneratorImpl
}

func NewGenExprDispatcher

func NewGenExprDispatcher(exprGeneratorImpl ExprGeneratorImpl) *GenExprDispatcher

func (*GenExprDispatcher) AcceptExpr

func (d *GenExprDispatcher) AcceptExpr(expr definition.Expr) (string, error)

func (*GenExprDispatcher) AcceptLiteral

func (d *GenExprDispatcher) AcceptLiteral(literal definition.Literal, impl ...LiteralGeneratorImpl) (string, error)

type GenLiteralDispatcher

type GenLiteralDispatcher struct {
	LiteralGeneratorImpl
}

func NewGenLiteralDispatcher

func NewGenLiteralDispatcher(literalGeneratorImpl LiteralGeneratorImpl) *GenLiteralDispatcher

func (*GenLiteralDispatcher) AcceptLiteral

func (d *GenLiteralDispatcher) AcceptLiteral(literal definition.Literal) (string, error)

type GenOptionSetter

type GenOptionSetter func(*GenOptions)

func DecimalNumber

func DecimalNumber(decnum bool) GenOptionSetter

func InnerClass

func InnerClass(inner bool) GenOptionSetter

func MinimalCode

func MinimalCode(minimal bool) GenOptionSetter

func SignExtMethod

func SignExtMethod(signext string) (GenOptionSetter, error)

func SingleFile

func SingleFile(single bool) GenOptionSetter

type GenOptions

type GenOptions struct {
	InnerClass    bool
	SingleFile    bool
	MinimalCode   bool
	DecimalNumber bool
	SignExtMethod SignExtMethodID
}

func NewGenOptions

func NewGenOptions(setter ...GenOptionSetter) *GenOptions

type GeneratorImpl

type GeneratorImpl interface {
	GenerateUnit(unit *definition.CompilationUnit) error

	// GenerateType(type_ definition.Type) (string, error)
	// GenerateTypeDefaultValue(type_ definition.Type) (string, error)
	GenerateBasicType(type_ *definition.BasicType) (string, error)
	GenerateBasicTypeDefaultValue(type_ *definition.BasicType) (string, error)
	GenerateString(string_ *definition.String) (string, error)
	GenerateStringDefaultValue(string_ *definition.String) (string, error)
	GenerateBytes(bytes *definition.Bytes) (string, error)
	GenerateBytesDefaultValue(bytes *definition.Bytes) (string, error)
	GenerateArray(array *definition.Array) (string, error)
	GenerateArrayDefaultValue(array *definition.Array) (string, error)

	GenerateStruct(structDef *definition.Struct) (string, error)
	GenerateStructDefaultValue(structDef *definition.Struct) (string, error)

	// GenerateField(field definition.Field) (string, error)
	GenerateNormalField(field *definition.NormalField) (string, error)
	GenerateVoidField(field *definition.VoidField) (string, error)
	GenerateEmbeddedField(field *definition.EmbeddedField) (string, error)
	GenerateConstantField(field *definition.ConstantField) (string, error)

	// GenerateMethod(method *definition.Method) (string, error)
	// GenerateMethodDecl(method *definition.Method) (string, error)
	GenerateDefaultGetterDecl(method *definition.GetMethod) (string, error) // unsupported for now
	GenerateDefaultSetterDecl(method *definition.SetMethod) (string, error) // unsupported for now
	GenerateCustomGetterDecl(method *definition.GetMethod) (string, error)
	GenerateCustomSetterDecl(method *definition.SetMethod) (string, error)
	// GenerateRawGetterDecl(method *definition.GetMethod) (string, error)
	// GenerateRawSetterDecl(method *definition.SetMethod) (string, error)
	GenerateDefaultGetter(method *definition.GetMethod) (string, error) // unsupported for now
	GenerateDefaultSetter(method *definition.SetMethod) (string, error) // unsupported for now
	GenerateCustomGetter(method *definition.GetMethod) (string, error)
	GenerateCustomSetter(method *definition.SetMethod) (string, error)

	GenerateEnum(enumDef *definition.Enum) (string, error)
	GenerateEnumDefaultValue(enumDef *definition.Enum) (string, error)
}

type LiteralGeneratorImpl

type LiteralGeneratorImpl interface {
	GenerateBoolLiteral(literal *definition.BoolLiteral) (string, error)
	GenerateIntLiteral(literal *definition.IntLiteral) (string, error)
	GenerateFloatLiteral(literal *definition.FloatLiteral) (string, error)
	GenerateStringLiteral(literal *definition.StringLiteral) (string, error)
}

type SignExtMethodID

type SignExtMethodID int
const (
	SignExtMethodDefault SignExtMethodID = iota
	SignExtMethodShift
	SignExtMethodArith
)

Jump to

Keyboard shortcuts

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