-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Substitute preprocessor definitions into token stream #46
Comments
I have started working on this, in branch define_macro. So far it correctly parses simple What I'd like to do is to somehow expand This approach is not perfect though, it will most likely fail for something like: #define FOO + 3.0 +
float bar = 5.0 FOO 1.0; because it will be too late to do that substitution and retain precise token boundaries. (Above should get parsed correctly though. EDIT: Yes it does) |
I've been having a look (via PsiViewer) at how CLion handles this for C++. I think we can do better than we're doing with regards to the PSI tree we generate. Considering the code: #define BAR (true)
// ...
BAR ? 1 : 2; CLion generates a tree that looks something like this:
So it generates an |
There is a lot to be improved in the preprocessor macro handling, but I don't have time and experience with/knowledge about psi and how it is implemented in IntelliJ. Their approach is what I attempted to do first, but I didn't find out how to "inject" those foreign tokens into the parsing token stream conveniently, without rewriting substantial amounts of code. However if you or anybody else figures that out, PRs are welcome. |
I'll investigate. |
Currently we just ignore the contents of all directives.
#define
should be able to actually define tokens to be expanded into another list of tokens. Ideally this would do function-like macros as well as variables, but variables only would be a good start.The text was updated successfully, but these errors were encountered: