aboutsummaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-09-21 09:59:19 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-09-21 19:18:28 +0200
commit26a50da482c12bbbfcc8cea46aecd9f0c8305ca6 (patch)
tree84f53a8df01856d03b6ba28c59af68e28bd98d9a /sources
parentea89199e0ec036957dd103bb55ff480979be8622 (diff)
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 <tismer@stackless.com> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources')
-rw-r--r--sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp7
-rw-r--r--sources/shiboken2/tests/libsample/samplenamespace.cpp2
-rw-r--r--sources/shiboken2/tests/libsample/samplenamespace.h2
-rw-r--r--sources/shiboken2/tests/samplebinding/namespace_test.py5
4 files changed, 15 insertions, 1 deletions
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