SrcGo

package
v0.0.0-...-eeb70d5 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2022 License: MIT, MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ERR_STR  = "[ERROR]"
	WARN_STR = "[WARNING]"
	FMT_STR  = "%-100s %s\n"
)

Variables

This section is empty.

Functions

func Arrayify

func Arrayify(typ ast.Expr, len ast.Expr) *ast.ArrayType

func ChangeReceiverNames

func ChangeReceiverNames(file *ast.File)

func CollectFuncNames

func CollectFuncNames(file *ast.File) map[string]*ast.FuncDecl

func ExpandFuncPtrCalls

func ExpandFuncPtrCalls(x *ast.CallExpr, retvals []ast.Expr, retTypes []types.Type, ti *types.Info, currFunc *ast.FuncDecl) []ast.Stmt

func FindParam

func FindParam(fn *ast.FuncDecl, name string) (*ast.Field, int)

func FindStmt

func FindStmt(a []ast.Stmt, x ast.Stmt) int

func GetFuncName

func GetFuncName(expr ast.Expr) string

func GetTypeBase

func GetTypeBase(t types.Type) types.Type

func IndexOfValue

func IndexOfValue[T comparable](a []T, x T) int

func InsertToIndex

func InsertToIndex[T any](a []T, index int, value T) []T

func IsFuncPtr

func IsFuncPtr(expr ast.Expr, typ *types.Info) bool

func IsMapType

func IsMapType(expr ast.Expr, typ *types.Info) bool

func MakeAssign

func MakeAssign(create bool) *ast.AssignStmt

func MakeBasicLit

func MakeBasicLit(tok token.Token, value string) *ast.BasicLit

func MakeBitNotExpr

func MakeBitNotExpr(e ast.Expr) *ast.UnaryExpr

func MakeEnumType

func MakeEnumType(name string, names []string, values []int64)

func MakeFunc

func MakeFunc(name string, recv *types.Var, params, results *types.Tuple, variadic bool)

func MakeFuncPtrArgCall

func MakeFuncPtrArgCall(arg ast.Expr, by_ref bool, pretyp types.Type, ti *types.Info) *ast.ExprStmt

func MakeIndex

func MakeIndex(index, x ast.Expr) *ast.IndexExpr

func MakeIntConst

func MakeIntConst(name string, num int64)

func MakeIntVar

func MakeIntVar(name string)

func MakeNamedType

func MakeNamedType(name string, typ types.Type, methods []*types.Func, builtins map[string]types.Object)

func MakeParams

func MakeParams(param_names []string, param_types []types.Type) *types.Tuple

func MakeParenExpr

func MakeParenExpr(e ast.Expr) *ast.ParenExpr

func MakeReference

func MakeReference(x ast.Expr) *ast.UnaryExpr

func MakeRet

func MakeRet(param_types []types.Type) *types.Tuple

func MakeTypeAlias

func MakeTypeAlias(name string, typ types.Type, strong bool, builtins map[string]types.Object)

func MakeVarDecl

func MakeVarDecl(names []*ast.Ident, val ast.Expr, typ types.Type, ti *types.Info) *ast.DeclStmt

func MergeRetTypes

func MergeRetTypes(file *ast.File)

* Pass #3 - Merge Return Types.

func MutateAndNotExpr

func MutateAndNotExpr(file *ast.File)

* Pass #4 - Mutate AND-NOT expressions. * So we basically turn `a &^ b` into `a & ^(b)` * which then becomes `a & ~(b)` in SourcePawn. * * Ditto for the `a &^= b` as well * `a &= ^(b)` becoming `a &= ~(b)`

func MutateAssignDefStmts

func MutateAssignDefStmts(owner_list *[]ast.Stmt, index int, s ast.Stmt, bm BlockMutator, ctxt any)

func MutateAssignStmts

func MutateAssignStmts(owner_list *[]ast.Stmt, index int, s ast.Stmt, bm BlockMutator, ctxt any)

func MutateBlock

func MutateBlock(b *ast.BlockStmt, mutator StmtMutator, ctxt any)

func MutateFuncLit

func MutateFuncLit(owner_list *[]ast.Stmt, index int, s ast.Stmt, bm BlockMutator, ctxt any)

