Skip to content

Commit

Permalink
Merge pull request #24 from elliotchance/cleanup
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
elliotchance authored Apr 14, 2017
2 parents c8585a2 + 0e68111 commit 217ad0a
Show file tree
Hide file tree
Showing 64 changed files with 1,818 additions and 1,756 deletions.
2 changes: 1 addition & 1 deletion always_inline_attr.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func parseAlwaysInlineAttr(line string) *AlwaysInlineAttr {
)

return &AlwaysInlineAttr{
Address: groups["address"],
Address: groups["address"],
Position: groups["position"],
Children: []interface{}{},
}
Expand Down
14 changes: 11 additions & 3 deletions array_subscript_expr.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package main

import "fmt"

type ArraySubscriptExpr struct {
Address string
Position string
Expand All @@ -15,10 +17,16 @@ func parseArraySubscriptExpr(line string) *ArraySubscriptExpr {
)

return &ArraySubscriptExpr{
Address: groups["address"],
Address: groups["address"],
Position: groups["position"],
Type: groups["type"],
Kind: groups["kind"],
Type: groups["type"],
Kind: groups["kind"],
Children: []interface{}{},
}
}

func (n *ArraySubscriptExpr) Render() []string {
children := n.Children
return []string{fmt.Sprintf("%s[%s]", renderExpression(children[0])[0],
renderExpression(children[1])[0]), "unknown1"}
}
6 changes: 3 additions & 3 deletions asm_label_attr.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ func parseAsmLabelAttr(line string) *AsmLabelAttr {
)

return &AsmLabelAttr{
Address: groups["address"],
Position: groups["position"],
Address: groups["address"],
Position: groups["position"],
FunctionName: groups["function"],
Children: []interface{}{},
Children: []interface{}{},
}
}
58 changes: 11 additions & 47 deletions ast.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
package main

import (
"bytes"
"regexp"
"strconv"
"strings"
)

type ExpressionRenderer interface {
// TODO: The two arguments returned are the rendered Go and the C type.
// This should be made into an appropriate type.
Render() []string
}

type LineRenderer interface {
RenderLine(out *bytes.Buffer, functionName string, indent int, returnType string)
}

func Parse(line string) interface{} {
nodeName := strings.SplitN(line, " ", 2)[0]
var node interface{}
Expand Down Expand Up @@ -149,49 +159,3 @@ func groupsFromRegex(rx, line string) map[string]string {

return result
}

func atoi(s string) int {
i, err := strconv.Atoi(s)
if err != nil {
panic(err)
}

return i
}

func removeQuotes(s string) string {
s = strings.TrimSpace(s)

if s == `""` {
return ""
}
if s == `''` {
return ""
}

if len(s) >= 2 && s[0] == '"' && s[len(s) - 1] == '"' {
return s[1:len(s) - 2]
}
if len(s) >= 2 && s[0] == '\'' && s[len(s) - 1] == '\'' {
return s[1:len(s) - 1]
}

return s
}

func atof(s string) float64 {
f, err := strconv.ParseFloat(s, 64)
if err != nil {
panic(err)
}

return f
}

func unescapeString(s string) string {
s = strings.Replace(s, "\\n", "\n", -1)
s = strings.Replace(s, "\\r", "\r", -1)
s = strings.Replace(s, "\\t", "\t", -1)

return s
}
Loading

0 comments on commit 217ad0a

Please sign in to comment.