nim-lang / c2nim

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
502 stars 62 forks source link

A failing construct will fail an entire statement list within an if directive. #227

Open izackp opened 2 years ago

izackp commented 2 years ago

Example:

//vec2d.hpp
//c2nim --debug --cdecl --cpp --header vec2d.hpp
//c2nim version: 0.9.18

class Vector2; 
#if !VECTORMATH_MODE_SCE
class Vector2
{
    float mX;
    float mY;

public:
    inline Vector2() { }
    inline Vector2(float x, float y);
};
inline Vector2::Vector2(float _x, float _y)
    : mX(_x), mY(_y)
{
}
#endif

Removing the if statement will allow c2nim to create functions for the constructors and type while failing for the last construct. However, with the if directive everything inside it fails.

I believe we should be less strict with failing in this case. I may come up a fix for this in my free time, but until then I'm creating an issue here.

As for the error causing the failing construct, Vector2::Vector2 seems to be read as a return value inside of declarationWithoutSemicolon at which point the next parentheses makes the parser think its reading a function pointer declaration rather than an inline constructor.

Also, the title of the issue is what I believe is happening so far... I'm not 100% sure yet.