Skip to content

Commit

Permalink
Merge pull request #204 from elliotchance/0.13.x/sqlite3-fixes
Browse files Browse the repository at this point in the history
Adding SQLite3 transpile as part of the build process
  • Loading branch information
elliotchance authored Jul 30, 2017
2 parents b772f12 + ab56404 commit 7354d3a
Show file tree
Hide file tree
Showing 37 changed files with 838 additions and 423 deletions.
65 changes: 10 additions & 55 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ os:
- osx

env:
- CLANG=3.9
- SCRIPT=test CLANG=3.9

matrix:
include:
- env: CLANG=3.8
- env: SCRIPT=test CLANG=3.4
os: linux
- env: CLANG=3.7
- env: SCRIPT=test CLANG=3.6
os: linux
- env: CLANG=3.6
- env: SCRIPT=test CLANG=3.7
os: linux
- env: CLANG=3.4
- env: SCRIPT=test CLANG=3.8
os: linux
- env: SCRIPT=lint CLANG=3.9
os: linux
- env: SCRIPT=sqlite3 CLANG=3.9
os: osx

before_install:
- |
Expand All @@ -39,56 +43,7 @@ before_install:
- go get -u github.com/wadey/gocovmerge

script:
- . ./.travis.gofmt.sh

# Run the unit/integration tests first
- |
set -e
echo "" > coverage.txt
# The code below was copied from:
# https://github.com/golang/go/issues/6909#issuecomment-232878416
#
# As in @rodrigocorsi2 comment above (using full path to grep due to
# 'grep -n' alias).
export PKGS=$(go list ./... | grep -v c2go/build | grep -v /vendor/)
# Make comma-separated.
export PKGS_DELIM=$(echo "$PKGS" | paste -sd "," -)
# Run tests and append all output to out.txt. It's important we have "-v"
# so that all the test names are printed. It's also important that the
# covermode be set to "count" so that the coverage profiles can be merged
# correctly together with gocovmerge.
#
# Exit code 123 will be returned if any of the tests fail.
rm -f /tmp/out.txt
go list -f 'go test -v -tags=integration -race -covermode count -coverprofile {{.Name}}.coverprofile -coverpkg $PKGS_DELIM {{.ImportPath}}' $PKGS |
xargs -I{} bash -c '{}'
# Merge coverage profiles.
COVERAGE_FILES=`ls -1 *.coverprofile 2>/dev/null | wc -l`
if [ $COVERAGE_FILES != 0 ]; then
gocovmerge `ls *.coverprofile` > coverage.txt
rm *.coverprofile
fi
# Print stats
echo "Unit tests: " $(grep "=== RUN" /tmp/out.txt | wc -l)
echo "Integration tests: " $(grep "# Total tests" /tmp/out.txt | cut -c21-)
# These steps are from the README to verify it can be installed and run as
# documented.
- cd /tmp
- export C2GO=$GOPATH/src/github.com/elliotchance/c2go
- c2go transpile $C2GO/examples/prime.c
- echo "47" | go run prime.go
- if [ $(c2go -v | wc -l) -ne 1 ]; then exit 1; fi
- if [ $(cat prime.go | wc -l) -eq 0 ]; then exit 1; fi
- if [ $(c2go ast $C2GO/examples/prime.c | wc -l) -eq 0 ]; then exit 1; fi

# Revert the cwd for any cleanup commands.
- cd -
- . ./travis/$SCRIPT.sh

