I have a project that must be parsed before original compilation. It's needed for reflection purposes. In short I want to check edited .h
files for some attributes in the code and gather info about it to generate specific include files.
For example reflectable classes/fields/methods will be marked as META(parameters...)
. This macro will be defined like this #define META(...) __attribute__(annotate("reflectable"))
.
The code should looks like this (similar to Qt QObject or Unreal Engine 4):
1.
// --- macros outside of header to parse ---
// Marks declaration as reflectable (with some metadata), empty for base compiler, useful for clang
#ifdef __clang__
#define META(...) __attribute__(annotate("reflectable"))
#else
#define META(...)
#endif
// Injects some generated code after parsing step, empty for clang, useful for base compiler
#ifdef __clang__
#define GENERATED_REFLECTION_INFO
#else
#define GENERATED_REFLECTION_INFO GENERATE_CODE(__FILE__, __LINE__)
#endif
// --- reflectable class ---
META(Serializable, Exposed, etc)
class MyReflectableClass : public BaseReflectableClass
{
GENERATED_REFLECTION_INFO
public:
// Fields examples
META()
int32 MyReflectableField;
META(SkipSerialize)
float MySecondaryReflectableField;
// Methods example
META(RemoteMethod)
void MyReflectableMethod(int32 Param1, uint8 Param2);
};
libclang was used for this goal. But when project has includes like <string>
or <memory>
, it causes long time parsing of long chain of dependencies in standard library.
Also if project has a lot of headers, similar situation would be happened.
How can I avoid parsing of full standard library? Probably some kind of caches that I could use in libclang?
Or probably are there some ways to skip analyzing of these includes and convince the parser that unknown types are acceptable?
So how can I optimize application to reduce the time of parsing?