Konstantin8105 / c4go

Transpiling C code to Go code
MIT License
363 stars 37 forks source link

can't convert open62541.c #242

Closed eugeis closed 5 years ago

eugeis commented 5 years ago

Hello, I am trying to convert https://github.com/open62541/open62541/releases/download/0.3-rc2/open62541.c

and get many AST error, see https://github.com/eugeis/gopen62541/blob/master/open62541.go

Is it easy to resolve or too difficult? Thank You

Konstantin8105 commented 5 years ago

Thank you for sending AST error. For myself - easy. I think tomorrow- I will fix.

Konstantin8105 commented 5 years ago

Dear @eugeis , Again thanks for AST ERROR. Please try transpile with argument -s like that:

c4go transpile -s open62541.c
eugeis commented 5 years ago

Dear @Konstantin8105 , thank you for your improvement.

It seems to be better now, but still some AST issues like

Cannot parse line: VarDecl 0x55b0fd0132f0 <col:5, col:37> col:20 used range 'UA_UInt32Range':'UA_UInt32Range' nrvo cinit. could not match regexp with string ^(?P

[0-9a-fx]+) (?:parent (?P0x[0-9a-f]+) )?(?:prev (?P0x[0-9a-f]+) )?<(?P.)>(?P .+:\d+)?(?P used)?(?P referenced)?(?P \w+)? '(?P.+?)'(?P:'.?')?(?P extern)?(?P static)?(?P tls)?(?P register)?(?P cinit)?(?P callinit)?(?P nrvo)?[\s]*$ 0x55b0fd0132f0 <col:5, col:37> col:20 used range 'UA_UInt32Range':'UA_UInt32Range' nrvo cinit

Would you like to check it out, I regenerated the file: https://raw.githubusercontent.com/eugeis/gopen62541/master/gen/open62541.go

Konstantin8105 commented 5 years ago

Dear @eugeis , this is maximal of translation. Now, transpilation is ok only for small source with minimal dependency. For example, for next header c4go haven't any implementation:

/usr/include/netinet/tcp.h
/usr/include/xlocale.h
/usr/include/arpa/inet.h
/usr/include/asm-generic/socket.h
...

Also, some variable have not UA_STRING_NULL implementation in C.

eugeis commented 5 years ago

ok, thank you for your fixes. I understand that the source code complex is, maybe be in some time it will be possible to achieve better results.