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

panic: could not match regexp with string (translation_unit_decl) #885

Open
zazola opened this issue Jul 15, 2021 · 2 comments
Open

panic: could not match regexp with string (translation_unit_decl) #885

zazola opened this issue Jul 15, 2021 · 2 comments

Comments

@zazola
Copy link

zazola commented Jul 15, 2021

$ c2go transpile ~/test9.c 
panic: could not match regexp with string
^(?P<address>[0-9a-fx]+) <(?P<position>.*)> <(?P<position2>.*)>[\s]*$
0x3228d60 <<invalid sloc>>


goroutine 21 [running]:
github.com/elliotchance/c2go/ast.groupsFromRegex(0xc000348000, 0x45, 0xc00015a014, 0x1a, 0x6ce701)
	/home/abrosaia/go/pkg/mod/github.com/elliotchance/[email protected]/ast/ast.go:310 +0x36a
github.com/elliotchance/c2go/ast.parseTranslationUnitDecl(0xc00015a014, 0x1a, 0x13)
	/home/abrosaia/go/pkg/mod/github.com/elliotchance/[email protected]/ast/translation_unit_decl.go:10 +0x4e
github.com/elliotchance/c2go/ast.Parse(0xc00015a000, 0x2e, 0x6cb230, 0x5)
	/home/abrosaia/go/pkg/mod/github.com/elliotchance/[email protected]/ast/ast.go:258 +0x2ea5
main.convertLinesToNodes(0xc000166000, 0xa0, 0x283, 0x0, 0x0, 0x0)
	/home/abrosaia/go/pkg/mod/github.com/elliotchance/[email protected]/main.go:89 +0x1b4
main.convertLinesToNodesParallel.func1.1(0xc0000ea4e0, 0xc00000e080, 0xc000166000, 0xa0, 0x283, 0x0)
	/home/abrosaia/go/pkg/mod/github.com/elliotchance/[email protected]/main.go:113 +0x53
created by main.convertLinesToNodesParallel.func1
	/home/abrosaia/go/pkg/mod/github.com/elliotchance/[email protected]/main.go:111 +0x12f
@zazola
Copy link
Author

zazola commented Jul 15, 2021

I see it's similar to #853 and #840, but I don't understand the code to be able to fix it

@elliotchance
Copy link
Owner

Yes, those are good example of similar fixes. I'll explain whats going on.

c2go calls clang to do the preprocessing, parsing and output a (rather unfriendly) text based representation of the AST of the source code. Having clang parse the source means that c2go doesn't have to have its own extremely complicated C parser and the clang output provides some extra insights (such as typing information) as well.

On the flip side, the text-based clang AST output is not designed to be machine ingested, it's (normally) just for debugging. So the format changes all the time. c2go relies on regexps to parse this back into a structure in memory before transpiling.

I decided to make c2go very strict about what it would accept so that nuanced cases would be caught rather than leading to bugs down the line. Of course, this also means that c2go can be very brittle as clang make changes to their parser.

The solution you see in those PRs is to copy the line that is failing (0x3228d60 <<invalid sloc>>) and add it as a unit test here. Then modify the regexp to match that input line that's currently failing.

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