From cb98e348f19df93bb0d8826c65f2df85c2c1c35c Mon Sep 17 00:00:00 2001 From: Martchus Date: Sun, 23 May 2021 18:10:09 +0200 Subject: [PATCH] WIP: Cope with macros --- generator/codegenerator.cpp | 2 +- generator/tests/morestructs.h | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/generator/codegenerator.cpp b/generator/codegenerator.cpp index 5ef257d..2e46d8d 100644 --- a/generator/codegenerator.cpp +++ b/generator/codegenerator.cpp @@ -52,7 +52,7 @@ std::string_view CodeGenerator::readAnnotation(const clang::Attr *annotation) co if (!m_sourceManager) { 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("\")")) { text = text.substr(10, text.size() - 12); } diff --git a/generator/tests/morestructs.h b/generator/tests/morestructs.h index 489e96b..8b1dc8b 100644 --- a/generator/tests/morestructs.h +++ b/generator/tests/morestructs.h @@ -67,9 +67,26 @@ struct PointerStruct : public BinarySerializable { std::shared_ptr 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 { 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