after_success:
- include_cov=coverage.txt bash <(curl -s https://codecov.io/bash)
Expand Down
6 changes: 5 additions & 1 deletion ast/asm_label_attr.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ package ast
type AsmLabelAttr struct {
Address string
Position string
Inherited bool
FunctionName string
Children []Node
}

func parseAsmLabelAttr(line string) *AsmLabelAttr {
groups := groupsFromRegex(
"<(?P<position>.*)> \"(?P<function>.+)\"",
`<(?P<position>.*)>
(?P<inherited> Inherited)?
"(?P<function>.+)"`,
line,
)

return &AsmLabelAttr{
Address: groups["address"],
Position: groups["position"],
Inherited: len(groups["inherited"]) > 0,
FunctionName: groups["function"],
Children: []Node{},
}
Expand Down
8 changes: 8 additions & 0 deletions ast/asm_label_attr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@ func TestAsmLabelAttr(t *testing.T) {
`0x7ff26d8224e8 </usr/include/sys/cdefs.h:569:36> "_fopen"`: &AsmLabelAttr{
Address: "0x7ff26d8224e8",
Position: "/usr/include/sys/cdefs.h:569:36",
Inherited: false,
FunctionName: "_fopen",
Children: []Node{},
},
`0x7fd55a169318 </usr/include/stdio.h:325:47> Inherited "_popen"`: &AsmLabelAttr{
Address: "0x7fd55a169318",
Position: "/usr/include/stdio.h:325:47",
Inherited: true,
FunctionName: "_popen",
Children: []Node{},
},
}

runNodeTests(t, nodes)
Expand Down
4 changes: 4 additions & 0 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ func Position(node Node) string {
return n.Position
case *UnaryOperator:
return n.Position
case *UnusedAttr:
return n.Position
case *VAArgExpr:
return n.Position
case *VarDecl:
Expand Down Expand Up @@ -380,6 +382,8 @@ func Parse(line string) Node {
return parseUnaryExprOrTypeTraitExpr(line)
case "UnaryOperator":
return parseUnaryOperator(line)
case "UnusedAttr":
return parseUnusedAttr(line)
case "VAArgExpr":
return parseVAArgExpr(line)
case "VarDecl":
Expand Down
47 changes: 31 additions & 16 deletions ast/member_expr.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,47 @@
package ast

type MemberExpr struct {
Address string
Position string
Type string
Lvalue bool
Name string
Address2 string
Children []Node
Address string
Position string
Type string
Type2 string
Name string
IsLvalue bool
IsBitfield bool
Address2 string
IsPointer bool
Children []Node
}

func parseMemberExpr(line string) *MemberExpr {
groups := groupsFromRegex(
`<(?P<position>.*)>
'(?P<type>.*?)'
(?P<tags>.*?)
(?P<type2>:'.*?')?
lvalue
(?P<bitfield> bitfield)?
(?P<pointer>[->.]+)
(?P<name>\w+)
(?P<address2>[0-9a-fx]+)`,
line,
)

type2 := groups["type2"]
if type2 != "" {
type2 = type2[2 : len(type2)-1]
}

return &MemberExpr{
Address: groups["address"],
Position: groups["position"],
Type: groups["type"],
Lvalue: true,
Name: groups["name"],
Address2: groups["address2"],
Children: []Node{},
Address: groups["address"],
Position: groups["position"],
Type: groups["type"],
Type2: type2,
IsPointer: groups["pointer"] == "->",
Name: groups["name"],
IsLvalue: true,
IsBitfield: len(groups["bitfield"]) > 0,
Address2: groups["address2"],
Children: []Node{},
}
}

Expand All @@ -37,7 +51,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
80 changes: 52 additions & 28 deletions ast/member_expr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,64 @@ import (
func TestMemberExpr(t *testing.T) {
nodes := map[string]Node{
`0x7fcc758e34a0 <col:8, col:12> 'int' lvalue ->_w 0x7fcc758d60c8`: &MemberExpr{
Address: "0x7fcc758e34a0",
Position: "col:8, col:12",
Type: "int",
Lvalue: true,
Name: "_w",
Address2: "0x7fcc758d60c8",
Children: []Node{},
Address: "0x7fcc758e34a0",
Position: "col:8, col:12",
Type: "int",
Type2: "",
IsLvalue: true,
IsBitfield: false,
Name: "_w",
Address2: "0x7fcc758d60c8",
IsPointer: true,
Children: []Node{},
},
`0x7fcc76004210 <col:12, col:16> 'unsigned char *' lvalue ->_p 0x7fcc758d6018`: &MemberExpr{
Address: "0x7fcc76004210",
Position: "col:12, col:16",
Type: "unsigned char *",
Lvalue: true,
Name: "_p",
Address2: "0x7fcc758d6018",
Children: []Node{},
Address: "0x7fcc76004210",
Position: "col:12, col:16",
Type: "unsigned char *",
Type2: "",
IsLvalue: true,
IsBitfield: false,
Name: "_p",
Address2: "0x7fcc758d6018",
IsPointer: true,
Children: []Node{},
},
`0x7f85338325b0 <col:4, col:13> 'float' lvalue .constant 0x7f8533832260`: &MemberExpr{
Address: "0x7f85338325b0",
Position: "col:4, col:13",
Type: "float",
Lvalue: true,
Name: "constant",
Address2: "0x7f8533832260",
Children: []Node{},
Address: "0x7f85338325b0",
Position: "col:4, col:13",
Type: "float",
Type2: "",
IsLvalue: true,
IsBitfield: false,
Name: "constant",
Address2: "0x7f8533832260",
IsPointer: false,
Children: []Node{},
},
`0x7f8533832670 <col:4, col:13> 'char *' lvalue .pointer 0x7f85338322b8`: &MemberExpr{
Address: "0x7f8533832670",
Position: "col:4, col:13",
Type: "char *",
Lvalue: true,
Name: "pointer",
Address2: "0x7f85338322b8",
Children: []Node{},
Address: "0x7f8533832670",
Position: "col:4, col:13",
Type: "char *",
Type2: "",
IsLvalue: true,
IsBitfield: false,
Name: "pointer",
Address2: "0x7f85338322b8",
IsPointer: false,
Children: []Node{},
},
`0x7fb7d5a49ac8 <col:3, col:6> 'bft':'unsigned int' lvalue bitfield ->isPrepareV2 0x7fb7d5967f40`: &MemberExpr{
Address: "0x7fb7d5a49ac8",
Position: "col:3, col:6",
Type: "bft",
Type2: "unsigned int",
IsLvalue: true,
IsBitfield: true,
Name: "isPrepareV2",
Address2: "0x7fb7d5967f40",
IsPointer: true,
Children: []Node{},
},
}

Expand Down
26 changes: 26 additions & 0 deletions ast/unused_attr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ast

type UnusedAttr struct {
Address string
Position string
Children []Node
}

func parseUnusedAttr(line string) *UnusedAttr {
groups := groupsFromRegex(
"<(?P<position>.*)> unused",
line,
)

return &UnusedAttr{
Address: groups["address"],
Position: groups["position"],
Children: []Node{},
}
}

// AddChild adds a new child node. Child nodes can then be accessed with the
// Children attribute.
func (n *UnusedAttr) AddChild(node Node) {
n.Children = append(n.Children, node)
}
17 changes: 17 additions & 0 deletions ast/unused_attr_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ast

import (
"testing"
)

func TestUnusedAttr(t *testing.T) {
nodes := map[string]Node{
`0x7fe3e01416d0 <col:47> unused`: &UnusedAttr{
Address: "0x7fe3e01416d0",
Position: "col:47",
Children: []Node{},
},
}

runNodeTests(t, nodes)
}
6 changes: 3 additions & 3 deletions darwin/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ func AssertRtn(
fmt.Fprintf(
os.Stderr,
"Assertion failed: (%s), function %s, file %s, line %d.\n",
noarch.NullTerminatedByteSlice(expression),
noarch.NullTerminatedByteSlice(functionName),
noarch.NullTerminatedByteSlice(filePath),
noarch.CStringToString(expression),
noarch.CStringToString(functionName),
noarch.CStringToString(filePath),
lineNumber,
)
os.Exit(134)
Expand Down
6 changes: 3 additions & 3 deletions linux/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ func AssertFail(
fmt.Fprintf(
os.Stderr,
"a.out: %s:%d: %s: Assertion `%s' failed.\n",
noarch.NullTerminatedByteSlice(filePath),
noarch.CStringToString(filePath),
lineNumber,
noarch.NullTerminatedByteSlice(functionName),
noarch.NullTerminatedByteSlice(expression),
noarch.CStringToString(functionName),
noarch.CStringToString(expression),
)
os.Exit(134)

Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ func Start(args ProgramArgs) error {
fmt.Println(l)
}
fmt.Println()

return nil
}

nodes := convertLinesToNodes(lines)
Expand Down
Loading

0 comments on commit 7354d3a

Please sign in to comment.