Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preprocessor #273

Closed
wants to merge 132 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
fa8595c
unused
Konstantin8105 Oct 5, 2017
9fd2eeb
unused flag for transpile
Konstantin8105 Oct 5, 2017
566bdb5
add unused var, const, type
Konstantin8105 Oct 6, 2017
e3ebd11
add unused func
Konstantin8105 Oct 6, 2017
a9bebc6
add TODO : remove unused imports
Konstantin8105 Oct 6, 2017
176df19
add position checking
Konstantin8105 Oct 6, 2017
94ec42e
add TODO
Konstantin8105 Oct 6, 2017
6a4f843
simplification
Konstantin8105 Oct 7, 2017
f29d966
Unused is Warning, not Error
Konstantin8105 Oct 7, 2017
854f04c
remove unused functions
Konstantin8105 Oct 7, 2017
e5af4f3
repair unused functions
Konstantin8105 Oct 7, 2017
6020a59
change warning
Konstantin8105 Oct 7, 2017
079f7d5
go vet
Konstantin8105 Oct 7, 2017
16a2629
add comment in script
Konstantin8105 Oct 7, 2017
cc1f1c8
add 20 minute for travis
Konstantin8105 Oct 7, 2017
9738323
remove travis
Konstantin8105 Oct 7, 2017
b037dec
prepare after commenting
Konstantin8105 Oct 9, 2017
23b9e5d
cli
Konstantin8105 Oct 9, 2017
47837b9
travis back
Konstantin8105 Oct 9, 2017
13fb3bf
panic - recover. Add ReadMe
Konstantin8105 Oct 9, 2017
cd2b304
README
Konstantin8105 Oct 9, 2017
162f639
add more verbose for avoid travis timeout
Konstantin8105 Oct 9, 2017
1f6f7c9
travis timeout fight
Konstantin8105 Oct 9, 2017
d7c146c
travis timeout fight
Konstantin8105 Oct 9, 2017
5fea2f6
travis timeout fight
Konstantin8105 Oct 9, 2017
cce09f6
travis timeout fight
Konstantin8105 Oct 9, 2017
ee0aaab
travis timeout fight
Konstantin8105 Oct 9, 2017
0b270f4
travis timeout fight
Konstantin8105 Oct 9, 2017
2ca09b5
travis timeout fight
Konstantin8105 Oct 9, 2017
65d06f9
travis timeout fight
Konstantin8105 Oct 9, 2017
93eb75d
travis timeout fight
Konstantin8105 Oct 9, 2017
95fa4d8
travis timeout fight
Konstantin8105 Oct 9, 2017
9008630
travis timeout fight
Konstantin8105 Oct 9, 2017
334b470
travis timeout fight
Konstantin8105 Oct 9, 2017
3fb9474
travis timeout fight
Konstantin8105 Oct 9, 2017
4ef6fac
travis timeout fight
Konstantin8105 Oct 9, 2017
1cf1dc3
travis timeout fight
Konstantin8105 Oct 9, 2017
8b97928
travis timeout fight
Konstantin8105 Oct 9, 2017
451848b
specify cover profile
Konstantin8105 Oct 9, 2017
eee877e
remove temp files
Konstantin8105 Oct 9, 2017
7d01cee
try to solve lines for GOLIST
Konstantin8105 Oct 9, 2017
e08afd1
3 <<< instand of 1
Konstantin8105 Oct 9, 2017
b495347
try for -do - done
Konstantin8105 Oct 9, 2017
e5ca5dc
next change
Konstantin8105 Oct 9, 2017
2c0fe4f
return back
Konstantin8105 Oct 9, 2017
7a26be7
add tee command
Konstantin8105 Oct 9, 2017
0d0b134
try use eval
Konstantin8105 Oct 9, 2017
cc638a7
try use eval
Konstantin8105 Oct 9, 2017
0cfbae7
try use eval
Konstantin8105 Oct 9, 2017
b05ae1f
try use eval
Konstantin8105 Oct 9, 2017
f9cac11
try use eval
Konstantin8105 Oct 9, 2017
9f46aa9
try use eval
Konstantin8105 Oct 9, 2017
8280f9a
try use eval
Konstantin8105 Oct 9, 2017
c6fffc1
simplification
Konstantin8105 Oct 9, 2017
2c78a37
Add wait
Konstantin8105 Oct 10, 2017
ff4b37c
after comments
Konstantin8105 Oct 10, 2017
4b2a214
after commit
Konstantin8105 Oct 10, 2017
818db53
add time ticker for travis
Konstantin8105 Oct 11, 2017
71f9c28
add time ticker for travis
Konstantin8105 Oct 11, 2017
d42cf5a
travis 30
Konstantin8105 Oct 11, 2017
a26c831
remove cleaner
Konstantin8105 Oct 11, 2017
2c4c9aa
remove cleaner
Konstantin8105 Oct 11, 2017
990948c
test unused entities only for one case
Konstantin8105 Oct 11, 2017
4b01377
add test with removing unused
Konstantin8105 Oct 11, 2017
0ca8ec7
add verbose check
Konstantin8105 Oct 11, 2017
4060583
remove recover in main.go
Konstantin8105 Oct 17, 2017
7aed24d
remove verbode for sqlite
Konstantin8105 Oct 17, 2017
3e295b5
added cleaner inside c2go
Konstantin8105 Oct 17, 2017
8480cbb
Merge branch 'master' into master
Konstantin8105 Oct 17, 2017
9ba2fdb
remove \reflect\ import
Konstantin8105 Oct 17, 2017
49a0c43
Merge branch 'master' into master
Konstantin8105 Oct 19, 2017
b701e99
prepare for PR
Konstantin8105 Oct 19, 2017
ca68f8b
avoid creating templorary test file in main project folder
Konstantin8105 Oct 19, 2017
06423ee
change preprocess test for avoid mistake
Konstantin8105 Oct 19, 2017
14b8b61
minor
Konstantin8105 Oct 20, 2017
f9c5c3b
Merge branch 'master' of https://github.com/elliotchance/c2go
Konstantin8105 Oct 20, 2017
91776a8
remove package cleaner
Konstantin8105 Oct 23, 2017
e614161
Merge branch 'master' of https://github.com/Konstantin8105/c2go
Konstantin8105 Oct 24, 2017
3cb5fa4
add comment in README
Konstantin8105 Oct 24, 2017
24471c0
prepare preprocessor analyzing
Konstantin8105 Oct 24, 2017
68e6d8a
add tests
Konstantin8105 Oct 24, 2017
63708bd
test are ok
Konstantin8105 Oct 24, 2017
e320214
add parse include list
Konstantin8105 Oct 24, 2017
96f0a1b
implementation to transpiler
Konstantin8105 Oct 24, 2017
4a01b69
add force TODOs
Konstantin8105 Oct 24, 2017
e1529d6
merge to master
Konstantin8105 Oct 25, 2017
8ce6b4a
add test for position of source
Konstantin8105 Oct 25, 2017
6ff7bf6
test are Ok
Konstantin8105 Oct 25, 2017
7585d15
tests are Ok
Konstantin8105 Oct 25, 2017
ca2daf2
Now, c2go test are FAIL
Konstantin8105 Oct 25, 2017
e717b87
Now, c2go test are FAIL
Konstantin8105 Oct 25, 2017
0ecb851
Remove wrong file
Konstantin8105 Oct 25, 2017
d05d6c8
add package os for OutputAsTest
Konstantin8105 Oct 25, 2017
93dc349
fix problem with ctype.h
Konstantin8105 Oct 25, 2017
208fdc2
fix problem with test enum.c
Konstantin8105 Oct 25, 2017
b760056
one more test is Ok
Konstantin8105 Oct 25, 2017
7369ac9
add support stdout,... in test
Konstantin8105 Oct 25, 2017
fdc0197
problem with stdio.c is fix
Konstantin8105 Oct 25, 2017
a868619
add test
Konstantin8105 Oct 25, 2017
d83a3b7
ignore fail tests
Konstantin8105 Oct 25, 2017
5527448
debug MacOS
Konstantin8105 Oct 26, 2017
5e79b2d
debug MacOS
Konstantin8105 Oct 26, 2017
0ac1eb5
debug MacOS
Konstantin8105 Oct 26, 2017
f4502c4
debug MacOS
Konstantin8105 Oct 26, 2017
3bef8d2
return all back
Konstantin8105 Oct 26, 2017
735a990
add new ast element
Oct 26, 2017
664faa4
test assert.c is OK
Konstantin8105 Oct 26, 2017
58e01e1
test exit.c is OK
Konstantin8105 Oct 26, 2017
b963b01
Commit with debug information
Konstantin8105 Oct 26, 2017
5ff9c9d
added simply tree viewer for AST like json
Konstantin8105 Oct 26, 2017
878ec81
test ctype.c is Ok, now
Konstantin8105 Oct 27, 2017
458d19a
Test math.h with only 2 error
Konstantin8105 Oct 27, 2017
8310d29
Remove debug option
Konstantin8105 Oct 27, 2017
0a4d178
test stdio.c is OK
Konstantin8105 Oct 27, 2017
701a8e3
tests are Ok
Konstantin8105 Oct 27, 2017
aa6c1d0
add test and fix 1 bug for sqlite
Konstantin8105 Oct 27, 2017
71f3613
sqlite test is OK
Konstantin8105 Oct 27, 2017
b4368c4
prepare for review
Konstantin8105 Oct 27, 2017
8abb3cb
prepare for review
Konstantin8105 Oct 27, 2017
3ce54ee
prepare for review
Konstantin8105 Oct 27, 2017
7b235fe
prepare for review
Konstantin8105 Oct 27, 2017
ed045c4
add flag
Konstantin8105 Oct 28, 2017
780d297
change argument test
Konstantin8105 Oct 28, 2017
7d9d67e
add type size_t
Konstantin8105 Oct 29, 2017
eac78ba
add removing temp file from stdio.h
Konstantin8105 Oct 30, 2017
1bcf1c6
solve 2 TODO
Konstantin8105 Oct 30, 2017
e655d1b
climate change
Konstantin8105 Oct 30, 2017
0d12e94
Merge branch 'master' into Preprocessor
Konstantin8105 Oct 31, 2017
adc3b38
Merge branch 'master' into Preprocessor
Konstantin8105 Oct 31, 2017
571c121
add more test for ast.Atos
Konstantin8105 Oct 31, 2017
b82e5db
solve 2 TODO
Konstantin8105 Oct 30, 2017
b1ef1e9
Merge branch 'Preprocessor' of https://github.com/Konstantin8105/c2go…
Konstantin8105 Nov 2, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .snapshots/c2go-TestCLI-func1-TranspileHelpFlag
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
([]string) (len=8) {
([]string) (len=10) {
(string) (len=59) "Usage: test transpile [-V] [-o file.go] [-p package] file.c",
(string) (len=31) " -V\tprint progress as comments",
(string) (len=27) " -h\tprint help information",
(string) (len=14) " -keep-unused",
(string) (len=105) " \tKeep unused constants, functions, variables, types and methods of unused types from C system headers",
(string) (len=11) " -o string",
(string) (len=51) " \toutput Go generated code to the specified file",
(string) (len=11) " -p string",
Expand Down
4 changes: 3 additions & 1 deletion .snapshots/c2go-TestCLI-func1-TranspileNoFilesHelp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
([]string) (len=8) {
([]string) (len=10) {
(string) (len=59) "Usage: test transpile [-V] [-o file.go] [-p package] file.c",
(string) (len=31) " -V\tprint progress as comments",
(string) (len=27) " -h\tprint help information",
(string) (len=14) " -keep-unused",
(string) (len=105) " \tKeep unused constants, functions, variables, types and methods of unused types from C system headers",
(string) (len=11) " -o string",
(string) (len=51) " \toutput Go generated code to the specified file",
(string) (len=11) " -p string",
Expand Down
57 changes: 57 additions & 0 deletions ast/alloc_size_attr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package ast

import (
"strings"

"github.com/elliotchance/c2go/util"
)

// AllocSizeAttr is a type of attribute that is optionally attached to a variable
// or struct field definition.
type AllocSizeAttr struct {
Addr Address
Pos Position
Inherited bool
A int
B int
ChildNodes []Node
}

func parseAllocSizeAttr(line string) *AllocSizeAttr {
groups := groupsFromRegex(
`<(?P<position>.*)>(?P<inherited> Inherited)?(?P<a> \d+)(?P<b> \d+)?`,
line,
)

return &AllocSizeAttr{
Addr: ParseAddress(groups["address"]),
Pos: NewPositionFromString(groups["position"]),
Inherited: len(groups["inherited"]) > 0,
A: util.Atoi(strings.TrimSpace(groups["a"])),
B: util.Atoi(strings.TrimSpace(groups["b"])),
ChildNodes: []Node{},
}
}

// AddChild adds a new child node. Child nodes can then be accessed with the
// Children attribute.
func (n *AllocSizeAttr) AddChild(node Node) {
n.ChildNodes = append(n.ChildNodes, node)
}

// Address returns the numeric address of the node. See the documentation for
// the Address type for more information.
func (n *AllocSizeAttr) Address() Address {
return n.Addr
}

// Children returns the child nodes. If this node does not have any children or
// this node does not support children it will always return an empty slice.
func (n *AllocSizeAttr) Children() []Node {
return n.ChildNodes
}

// Position returns the position in the original source code.
func (n *AllocSizeAttr) Position() Position {
return n.Pos
}
27 changes: 27 additions & 0 deletions ast/alloc_size_attr_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ast

import (
"testing"
)

func TestAllocSizeAttr(t *testing.T) {
nodes := map[string]Node{
`0x7f8e390a5d38 <col:100, col:114> 1 2`: &AllocSizeAttr{
Addr: 0x7f8e390a5d38,
Pos: NewPositionFromString("col:100, col:114"),
A: 1,
B: 2,
ChildNodes: []Node{},
},
`0x7fbd1a167f48 </usr/include/stdlib.h:342:37> Inherited 1 0`: &AllocSizeAttr{
Addr: 0x7fbd1a167f48,
Pos: NewPositionFromString("/usr/include/stdlib.h:342:37"),
Inherited: true,
A: 1,
B: 0,
ChildNodes: []Node{},
},
}

runNodeTests(t, nodes)
}
4 changes: 4 additions & 0 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func Parse(line string) Node {
switch nodeName {
case "AlignedAttr":
return parseAlignedAttr(line)
case "AllocSizeAttr":
return parseAllocSizeAttr(line)
case "AlwaysInlineAttr":
return parseAlwaysInlineAttr(line)
case "ArraySubscriptExpr":
Expand Down Expand Up @@ -85,6 +87,8 @@ func Parse(line string) Node {
return parseDeclStmt(line)
case "DefaultStmt":
return parseDefaultStmt(line)
case "DisableTailCallsAttr":
return parseDisableTailCallsAttr(line)
case "DeprecatedAttr":
return parseDeprecatedAttr(line)
case "DoStmt":
Expand Down
20 changes: 20 additions & 0 deletions ast/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,23 @@ func runNodeTests(t *testing.T, tests map[string]Node) {
})
}
}

func TestPrint(t *testing.T) {
cond := &ConditionalOperator{}
cond.AddChild(&ImplicitCastExpr{})
cond.AddChild(&ImplicitCastExpr{})
s := Atos(cond)
if len(s) == 0 {
t.Fatalf("Cannot convert AST tree : %#v", cond)
}
lines := strings.Split(s, "\n")
var amount int
for _, l := range lines {
if strings.Contains(l, "ImplicitCastExpr") {
amount++
}
}
if amount != 2 {
t.Error("Not correct design of output")
}
}
45 changes: 45 additions & 0 deletions ast/disable_tail_calls_attr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package ast

// DisableTailCallsAttr is a type of attribute that is optionally attached to a variable
// or struct field definition.
type DisableTailCallsAttr struct {
Addr Address
Pos Position
ChildNodes []Node
}

func parseDisableTailCallsAttr(line string) *DisableTailCallsAttr {
groups := groupsFromRegex(
"<(?P<position>.*)>",
line,
)

return &DisableTailCallsAttr{
Addr: ParseAddress(groups["address"]),
Pos: NewPositionFromString(groups["position"]),
ChildNodes: []Node{},
}
}

// AddChild adds a new child node. Child nodes can then be accessed with the
// Children attribute.
func (n *DisableTailCallsAttr) AddChild(node Node) {
n.ChildNodes = append(n.ChildNodes, node)
}

// Address returns the numeric address of the node. See the documentation for
// the Address type for more information.
func (n *DisableTailCallsAttr) Address() Address {
return n.Addr
}

// Children returns the child nodes. If this node does not have any children or
// this node does not support children it will always return an empty slice.
func (n *DisableTailCallsAttr) Children() []Node {
return n.ChildNodes
}

// Position returns the position in the original source code.
func (n *DisableTailCallsAttr) Position() Position {
return n.Pos
}
17 changes: 17 additions & 0 deletions ast/disable_tail_calls_attr_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ast

import (
"testing"
)

func TestDisableTailCallsAttr(t *testing.T) {
nodes := map[string]Node{
`0x7fc8fa094558 <col:107> `: &DisableTailCallsAttr{
Addr: 0x7fc8fa094558,
Pos: NewPositionFromString("col:107"),
ChildNodes: []Node{},
},
}

runNodeTests(t, nodes)
}
3 changes: 2 additions & 1 deletion ast/floating_literal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package ast
import (
"errors"
"fmt"
"github.com/elliotchance/c2go/cc"
"reflect"

"github.com/elliotchance/c2go/cc"
)

type FloatingLiteral struct {
Expand Down
7 changes: 7 additions & 0 deletions ast/floating_literal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ func TestFloatingLiteral(t *testing.T) {
Value: 1.23,
ChildNodes: []Node{},
},
`0x21c65b8 <col:41> 'double' 2.718282e+00`: &FloatingLiteral{
Addr: 0x21c65b8,
Pos: NewPositionFromString("col:41"),
Type: "double",
Value: 2.718282e+00,
ChildNodes: []Node{},
},
}

runNodeTests(t, nodes)
Expand Down
4 changes: 4 additions & 0 deletions ast/position.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ func setPosition(node Node, position Position) {
switch n := node.(type) {
case *AlignedAttr:
n.Pos = position
case *AllocSizeAttr:
n.Pos = position
case *AlwaysInlineAttr:
n.Pos = position
case *ArraySubscriptExpr:
Expand Down Expand Up @@ -255,6 +257,8 @@ func setPosition(node Node, position Position) {
n.Pos = position
case *DeprecatedAttr:
n.Pos = position
case *DisableTailCallsAttr:
n.Pos = position
case *DoStmt:
n.Pos = position
case *EnumConstantDecl:
Expand Down
41 changes: 41 additions & 0 deletions ast/util.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package ast

import (
"bytes"
"encoding/json"
"fmt"
"strconv"
"strings"
)
Expand Down Expand Up @@ -33,3 +36,41 @@ func atof(s string) float64 {

return f
}

// Atos - ASTree to string
// Typically using for debug
func Atos(node Node) string {
j, err := json.Marshal(node)
if err != nil {
panic(err)
}
var out bytes.Buffer
err = json.Indent(&out, j, "", "\t")
if err != nil {
panic(err)
}
var str string
str += fmt.Sprint("==== START OF AST tree ====\n")
str += out.String()
str += fmt.Sprintf("\nTypes tree:\n")
str += typesTree(node, 0)
str += fmt.Sprint("==== END OF AST tree ====\n")
return str
}

func typesTree(node Node, depth int) (str string) {
if node == (Node)(nil) {
return ""
}
for i := 0; i < depth; i++ {
str += "\t"
}
str += fmt.Sprintf("%T\n", node)
depth++
if len(node.Children()) > 0 {
for _, n := range node.Children() {
str += typesTree(n, depth)
}
}
return str
}
Loading