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

i met a panic when parse c code #794

Open
carolove opened this issue Sep 2, 2018 · 1 comment
Open

i met a panic when parse c code #794

carolove opened this issue Sep 2, 2018 · 1 comment

Comments

@carolove
Copy link

carolove commented Sep 2, 2018

when i build c code at my macbook, the code is fine,
while when i execute c2go transpile main.c
the c2go panic,here is the log

panic: could not match regexp with string
^(?P<address>[0-9a-fx]+) (?:prev (?P<prev>0x[0-9a-f]+) )?(?:parent (?P<parent>0x[0-9a-f]+) )?<(?P<position>.*)>(?P<position2> .+:\d+)?(?P<used>used)?(?P<referenced> referenced)?(?P<name> \w+)? '(?P<type>.+?)'(?P<type2>:'.*?')?(?P<extern> extern)?(?P<static> static)?(?P<cinit> cinit)?(?P<register> register)?[\s]*$
0x7f9d279ba938 <col:13, col:39> col:35 used c 'unsigned int' register cinit


goroutine 35 [running]:
github.com/elliotchance/c2go/ast.groupsFromRegex(0xc0009dd040, 0x13b, 0xc0005e09c0, 0x4b, 0xc0005e0990)
        /Users/chendan/project/gopath/src/github.com/elliotchance/c2go/ast/ast.go:286 +0x379
github.com/elliotchance/c2go/ast.parseVarDecl(0xc0005e09c0, 0x4b, 0x1295391)
        /Users/chendan/project/gopath/src/github.com/elliotchance/c2go/ast/var_decl.go:26 +0x65
github.com/elliotchance/c2go/ast.Parse(0xc0005e09b8, 0x53, 0x1294334, 0x5)
        /Users/chendan/project/gopath/src/github.com/elliotchance/c2go/ast/ast.go:252 +0x46c
main.convertLinesToNodes(0xc0015d1cb0, 0x29cb, 0x7d61, 0x0, 0x0, 0x0)
        /Users/chendan/project/gopath/src/github.com/elliotchance/c2go/main.go:89 +0x1cf
main.convertLinesToNodesParallel.func1.2(0xc00010e060, 0xc000080018, 0xc0015d1cb0, 0x29cb, 0x7d61, 0x0)
        /Users/chendan/project/gopath/src/github.com/elliotchance/c2go/main.go:121 +0x59
created by main.convertLinesToNodesParallel.func1
        /Users/chendan/project/gopath/src/github.com/elliotchance/c2go/main.go:119 +0x19d
@elliotchance
Copy link
Owner

This is because c2go does not understand one of the output lines from the clang AST. It can be fixed by adding a test case to var_decl_test.go, just like this: https://github.com/elliotchance/c2go/blob/master/ast/var_decl_test.go#L137-L152

The test should fail, then you can adjust the regexp here to satisfy the test: https://github.com/elliotchance/c2go/blob/master/ast/var_decl.go#L26-L41

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants