Plugin development

Answered

Hello

Currently i am developing device tree language plugin for CLion IDE.
Device tree language supports the use of preprocessor directives from c/c++ header files and i would like to add reference resolve to the plugin.

So my question is how should i go in resolving original preprocessor macro definition from device tree file.
What index should i use( or should i use index at all )?


0
2 comments

Hi, Alexey!

If you have just a macro name, and not the original file it comes from, the easiest way would be something like

Project project = myProject;
Processor<OCSymbol> symbolProcessor = symbol -> {
if (symbol.getKind() == OCSymbolKind.MACRO) { // or just `symbol instanceof OCMacroSymbol`
OCMacroSymbol macroSymbol = (OCMacroSymbol)symbol;
// do stuff
return false; // stop processing symbols
}
return true; // keep going
};
OCGlobalProjectSymbolsCache.processTopLevelSymbols(project, symbolProcessor, "MACRO_NAME");

Please note that this might be (very) expensive if project symbol caches are invalidated (i.e. a commonly-used header was significantly changed), so please make sure it's cancellable and not called from UI thread.

If you know the header file (or a root .c/cpp file the header in included into) containing the macro - please let me know, there might be cheaper ways to get it in this case.

0
Avatar
Permanently deleted user

Thanks!
I have implemented suggested solution and it works well on test project.

But maybe there is a better way.
Here is example of device tree file.
It has DT_SIZE_K macro that is defined inside <mem.h> header file.
Is there a better way to resolve reference?

#include <mem.h>
#include <st/f1/stm32f1.dtsi>

/ {
sram0: memory@20000000 {
reg = <0x20000000 DT_SIZE_K(20)>;
};
};







0

Please sign in to leave a comment.