aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2017-02-27 11:31:50 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2017-02-28 07:10:25 +0000
commit107cfc1677587bb9e21621af9b96168b3ff8dc0e (patch)
tree591afc9b7461e273733f1eb61fe15c0536bc3a88
parent80fef1705ca23be01edbb12ece1b8bd49473bafe (diff)
Refactor AbstractMetaType::decideUsagePattern()
Split out the const-part into a new function AbstractMetaType::determineUsagePattern() const to improve code clarity. Task-number: PYSIDE-323 Change-Id: I2ef66c3c828c601b1c715e4585501e231f688873 Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r--ApiExtractor/abstractmetalang.cpp153
-rw-r--r--ApiExtractor/abstractmetalang.h2
2 files changed, 77 insertions, 78 deletions
diff --git a/ApiExtractor/abstractmetalang.cpp b/ApiExtractor/abstractmetalang.cpp
index 3e7ff3f60..b1b758075 100644
--- a/ApiExtractor/abstractmetalang.cpp
+++ b/ApiExtractor/abstractmetalang.cpp
@@ -184,96 +184,93 @@ QString AbstractMetaType::cppSignature() const
return m_cachedCppSignature;
}
-void AbstractMetaType::decideUsagePattern()
+AbstractMetaType::TypeUsagePattern AbstractMetaType::determineUsagePattern() const
{
- const TypeEntry* type = typeEntry();
+ if (m_typeEntry->isTemplateArgument() || m_referenceType == RValueReference)
+ return InvalidPattern;
- if (type->isPrimitive() && (!actualIndirections()
+ if (m_typeEntry->isPrimitive() && (!actualIndirections()
|| (isConstant() && m_referenceType == LValueReference && !indirections()))) {
- setTypeUsagePattern(AbstractMetaType::PrimitivePattern);
-
- } else if (type->isVoid()) {
- setTypeUsagePattern(AbstractMetaType::NativePointerPattern);
-
- } else if (type->isVarargs()) {
- setTypeUsagePattern(AbstractMetaType::VarargsPattern);
-
- } else if (type->isString()
- && indirections() == 0
- && (isConstant() == (m_referenceType == LValueReference)
- || isConstant())) {
- setTypeUsagePattern(AbstractMetaType::StringPattern);
-
- } else if (type->isChar()
- && !indirections()
- && isConstant() == (m_referenceType == LValueReference)) {
- setTypeUsagePattern(AbstractMetaType::CharPattern);
-
- } else if (type->isJObjectWrapper()
- && !indirections()
- && isConstant() == (m_referenceType == LValueReference)) {
- setTypeUsagePattern(AbstractMetaType::JObjectWrapperPattern);
-
- } else if (type->isVariant()
- && !indirections()
- && isConstant() == (m_referenceType == LValueReference)) {
- setTypeUsagePattern(AbstractMetaType::VariantPattern);
-
- } else if (type->isEnum() && !actualIndirections()) {
- setTypeUsagePattern(AbstractMetaType::EnumPattern);
-
- } else if (type->isObject() && indirections() == 0) {
- if (m_referenceType == LValueReference) {
- if (((ComplexTypeEntry*) type)->isQObject())
- setTypeUsagePattern(AbstractMetaType::QObjectPattern);
- else
- setTypeUsagePattern(AbstractMetaType::ObjectPattern);
- } else {
- setTypeUsagePattern(AbstractMetaType::ValuePattern);
- }
+ return PrimitivePattern;
+ }
- } else if (type->isObject()
- && indirections() == 1) {
- if (((ComplexTypeEntry*) type)->isQObject())
- setTypeUsagePattern(AbstractMetaType::QObjectPattern);
- else
- setTypeUsagePattern(AbstractMetaType::ObjectPattern);
+ if (m_typeEntry->isVoid())
+ return NativePointerPattern;
- // const-references to pointers can be passed as pointers
- if (referenceType() == LValueReference && isConstant()) {
- setReferenceType(NoReference);
- setConstant(false);
- }
+ if (m_typeEntry->isVarargs())
+ return VarargsPattern;
- } else if (type->isContainer() && !indirections()) {
- setTypeUsagePattern(AbstractMetaType::ContainerPattern);
+ if (m_typeEntry->isString() && indirections() == 0
+ && (isConstant() == (m_referenceType == LValueReference)
+ || isConstant())) {
+ return StringPattern;
+ }
+
+ if (m_typeEntry->isChar()
+ && indirections() == 0
+ && isConstant() == (m_referenceType == LValueReference)) {
+ return CharPattern;
+ }
+
+ if (m_typeEntry->isJObjectWrapper()
+ && indirections() == 0
+ && isConstant() == (m_referenceType == LValueReference)) {
+ return JObjectWrapperPattern;
+ }
+
+ if (m_typeEntry->isVariant()
+ && indirections() == 0
+ && isConstant() == (m_referenceType == LValueReference)) {
+ return VariantPattern;
+ }
- } else if (type->isTemplateArgument()) {
+ if (m_typeEntry->isEnum() && actualIndirections() == 0)
+ return EnumPattern;
- } else if (type->isFlags()
- && !indirections()
- && (isConstant() == (m_referenceType == LValueReference))) {
- setTypeUsagePattern(AbstractMetaType::FlagsPattern);
+ if (m_typeEntry->isObject()) {
+ if (indirections() == 0 && m_referenceType == NoReference)
+ return ValuePattern;
+ return static_cast<const ComplexTypeEntry *>(m_typeEntry)->isQObject()
+ ? QObjectPattern : ObjectPattern;
+ }
- } else if (type->isArray()) {
- setTypeUsagePattern(AbstractMetaType::ArrayPattern);
+ if (m_typeEntry->isContainer() && indirections() == 0)
+ return ContainerPattern;
- } else if (type->isThread()) {
+ if (m_typeEntry->isFlags() && indirections() == 0
+ && (isConstant() == (m_referenceType == LValueReference)))
+ return FlagsPattern;
+
+ if (m_typeEntry->isArray())
+ return ArrayPattern;
+
+ if (m_typeEntry->isThread()) {
Q_ASSERT(indirections() == 1);
- setTypeUsagePattern(AbstractMetaType::ThreadPattern);
- } else if (type->isValue()) {
- if (indirections() == 1) {
- setTypeUsagePattern(AbstractMetaType::ValuePointerPattern);
- } else {
- setTypeUsagePattern(AbstractMetaType::ValuePattern);
- }
- } else {
- setTypeUsagePattern(AbstractMetaType::NativePointerPattern);
- if (ReportHandler::isDebug(ReportHandler::FullDebug)) {
- qCDebug(lcShiboken)
- << QStringLiteral("native pointer pattern for '%1'").arg(cppSignature());
- }
+ return ThreadPattern;
+ }
+
+ if (m_typeEntry->isValue())
+ return indirections() == 1 ? ValuePointerPattern : ValuePattern;
+
+ if (ReportHandler::isDebug(ReportHandler::FullDebug)) {
+ qCDebug(lcShiboken)
+ << QStringLiteral("native pointer pattern for '%1'").arg(cppSignature());
+ }
+ return NativePointerPattern;
+}
+
+void AbstractMetaType::decideUsagePattern()
+{
+ TypeUsagePattern pattern = determineUsagePattern();
+ if (m_typeEntry->isObject() && indirections() == 1
+ && m_referenceType == LValueReference && isConstant()) {
+ // const-references to pointers can be passed as pointers
+ setReferenceType(NoReference);
+ setConstant(false);
+ pattern = static_cast<const ComplexTypeEntry *>(m_typeEntry)->isQObject()
+ ? QObjectPattern : ObjectPattern;
}
+ setTypeUsagePattern(pattern);
}
bool AbstractMetaType::hasTemplateChildren() const
diff --git a/ApiExtractor/abstractmetalang.h b/ApiExtractor/abstractmetalang.h
index dc38e7009..c54982dd9 100644
--- a/ApiExtractor/abstractmetalang.h
+++ b/ApiExtractor/abstractmetalang.h
@@ -599,6 +599,8 @@ public:
bool hasTemplateChildren() const;
private:
+ TypeUsagePattern determineUsagePattern() const;
+
const TypeEntry *m_typeEntry;
AbstractMetaTypeList m_instantiations;
QString m_package;