c2nim is a tool to translate Ansi C code to Nim. The output is human-readable Nim code that is meant to be tweaked by hand before and after the translation process.
MIT License
509
stars
63
forks
source link
Reorder comments, function attributes, and macro def args #251
Parsing __attributes__ and --def: makes it posible to handle the GCC C function pragmas style. For example --def:RCL_WARN_UNUSED='__attribute__ ()' and --def:RCL_PUBLIC='__attribute__ ()' will make the below parse:
// function defined with macros attributes:
RCL_PUBLIC RCL_WARN_UNUSED int rcl_arguments_get_count_unparsed(const rcl_arguments_t * args);
// expands to:
__attribute__(public) __attribute__(...) int rcl_arguments_get_count_unparsed(const rcl_arguments_t * args);
That last change is responsible for a good portion of C files not parsing properly. Eventually it'd be nice to add pragmas to the Nim procs so people could define them, but that's a project for another day.
Some changes I've wanted for a while. Still a bit of a WIP.
__attribute__
to list of declarations for functions to help with parsing function attributes--def
arg to allow defining a macro from the command line--stdints
pre-defined mangle to convert C stdint to Nim intsExample usage:
Example re-order comments:
becomes:
Parsing
__attributes__
and--def:
makes it posible to handle the GCC C function pragmas style. For example--def:RCL_WARN_UNUSED='__attribute__ ()'
and--def:RCL_PUBLIC='__attribute__ ()'
will make the below parse:That last change is responsible for a good portion of C files not parsing properly. Eventually it'd be nice to add pragmas to the Nim procs so people could define them, but that's a project for another day.