/ func(params){code}(args) => func _srcgo_func#(params){code} ... _srcgo_func#(args)

func MutateFuncLitExprs

func MutateFuncLitExprs(e *ast.Expr, ctxt any)

func MutateNoRetCallStmts

func MutateNoRetCallStmts(owner_list *[]ast.Stmt, index int, s ast.Stmt, bm BlockMutator, ctxt any)

func MutateRangeStmts

func MutateRangeStmts(owner_list *[]ast.Stmt, index int, s ast.Stmt, bm BlockMutator, ctxt any)

func MutateRetStmts

func MutateRetStmts(owner_list *[]ast.Stmt, index int, s ast.Stmt, bm BlockMutator, ctxt any)

func MutateRetTypes

func MutateRetTypes(retvals **ast.FieldList, curr_params *ast.FieldList, obj_name string) []*ast.Field

* Modifies the return values of a function by mutating them into references and moving them to the parameters. * Example Go code: func f() (int, float) {} * Result Go code: func f(f_param1 *float) int {}

func NameAnonFuncs

func NameAnonFuncs(file *ast.File)

* Pass #2 - Name Anonymous Functions * Any unnamed function literal is to be named so they can be generated * as an incrementally named function in SourcePawn. * * This AST pass has to be second because we later * mutate the multi-return types for functions! * * So best get to naming the lambdas before things get really serious!

func PrettyPrintAST

func PrettyPrintAST(n ast.Node) string

func PrintAST

func PrintAST(n ast.Node) string

func PtrizeExpr

func PtrizeExpr(x ast.Expr) *ast.StarExpr

func TypeToASTExpr

func TypeToASTExpr(typ types.Type) ast.Expr

func ValueToTypeExpr

func ValueToTypeExpr(val ast.Expr, ti *types.Info) ast.Expr

Turn a value expr into a type expr.

Types

type AstTransmitter

type AstTransmitter struct {
	Errors    []error
	FileSet   *token.FileSet
	TypeInfo  *types.Info
	Userdata  any
	TmpVar    uint
	DebugMode bool
}

func MakeAstTransmitter

func MakeAstTransmitter(fs *token.FileSet, ti *types.Info, userdata any, debug_mode bool) AstTransmitter

func (*AstTransmitter) AnalyzeIllegalCode

func (a *AstTransmitter) AnalyzeIllegalCode(file *ast.File) bool

* Pass #1 - Analyze Illegal Code * checks for ANY Go constructs that cannot be faithfully recreated in SourcePawn.

func (*AstTransmitter) MutateAssignDecls

func (a *AstTransmitter) MutateAssignDecls(file *ast.File)

Case Studies of Changing assignment definitions: * * a,b,c := f() * * if not func ptr: * var a,b,c type * a = f(&b, &c) * * if func ptr: * var a,b,c type * Call_StartFunction(nil, f) * Call_PushCellRef(&b) * Call_PushCellRef(&c) * Call_Finish(&a) *

func (*AstTransmitter) MutateAssigns

func (a *AstTransmitter) MutateAssigns(file *ast.File)

Case Studies of Changing non-defining assignments: *

func (*AstTransmitter) MutateNoRetCalls

func (a *AstTransmitter) MutateNoRetCalls(file *ast.File)

func (*AstTransmitter) MutateRanges

func (a *AstTransmitter) MutateRanges(file *ast.File)

func (*AstTransmitter) MutateRetExprs

func (a *AstTransmitter) MutateRetExprs(file *ast.File)

Case Studies of Returning statements to transform: * * return m3() /// func m3() (type, type, type) * * return int, float, m1() /// func m1() type

func (*AstTransmitter) PrintErr

func (a *AstTransmitter) PrintErr(p token.Pos, msg string)

func (*AstTransmitter) PrintErrs

func (a *AstTransmitter) PrintErrs()

type BlockMutator

type BlockMutator func(b *ast.BlockStmt, mutator StmtMutator, ctxt any)

type StmtMutator

type StmtMutator func(owner_list *[]ast.Stmt, index int, s ast.Stmt, bm BlockMutator, ctxt any)

Jump to

Keyboard shortcuts

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