From 26a50da482c12bbbfcc8cea46aecd9f0c8305ca6 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 21 Sep 2020 09:59:19 +0200 Subject: shiboken2: Add namespace variables They were ignored in the code parser. Take them into account and add a test. Task-number: PYSIDE-1224 Change-Id: I3baca95556129d695db294fdcc1ad92fc831672d Reviewed-by: Christian Tismer Reviewed-by: Cristian Maureira-Fredes --- sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp | 7 ++++++- sources/shiboken2/tests/libsample/samplenamespace.cpp | 2 ++ sources/shiboken2/tests/libsample/samplenamespace.h | 2 ++ sources/shiboken2/tests/samplebinding/namespace_test.py | 5 +++++ 4 files changed, 15 insertions(+), 1 deletion(-) (limited to 'sources') diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp index 6eb7e7b0c..73b1aca63 100644 --- a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp +++ b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp @@ -59,6 +59,11 @@ static inline bool isClassCursor(const CXCursor &c) || c.kind == CXCursor_ClassTemplatePartialSpecialization; } +static inline bool isClassOrNamespaceCursor(const CXCursor &c) +{ + return c.kind == CXCursor_Namespace || isClassCursor(c); +} + static inline bool withinClassDeclaration(const CXCursor &cursor) { return isClassCursor(clang_getCursorLexicalParent(cursor)); @@ -972,7 +977,7 @@ BaseVisitor::StartTokenResult Builder::startToken(const CXCursor &cursor) break; case CXCursor_VarDecl: // static class members are seen as CXCursor_VarDecl - if (!d->m_currentClass.isNull() && isClassCursor(clang_getCursorSemanticParent(cursor))) { + if (isClassOrNamespaceCursor(clang_getCursorSemanticParent(cursor))) { d->addField(cursor); d->m_currentField->setStatic(true); } diff --git a/sources/shiboken2/tests/libsample/samplenamespace.cpp b/sources/shiboken2/tests/libsample/samplenamespace.cpp index fc9f6d395..b3ef96f5a 100644 --- a/sources/shiboken2/tests/libsample/samplenamespace.cpp +++ b/sources/shiboken2/tests/libsample/samplenamespace.cpp @@ -132,4 +132,6 @@ passReferenceToObjectType(const ObjectType& obj, int multiplier) return obj.objectName().size() * multiplier; } +int variableInNamespace = 42; + } // namespace SampleNamespace diff --git a/sources/shiboken2/tests/libsample/samplenamespace.h b/sources/shiboken2/tests/libsample/samplenamespace.h index 9e46b2ad6..0d418de16 100644 --- a/sources/shiboken2/tests/libsample/samplenamespace.h +++ b/sources/shiboken2/tests/libsample/samplenamespace.h @@ -173,6 +173,8 @@ LIBSAMPLE_API double passReferenceToValueType(const Point& point, double multipl // Add a new signature on type system with only a ObjectType pointer as parameter. LIBSAMPLE_API int passReferenceToObjectType(const ObjectType& obj, int multiplier); +extern LIBSAMPLE_API int variableInNamespace; + } // namespace SampleNamespace #endif // SAMPLENAMESPACE_H diff --git a/sources/shiboken2/tests/samplebinding/namespace_test.py b/sources/shiboken2/tests/samplebinding/namespace_test.py index 23480d4c4..8171e0e43 100644 --- a/sources/shiboken2/tests/samplebinding/namespace_test.py +++ b/sources/shiboken2/tests/samplebinding/namespace_test.py @@ -43,6 +43,11 @@ from sample import * from shiboken_test_helper import objectFullname +class TestVariablesUnderNamespace(unittest.TestCase): + def testIt(self): + self.assertEqual(SampleNamespace.variableInNamespace, 42) + + class TestEnumUnderNamespace(unittest.TestCase): def testInvisibleNamespace(self): o1 = EnumOnNamespace.Option1 -- cgit v1.2.3