Open ratijas opened 3 years ago
After careful observation it becomes clear that whitespaces were actually a macro invocation code and rust syntax tokens. They got replaced instead of being removed to keep inner macro tokens at the same relative line:column locations as in original code.
So even though this
&*cpp!([]-> *const QObjectDescriptor as "RustQObjectDescriptor const*" {
return RustQObjectDescriptor::instance<RustObject<QObject>>();
})
becomes this
#line 339 "src/lib.rs"
return RustQObjectDescriptor::instance<RustObject<QObject>>();
}
that's only to keep things in place which could possibly come after cpp!([]-> *const QObjectDescriptor as "RustQObjectDescriptor const*" {
characters. It could be solved by "stripping" lines at the beginning & end of a macro, and incrementing #line
counter accordingly.
But the extra whitespace is not really a problem, is it?
No, not really a technical issue AFAICT. It's just my stupid perfectionism. Cuts my eye, so to say. Probably not worth fixing something that just works.
What's important is that the error message the the compiler still points to the right location. The trailing whitespace at the end of the line don't matter, but if it is not trailing, it is important to keep them.
the error location could be perfected. For example, the return type and the argument type are not in lines that are marked with #line so if there is a typo in these, it leads to difficult errors.
In the generated cpp_closures.cpp, every chunk of code copied verbatim from
cpp!([]{})
content is preceded by#line
pragma and a line with an inconsistently large amount of spaces. Which probably indicated there is some minor bug in parser.For example, these fragments of Rust:
produce this C++ output:
Macro code responsible for this is probably somewhere around here:
https://github.com/mystor/rust-cpp/blob/b826bc5beb7abc15c4862be748e0c3ac0b8b2d61/cpp_build/src/lib.rs#L43-L52