From 1b10ce6a08edbc2ac7e8fd7e97e3fc691f2081df Mon Sep 17 00:00:00 2001 From: Karsten Heimrich Date: Tue, 16 Jun 2020 10:23:19 +0200 Subject: Port QtDeclarative from QStringRef to QStringView MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTBUG-84319 Change-Id: I2dcfb8a2db98282c7a1acdad1e6f4f949f26df15 Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Shawn Rutledge Reviewed-by: Timur Pocheptsov --- src/qml/compiler/qqmlirbuilder.cpp | 36 +++++++++++++-------------- src/qml/compiler/qqmlirbuilder_p.h | 12 ++++----- src/qml/compiler/qv4codegen.cpp | 6 ++--- src/qml/compiler/qv4codegen_p.h | 6 ++--- src/qml/compiler/qv4compilerscanfunctions.cpp | 8 +++--- src/qml/compiler/qv4compilerscanfunctions_p.h | 2 +- 6 files changed, 35 insertions(+), 35 deletions(-) (limited to 'src/qml/compiler') diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index bc979a81e0..8ea97ab956 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -407,7 +407,7 @@ void ScriptDirectivesCollector::importModule(const QString &uri, const QString & QV4::CompiledData::Import *import = engine->pool()->New(); import->type = QV4::CompiledData::Import::ImportLibrary; import->uriIndex = jsGenerator->registerString(uri); - import->version = IRBuilder::extractVersion(QStringRef(&version)); + import->version = IRBuilder::extractVersion(QStringView(version)); import->qualifierIndex = jsGenerator->registerString(module); import->location.line = lineNumber; import->location.column = column; @@ -526,7 +526,7 @@ bool IRBuilder::visit(QQmlJS::AST::UiObjectDefinition *node) QQmlJS::AST::UiQualifiedId *lastId = node->qualifiedTypeNameId; while (lastId->next) lastId = lastId->next; - bool isType = lastId->name.unicode()->isUpper(); + bool isType = lastId->name.data()->isUpper(); if (isType) { int idx = 0; if (!defineQMLObject(&idx, node)) @@ -915,7 +915,7 @@ bool IRBuilder::visit(QQmlJS::AST::UiPublicMember *node) if (memberType == QLatin1String("alias")) { return appendAlias(node); } else { - const QStringRef &name = node->name; + const QStringView &name = node->name; Property *property = New(); property->isReadOnly = node->isReadonlyMember; @@ -927,7 +927,7 @@ bool IRBuilder::visit(QQmlJS::AST::UiPublicMember *node) property->setBuiltinType(builtinPropertyType); if (!typeFound && memberType.at(0).isUpper()) { - const QStringRef &typeModifier = node->typeModifier; + const QStringView &typeModifier = node->typeModifier; property->setCustomType(registerString(memberType)); if (typeModifier == QLatin1String("list")) { @@ -1043,15 +1043,15 @@ QString IRBuilder::asString(QQmlJS::AST::UiQualifiedId *node) return s; } -QStringRef IRBuilder::asStringRef(QQmlJS::AST::Node *node) +QStringView IRBuilder::asStringRef(QQmlJS::AST::Node *node) { if (!node) - return QStringRef(); + return QStringView(); return textRefAt(node->firstSourceLocation(), node->lastSourceLocation()); } -QTypeRevision IRBuilder::extractVersion(const QStringRef &string) +QTypeRevision IRBuilder::extractVersion(QStringView string) { if (string.isEmpty()) return QTypeRevision(); @@ -1062,9 +1062,9 @@ QTypeRevision IRBuilder::extractVersion(const QStringRef &string) : QTypeRevision::fromVersion(string.left(dot).toInt(), string.mid(dot + 1).toInt()); } -QStringRef IRBuilder::textRefAt(const QQmlJS::SourceLocation &first, const QQmlJS::SourceLocation &last) const +QStringView IRBuilder::textRefAt(const QQmlJS::SourceLocation &first, const QQmlJS::SourceLocation &last) const { - return QStringRef(&sourceCode, first.offset, last.offset + last.length - first.offset); + return QStringView(sourceCode).mid(first.offset, last.offset + last.length - first.offset); } void IRBuilder::setBindingValue(QV4::CompiledData::Binding *binding, QQmlJS::AST::Statement *statement, QQmlJS::AST::Node *parentNode) @@ -1127,7 +1127,7 @@ void IRBuilder::setBindingValue(QV4::CompiledData::Binding *binding, QQmlJS::AST } } -void IRBuilder::tryGeneratingTranslationBinding(const QStringRef &base, AST::ArgumentList *args, QV4::CompiledData::Binding *binding) +void IRBuilder::tryGeneratingTranslationBinding(QStringView base, AST::ArgumentList *args, QV4::CompiledData::Binding *binding) { if (base == QLatin1String("qsTr")) { QV4::CompiledData::TranslationData translationData; @@ -1138,7 +1138,7 @@ void IRBuilder::tryGeneratingTranslationBinding(const QStringRef &base, AST::Arg if (!args || !args->expression) return; // no arguments, stop - QStringRef translation; + QStringView translation; if (QQmlJS::AST::StringLiteral *arg1 = QQmlJS::AST::cast(args->expression)) { translation = arg1->value; } else { @@ -1179,7 +1179,7 @@ void IRBuilder::tryGeneratingTranslationBinding(const QStringRef &base, AST::Arg if (!args || !args->expression) return; // no arguments, stop - QStringRef id; + QStringView id; if (QQmlJS::AST::StringLiteral *arg1 = QQmlJS::AST::cast(args->expression)) { id = arg1->value; } else { @@ -1207,7 +1207,7 @@ void IRBuilder::tryGeneratingTranslationBinding(const QStringRef &base, AST::Arg if (!args || !args->expression) return; // no arguments, stop - QStringRef str; + QStringView str; if (QQmlJS::AST::StringLiteral *arg1 = QQmlJS::AST::cast(args->expression)) { str = arg1->value; } else { @@ -1228,7 +1228,7 @@ void IRBuilder::tryGeneratingTranslationBinding(const QStringRef &base, AST::Arg if (!args || !args->expression) return; // no second arguments, stop - QStringRef str; + QStringView str; if (QQmlJS::AST::StringLiteral *arg2 = QQmlJS::AST::cast(args->expression)) { str = arg2->value; } else { @@ -1408,7 +1408,7 @@ Object *IRBuilder::bindingsTarget() const bool IRBuilder::setId(const QQmlJS::SourceLocation &idLocation, QQmlJS::AST::Statement *value) { QQmlJS::SourceLocation loc = value->firstSourceLocation(); - QStringRef str; + QStringView str; QQmlJS::AST::Node *node = value; if (QQmlJS::AST::ExpressionStatement *stmt = QQmlJS::AST::cast(node)) { @@ -1433,7 +1433,7 @@ bool IRBuilder::setId(const QQmlJS::SourceLocation &idLocation, QQmlJS::AST::Sta if (!ch.isLetter() && ch != u) COMPILE_EXCEPTION(loc, tr( "IDs must start with a letter or underscore")); - for (int ii = 1; ii < str.count(); ++ii) { + for (int ii = 1; ii < str.size(); ++ii) { ch = str.at(ii); if (!ch.isLetterOrNumber() && ch != u) COMPILE_EXCEPTION(loc, tr( "IDs must contain only letters, numbers, and underscores")); @@ -1469,7 +1469,7 @@ bool IRBuilder::resolveQualifiedId(QQmlJS::AST::UiQualifiedId **nameToResolve, O qualifiedIdElement = qualifiedIdElement->next; currentName += QLatin1Char('.') + qualifiedIdElement->name; - if (!qualifiedIdElement->name.unicode()->isUpper()) + if (!qualifiedIdElement->name.data()->isUpper()) COMPILE_EXCEPTION(qualifiedIdElement->firstSourceLocation(), tr("Expected type name")); break; @@ -1479,7 +1479,7 @@ bool IRBuilder::resolveQualifiedId(QQmlJS::AST::UiQualifiedId **nameToResolve, O *object = _object; while (qualifiedIdElement->next) { const quint32 propertyNameIndex = registerString(currentName); - const bool isAttachedProperty = qualifiedIdElement->name.unicode()->isUpper(); + const bool isAttachedProperty = qualifiedIdElement->name.data()->isUpper(); Binding *binding = (*object)->findBinding(propertyNameIndex); if (binding) { diff --git a/src/qml/compiler/qqmlirbuilder_p.h b/src/qml/compiler/qqmlirbuilder_p.h index 254d21001b..7e6c8c1272 100644 --- a/src/qml/compiler/qqmlirbuilder_p.h +++ b/src/qml/compiler/qqmlirbuilder_p.h @@ -497,16 +497,16 @@ public: { return defineQMLObject(objectIndex, node->qualifiedTypeNameId, node->qualifiedTypeNameId->firstSourceLocation(), node->initializer, declarationsOverride); } static QString asString(QQmlJS::AST::UiQualifiedId *node); - QStringRef asStringRef(QQmlJS::AST::Node *node); - static QTypeRevision extractVersion(const QStringRef &string); - QStringRef textRefAt(const QQmlJS::SourceLocation &loc) const - { return QStringRef(&sourceCode, loc.offset, loc.length); } - QStringRef textRefAt(const QQmlJS::SourceLocation &first, + QStringView asStringRef(QQmlJS::AST::Node *node); + static QTypeRevision extractVersion(QStringView string); + QStringView textRefAt(const QQmlJS::SourceLocation &loc) const + { return QStringView(sourceCode).mid(loc.offset, loc.length); } + QStringView textRefAt(const QQmlJS::SourceLocation &first, const QQmlJS::SourceLocation &last) const; void setBindingValue(QV4::CompiledData::Binding *binding, QQmlJS::AST::Statement *statement, QQmlJS::AST::Node *parentNode); - void tryGeneratingTranslationBinding(const QStringRef &base, QQmlJS::AST::ArgumentList *args, QV4::CompiledData::Binding *binding); + void tryGeneratingTranslationBinding(QStringView base, QQmlJS::AST::ArgumentList *args, QV4::CompiledData::Binding *binding); void appendBinding(QQmlJS::AST::UiQualifiedId *name, QQmlJS::AST::Statement *value, QQmlJS::AST::Node *parentNode); diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index 4588690307..f642797761 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -3969,14 +3969,14 @@ public: } private: - void collectIdentifiers(QVector &ids, AST::Node *node) { + void collectIdentifiers(QList &ids, AST::Node *node) { class Collector: public QQmlJS::AST::Visitor { private: - QVector &ids; + QList &ids; VolatileMemoryLocationScanner *parent; public: - Collector(QVector &ids, VolatileMemoryLocationScanner *parent) : + Collector(QList &ids, VolatileMemoryLocationScanner *parent) : QQmlJS::AST::Visitor(parent->recursionDepth()), ids(ids), parent(parent) {} diff --git a/src/qml/compiler/qv4codegen_p.h b/src/qml/compiler/qv4codegen_p.h index 255698d790..e7d7a21294 100644 --- a/src/qml/compiler/qv4codegen_p.h +++ b/src/qml/compiler/qv4codegen_p.h @@ -105,15 +105,15 @@ public: class VolatileMemoryLocations { friend VolatileMemoryLocationScanner; bool allVolatile = false; - QVector specificLocations; + QList specificLocations; public: - bool isVolatile(const QStringView &name) { + bool isVolatile(QStringView name) { if (allVolatile) return true; return specificLocations.contains(name); } - void add(const QStringRef &name) { if (!allVolatile) specificLocations.append(name); } + void add(QStringView name) { if (!allVolatile) specificLocations.append(name); } void setAllVolatile() { allVolatile = true; } }; class RValue { diff --git a/src/qml/compiler/qv4compilerscanfunctions.cpp b/src/qml/compiler/qv4compilerscanfunctions.cpp index a1ddee8234..4c8f0d0658 100644 --- a/src/qml/compiler/qv4compilerscanfunctions.cpp +++ b/src/qml/compiler/qv4compilerscanfunctions.cpp @@ -115,7 +115,7 @@ void ScanFunctions::checkDirectivePrologue(StatementList *ast) // allowed. if (strLit->literalToken.length < 2) continue; - QStringRef str = _sourceCode.midRef(strLit->literalToken.offset + 1, strLit->literalToken.length - 2); + QStringView str = QStringView{_sourceCode}.mid(strLit->literalToken.offset + 1, strLit->literalToken.length - 2); if (str == QLatin1String("use strict")) { _context->isStrict = true; } else { @@ -129,7 +129,7 @@ void ScanFunctions::checkDirectivePrologue(StatementList *ast) } } -void ScanFunctions::checkName(const QStringRef &name, const QQmlJS::SourceLocation &loc) +void ScanFunctions::checkName(QStringView name, const QQmlJS::SourceLocation &loc) { if (_context->isStrict) { if (name == QLatin1String("implements") @@ -337,7 +337,7 @@ bool ScanFunctions::visit(PatternElement *ast) for (const auto &name : qAsConst(names)) { if (_context->isStrict && (name.id == QLatin1String("eval") || name.id == QLatin1String("arguments"))) _cg->throwSyntaxError(ast->identifierToken, QStringLiteral("Variable name may not be eval or arguments in strict mode")); - checkName(QStringRef(&name.id), ast->identifierToken); + checkName(QStringView(name.id), ast->identifierToken); if (name.id == QLatin1String("arguments")) _context->usesArgumentsObject = Context::ArgumentsObjectNotUsed; if (ast->scope == VariableScope::Const && !ast->initializer && !ast->isForDeclaration && !ast->destructuringPattern()) { @@ -376,7 +376,7 @@ bool ScanFunctions::visit(ExpressionStatement *ast) return false; } else { SourceLocation firstToken = ast->firstSourceLocation(); - if (_sourceCode.midRef(firstToken.offset, firstToken.length) == QLatin1String("function")) { + if (QStringView{_sourceCode}.mid(firstToken.offset, firstToken.length) == QLatin1String("function")) { _cg->throwSyntaxError(firstToken, QStringLiteral("unexpected token")); } } diff --git a/src/qml/compiler/qv4compilerscanfunctions_p.h b/src/qml/compiler/qv4compilerscanfunctions_p.h index e39aa2454e..0336398cac 100644 --- a/src/qml/compiler/qv4compilerscanfunctions_p.h +++ b/src/qml/compiler/qv4compilerscanfunctions_p.h @@ -97,7 +97,7 @@ protected: void checkDirectivePrologue(QQmlJS::AST::StatementList *ast); - void checkName(const QStringRef &name, const QQmlJS::SourceLocation &loc); + void checkName(QStringView name, const QQmlJS::SourceLocation &loc); bool visit(QQmlJS::AST::Program *ast) override; void endVisit(QQmlJS::AST::Program *) override; -- cgit v1.2.3