Clang: Make Q_PROPERTY replacement simpler

The infrastructure around Q_PROPERTY extraction
allows to make it static assert and still find
it's parent.
This way makes it easier for Clang to parse
and does not provide unexisting functions for class.

Change-Id: I1c40550c72d214c2448169094a46c6f793132f23
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Ivan Donchevskii
2018-02-21 09:02:15 +01:00
parent 38d15ebe2f
commit 34fec1cad2
2 changed files with 4 additions and 10 deletions

View File

@@ -60,14 +60,8 @@
# define Q_SLOT __attribute__((annotate("qt_slot"))) # define Q_SLOT __attribute__((annotate("qt_slot")))
#endif #endif
template <char... chars> // static_assert can be found as a class child but does not add extra AST nodes for copmpletion
using QPropertyMagicString = std::integer_sequence<char, chars...>; #define Q_PROPERTY(arg) static_assert("Q_PROPERTY", #arg);
template <class T, T... chars>
constexpr QPropertyMagicString<chars...> operator""_qpropstr() { return { }; }
// Create unique AST node for the property.
#define Q_PROPERTY(arg) void QPropertyMagicFunction(decltype(#arg ## _qpropstr));
#pragma clang diagnostic pop #pragma clang diagnostic pop

View File

@@ -86,7 +86,7 @@ static Utf8String propertyParentSpelling(CXTranslationUnit cxTranslationUnit,
tuCursor.visit([&filePath, line, column, &parentSpelling](CXCursor cxCursor, CXCursor parent) { tuCursor.visit([&filePath, line, column, &parentSpelling](CXCursor cxCursor, CXCursor parent) {
const CXCursorKind kind = clang_getCursorKind(cxCursor); const CXCursorKind kind = clang_getCursorKind(cxCursor);
if (kind == CXCursor_Namespace || kind == CXCursor_StructDecl if (kind == CXCursor_Namespace || kind == CXCursor_StructDecl
|| kind == CXCursor_ClassDecl || kind == CXCursor_CXXMethod) { || kind == CXCursor_ClassDecl || kind == CXCursor_StaticAssert) {
Cursor cursor(cxCursor); Cursor cursor(cxCursor);
const SourceRange range = cursor.sourceRange(); const SourceRange range = cursor.sourceRange();
if (range.start().filePath() != filePath) if (range.start().filePath() != filePath)
@@ -96,7 +96,7 @@ static Utf8String propertyParentSpelling(CXTranslationUnit cxTranslationUnit,
|| kind == CXCursor_ClassDecl) { || kind == CXCursor_ClassDecl) {
return CXChildVisit_Recurse; return CXChildVisit_Recurse;
} }
// CXCursor_CXXMethod case. This is Q_PROPERTY_MAGIC_FUNCTION // CXCursor_StaticAssert case. This is Q_PROPERTY static_assert
parentSpelling = Cursor(parent).type().spelling(); parentSpelling = Cursor(parent).type().spelling();
return CXChildVisit_Break; return CXChildVisit_Break;
} }