From 967aa3a520cc19694f8952a1e857e121dbbf967b Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 1 Apr 2019 15:50:10 +0200 Subject: shiboken: Remove member m_currentClass from AbstractMetaBuilderPrivate Pass the current class as function parameter instead while traversing instead of setting and restoring m_currentClass. Change-Id: I38391dff9a52ff99593c25208e1e2bf7d98d17d6 Reviewed-by: Christian Tismer --- .../shiboken2/ApiExtractor/abstractmetabuilder.cpp | 175 +++++++++------------ .../shiboken2/ApiExtractor/abstractmetabuilder_p.h | 31 ++-- 2 files changed, 98 insertions(+), 108 deletions(-) diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp index 685cbb78d..de971532d 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp +++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp @@ -111,7 +111,7 @@ static QStringList parseTemplateType(const QString& name) { return result; } -AbstractMetaBuilderPrivate::AbstractMetaBuilderPrivate() : m_currentClass(0), +AbstractMetaBuilderPrivate::AbstractMetaBuilderPrivate() : m_logDirectory(QLatin1String(".") + QDir::separator()), m_skipDeprecated(false) { @@ -223,10 +223,11 @@ void AbstractMetaBuilderPrivate::checkFunctionModifications() } } -AbstractMetaClass *AbstractMetaBuilderPrivate::argumentToClass(const ArgumentModelItem &argument) +AbstractMetaClass *AbstractMetaBuilderPrivate::argumentToClass(const ArgumentModelItem &argument, + AbstractMetaClass *currentClass) { AbstractMetaClass* returned = 0; - AbstractMetaType *type = translateType(argument->type()); + AbstractMetaType *type = translateType(argument->type(), currentClass); if (type && type->typeEntry() && type->typeEntry()->isComplex()) { const TypeEntry *entry = type->typeEntry(); returned = AbstractMetaClass::findClass(m_metaClasses, entry); @@ -238,11 +239,12 @@ AbstractMetaClass *AbstractMetaBuilderPrivate::argumentToClass(const ArgumentMod /** * Checks the argument of a hash function and flags the type if it is a complex type */ -void AbstractMetaBuilderPrivate::registerHashFunction(const FunctionModelItem &function_item) +void AbstractMetaBuilderPrivate::registerHashFunction(const FunctionModelItem &function_item, + AbstractMetaClass *currentClass) { ArgumentList arguments = function_item->arguments(); if (arguments.size() == 1) { - if (AbstractMetaClass *cls = argumentToClass(arguments.at(0))) + if (AbstractMetaClass *cls = argumentToClass(arguments.at(0), currentClass)) cls->setHasHashFunction(true); } } @@ -251,13 +253,14 @@ void AbstractMetaBuilderPrivate::registerHashFunction(const FunctionModelItem &f * Check if a class has a debug stream operator that can be used as toString */ -void AbstractMetaBuilderPrivate::registerToStringCapability(const FunctionModelItem &function_item) +void AbstractMetaBuilderPrivate::registerToStringCapability(const FunctionModelItem &function_item, + AbstractMetaClass *currentClass) { ArgumentList arguments = function_item->arguments(); if (arguments.size() == 2) { if (arguments.at(0)->type().toString() == QLatin1String("QDebug")) { const ArgumentModelItem &arg = arguments.at(1); - if (AbstractMetaClass *cls = argumentToClass(arg)) { + if (AbstractMetaClass *cls = argumentToClass(arg, currentClass)) { if (arg->type().indirections() < 2) cls->setToStringCapability(true); } @@ -265,28 +268,28 @@ void AbstractMetaBuilderPrivate::registerToStringCapability(const FunctionModelI } } -void AbstractMetaBuilderPrivate::traverseOperatorFunction(const FunctionModelItem &item) +void AbstractMetaBuilderPrivate::traverseOperatorFunction(const FunctionModelItem &item, + AbstractMetaClass *currentClass) { if (item->accessPolicy() != CodeModel::Public) return; ArgumentList arguments = item->arguments(); - AbstractMetaClass* baseoperandClass; bool firstArgumentIsSelf = true; bool unaryOperator = false; - baseoperandClass = argumentToClass(arguments.at(0)); + auto baseoperandClass = argumentToClass(arguments.at(0), currentClass); if (arguments.size() == 1) { unaryOperator = true; } else if (!baseoperandClass || !(baseoperandClass->typeEntry()->codeGeneration() & TypeEntry::GenerateTargetLang)) { - baseoperandClass = argumentToClass(arguments.at(1)); + baseoperandClass = argumentToClass(arguments.at(1), currentClass); firstArgumentIsSelf = false; } else { - AbstractMetaType *type = translateType(item->type()); + AbstractMetaType *type = translateType(item->type(), currentClass); const TypeEntry *retType = type ? type->typeEntry() : nullptr; - AbstractMetaClass* otherArgClass = argumentToClass(arguments.at(1)); + AbstractMetaClass *otherArgClass = argumentToClass(arguments.at(1), currentClass); if (otherArgClass && retType && (retType->isValue() || retType->isObject()) && retType != baseoperandClass->typeEntry() @@ -298,9 +301,7 @@ void AbstractMetaBuilderPrivate::traverseOperatorFunction(const FunctionModelIte } if (baseoperandClass) { - AbstractMetaClass* oldCurrentClass = m_currentClass; - m_currentClass = baseoperandClass; - AbstractMetaFunction *metaFunction = traverseFunction(item); + AbstractMetaFunction *metaFunction = traverseFunction(item, baseoperandClass); if (metaFunction) { // Strip away first argument, since that is the containing object AbstractMetaArgumentList arguments = metaFunction->arguments(); @@ -333,22 +334,19 @@ void AbstractMetaBuilderPrivate::traverseOperatorFunction(const FunctionModelIte } else { delete metaFunction; } - - m_currentClass = oldCurrentClass; } } -void AbstractMetaBuilderPrivate::traverseStreamOperator(const FunctionModelItem &item) +void AbstractMetaBuilderPrivate::traverseStreamOperator(const FunctionModelItem &item, + AbstractMetaClass *currentClass) { ArgumentList arguments = item->arguments(); if (arguments.size() == 2 && item->accessPolicy() == CodeModel::Public) { - AbstractMetaClass* streamClass = argumentToClass(arguments.at(0)); - AbstractMetaClass* streamedClass = argumentToClass(arguments.at(1)); + AbstractMetaClass *streamClass = argumentToClass(arguments.at(0), currentClass); + AbstractMetaClass *streamedClass = argumentToClass(arguments.at(1), currentClass); if (streamClass && streamedClass && (streamClass->isStream())) { - AbstractMetaClass *oldCurrentClass = m_currentClass; - m_currentClass = streamedClass; - AbstractMetaFunction *streamFunction = traverseFunction(item); + AbstractMetaFunction *streamFunction = traverseFunction(item, streamedClass); if (streamFunction) { streamFunction->setFunctionType(AbstractMetaFunction::GlobalScopeFunction); @@ -385,7 +383,6 @@ void AbstractMetaBuilderPrivate::traverseStreamOperator(const FunctionModelItem else funcClass->typeEntry()->addExtraInclude(streamClass->typeEntry()->include()); - m_currentClass = oldCurrentClass; } else { delete streamFunction; } @@ -459,7 +456,7 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom) for (const ClassModelItem &item : typeValues) { ReportHandler::progress(QStringLiteral("Generating class model (%1)...") .arg(typeValues.size())); - if (AbstractMetaClass *cls = traverseClass(dom, item)) + if (AbstractMetaClass *cls = traverseClass(dom, item, nullptr)) addAbstractMetaClass(cls, item.data()); } @@ -492,7 +489,7 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom) for (const TypeDefModelItem &typeDef : typeDefs) { ReportHandler::progress(QStringLiteral("Resolving typedefs (%1)...") .arg(typeDefs.size())); - if (AbstractMetaClass *cls = traverseTypeDef(dom, typeDef)) + if (AbstractMetaClass *cls = traverseTypeDef(dom, typeDef, nullptr)) addAbstractMetaClass(cls, typeDef.data()); } @@ -514,7 +511,7 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom) if (!funcEntry || !funcEntry->generateCode()) continue; - AbstractMetaFunction* metaFunc = traverseFunction(func); + AbstractMetaFunction* metaFunc = traverseFunction(func, nullptr); if (!metaFunc) continue; @@ -621,13 +618,13 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom) { const FunctionList &hashFunctions = dom->findFunctions(QLatin1String("qHash")); for (const FunctionModelItem &item : hashFunctions) - registerHashFunction(item); + registerHashFunction(item, nullptr); } { const FunctionList &streamOps = dom->findFunctions(QLatin1String("operator<<")); for (const FunctionModelItem &item : streamOps) - registerToStringCapability(item); + registerToStringCapability(item, nullptr); } { @@ -655,14 +652,14 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom) binaryOperators.append(dom->findFunctions(QStringLiteral("operator>"))); for (const FunctionModelItem &item : qAsConst(binaryOperators)) - traverseOperatorFunction(item); + traverseOperatorFunction(item, nullptr); } { const FunctionList streamOperators = dom->findFunctions(QLatin1String("operator<<")) + dom->findFunctions(QLatin1String("operator>>")); for (const FunctionModelItem &item : streamOperators) - traverseStreamOperator(item); + traverseStreamOperator(item, nullptr); } checkFunctionModifications(); @@ -687,8 +684,6 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom) sortLists(); - m_currentClass = 0; - // Functions added to the module on the type system. const AddedFunctionList &globalUserFunctions = types->globalUserFunctions(); for (const AddedFunction &addedFunc : globalUserFunctions) { @@ -785,8 +780,6 @@ AbstractMetaClass *AbstractMetaBuilderPrivate::traverseNamespace(const FileModel *metaClass += AbstractMetaAttributes::Public; - m_currentClass = metaClass; - if (ReportHandler::isDebug(ReportHandler::SparseDebug)) { qCDebug(lcShiboken) << QStringLiteral("namespace '%1.%2'").arg(metaClass->package(), namespaceItem->name()); @@ -799,7 +792,7 @@ AbstractMetaClass *AbstractMetaBuilderPrivate::traverseNamespace(const FileModel const ClassList &classes = namespaceItem->classes(); for (const ClassModelItem &cls : classes) { - AbstractMetaClass* mjc = traverseClass(dom, cls); + AbstractMetaClass* mjc = traverseClass(dom, cls, metaClass); if (mjc) { metaClass->addInnerClass(mjc); mjc->setEnclosingClass(metaClass); @@ -811,7 +804,7 @@ AbstractMetaClass *AbstractMetaBuilderPrivate::traverseNamespace(const FileModel // specific typedefs to be used as classes. const TypeDefList typeDefs = namespaceItem->typeDefs(); for (const TypeDefModelItem &typeDef : typeDefs) { - AbstractMetaClass *cls = traverseTypeDef(dom, typeDef); + AbstractMetaClass *cls = traverseTypeDef(dom, typeDef, metaClass); if (cls) { metaClass->addInnerClass(cls); cls->setEnclosingClass(metaClass); @@ -829,8 +822,6 @@ AbstractMetaClass *AbstractMetaBuilderPrivate::traverseNamespace(const FileModel } } - m_currentClass = 0; - popScope(); m_namespacePrefix = currentScope()->qualifiedName().join(colonColon()); @@ -873,8 +864,8 @@ AbstractMetaEnum *AbstractMetaBuilderPrivate::traverseEnum(const EnumModelItem & QString enumName = enumItem->name(); QString className; - if (m_currentClass) - className = m_currentClass->typeEntry()->qualifiedCppName(); + if (enclosing) + className = enclosing->typeEntry()->qualifiedCppName(); QString rejectReason; if (TypeDatabase::instance()->isEnumRejected(className, enumName, &rejectReason)) { @@ -884,8 +875,8 @@ AbstractMetaEnum *AbstractMetaBuilderPrivate::traverseEnum(const EnumModelItem & return 0; } - const bool rejectionWarning = !m_currentClass - || (m_currentClass->typeEntry()->codeGeneration() & TypeEntry::GenerateTargetLang); + const bool rejectionWarning = !enclosing + || (enclosing->typeEntry()->codeGeneration() & TypeEntry::GenerateTargetLang); if (!typeEntry) { if (rejectionWarning) @@ -984,15 +975,16 @@ AbstractMetaEnum *AbstractMetaBuilderPrivate::traverseEnum(const EnumModelItem & } AbstractMetaClass* AbstractMetaBuilderPrivate::traverseTypeDef(const FileModelItem &dom, - const TypeDefModelItem &typeDef) + const TypeDefModelItem &typeDef, + AbstractMetaClass *currentClass) { TypeDatabase* types = TypeDatabase::instance(); QString className = stripTemplateArgs(typeDef->name()); QString fullClassName = className; // we have an inner class - if (m_currentClass) { - fullClassName = stripTemplateArgs(m_currentClass->typeEntry()->qualifiedCppName()) + if (currentClass) { + fullClassName = stripTemplateArgs(currentClass->typeEntry()->qualifiedCppName()) + colonColon() + fullClassName; } @@ -1047,14 +1039,15 @@ void AbstractMetaBuilderPrivate::traverseTypesystemTypedefs() } AbstractMetaClass *AbstractMetaBuilderPrivate::traverseClass(const FileModelItem &dom, - const ClassModelItem &classItem) + const ClassModelItem &classItem, + AbstractMetaClass *currentClass) { QString className = stripTemplateArgs(classItem->name()); QString fullClassName = className; // we have inner an class - if (m_currentClass) { - fullClassName = stripTemplateArgs(m_currentClass->typeEntry()->qualifiedCppName()) + if (currentClass) { + fullClassName = stripTemplateArgs(currentClass->typeEntry()->qualifiedCppName()) + colonColon() + fullClassName; } @@ -1098,9 +1091,6 @@ AbstractMetaClass *AbstractMetaBuilderPrivate::traverseClass(const FileModelItem if (type->stream()) metaClass->setStream(true); - AbstractMetaClass* oldCurrentClass = m_currentClass; - m_currentClass = metaClass; - if (ReportHandler::isDebug(ReportHandler::SparseDebug)) { const QString message = type->isContainer() ? QStringLiteral("container: '%1'").arg(fullClassName) @@ -1127,7 +1117,7 @@ AbstractMetaClass *AbstractMetaBuilderPrivate::traverseClass(const FileModelItem { const ClassList &innerClasses = classItem->classes(); for (const ClassModelItem &ci : innerClasses) { - AbstractMetaClass *cl = traverseClass(dom, ci); + AbstractMetaClass *cl = traverseClass(dom, ci, metaClass); if (cl) { cl->setEnclosingClass(metaClass); metaClass->addInnerClass(cl); @@ -1141,16 +1131,13 @@ AbstractMetaClass *AbstractMetaBuilderPrivate::traverseClass(const FileModelItem // specific typedefs to be used as classes. const TypeDefList typeDefs = classItem->typeDefs(); for (const TypeDefModelItem &typeDef : typeDefs) { - AbstractMetaClass *cls = traverseTypeDef(dom, typeDef); + AbstractMetaClass *cls = traverseTypeDef(dom, typeDef, metaClass); if (cls) { cls->setEnclosingClass(metaClass); addAbstractMetaClass(cls, typeDef.data()); } } - - m_currentClass = oldCurrentClass; - // Set the default include file name if (!type->include().isValid()) setInclude(type, classItem->fileName()); @@ -1177,13 +1164,8 @@ void AbstractMetaBuilderPrivate::traverseClassMembers(ClassModelItem item) if (!metaClass) return; - AbstractMetaClass* oldCurrentClass = m_currentClass; - m_currentClass = metaClass; - // Class members traverseScopeMembers(item, metaClass); - - m_currentClass = oldCurrentClass; } void AbstractMetaBuilderPrivate::traverseNamespaceMembers(NamespaceModelItem item) @@ -1192,9 +1174,6 @@ void AbstractMetaBuilderPrivate::traverseNamespaceMembers(NamespaceModelItem ite if (!metaClass) return; - AbstractMetaClass* oldCurrentClass = m_currentClass; - m_currentClass = metaClass; - // Namespace members traverseScopeMembers(item, metaClass); @@ -1202,7 +1181,6 @@ void AbstractMetaBuilderPrivate::traverseNamespaceMembers(NamespaceModelItem ite for (const NamespaceModelItem &ni : item->namespaces()) traverseNamespaceMembers(ni); - m_currentClass = oldCurrentClass; } static inline QString fieldSignatureWithType(const VariableModelItem &field) @@ -1217,10 +1195,10 @@ static inline QString qualifiedFieldSignatureWithType(const QString &className, } AbstractMetaField *AbstractMetaBuilderPrivate::traverseField(const VariableModelItem &field, - const AbstractMetaClass *cls) + AbstractMetaClass *cls) { QString fieldName = field->name(); - QString className = m_currentClass->typeEntry()->qualifiedCppName(); + QString className = cls->typeEntry()->qualifiedCppName(); // Ignore friend decl. if (field->isFriend()) @@ -1242,14 +1220,14 @@ AbstractMetaField *AbstractMetaBuilderPrivate::traverseField(const VariableModel metaField->setEnclosingClass(cls); TypeInfo fieldType = field->type(); - AbstractMetaType *metaType = translateType(fieldType); + AbstractMetaType *metaType = translateType(fieldType, cls); if (!metaType) { const QString type = TypeInfo::resolveType(fieldType, currentScope()).qualifiedName().join(colonColon()); - if (m_currentClass->typeEntry()->codeGeneration() & TypeEntry::GenerateTargetLang) { + if (cls->typeEntry()->codeGeneration() & TypeEntry::GenerateTargetLang) { qCWarning(lcShiboken).noquote().nospace() << QStringLiteral("skipping field '%1::%2' with unmatched type '%3'") - .arg(m_currentClass->name(), fieldName, type); + .arg(cls->name(), fieldName, type); } delete metaField; return 0; @@ -1352,14 +1330,15 @@ static bool _compareAbstractMetaFunctions(const AbstractMetaFunction* func, cons } AbstractMetaFunctionList AbstractMetaBuilderPrivate::classFunctionList(const ScopeModelItem &scopeItem, - AbstractMetaClass::Attributes *constructorAttributes) + AbstractMetaClass::Attributes *constructorAttributes, + AbstractMetaClass *currentClass) { *constructorAttributes = 0; AbstractMetaFunctionList result; const FunctionList &scopeFunctionList = scopeItem->functions(); result.reserve(scopeFunctionList.size()); for (const FunctionModelItem &function : scopeFunctionList) { - if (AbstractMetaFunction *metaFunction = traverseFunction(function)) { + if (AbstractMetaFunction *metaFunction = traverseFunction(function, currentClass)) { result.append(metaFunction); } else if (function->functionType() == CodeModel::Constructor) { auto arguments = function->arguments(); @@ -1399,7 +1378,7 @@ void AbstractMetaBuilderPrivate::traverseFunctions(ScopeModelItem scopeItem, { AbstractMetaAttributes::Attributes constructorAttributes; const AbstractMetaFunctionList functions = - classFunctionList(scopeItem, &constructorAttributes); + classFunctionList(scopeItem, &constructorAttributes, metaClass); metaClass->setAttributes(metaClass->attributes() | constructorAttributes); for (AbstractMetaFunction *metaFunction : functions){ @@ -1717,11 +1696,11 @@ AbstractMetaFunction* AbstractMetaBuilderPrivate::traverseFunction(const AddedFu //use relace-default-expression for set default value QString replacedExpression; - if (m_currentClass) - replacedExpression = metaFunction->replacedDefaultExpression(m_currentClass, i + 1); + if (metaClass) + replacedExpression = metaFunction->replacedDefaultExpression(metaClass, i + 1); if (!replacedExpression.isEmpty()) { - if (!metaFunction->removedDefaultExpression(m_currentClass, i + 1)) { + if (!metaFunction->removedDefaultExpression(metaClass, i + 1)) { metaArg->setDefaultValueExpression(replacedExpression); metaArg->setOriginalDefaultValueExpression(replacedExpression); } @@ -1730,7 +1709,7 @@ AbstractMetaFunction* AbstractMetaBuilderPrivate::traverseFunction(const AddedFu metaFunction->setOriginalAttributes(metaFunction->attributes()); if (!metaArguments.isEmpty()) - fixArgumentNames(metaFunction, metaFunction->modifications(m_currentClass)); + fixArgumentNames(metaFunction, metaFunction->modifications(metaClass)); if (metaClass) { const AbstractMetaArgumentList fargs = metaFunction->arguments(); @@ -1847,20 +1826,21 @@ static bool applyArrayArgumentModifications(const FunctionModificationList &func return true; } -AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(const FunctionModelItem &functionItem) +AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(const FunctionModelItem &functionItem, + AbstractMetaClass *currentClass) { if (functionItem->isDeleted() || !functionItem->templateParameters().isEmpty()) return nullptr; QString functionName = functionItem->name(); QString className; - if (m_currentClass) { + if (currentClass) { // Clang: Skip qt_metacast(), qt_metacall(), expanded from Q_OBJECT // and overridden metaObject(), QGADGET helpers if (functionName == QLatin1String("qt_check_for_QGADGET_macro") || functionName.startsWith(QLatin1String("qt_meta"))) { return nullptr; } - className = m_currentClass->typeEntry()->qualifiedCppName(); + className = currentClass->typeEntry()->qualifiedCppName(); if (functionName == QLatin1String("metaObject") && className != QLatin1String("QObject")) return nullptr; } @@ -1943,7 +1923,7 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(const Functio break; case AbstractMetaFunction::ConstructorFunction: metaFunction->setExplicit(functionItem->isExplicit()); - metaFunction->setName(m_currentClass->name()); + metaFunction->setName(currentClass->name()); break; default: { TypeInfo returnType = functionItem->type(); @@ -1956,7 +1936,7 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(const Functio AbstractMetaType *type = nullptr; if (!returnType.isVoid()) { - type = translateType(returnType, true, &errorMessage); + type = translateType(returnType, currentClass, true, &errorMessage); if (!type) { const QString reason = msgUnmatchedReturnType(functionItem, errorMessage); qCWarning(lcShiboken, "%s", @@ -1992,12 +1972,12 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(const Functio return nullptr; } - AbstractMetaType *metaType = translateType(arg->type(), true, &errorMessage); + AbstractMetaType *metaType = translateType(arg->type(), currentClass, true, &errorMessage); if (!metaType) { // If an invalid argument has a default value, simply remove it if (arg->defaultValue()) { - if (!m_currentClass - || (m_currentClass->typeEntry()->codeGeneration() + if (!currentClass + || (currentClass->typeEntry()->codeGeneration() & TypeEntry::GenerateTargetLang)) { qCWarning(lcShiboken).noquote().nospace() << "Stripping argument #" << (i + 1) << " of " @@ -2029,7 +2009,7 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(const Functio metaFunction->setArguments(metaArguments); - const FunctionModificationList functionMods = metaFunction->modifications(m_currentClass); + const FunctionModificationList functionMods = metaFunction->modifications(currentClass); for (const FunctionModification &mod : functionMods) { if (mod.exceptionHandling() != TypeSystem::ExceptionHandling::Unspecified) @@ -2045,8 +2025,8 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(const Functio //use relace-default-expression for set default value QString replacedExpression; - if (m_currentClass) { - replacedExpression = metaFunction->replacedDefaultExpression(m_currentClass, i + 1); + if (currentClass) { + replacedExpression = metaFunction->replacedDefaultExpression(currentClass, i + 1); } else { if (!functionMods.isEmpty()) { QVector argMods = functionMods.constFirst().argument_mods; @@ -2058,10 +2038,10 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(const Functio bool hasDefaultValue = false; if (arg->defaultValue() || !replacedExpression.isEmpty()) { QString expr = arg->defaultValueExpression(); - expr = fixDefaultValue(arg, metaArg->type(), metaFunction, m_currentClass, i); + expr = fixDefaultValue(arg, metaArg->type(), metaFunction, currentClass, i); metaArg->setOriginalDefaultValueExpression(expr); - if (metaFunction->removedDefaultExpression(m_currentClass, i + 1)) { + if (metaFunction->removedDefaultExpression(currentClass, i + 1)) { expr.clear(); } else if (!replacedExpression.isEmpty()) { expr = replacedExpression; @@ -2075,7 +2055,7 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(const Functio && !metaArg->hasName() && !metaFunction->isOperatorOverload() && !metaFunction->isSignal() - && metaFunction->argumentName(i+1, false, m_currentClass).isEmpty()) { + && metaFunction->argumentName(i + 1, false, currentClass).isEmpty()) { qCWarning(lcShiboken).noquote().nospace() << QStringLiteral("Argument %1 on function '%2::%3' has default expression but does not have name.") .arg(i+1).arg(className, metaFunction->minimalSignature()); @@ -2093,9 +2073,9 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(const Functio } // Determine class special functions - if (m_currentClass && metaFunction->arguments().size() == 1) { + if (currentClass && metaFunction->arguments().size() == 1) { const AbstractMetaType *argType = metaFunction->arguments().constFirst()->type(); - if (argType->typeEntry() == m_currentClass->typeEntry() && argType->indirections() == 0) { + if (argType->typeEntry() == currentClass->typeEntry() && argType->indirections() == 0) { if (metaFunction->name() == QLatin1String("operator=")) { switch (argType->referenceType()) { case NoReference: @@ -2195,10 +2175,11 @@ static const TypeEntry* findTypeEntryUsingContext(const AbstractMetaClass* metaC } AbstractMetaType *AbstractMetaBuilderPrivate::translateType(const TypeInfo &_typei, + AbstractMetaClass *currentClass, bool resolveType, QString *errorMessage) { - return translateTypeStatic(_typei, m_currentClass, this, resolveType, errorMessage); + return translateTypeStatic(_typei, currentClass, this, resolveType, errorMessage); } AbstractMetaType *AbstractMetaBuilderPrivate::translateTypeStatic(const TypeInfo &_typei, @@ -2907,7 +2888,7 @@ void AbstractMetaBuilderPrivate::parseQ_Property(AbstractMetaClass *metaClass, TypeInfo info; info.setQualifiedName((scope + l.at(0)).split(colonColon())); - type = translateType(info); + type = translateType(info, metaClass); if (type) break; } diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h b/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h index 8d5b924dd..b7d4dc7bc 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h +++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h @@ -60,14 +60,17 @@ public: ScopeModelItem currentScope() const { return m_scopes.constLast(); } - AbstractMetaClass *argumentToClass(const ArgumentModelItem &); + AbstractMetaClass *argumentToClass(const ArgumentModelItem &, + AbstractMetaClass *currentClass); void addAbstractMetaClass(AbstractMetaClass *cls, const _CodeModelItem *item); AbstractMetaClass *traverseTypeDef(const FileModelItem &dom, - const TypeDefModelItem &typeDef); + const TypeDefModelItem &typeDef, + AbstractMetaClass *currentClass); void traverseTypesystemTypedefs(); AbstractMetaClass *traverseClass(const FileModelItem &dom, - const ClassModelItem &item); + const ClassModelItem &item, + AbstractMetaClass *currentClass); void traverseScopeMembers(ScopeModelItem item, AbstractMetaClass *metaClass); void traverseClassMembers(ClassModelItem scopeItem); void traverseNamespaceMembers(NamespaceModelItem scopeItem); @@ -79,24 +82,30 @@ public: void traverseEnums(const ScopeModelItem &item, AbstractMetaClass *parent, const QStringList &enumsDeclarations); AbstractMetaFunctionList classFunctionList(const ScopeModelItem &scopeItem, - AbstractMetaClass::Attributes *constructorAttributes); + AbstractMetaClass::Attributes *constructorAttributes, + AbstractMetaClass *currentClass); AbstractMetaFunctionList templateClassFunctionList(const ScopeModelItem &scopeItem, AbstractMetaClass *metaClass, bool *constructorRejected); void traverseFunctions(ScopeModelItem item, AbstractMetaClass *parent); void applyFunctionModifications(AbstractMetaFunction* func); void traverseFields(const ScopeModelItem &item, AbstractMetaClass *parent); - void traverseStreamOperator(const FunctionModelItem &functionItem); - void traverseOperatorFunction(const FunctionModelItem &item); + void traverseStreamOperator(const FunctionModelItem &functionItem, + AbstractMetaClass *currentClass); + void traverseOperatorFunction(const FunctionModelItem &item, + AbstractMetaClass *currentClass); AbstractMetaFunction* traverseFunction(const AddedFunction &addedFunc); AbstractMetaFunction* traverseFunction(const AddedFunction &addedFunc, AbstractMetaClass *metaClass); - AbstractMetaFunction *traverseFunction(const FunctionModelItem &function); + AbstractMetaFunction *traverseFunction(const FunctionModelItem &function, + AbstractMetaClass *currentClass); AbstractMetaField *traverseField(const VariableModelItem &field, - const AbstractMetaClass *cls); + AbstractMetaClass *cls); void checkFunctionModifications(); - void registerHashFunction(const FunctionModelItem &functionItem); - void registerToStringCapability(const FunctionModelItem &functionItem); + void registerHashFunction(const FunctionModelItem &functionItem, + AbstractMetaClass *currentClass); + void registerToStringCapability(const FunctionModelItem &functionItem, + AbstractMetaClass *currentClass); /** * A conversion operator function should not have its owner class as @@ -123,6 +132,7 @@ public: int argumentIndex); AbstractMetaType *translateType(const AddedFunction::TypeInfo &typeInfo); AbstractMetaType *translateType(const TypeInfo &type, + AbstractMetaClass *currentClass, bool resolveType = true, QString *errorMessage = nullptr); static AbstractMetaType *translateTypeStatic(const TypeInfo &type, @@ -175,7 +185,6 @@ public: QHash m_enums; - AbstractMetaClass *m_currentClass; QList m_scopes; QString m_namespacePrefix; -- cgit v1.2.3