aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/ApiExtractor/typesystemparser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken2/ApiExtractor/typesystemparser.cpp')
-rw-r--r--sources/shiboken2/ApiExtractor/typesystemparser.cpp166
1 files changed, 102 insertions, 64 deletions
diff --git a/sources/shiboken2/ApiExtractor/typesystemparser.cpp b/sources/shiboken2/ApiExtractor/typesystemparser.cpp
index d2648d0b4..9ad9322b2 100644
--- a/sources/shiboken2/ApiExtractor/typesystemparser.cpp
+++ b/sources/shiboken2/ApiExtractor/typesystemparser.cpp
@@ -143,8 +143,8 @@ static QString extractSnippet(const QString &code, const QString &snippetLabel)
bool useLine = false;
QString result;
- const auto lines = code.splitRef(QLatin1Char('\n'));
- for (const QStringRef &line : lines) {
+ const auto lines = QStringView{code}.split(QLatin1Char('\n'));
+ for (const auto &line : lines) {
if (snippetRe.match(line).hasMatch()) {
useLine = !useLine;
if (!useLine)
@@ -429,7 +429,7 @@ static QString msgInvalidAttributeValue(const QXmlStreamAttribute &attribute)
return result;
}
-static QString msgUnusedAttributes(const QStringRef &tag, const QXmlStreamAttributes &attributes)
+static QString msgUnusedAttributes(QStringView tag, const QXmlStreamAttributes &attributes)
{
QString result;
QTextStream str(&result);
@@ -545,18 +545,20 @@ static QString msgReaderError(const QXmlStreamReader &reader, const QString &wha
}
static QString msgUnimplementedElementWarning(const QXmlStreamReader &reader,
- const QStringRef &name)
+ QStringView name)
{
- const QString message = QLatin1String("The element \"") +
- name + QLatin1String("\" is not implemented.");
+ QString message;
+ QTextStream(&message) << "The element \"" << name
+ << "\" is not implemented.";
return msgReaderMessage(reader, "Warning", message);
}
static QString msgUnimplementedAttributeWarning(const QXmlStreamReader &reader,
- const QStringRef &name)
+ QStringView name)
{
- const QString message = QLatin1String("The attribute \"") +
- name + QLatin1String("\" is not implemented.");
+ QString message;
+ QTextStream(&message) << "The attribute \"" << name
+ << "\" is not implemented.";
return msgReaderMessage(reader, "Warning", message);
}
@@ -600,7 +602,7 @@ static bool addRejection(TypeDatabase *database, QXmlStreamAttributes *attribute
return false;
for (int i = attributes->size() - 1; i >= 0; --i) {
- const QStringRef name = attributes->at(i).qualifiedName();
+ const auto name = attributes->at(i).qualifiedName();
const TypeRejection::MatchType type = typeRejectionFromAttribute(name);
switch (type) {
case TypeRejection::Function:
@@ -746,7 +748,7 @@ bool TypeSystemParser::setupSmartPointerInstantiations()
return true;
}
-bool TypeSystemParser::endElement(const QStringRef &localName)
+bool TypeSystemParser::endElement(QStringView localName)
{
if (m_ignoreDepth) {
--m_ignoreDepth;
@@ -992,11 +994,11 @@ bool TypeSystemParser::importFileElement(const QXmlStreamAttributes &atts)
}
}
- const QStringRef quoteFrom = atts.value(quoteAfterLineAttribute());
+ const auto quoteFrom = atts.value(quoteAfterLineAttribute());
bool foundFromOk = quoteFrom.isEmpty();
bool from = quoteFrom.isEmpty();
- const QStringRef quoteTo = atts.value(quoteBeforeLineAttribute());
+ const auto quoteTo = atts.value(quoteBeforeLineAttribute());
bool foundToOk = quoteTo.isEmpty();
bool to = true;
@@ -1123,16 +1125,44 @@ bool TypeSystemParser::checkRootElement()
return ok;
}
-void TypeSystemParser::applyCommonAttributes(const QXmlStreamReader &reader, TypeEntry *type,
- QXmlStreamAttributes *attributes) const
+static TypeEntry *findViewedType(const QString &name)
+{
+ const auto range = TypeDatabase::instance()->entries().equal_range(name);
+ for (auto i = range.first; i != range.second; ++i) {
+ switch (i.value()->type()) {
+ case TypeEntry::BasicValueType:
+ case TypeEntry::PrimitiveType:
+ case TypeEntry::ContainerType:
+ case TypeEntry::ObjectType:
+ return i.value();
+ default:
+ break;
+ }
+ }
+ return nullptr;
+}
+
+bool TypeSystemParser::applyCommonAttributes(const QXmlStreamReader &reader, TypeEntry *type,
+ QXmlStreamAttributes *attributes)
{
type->setSourceLocation(SourceLocation(m_currentFile,
reader.lineNumber()));
type->setCodeGeneration(m_generate);
- const int revisionIndex =
- indexOfAttribute(*attributes, u"revision");
- if (revisionIndex != -1)
- type->setRevision(attributes->takeAt(revisionIndex).value().toInt());
+ for (int i = attributes->size() - 1; i >= 0; --i) {
+ const auto name = attributes->at(i).qualifiedName();
+ if (name == u"revision") {
+ type->setRevision(attributes->takeAt(i).value().toInt());
+ } else if (name == u"view-on") {
+ const QString name = attributes->takeAt(i).value().toString();
+ TypeEntry *views = findViewedType(name);
+ if (views == nullptr) {
+ m_error = msgCannotFindView(name, type->name());
+ return false;
+ }
+ type->setViewOn(views);
+ }
+ }
+ return true;
}
FlagsTypeEntry *
@@ -1157,7 +1187,8 @@ FlagsTypeEntry *
}
ftype->setOriginalName(flagName);
- applyCommonAttributes(reader, ftype, attributes);
+ if (!applyCommonAttributes(reader, ftype, attributes))
+ return nullptr;
QStringList lst = flagName.split(colonColon());
const QString targetLangFlagName = QStringList(lst.mid(0, lst.size() - 1)).join(QLatin1Char('.'));
@@ -1194,7 +1225,7 @@ SmartPointerTypeEntry *
QString refCountMethodName;
QString instantiations;
for (int i = attributes->size() - 1; i >= 0; --i) {
- const QStringRef name = attributes->at(i).qualifiedName();
+ const auto name = attributes->at(i).qualifiedName();
if (name == QLatin1String("type")) {
smartPointerType = attributes->takeAt(i).value().toString();
} else if (name == QLatin1String("getter")) {
@@ -1236,7 +1267,8 @@ SmartPointerTypeEntry *
auto *type = new SmartPointerTypeEntry(name, getter, smartPointerType,
refCountMethodName, since, currentParentTypeEntry());
- applyCommonAttributes(reader, type, attributes);
+ if (!applyCommonAttributes(reader, type, attributes))
+ return nullptr;
m_smartPointerInstantiations.insert(type, instantiations);
return type;
}
@@ -1249,9 +1281,10 @@ PrimitiveTypeEntry *
if (!checkRootElement())
return nullptr;
auto *type = new PrimitiveTypeEntry(name, since, currentParentTypeEntry());
- applyCommonAttributes(reader, type, attributes);
+ if (!applyCommonAttributes(reader, type, attributes))
+ return nullptr;
for (int i = attributes->size() - 1; i >= 0; --i) {
- const QStringRef name = attributes->at(i).qualifiedName();
+ const auto name = attributes->at(i).qualifiedName();
if (name == targetLangNameAttribute()) {
type->setTargetLangName(attributes->takeAt(i).value().toString());
} else if (name == QLatin1String("target-lang-api-name")) {
@@ -1286,14 +1319,15 @@ ContainerTypeEntry *
m_error = QLatin1String("no 'type' attribute specified");
return nullptr;
}
- const QStringRef typeName = attributes->takeAt(typeIndex).value();
+ const auto typeName = attributes->takeAt(typeIndex).value();
ContainerTypeEntry::ContainerKind containerType = containerTypeFromAttribute(typeName);
if (containerType == ContainerTypeEntry::NoContainer) {
m_error = QLatin1String("there is no container of type ") + typeName.toString();
return nullptr;
}
auto *type = new ContainerTypeEntry(name, containerType, since, currentParentTypeEntry());
- applyCommonAttributes(reader, type, attributes);
+ if (!applyCommonAttributes(reader, type, attributes))
+ return nullptr;
return type;
}
@@ -1310,7 +1344,7 @@ EnumTypeEntry *
QString flagNames;
for (int i = attributes->size() - 1; i >= 0; --i) {
- const QStringRef name = attributes->at(i).qualifiedName();
+ const auto name = attributes->at(i).qualifiedName();
if (name == QLatin1String("upper-bound")) {
qCWarning(lcShiboken, "%s",
qPrintable(msgUnimplementedAttributeWarning(reader, name)));
@@ -1349,7 +1383,7 @@ NamespaceTypeEntry *
auto visibility = TypeSystem::Visibility::Unspecified;
applyCommonAttributes(reader, result.data(), attributes);
for (int i = attributes->size() - 1; i >= 0; --i) {
- const QStringRef attributeName = attributes->at(i).qualifiedName();
+ const auto attributeName = attributes->at(i).qualifiedName();
if (attributeName == QLatin1String("files")) {
const QString pattern = attributes->takeAt(i).value().toString();
QRegularExpression re(pattern);
@@ -1366,7 +1400,7 @@ NamespaceTypeEntry *
return e->targetLangPackage() == extendsPackageName;
});
if (extendsIt == allEntries.cend()) {
- m_error = msgCannotFindNamespaceToExtend(name, extendsPackageName);
+ m_error = msgCannotFindNamespaceToExtend(name, extendsPackageName.toString());
return nullptr;
}
result->setExtends(*extendsIt);
@@ -1483,7 +1517,7 @@ void TypeSystemParser::applyComplexTypeAttributes(const QXmlStreamReader &reader
QString package = m_defaultPackage;
for (int i = attributes->size() - 1; i >= 0; --i) {
- const QStringRef name = attributes->at(i).qualifiedName();
+ const auto name = attributes->at(i).qualifiedName();
if (name == streamAttribute()) {
ctype->setStream(convertBoolean(attributes->takeAt(i).value(), streamAttribute(), false));
} else if (name == generateAttribute()) {
@@ -1564,7 +1598,7 @@ bool TypeSystemParser::parseRenameFunction(const QXmlStreamReader &,
QString signature;
QString rename;
for (int i = attributes->size() - 1; i >= 0; --i) {
- const QStringRef name = attributes->at(i).qualifiedName();
+ const auto name = attributes->at(i).qualifiedName();
if (name == signatureAttribute()) {
// Do not remove as it is needed for the type entry later on
signature = attributes->at(i).value().toString();
@@ -1619,16 +1653,17 @@ bool TypeSystemParser::parseInjectDocumentation(const QXmlStreamReader &,
TypeSystem::DocModificationMode mode = TypeSystem::DocModificationReplace;
TypeSystem::Language lang = TypeSystem::NativeCode;
for (int i = attributes->size() - 1; i >= 0; --i) {
- const QStringRef name = attributes->at(i).qualifiedName();
+ const auto name = attributes->at(i).qualifiedName();
if (name == QLatin1String("mode")) {
- const QStringRef modeName = attributes->takeAt(i).value();
+ const auto modeName = attributes->takeAt(i).value();
mode = docModificationFromAttribute(modeName);
if (mode == TypeSystem::DocModificationInvalid) {
- m_error = QLatin1String("Unknown documentation injection mode: ") + modeName;
+ m_error = QLatin1String("Unknown documentation injection mode: ");
+ m_error += modeName;
return false;
}
} else if (name == formatAttribute()) {
- const QStringRef format = attributes->takeAt(i).value();
+ const auto format = attributes->takeAt(i).value();
lang = languageFromAttribute(format);
if (lang != TypeSystem::TargetLangCode && lang != TypeSystem::NativeCode) {
m_error = QStringLiteral("unsupported class attribute: '%1'").arg(format);
@@ -1676,7 +1711,7 @@ TypeSystemTypeEntry *TypeSystemParser::parseRootElement(const QXmlStreamReader &
QXmlStreamAttributes *attributes)
{
for (int i = attributes->size() - 1; i >= 0; --i) {
- const QStringRef name = attributes->at(i).qualifiedName();
+ const auto name = attributes->at(i).qualifiedName();
if (name == packageAttribute()) {
m_defaultPackage = attributes->takeAt(i).value().toString();
} else if (name == defaultSuperclassAttribute()) {
@@ -1726,7 +1761,7 @@ bool TypeSystemParser::loadTypesystem(const QXmlStreamReader &,
QString typeSystemName;
bool generateChild = true;
for (int i = attributes->size() - 1; i >= 0; --i) {
- const QStringRef name = attributes->at(i).qualifiedName();
+ const auto name = attributes->at(i).qualifiedName();
if (name == nameAttribute())
typeSystemName = attributes->takeAt(i).value().toString();
else if (name == generateAttribute())
@@ -1795,9 +1830,9 @@ bool TypeSystemParser::parseCustomConversion(const QXmlStreamReader &,
QString snippetLabel;
TypeSystem::Language lang = TypeSystem::NativeCode;
for (int i = attributes->size() - 1; i >= 0; --i) {
- const QStringRef name = attributes->at(i).qualifiedName();
+ const auto name = attributes->at(i).qualifiedName();
if (name == classAttribute()) {
- const QStringRef languageAttribute = attributes->takeAt(i).value();
+ const auto languageAttribute = attributes->takeAt(i).value();
lang = languageFromAttribute(languageAttribute);
if (lang != TypeSystem::TargetLangCode && lang != TypeSystem::NativeCode) {
m_error = QStringLiteral("unsupported class attribute: '%1'").arg(languageAttribute);
@@ -1880,7 +1915,7 @@ bool TypeSystemParser::parseAddConversion(const QXmlStreamReader &,
if (!readFileSnippet(attributes, &snip))
return false;
for (int i = attributes->size() - 1; i >= 0; --i) {
- const QStringRef name = attributes->at(i).qualifiedName();
+ const auto name = attributes->at(i).qualifiedName();
if (name == QLatin1String("type"))
sourceTypeName = attributes->takeAt(i).value().toString();
else if (name == QLatin1String("check"))
@@ -1932,7 +1967,7 @@ bool TypeSystemParser::parseModifyArgument(const QXmlStreamReader &,
QString replaceValue;
bool resetAfterUse = false;
for (int i = attributes->size() - 1; i >= 0; --i) {
- const QStringRef name = attributes->at(i).qualifiedName();
+ const auto name = attributes->at(i).qualifiedName();
if (name == indexAttribute()) {
index = attributes->takeAt(i).value().toString();
} else if (name == QLatin1String("replace-value")) {
@@ -1997,9 +2032,9 @@ bool TypeSystemParser::parseDefineOwnership(const QXmlStreamReader &,
TypeSystem::Language lang = TypeSystem::TargetLangCode;
QString ownership;
for (int i = attributes->size() - 1; i >= 0; --i) {
- const QStringRef name = attributes->at(i).qualifiedName();
+ const auto name = attributes->at(i).qualifiedName();
if (name == classAttribute()) {
- const QStringRef className = attributes->takeAt(i).value();
+ const auto className = attributes->takeAt(i).value();
lang = languageFromAttribute(className);
if (lang != TypeSystem::TargetLangCode && lang != TypeSystem::NativeCode) {
m_error = QStringLiteral("unsupported class attribute: '%1'").arg(className);
@@ -2030,7 +2065,7 @@ bool TypeSystemParser::parseArgumentMap(const QXmlStreamReader &,
int pos = 1;
QString metaName;
for (int i = attributes->size() - 1; i >= 0; --i) {
- const QStringRef name = attributes->at(i).qualifiedName();
+ const auto name = attributes->at(i).qualifiedName();
if (name == indexAttribute()) {
if (!parseIndex(attributes->takeAt(i).value().toString(), &pos, &m_error))
return false;
@@ -2067,7 +2102,7 @@ bool TypeSystemParser::parseRemoval(const QXmlStreamReader &,
TypeSystem::Language lang = TypeSystem::All;
const int classIndex = indexOfAttribute(*attributes, classAttribute());
if (classIndex != -1) {
- const QStringRef value = attributes->takeAt(classIndex).value();
+ const auto value = attributes->takeAt(classIndex).value();
lang = languageFromAttribute(value);
if (lang == TypeSystem::TargetLangCode) // "target" means TargetLangAndNativeCode here
lang = TypeSystem::TargetLangAndNativeCode;
@@ -2118,7 +2153,7 @@ bool TypeSystemParser::parseRename(const QXmlStreamReader &reader,
m_error = msgMissingAttribute(modifierAttribute());
return false;
}
- const QStringRef modifier = attributes->takeAt(modifierIndex).value();
+ const auto modifier = attributes->takeAt(modifierIndex).value();
modifierFlag = modifierFromAttribute(modifier);
if (modifierFlag == Modification::InvalidModifier) {
m_error = QStringLiteral("Unknown access modifier: '%1'").arg(modifier);
@@ -2141,7 +2176,7 @@ bool TypeSystemParser::parseModifyField(const QXmlStreamReader &reader,
FieldModification fm;
fm.modifiers = FieldModification::Readable | FieldModification::Writable;
for (int i = attributes->size() - 1; i >= 0; --i) {
- const QStringRef name = attributes->at(i).qualifiedName();
+ const auto name = attributes->at(i).qualifiedName();
if (name == nameAttribute()) {
fm.name = attributes->takeAt(i).value().toString();
} else if (name == removeAttribute()) {
@@ -2194,7 +2229,7 @@ bool TypeSystemParser::parseAddFunction(const QXmlStreamReader &,
QString access;
int overloadNumber = TypeSystem::OverloadNumberUnset;
for (int i = attributes->size() - 1; i >= 0; --i) {
- const QStringRef name = attributes->at(i).qualifiedName();
+ const auto name = attributes->at(i).qualifiedName();
if (name == QLatin1String("signature")) {
originalSignature = attributes->takeAt(i).value().toString();
} else if (name == QLatin1String("return-type")) {
@@ -2305,7 +2340,7 @@ bool TypeSystemParser::parseModifyFunction(const QXmlStreamReader &reader,
TypeSystem::ExceptionHandling exceptionHandling = TypeSystem::ExceptionHandling::Unspecified;
TypeSystem::AllowThread allowThread = TypeSystem::AllowThread::Unspecified;
for (int i = attributes->size() - 1; i >= 0; --i) {
- const QStringRef name = attributes->at(i).qualifiedName();
+ const auto name = attributes->at(i).qualifiedName();
if (name == QLatin1String("signature")) {
originalSignature = attributes->takeAt(i).value().toString();
} else if (name == accessAttribute()) {
@@ -2433,7 +2468,7 @@ CustomFunction *
? QLatin1String("_create") : QLatin1String("_delete"));
QString paramName = QLatin1String("copy");
for (int i = attributes->size() - 1; i >= 0; --i) {
- const QStringRef name = attributes->at(i).qualifiedName();
+ const auto name = attributes->at(i).qualifiedName();
if (name == nameAttribute())
functionName = attributes->takeAt(i).value().toString();
else if (name == QLatin1String("param-name"))
@@ -2455,14 +2490,15 @@ bool TypeSystemParser::parseReferenceCount(const QXmlStreamReader &reader,
ReferenceCount rc;
for (int i = attributes->size() - 1; i >= 0; --i) {
- const QStringRef name = attributes->at(i).qualifiedName();
+ const auto name = attributes->at(i).qualifiedName();
if (name == actionAttribute()) {
const QXmlStreamAttribute attribute = attributes->takeAt(i);
rc.action = referenceCountFromAttribute(attribute.value());
switch (rc.action) {
case ReferenceCount::Invalid:
- m_error = QLatin1String("unrecognized value '") + attribute.value()
- + QLatin1String("' for action attribute.");
+ m_error = QLatin1String("unrecognized value '");
+ m_error += attribute.value();
+ m_error += QLatin1String("' for action attribute.");
return false;
case ReferenceCount::AddAll:
case ReferenceCount::Ignore:
@@ -2491,16 +2527,18 @@ bool TypeSystemParser::parseParentOwner(const QXmlStreamReader &,
}
ArgumentOwner ao;
for (int i = attributes->size() - 1; i >= 0; --i) {
- const QStringRef name = attributes->at(i).qualifiedName();
+ const auto name = attributes->at(i).qualifiedName();
if (name == indexAttribute()) {
const QString index = attributes->takeAt(i).value().toString();
if (!parseArgumentIndex(index, &ao.index, &m_error))
return false;
} else if (name == actionAttribute()) {
- const QStringRef action = attributes->takeAt(i).value();
+ const auto action = attributes->takeAt(i).value();
ao.action = argumentOwnerActionFromAttribute(action);
if (ao.action == ArgumentOwner::Invalid) {
- m_error = QLatin1String("Invalid parent actionr '") + action + QLatin1String("'.");
+ m_error = QLatin1String("Invalid parent action '");
+ m_error += action;
+ m_error += QLatin1String("'.");
return false;
}
}
@@ -2514,7 +2552,7 @@ bool TypeSystemParser::readFileSnippet(QXmlStreamAttributes *attributes, CodeSni
QString fileName;
QString snippetLabel;
for (int i = attributes->size() - 1; i >= 0; --i) {
- const QStringRef name = attributes->at(i).qualifiedName();
+ const auto name = attributes->at(i).qualifiedName();
if (name == QLatin1String("file")) {
fileName = attributes->takeAt(i).value().toString();
} else if (name == snippetAttribute()) {
@@ -2567,16 +2605,16 @@ bool TypeSystemParser::parseInjectCode(const QXmlStreamReader &,
if (!readFileSnippet(attributes, &snip))
return false;
for (int i = attributes->size() - 1; i >= 0; --i) {
- const QStringRef name = attributes->at(i).qualifiedName();
+ const auto name = attributes->at(i).qualifiedName();
if (name == classAttribute()) {
- const QStringRef className = attributes->takeAt(i).value();
+ const auto className = attributes->takeAt(i).value();
lang = languageFromAttribute(className);
if (lang == TypeSystem::NoLanguage) {
m_error = QStringLiteral("Invalid class specifier: '%1'").arg(className);
return false;
}
} else if (name == positionAttribute()) {
- const QStringRef value = attributes->takeAt(i).value();
+ const auto value = attributes->takeAt(i).value();
position = codeSnipPositionFromAttribute(value);
if (position == TypeSystem::CodeSnipPositionInvalid) {
m_error = QStringLiteral("Invalid position: '%1'").arg(value);
@@ -2610,7 +2648,7 @@ bool TypeSystemParser::parseInclude(const QXmlStreamReader &,
QString fileName;
QString location;
for (int i = attributes->size() - 1; i >= 0; --i) {
- const QStringRef name = attributes->at(i).qualifiedName();
+ const auto name = attributes->at(i).qualifiedName();
if (name == fileNameAttribute())
fileName = attributes->takeAt(i).value().toString();
else if (name == locationAttribute())
@@ -2682,7 +2720,7 @@ bool TypeSystemParser::parseReplace(const QXmlStreamReader &,
QString from;
QString to;
for (int i = attributes->size() - 1; i >= 0; --i) {
- const QStringRef name = attributes->at(i).qualifiedName();
+ const auto name = attributes->at(i).qualifiedName();
if (name == QLatin1String("from"))
from = attributes->takeAt(i).value().toString();
else if (name == toAttribute())
@@ -2710,12 +2748,12 @@ bool TypeSystemParser::startElement(const QXmlStreamReader &reader)
return true;
}
- const QStringRef tagName = reader.name();
+ const auto tagName = reader.name();
QXmlStreamAttributes attributes = reader.attributes();
VersionRange versionRange;
for (int i = attributes.size() - 1; i >= 0; --i) {
- const QStringRef name = attributes.at(i).qualifiedName();
+ const auto name = attributes.at(i).qualifiedName();
if (name == sinceAttribute()) {
if (!parseVersion(attributes.takeAt(i).value().toString(),
m_defaultPackage, &versionRange.since, &m_error)) {