WIP: Cope with macros

This commit is contained in:
Martchus 2021-05-23 18:10:09 +02:00
parent a6461795a7
commit cb98e348f1
2 changed files with 19 additions and 2 deletions

View File

@ -52,7 +52,7 @@ std::string_view CodeGenerator::readAnnotation(const clang::Attr *annotation) co
if (!m_sourceManager) { if (!m_sourceManager) {
return std::string_view(); return std::string_view();
} }
auto text = clang::Lexer::getSourceText(clang::CharSourceRange::getTokenRange(annotation->getRange()), *sourceManager(), clang::LangOptions()); auto text = clang::Lexer::getSourceText(sourceManager()->getExpansionRange(annotation->getRange()), *sourceManager(), clang::LangOptions());
if (text.size() >= 12 && text.startswith("annotate(\"") && text.endswith("\")")) { if (text.size() >= 12 && text.startswith("annotate(\"") && text.endswith("\")")) {
text = text.substr(10, text.size() - 12); text = text.substr(10, text.size() - 12);
} }

View File

@ -67,9 +67,26 @@ struct PointerStruct : public BinarySerializable<PointerStruct> {
std::shared_ptr<PointerTarget> s3; std::shared_ptr<PointerTarget> s3;
}; };
#ifdef REFLECTIVE_RAPIDJSON_GENERATOR
#define RR_ATTR(text) __attribute__((annotate(text)))
#define RR_V1 RR_ATTR("cond: version >= 1")
#else
#define RR_ATTR(text)
#define RR_V1
#endif
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wattributes"
#endif
struct AnnotatedStruct : public BinarySerializable<AnnotatedStruct> { struct AnnotatedStruct : public BinarySerializable<AnnotatedStruct> {
int anyVersion; int anyVersion;
__attribute__((annotate("cond:version >= 1"))) __attribute__((annotate("foo"))) int newInVersion1; RR_V1 RR_ATTR("cond: version >= 2") RR_ATTR("foo") __attribute__((annotate("bar"))) int newInVersion1;
}; };
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#endif // REFLECTIVE_RAPIDJSON_TESTS_MORE_STRUCTS_H #endif // REFLECTIVE_RAPIDJSON_TESTS_MORE_STRUCTS_H