Skip to content

Commit

Permalink
Code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotchance committed Jul 23, 2017
1 parent 19497b2 commit 56e679e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions ast/member_expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ type MemberExpr struct {
}

func parseMemberExpr(line string) *MemberExpr {
// 0x7fcc758e34a0 <col:8, col:12> 'int' lvalue ->_w 0x7fcc758d60c8
groups := groupsFromRegex(
`<(?P<position>.*)>
'(?P<type>.*?)'
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion noarch/stdio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
12 changes: 12 additions & 0 deletions noarch/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions transpiler/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 56e679e

Please sign in to comment.