c2rust icon indicating copy to clipboard operation
c2rust copied to clipboard

`ASTExporter` doesn't support built-in macros, like `__LINE__`

Open ijustlovemath opened this issue 4 years ago • 5 comments

It's listed as a TODO: https://github.com/immunant/c2rust/blob/master/c2rust-ast-exporter/src/AstExporter.cpp#L647

List of builtin macros starts at Line 148: https://clang.llvm.org/doxygen/Preprocessor_8h_source.html

I'd be willing to do the translation work, eg converting __LINE__ to line!(), I just need to know the general structure and where to look. Any help is appreciated!

ijustlovemath avatar May 01 '20 03:05 ijustlovemath

Thanks for opening this issue @ijustlovemath. We're happy to review your patch if you open a PR.

I recommend looking at the PR that adds support for const macro's as a starting point: https://github.com/immunant/c2rust/pull/87.

thedataking avatar May 01 '20 14:05 thedataking

@thedataking @rinon Where is the actually lookup table conversion happening here? Is it through cbor_encoder_*? the macros map? I just need to know what to populate, seems like a lot of the hard work is done already!

ijustlovemath avatar May 01 '20 16:05 ijustlovemath

It seems like the macros map is a logical place to start, but I can't see where it's getting its values. I suspect I'm missing some place where there's some kind of reference-based c++ magic happening here.

ijustlovemath avatar May 01 '20 16:05 ijustlovemath

@ijustlovemath I recommend you spend some time familiarizing yourself with the code, maybe stepping through key parts of a minimal input sample in a debugger. I wish we had more time to guide you through the process at a more granular level, but unfortunately we do not.

thedataking avatar May 01 '20 18:05 thedataking

Just an educated guess, but I would start by checking here https://github.com/immunant/c2rust/blob/master/c2rust-ast-exporter/src/AstExporter.cpp#L646-L648 to see if the __LINE__ macro is recoverable at that point. If it is you can export it as either a new tag (see ast_tags.hpp) or a function call to a builtin.

rinon avatar May 01 '20 18:05 rinon