robertoraggi / cplusplus

A compiler front end for the C++ language
https://robertoraggi.github.io/cplusplus/
MIT License
118 stars 11 forks source link

Question regarding preprocessor directives #17

Open JakeSays opened 3 years ago

JakeSays commented 3 years ago

Hello,

I am thinking about using cplusplus to write some personal source analysis and transformation tools. The first one i want to implement is a simple file dependency analyzer.

Is this possible? At first glance it doesn't appear that the include directives are preserved. Am i missing something?

For me the value of your project is in a lighter libclang (like about 50 tones lighter) for analysis purposes.

robertoraggi commented 3 years ago

Hi @JakeSays,

Thanks for showing interest in this project.

I'm afraid the C++20 frontend is not ready for writing such tools. I recently started to work on the type checker and the semantic passes required to correctly parse modern C++ code. As soon as I'm done with the type checker I will try to expose a set of APIs to use the preprocessor, the parser and the code model in C++ and JS apps.

JakeSays commented 3 years ago

Ah ok. I thought this was a continuation of the one that was used in qt creator. Is that version available somewhere? I looked for it in the creator repo but I couldn't find it.

Also I would be interested in writing a c# binding for this project when you get to that point.

robertoraggi commented 3 years ago

Yeah, modern C++ is considerably different than the versions of C++ I implemented in the past so I thought it was easier to start from scratch.

You can find the Qt Creator C++ parser in these two directories but I don't know if you can still compile it as a standalone library.

https://github.com/qt-creator/qt-creator/tree/master/src/libs/3rdparty/cplusplus https://github.com/qt-creator/qt-creator/tree/master/src/libs/cplusplus

asmwarrior commented 2 years ago

I see there is a file named:

https://github.com/robertoraggi/cplusplus/blob/main/src/cxx/preprocessor.cc

which I see is a preprocessor.

Good work!

robertoraggi commented 2 years ago

@asmwarrior yes, the preprocessor is almost complete but I still need to add APIs to abstract the file system access and configure the predefined macros and the system include paths.