-
Notifications
You must be signed in to change notification settings - Fork 108
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
Issue with handling preprocessor attributes #13
Comments
Yeah, this is a tough one. We don't have a very good way to handle this kind of preprocessor usage without both
I don't think either of these are compatible with incremental parsing. Maybe we could add some heuristic, where all-caps identifiers are treated specially in cases like these? |
Oops, I closed the wrong with that commit. |
Macros are really a big big pain... and can give some very messy asts.
And as you proposed it could be interesting at least to have the possibility to set some callbacks on #include to parse the file and with another parser get all the #define....etc and then feed a data structure which could be used with the callbacks for macros. |
An other idea I had:
Anyway it could be interesting in general (not necessarily limited to c/c++) to have this kind of magic token. |
I do something similar in nimterop - I run the file thru gcc -E and get the defines using -dD. |
Is it possible to change the current implementation to at least cover cases like this
assuming that token closest to function name is a type. That's how emacs e.g. is dealing with this situation. When it doesn't fix the problem from the description it will at least fix the most common use case. |
Yeah, good point @vladimir-didenko; I agree that this is the most common case where the current grammar breaks. If I get a chance, I may try to figure out a way to handle this specific case better. |
Hi, has any progress been made on this special case? If not, I'd be happy to look into it. |
As an emacs user trying out treesitter support: Unfortunately, I think that the crufty codebases that would most benefit from tree-sitter-derived performance improvements are also those that are most likely to have grown some non-ident-compatible macros. One common use case in our codebase is a macro for A heuristic assumption that upper-case names are macros would work well for this code base, as bad as it feels. Thinking about alternatives: I would probably be happier teaching my editor about problem macro names as I encounter them than I would be teaching it how to correctly preprocess sources and handle #includes for the usual non-heuristic solution (and then thinking about the ccache-esque caching system that it'd probably need to have to avoid tanking edit perf). For example, to get rtags set up, we maintain rtags binaries and .el files capable of running in our intentionally-ancient docker build env, postprocess our compile_commands.json to avoid things that its command parsing doesn't understand, and write glue code to manage actually running and talking to the rtags server from editors running outside our build container. Only a subset of people use rtags, so small problems with the setup wind up going unfixed for a long time, encouraging even fewer people to use it. |
For example from libclipboard.h:
Here, LCB_API is a preprocessor attribute:
This results in an ERROR:
LCB_API gets treated as a type rather than a marker.
The text was updated successfully, but these errors were encountered: