cplusplus icon indicating copy to clipboard operation
cplusplus copied to clipboard

Question regarding preprocessor directives

Open JakeSays opened this issue 4 years ago • 5 comments
trafficstars

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.

JakeSays avatar Jun 06 '21 01:06 JakeSays

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.

robertoraggi avatar Jun 06 '21 12:06 robertoraggi

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.

JakeSays avatar Jun 06 '21 17:06 JakeSays

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

robertoraggi avatar Jun 06 '21 19:06 robertoraggi

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!

asmwarrior avatar Oct 31 '21 02:10 asmwarrior

@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.

robertoraggi avatar Nov 01 '21 14:11 robertoraggi