diff options
4 files changed, 22 insertions, 6 deletions
diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp index ba33f78d9..7cba99839 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp +++ b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp @@ -189,6 +189,11 @@ AbstractMetaTypeCList AbstractMetaType::nestedArrayTypes() const return result; } +bool AbstractMetaType::isConstRef() const +{ + return isConstant() && m_referenceType == LValueReference && indirections() == 0; +} + QString AbstractMetaType::cppSignature() const { if (m_cachedCppSignature.isEmpty()) @@ -201,10 +206,8 @@ AbstractMetaType::TypeUsagePattern AbstractMetaType::determineUsagePattern() con if (m_typeEntry->isTemplateArgument() || m_referenceType == RValueReference) return InvalidPattern; - if (m_typeEntry->isPrimitive() && (!actualIndirections() - || (isConstant() && m_referenceType == LValueReference && !indirections()))) { + if (m_typeEntry->isPrimitive() && (actualIndirections() == 0 || isConstRef())) return PrimitivePattern; - } if (m_typeEntry->isVoid()) return NativePointerPattern; @@ -212,7 +215,7 @@ AbstractMetaType::TypeUsagePattern AbstractMetaType::determineUsagePattern() con if (m_typeEntry->isVarargs()) return VarargsPattern; - if (m_typeEntry->isEnum() && actualIndirections() == 0) + if (m_typeEntry->isEnum() && (actualIndirections() == 0 || isConstRef())) return EnumPattern; if (m_typeEntry->isObject()) { @@ -228,8 +231,7 @@ AbstractMetaType::TypeUsagePattern AbstractMetaType::determineUsagePattern() con if (m_typeEntry->isSmartPointer() && indirections() == 0) return SmartPointerPattern; - if (m_typeEntry->isFlags() && indirections() == 0 - && (isConstant() == (m_referenceType == LValueReference))) + if (m_typeEntry->isFlags() && (actualIndirections() == 0 || isConstRef())) return FlagsPattern; if (m_typeEntry->isArray()) diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang.h b/sources/shiboken2/ApiExtractor/abstractmetalang.h index c31c5a386..cfc8b7246 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetalang.h +++ b/sources/shiboken2/ApiExtractor/abstractmetalang.h @@ -434,6 +434,8 @@ public: m_constant = constant; } + bool isConstRef() const; + ReferenceType referenceType() const { return m_referenceType; } void setReferenceType(ReferenceType ref) { m_referenceType = ref; } diff --git a/sources/shiboken2/tests/libsample/objecttype.h b/sources/shiboken2/tests/libsample/objecttype.h index 9d659faa4..bcb4f3332 100644 --- a/sources/shiboken2/tests/libsample/objecttype.h +++ b/sources/shiboken2/tests/libsample/objecttype.h @@ -53,6 +53,10 @@ struct Event Event(EventType eventType) : m_eventType(eventType) {} EventType eventType() { return m_eventType; } + + void setEventType(EventType et) { m_eventType = et; } + void setEventTypeByConstRef(const EventType &et) { m_eventType = et; } + private: EventType m_eventType; }; diff --git a/sources/shiboken2/tests/samplebinding/enum_test.py b/sources/shiboken2/tests/samplebinding/enum_test.py index 0a5a84c4a..7e1cac8c0 100644 --- a/sources/shiboken2/tests/samplebinding/enum_test.py +++ b/sources/shiboken2/tests/samplebinding/enum_test.py @@ -115,6 +115,14 @@ class EnumTest(unittest.TestCase): sum = Event.EventTypeClass.Value1 + Event.EventTypeClass.Value2 self.assertEqual(sum, 1) + def testSetEnum(self): + event = Event(Event.ANY_EVENT) + self.assertEqual(event.eventType(), Event.ANY_EVENT) + event.setEventType(Event.BASIC_EVENT) + self.assertEqual(event.eventType(), Event.BASIC_EVENT) + event.setEventTypeByConstRef(Event.SOME_EVENT) + self.assertEqual(event.eventType(), Event.SOME_EVENT) + def testEnumTpPrintImplementation(self): '''Without SbkEnum.tp_print 'print' returns the enum represented as an int.''' tmpfile = createTempFile() |