From 56e679e6315a50b47088cd8f71c5968987fdb5a2 Mon Sep 17 00:00:00 2001 From: Elliot Chance Date: Sun, 23 Jul 2017 21:09:15 +1000 Subject: [PATCH] Code review changes --- ast/member_expr.go | 4 ++-- noarch/stdio.go | 1 - noarch/util.go | 12 ++++++++++++ transpiler/binary.go | 4 ++-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/ast/member_expr.go b/ast/member_expr.go index a2427a833..daadb3467 100644 --- a/ast/member_expr.go +++ b/ast/member_expr.go @@ -12,7 +12,6 @@ type MemberExpr struct { } func parseMemberExpr(line string) *MemberExpr { - // 0x7fcc758e34a0 'int' lvalue ->_w 0x7fcc758d60c8 groups := groupsFromRegex( `<(?P.*)> '(?P.*?)' @@ -41,7 +40,8 @@ func (n *MemberExpr) AddChild(node Node) { n.Children = append(n.Children, node) } -// GetDeclRefExpr gets DeclRefExpr from MemberExpr, or nil if there is no DeclRefExpr +// GetDeclRefExpr gets DeclRefExpr from MemberExpr, or nil if there is no +// DeclRefExpr func (n *MemberExpr) GetDeclRefExpr() *DeclRefExpr { for _, child := range n.Children { res, ok := child.(*DeclRefExpr) diff --git a/noarch/stdio.go b/noarch/stdio.go index df0e8e167..48ebe12d6 100644 --- a/noarch/stdio.go +++ b/noarch/stdio.go @@ -386,7 +386,6 @@ func Fscanf(f *File, format []byte, args ...interface{}) int { n, err := fmt.Fscanf(f.OsFile, CStringToString(format), realArgs...) if err != nil { - panic(err) return -1 } diff --git a/noarch/util.go b/noarch/util.go index ab63dd610..18c891afd 100644 --- a/noarch/util.go +++ b/noarch/util.go @@ -40,12 +40,24 @@ func CStringIsNull(s []byte) bool { return s[0] == 0 } +// CPointerToGoPointer converts a C-style pointer into a Go-style pointer. +// +// C pointers are represented as slices that have one element pointing to where +// the original C pointer would be referencing. This isn't useful if the pointed +// value needs to be passed to another Go function in these libraries. +// +// See also GoPointerToCPointer. func CPointerToGoPointer(a interface{}) interface{} { t := reflect.TypeOf(a).Elem() return reflect.New(t).Elem().Addr().Interface() } +// GoPointerToCPointer does the opposite of CPointerToGoPointer. +// +// A Go pointer (simply a pointer) is converted back into the original slice +// structure (of the original slice reference) so that the calling functions +// will be able to see the new data of that pointer. func GoPointerToCPointer(destination interface{}, value interface{}) { v := reflect.ValueOf(destination).Elem() reflect.ValueOf(value).Index(0).Set(v) diff --git a/transpiler/binary.go b/transpiler/binary.go index 33c76eddd..4d31b5632 100644 --- a/transpiler/binary.go +++ b/transpiler/binary.go @@ -171,7 +171,7 @@ func transpileBinaryOperator(n *ast.BinaryOperator, p *program.Program) ( resolvedLeftType, err := types.ResolveType(p, leftType) if err != nil { - panic(err) + p.AddMessage(ast.GenerateWarningMessage(err, n)) } return util.NewBinaryExpr(left, operator, right, resolvedLeftType), "bool", @@ -289,7 +289,7 @@ func transpileBinaryOperator(n *ast.BinaryOperator, p *program.Program) ( resolvedLeftType, err := types.ResolveType(p, leftType) if err != nil { - panic(err) + p.AddMessage(ast.GenerateWarningMessage(err, n)) } return util.NewBinaryExpr(left, operator, right, resolvedLeftType),