summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2018-05-30 08:26:47 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2018-05-30 11:57:29 +0000
commit50dd4ae202d7afb3556335c056db003f5ef50532 (patch)
treef228d0714160bd8e31f068d10ab32b7c744058ec
parent3be012086ed261ae41547b454189f6806fa9e375 (diff)
shiboken: Streamline the type parsing code
- Remove bool *ok-parameter from AbstractMetaBuilderPrivate::translateType() It was only used to handle the special case of void return values of functions where translateType() returned nullptr/ok = true. Add a check TypeInfo::isVoid for this purpose and move this handling to traverseFunction instead. For all other cases, translateType() returning nullptr means failure. - Remove the code triggered by the bool resolveScope parameter of AbstractMetaBuilderPrivate::translateType(). It has been observed to not find any matches, likely due to the types being fully qualified by Clang. - Remove function AbstractMetaBuilderPrivate::decideUsagePattern() which was a one-liner calling AbstractMetaType::decideUsagePattern() Task-number: PYSIDE-672 Change-Id: I0336896917cb914d4d622eefa0a21e6e319efa0f Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r--sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp135
-rw-r--r--sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h7
-rw-r--r--sources/shiboken2/ApiExtractor/parser/codemodel.cpp8
-rw-r--r--sources/shiboken2/ApiExtractor/parser/codemodel.h2
4 files changed, 54 insertions, 98 deletions
diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
index 23feeafa..ce582d21 100644
--- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
+++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
@@ -241,9 +241,8 @@ void AbstractMetaBuilderPrivate::checkFunctionModifications()
AbstractMetaClass *AbstractMetaBuilderPrivate::argumentToClass(ArgumentModelItem argument)
{
AbstractMetaClass* returned = 0;
- bool ok = false;
- AbstractMetaType* type = translateType(argument->type(), &ok);
- if (ok && type && type->typeEntry() && type->typeEntry()->isComplex()) {
+ AbstractMetaType *type = translateType(argument->type());
+ if (type && type->typeEntry() && type->typeEntry()->isComplex()) {
const TypeEntry *entry = type->typeEntry();
returned = AbstractMetaClass::findClass(m_metaClasses, entry->name());
}
@@ -300,9 +299,8 @@ void AbstractMetaBuilderPrivate::traverseOperatorFunction(FunctionModelItem item
baseoperandClass = argumentToClass(arguments.at(1));
firstArgumentIsSelf = false;
} else {
- bool ok;
- AbstractMetaType* type = translateType(item->type(), &ok);
- const TypeEntry* retType = ok ? type->typeEntry() : 0;
+ AbstractMetaType *type = translateType(item->type());
+ const TypeEntry *retType = type ? type->typeEntry() : nullptr;
AbstractMetaClass* otherArgClass = argumentToClass(arguments.at(1));
if (otherArgClass && retType
&& (retType->isValue() || retType->isObject())
@@ -1238,11 +1236,10 @@ AbstractMetaField *AbstractMetaBuilderPrivate::traverseField(VariableModelItem f
metaField->setName(fieldName);
metaField->setEnclosingClass(cls);
- bool ok;
TypeInfo fieldType = field->type();
- AbstractMetaType *metaType = translateType(fieldType, &ok);
+ AbstractMetaType *metaType = translateType(fieldType);
- if (!metaType || !ok) {
+ if (!metaType) {
const QString type = TypeInfo::resolveType(fieldType, currentScope()).qualifiedName().join(colonColon());
if (m_currentClass->typeEntry()->codeGeneration() & TypeEntry::GenerateTargetLang) {
qCWarning(lcShiboken).noquote().nospace()
@@ -1749,7 +1746,7 @@ AbstractMetaFunction* AbstractMetaBuilderPrivate::traverseFunction(const AddedFu
AddedFunction::TypeInfo& typeInfo = args[i];
AbstractMetaArgument *metaArg = new AbstractMetaArgument;
AbstractMetaType *type = translateType(typeInfo);
- decideUsagePattern(type);
+ type->decideUsagePattern();
metaArg->setType(type);
metaArg->setArgumentIndex(i);
metaArg->setDefaultValueExpression(typeInfo.defaultValue);
@@ -1963,9 +1960,8 @@ bool AbstractMetaBuilderPrivate::setArrayArgumentType(AbstractMetaFunction *func
}
TypeInfo elementType = functionItem->arguments().at(i)->type();
elementType.setIndirections(elementType.indirections() - 1);
- bool ok;
- AbstractMetaType *element = translateType(elementType, &ok);
- if (element == nullptr || !ok) {
+ AbstractMetaType *element = translateType(elementType);
+ if (element == nullptr) {
qCWarning(lcShiboken).noquote()
<< msgCannotSetArrayUsage(func->minimalSignature(), i,
QLatin1String("Cannot translate element type ") + elementType.toString());
@@ -2068,16 +2064,17 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(FunctionModel
return nullptr;
}
- bool ok;
- AbstractMetaType *type = translateType(returnType, &ok);
- if (!ok) {
- Q_ASSERT(type == 0);
- const QString reason = msgUnmatchedReturnType(functionItem);
- qCWarning(lcShiboken, "%s",
- qPrintable(msgSkippingFunction(functionItem, originalQualifiedSignatureWithReturn, reason)));
- m_rejectedFunctions.insert(originalQualifiedSignatureWithReturn, AbstractMetaBuilder::UnmatchedReturnType);
- delete metaFunction;
- return nullptr;
+ AbstractMetaType *type = nullptr;
+ if (!returnType.isVoid()) {
+ type = translateType(returnType);
+ if (!type) {
+ const QString reason = msgUnmatchedReturnType(functionItem);
+ qCWarning(lcShiboken, "%s",
+ qPrintable(msgSkippingFunction(functionItem, originalQualifiedSignatureWithReturn, reason)));
+ m_rejectedFunctions.insert(originalQualifiedSignatureWithReturn, AbstractMetaBuilder::UnmatchedReturnType);
+ delete metaFunction;
+ return nullptr;
+ }
}
metaFunction->setType(type);
@@ -2105,9 +2102,8 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(FunctionModel
return nullptr;
}
- bool ok;
- AbstractMetaType* metaType = translateType(arg->type(), &ok);
- if (!ok) {
+ AbstractMetaType *metaType = translateType(arg->type());
+ if (!metaType) {
// If an invalid argument has a default value, simply remove it
if (arg->defaultValue()) {
if (!m_currentClass
@@ -2316,21 +2312,14 @@ static const TypeEntry* findTypeEntryUsingContext(const AbstractMetaClass* metaC
}
AbstractMetaType *AbstractMetaBuilderPrivate::translateType(const TypeInfo &_typei,
- bool *ok, bool resolveType,
- bool resolveScope)
+ bool resolveType)
{
- Q_ASSERT(ok);
- *ok = true;
-
// 1. Test the type info without resolving typedefs in case this is present in the
// type system
TypeInfo typei;
if (resolveType) {
- bool ok;
- AbstractMetaType* t = translateType(_typei, &ok, false, resolveScope);
- if (t && ok)
- return t;
- Q_ASSERT(t == 0);
+ if (AbstractMetaType *resolved = translateType(_typei, false))
+ return resolved;
}
if (!resolveType) {
@@ -2350,17 +2339,14 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateType(const TypeInfo &_typ
}
- if (typei.isFunctionPointer()) {
- *ok = false;
- return 0;
- }
+ if (typei.isFunctionPointer())
+ return nullptr;
QString errorMessage;
TypeParser::Info typeInfo = TypeParser::parse(typei.toString(), &errorMessage);
if (typeInfo.is_busted) {
qWarning().noquote().nospace() << "Unable to translate type \"" << _typei.toString()
<< "\": " << errorMessage;
- *ok = false;
return 0;
}
@@ -2395,9 +2381,9 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateType(const TypeInfo &_typ
newInfo.setReferenceType(typei.referenceType());
newInfo.setVolatile(typei.isVolatile());
- AbstractMetaType* elementType = translateType(newInfo, ok);
- if (!(*ok))
- return 0;
+ AbstractMetaType *elementType = translateType(newInfo);
+ if (!elementType)
+ return nullptr;
for (int i = typeInfo.arrays.size() - 1; i >= 0; --i) {
AbstractMetaType *arrayType = new AbstractMetaType;
@@ -2409,7 +2395,7 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateType(const TypeInfo &_typ
arrayType->setArrayElementCount(int(elems));
}
arrayType->setTypeEntry(new ArrayTypeEntry(elementType->typeEntry() , elementType->typeEntry()->version()));
- decideUsagePattern(arrayType);
+ arrayType->decideUsagePattern();
elementType = arrayType;
}
@@ -2421,17 +2407,12 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateType(const TypeInfo &_typ
if (qualifierList.isEmpty()) {
qCWarning(lcShiboken).noquote().nospace()
<< QStringLiteral("horribly broken type '%1'").arg(_typei.toString());
- *ok = false;
- return 0;
+ return nullptr;
}
QString qualifiedName = qualifierList.join(colonColon());
QString name = qualifierList.takeLast();
- // 3. Special case 'void' type
- if (name == QLatin1String("void") && !typeInfo.indirections)
- return 0;
-
// 4. Special case QFlags (include instantiation in name)
if (qualifiedName == QLatin1String("QFlags"))
qualifiedName = typeInfo.toString();
@@ -2476,34 +2457,8 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateType(const TypeInfo &_typ
}
}
- // 9. Try finding the type by prefixing it with the current
- // context and all baseclasses of the current context
- if (!type && !TypeDatabase::instance()->isClassRejected(qualifiedName) && m_currentClass && resolveScope) {
- QStringList contexts;
- contexts.append(m_currentClass->qualifiedCppName());
- contexts.append(currentScope()->qualifiedName().join(colonColon()));
-
-
- TypeInfo info = typei;
- bool subclassesDone = false;
- while (!contexts.isEmpty() && !type) {
- type = TypeDatabase::instance()->findType(contexts.at(0) + colonColon() + qualifiedName);
- contexts.pop_front();
-
- // 10. Last resort: Special cased prefix of Qt namespace since the meta object implicitly inherits this, so
- // enum types from there may be addressed without any scope resolution in properties.
- if (!contexts.size() && !subclassesDone) {
- contexts << QLatin1String("Qt");
- subclassesDone = true;
- }
- }
-
- }
-
- if (!type) {
- *ok = false;
- return 0;
- }
+ if (!type)
+ return nullptr;
// Used to for diagnostics later...
m_usedTypes << type;
@@ -2527,10 +2482,10 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateType(const TypeInfo &_typ
info.setFunctionPointer(false);
info.setQualifiedName(ta.instantiationName().split(colonColon()));
- AbstractMetaType* targType = translateType(info, ok);
- if (!(*ok)) {
+ AbstractMetaType *targType = translateType(info);
+ if (!targType) {
delete metaType;
- return 0;
+ return nullptr;
}
metaType->addInstantiation(targType, true);
@@ -2540,7 +2495,7 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateType(const TypeInfo &_typ
// instantiations have been determined, or else the absence of
// such instantiations will break the caching scheme of
// AbstractMetaType::cppSignature().
- decideUsagePattern(metaType);
+ metaType->decideUsagePattern();
return metaType;
}
@@ -2583,11 +2538,6 @@ qint64 AbstractMetaBuilderPrivate::findOutValueFromString(const QString &stringV
return 0;
}
-void AbstractMetaBuilderPrivate::decideUsagePattern(AbstractMetaType *metaType)
-{
- metaType->decideUsagePattern();
-}
-
QString AbstractMetaBuilderPrivate::fixDefaultValue(ArgumentModelItem item,
AbstractMetaType *type,
AbstractMetaFunction *fnc,
@@ -2821,7 +2771,7 @@ AbstractMetaType* AbstractMetaBuilderPrivate::inheritTemplateType(const QVector<
AbstractMetaType* t = returned->copy();
t->setTypeEntry(templateTypes.at(tae->ordinal())->typeEntry());
t->setIndirections(templateTypes.at(tae->ordinal())->indirections() + t->indirections() ? 1 : 0);
- decideUsagePattern(t);
+ t->decideUsagePattern();
delete returned;
returned = inheritTemplateType(templateTypes, t, ok);
@@ -3003,7 +2953,6 @@ void AbstractMetaBuilderPrivate::parseQ_Property(AbstractMetaClass *metaClass,
QStringList qualifiedScopeName = currentScope()->qualifiedName();
- bool ok = false;
AbstractMetaType* type = 0;
QString scope;
for (int j = qualifiedScopeName.size(); j >= 0; --j) {
@@ -3011,12 +2960,12 @@ void AbstractMetaBuilderPrivate::parseQ_Property(AbstractMetaClass *metaClass,
TypeInfo info;
info.setQualifiedName((scope + l.at(0)).split(colonColon()));
- type = translateType(info, &ok);
- if (type && ok)
+ type = translateType(info);
+ if (type)
break;
}
- if (!type || !ok) {
+ if (!type) {
qCWarning(lcShiboken).noquote().nospace()
<< QStringLiteral("Unable to decide type of property: '%1' in class '%2'")
.arg(l.at(0), metaClass->name());
diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h b/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h
index 7becb2c3..95973446 100644
--- a/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h
+++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h
@@ -120,14 +120,11 @@ public:
AbstractMetaFunction *fnc, AbstractMetaClass *,
int argumentIndex);
AbstractMetaType *translateType(const AddedFunction::TypeInfo &typeInfo);
- AbstractMetaType *translateType(const TypeInfo &type, bool *ok,
- bool resolveType = true,
- bool resolveScope = true);
+ AbstractMetaType *translateType(const TypeInfo &type,
+ bool resolveType = true);
qint64 findOutValueFromString(const QString &stringValue, bool &ok);
- void decideUsagePattern(AbstractMetaType *type);
-
AbstractMetaClass *findTemplateClass(const QString& name, const AbstractMetaClass *context,
TypeParser::Info *info = Q_NULLPTR,
ComplexTypeEntry **baseContainerType = Q_NULLPTR) const;
diff --git a/sources/shiboken2/ApiExtractor/parser/codemodel.cpp b/sources/shiboken2/ApiExtractor/parser/codemodel.cpp
index a06f5643..0af4905f 100644
--- a/sources/shiboken2/ApiExtractor/parser/codemodel.cpp
+++ b/sources/shiboken2/ApiExtractor/parser/codemodel.cpp
@@ -146,6 +146,14 @@ TypeInfo TypeInfo::combine(const TypeInfo &__lhs, const TypeInfo &__rhs)
return __result;
}
+bool TypeInfo::isVoid() const
+{
+ return m_indirections == 0 && m_referenceType == NoReference
+ && m_arguments.isEmpty() && m_arrayElements.isEmpty()
+ && m_qualifiedName.size() == 1
+ && m_qualifiedName.constFirst() == QLatin1String("void");
+}
+
TypeInfo TypeInfo::resolveType(TypeInfo const &__type, CodeModelItem __scope)
{
CodeModel *__model = __scope->model();
diff --git a/sources/shiboken2/ApiExtractor/parser/codemodel.h b/sources/shiboken2/ApiExtractor/parser/codemodel.h
index 9a77c5f4..d0d7b677 100644
--- a/sources/shiboken2/ApiExtractor/parser/codemodel.h
+++ b/sources/shiboken2/ApiExtractor/parser/codemodel.h
@@ -111,6 +111,8 @@ public:
m_qualifiedName = qualified_name;
}
+ bool isVoid() const;
+
bool isConstant() const
{
return m_constant;