Documentation ¶
Index ¶
- func Atoi(s string) int
- func CreateSliceFromReference(goType string, expr goast.Expr) *goast.SliceExpr
- func GetExportedName(field string) string
- func GroupsFromRegex(rx, line string) map[string]string
- func InStrings(item string, items []string) bool
- func IsAValidFunctionName(s string) bool
- func IsGoKeyword(w string) bool
- func NewBinaryExpr(left goast.Expr, operator token.Token, right goast.Expr, returnType string, ...) goast.Expr
- func NewCallExpr(functionName string, args ...goast.Expr) *goast.CallExpr
- func NewExprStmt(expr goast.Expr) *goast.ExprStmt
- func NewFloatLit(value float64) *goast.BasicLit
- func NewFuncClosure(returnType string, stmts ...goast.Stmt) *goast.CallExpr
- func NewFuncType(fieldList *goast.FieldList, returnType string) *goast.FuncType
- func NewIdent(name string) *goast.Ident
- func NewIntLit(value int) *goast.BasicLit
- func NewNil() *goast.Ident
- func NewStringLit(value string) *goast.BasicLit
- func NewTypeIdent(name string) goast.Expr
- func NewUnaryExpr(operator token.Token, right goast.Expr) *goast.UnaryExpr
- func PanicIfNil(check interface{}, message string)
- func PanicOnError(err error, message string)
- func ShowDiff(a, b string) string
- func Ucfirst(word string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Atoi ¶ added in v0.9.0
Atoi converts a string to an integer in cases where we are sure that s will be a valid integer, otherwise it will panic.
func CreateSliceFromReference ¶ added in v0.14.0
func GetExportedName ¶ added in v0.9.0
GetExportedName returns a deterministic and Go safe name for a C type. For example, "*__foo[]" will return "FooSlice".
func GroupsFromRegex ¶ added in v0.13.3
GroupsFromRegex gets RegExp groups after matching it on a line
func IsAValidFunctionName ¶ added in v0.12.4
IsAValidFunctionName performs a check to see if a string would make a valid function name in Go. Go allows unicode characters, but C doesn't.
func IsGoKeyword ¶ added in v0.14.0
IsGoKeyword will return true if a word is one of the reserved words in Go. This means that it cannot be used as an identifier, function name, etc.
The list of reserved words has been taken from the spec at https://golang.org/ref/spec#Keywords
func NewBinaryExpr ¶ added in v0.11.0
func NewBinaryExpr(left goast.Expr, operator token.Token, right goast.Expr, returnType string, stmt bool) goast.Expr
NewBinaryExpr create a new Go AST binary expression with a left, operator and right operand.
You should use this instead of BinaryExpr directly so that nil left and right operands can be caught (and panic) before Go tried to render the source - which would result in a very hard to debug error.
Assignment operators in C can be nested inside other expressions, like:
a + (b += 3)
In Go this is not allowed. Since the operators mutate variables it is not possible in some cases to move the statements before or after. The only safe (and generic) way around this is to create an immediately executing closure, like:
a + (func () int { b += 3; return b }())
In a lot of cases this may be unnecessary and obfuscate the Go output but these will have to be optimised over time and be strict about the situation they are simplifying.
If stmt is true then the binary expression is the whole statement. This means that the closure above does not need to applied. This makes the output code much neater.
func NewCallExpr ¶ added in v0.11.0
NewCallExpr creates a new *"go/ast".CallExpr with each of the arguments (after the function name) being each of the expressions that represent the individual arguments.
The function name is checked with IsAValidFunctionName and will panic if the function name is deemed to be not valid.
func NewExprStmt ¶ added in v0.11.3
NewExprStmt returns a new ExprStmt from an expression. It is used when converting a single expression into a statement for another receiver.
It is recommended you use this method of instantiating the ExprStmt yourself because NewExprStmt will check that the expr is not nil (or panic). This is much more helpful when trying to debug why the Go source build crashes becuase of a nil pointer - which eventually leads back to a nil expr.
func NewFloatLit ¶ added in v0.13.2
NewFloatLit creates a new Float Literal.
func NewFuncClosure ¶ added in v0.12.4
NewFuncClosure creates a new *"go/ast".CallExpr that calls a function literal closure. The first argument is the Go return type of the closure, and the remainder of the arguments are the statements of the closure body.
func NewFuncType ¶ added in v0.14.0
func NewNil ¶ added in v0.12.0
NewNil returns a Go AST identity that can be used to represent "nil".
func NewStringLit ¶ added in v0.11.0
NewStringLit returns a new Go basic literal with a string value.
func NewTypeIdent ¶ added in v0.13.2
NewTypeIdent created a new Go identity that is to be used for a Go type. This is different from NewIdent in how the input string is validated.
func NewUnaryExpr ¶ added in v0.13.2
NewUnaryExpr creates a new Go unary expression. You should use this function instead of instantiating the UnaryExpr directly because this funtion has extra error checking.
func PanicIfNil ¶ added in v0.13.7
func PanicIfNil(check interface{}, message string)
PanicIfNil will panic with the message provided if the check is nil. This is a convieniance method to avoid many similar if statements.
func PanicOnError ¶ added in v0.13.7
PanicOnError will panic with the message and error if the error is not nil. If the error is nil (no error) then nothing happens.
Types ¶
This section is empty.