elliotchance / c2go

⚖️ A tool for transpiling C to Go.
MIT License
2.06k stars 151 forks source link

Transpillation on MacOS 10.15 causes `panic: could not match regexp with string` #856

Open mharvey opened 4 years ago

mharvey commented 4 years ago

When attempting to run c2go transpile, the AvailabilityAttr items in the AST cause a panic.

panic: could not match regexp with string
^(?P<address>[0-9a-fx]+) <(?P<position>.*)>(?P<inherited> Inherited)? (?P<os>\w+) (?P<version>[\d.]+) (?P<unknown1>[\d.]+) (?P<unknown2>[\d.]+)(?P<unavalable> Unavailable)? "(?P<message1>.*?)"(?P<message2> ".*?")?[\s]*$
0x7fc5ba891778 <col:108, col:143> macos 10.7 0 0 "" "" 0

goroutine 98 [running]:
github.com/elliotchance/c2go/ast.groupsFromRegex(0xc0006e42a0, 0xdb, 0xc00099de9c, 0x38, 0xc00099de8b)
    /Users/morganharvey/go/src/github.com/elliotchance/c2go/ast/ast.go:310 +0x360
github.com/elliotchance/c2go/ast.parseAvailabilityAttr(0xc00099de9c, 0x38, 0x12b3340)
    /Users/morganharvey/go/src/github.com/elliotchance/c2go/ast/availability_attr.go:24 +0x62
github.com/elliotchance/c2go/ast.Parse(0xc00099de8b, 0x49, 0x12adcd4, 0x5)
    /Users/morganharvey/go/src/github.com/elliotchance/c2go/ast/ast.go:86 +0x2701
main.convertLinesToNodes(0xc00011ecb0, 0x2cc, 0x29f4, 0x0, 0x0, 0x0)
    /Users/morganharvey/go/src/github.com/elliotchance/c2go/main.go:89 +0x1a6
main.convertLinesToNodesParallel.func1.2(0xc000118000, 0xc00011a028, 0xc00011ecb0, 0x2cc, 0x29f4, 0x0)
    /Users/morganharvey/go/src/github.com/elliotchance/c2go/main.go:121 +0x53
created by main.convertLinesToNodesParallel.func1
    /Users/morganharvey/go/src/github.com/elliotchance/c2go/main.go:119 +0x1b5

I've included the full AST in case it helps with debugging.

ast.txt

elliotchance commented 4 years ago

This happens when c2go can't understand a particular line of the clang AWS output. You can fix this by adding a test and modifying the regep. Here is an example: https://github.com/elliotchance/c2go/pull/840/files

mharvey commented 4 years ago

That appears to be pretty straightforward. Thanks for the pointer. I'll throw a PR your way as my week allows.