diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/moc/main.cpp | 2 | ||||
| -rw-r--r-- | src/tools/moc/moc.cpp | 58 | ||||
| -rw-r--r-- | src/tools/moc/parser.h | 2 | ||||
| -rw-r--r-- | src/tools/moc/preprocessor.cpp | 15 | ||||
| -rw-r--r-- | src/tools/moc/symbols.h | 2 |
5 files changed, 41 insertions, 38 deletions
diff --git a/src/tools/moc/main.cpp b/src/tools/moc/main.cpp index 3c49128476d..77f3329ac4a 100644 --- a/src/tools/moc/main.cpp +++ b/src/tools/moc/main.cpp @@ -106,7 +106,7 @@ QByteArray composePreprocessorOutput(const Symbols &symbols) { output.chop(2); else break; - output += sym.lexem().mid(1); + output += sym.lexemView().mid(1); secondlast = last; last = PP_STRING_LITERAL; continue; diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index 64fd334d467..47c91f53b47 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -65,14 +65,14 @@ bool Moc::parseClassHead(ClassDef *def) return false; name = lexem(); } else if (test(IDENTIFIER)) { - const QByteArray lex = lexem(); + const QByteArrayView lex = lexemView(); if (lex != "final" && lex != "sealed" && lex != "Q_DECL_FINAL") - name = lex; + name = lexem(); } def->qualified += name; while (test(SCOPE)) { - def->qualified += lexem(); + def->qualified += lexemView(); if (test(IDENTIFIER)) { name = lexem(); def->qualified += name; @@ -82,7 +82,7 @@ bool Moc::parseClassHead(ClassDef *def) def->lineNumber = symbol().lineNum; if (test(IDENTIFIER)) { - const QByteArray lex = lexem(); + const QByteArrayView lex = lexemView(); if (lex != "final" && lex != "sealed" && lex != "Q_DECL_FINAL") return false; } @@ -138,7 +138,7 @@ Type Moc::parseType() Q_FALLTHROUGH(); case CONST: case VOLATILE: - type.name += lexem(); + type.name += lexemView(); type.name += ' '; if (lookup(0) == VOLATILE) type.isVolatile = true; @@ -150,7 +150,7 @@ Type Moc::parseType() case Q_SLOTS_TOKEN: case Q_SIGNAL_TOKEN: case Q_SLOT_TOKEN: - type.name += lexem(); + type.name += lexemView(); return type; case NOTOKEN: return type; @@ -182,7 +182,7 @@ Type Moc::parseType() case SHORT: case INT: case LONG: - type.name += lexem(); + type.name += lexemView(); // preserve '[unsigned] long long', 'short int', 'long int', 'long double' if (test(LONG) || test(INT) || test(DOUBLE)) { type.name += ' '; @@ -195,7 +195,7 @@ Type Moc::parseType() case VOID: case BOOL: case AUTO: - type.name += lexem(); + type.name += lexemView(); isVoid |= (lookup(0) == VOID); break; case NOTOKEN: @@ -212,7 +212,7 @@ Type Moc::parseType() type.name += lexemUntil(RANGLE); } if (test(SCOPE)) { - type.name += lexem(); + type.name += lexemView(); type.isScoped = true; } else { break; @@ -221,7 +221,7 @@ Type Moc::parseType() while (test(CONST) || test(VOLATILE) || test(SIGNED) || test(UNSIGNED) || test(STAR) || test(AND) || test(ANDAND)) { type.name += ' '; - type.name += lexem(); + type.name += lexemView(); if (lookup(0) == AND) type.referenceType = Type::Reference; else if (lookup(0) == ANDAND) @@ -318,7 +318,7 @@ void Moc::parseFunctionArguments(FunctionDef *def) } if (test(CONST) || test(VOLATILE)) { arg.rightType += ' '; - arg.rightType += lexem(); + arg.rightType += lexemView(); } arg.normalizedType = normalizeType(QByteArray(arg.type.name + ' ' + arg.rightType)); if (test(EQ)) @@ -993,7 +993,7 @@ void Moc::parse() break; case IDENTIFIER: { - const QByteArray lex = lexem(); + const QByteArrayView lex = lexemView(); if (lex.startsWith("QML_")) { if ( lex == "QML_ELEMENT" || lex == "QML_NAMED_ELEMENT" || lex == "QML_ANONYMOUS" || lex == "QML_VALUE_TYPE") { @@ -1417,7 +1417,7 @@ void Moc::parsePropertyAttributes(PropertyDef &propDef) while (test(IDENTIFIER)) { const Symbol &lsym = symbol(); - const QByteArray l = lsym.lexem(); + const QByteArrayView l = lsym.lexemView(); if (l[0] == 'C' && l == "CONSTANT") { propDef.constant = true; continue; @@ -1565,7 +1565,7 @@ void Moc::parsePluginData(ClassDef *def) def->pluginData.uri = unquotedLexem(); } else if (l == "FILE") { next(STRING_LITERAL); - QByteArray metaDataFile = unquotedLexem(); + QByteArrayView metaDataFile = unquotedLexemView(); QFileInfo fi(QFileInfo(QString::fromLocal8Bit(currentFilenames.top())).dir(), QString::fromLocal8Bit(metaDataFile)); for (const IncludePath &p : std::as_const(includes)) { @@ -1574,7 +1574,7 @@ void Moc::parsePluginData(ClassDef *def) if (p.isFrameworkPath) continue; - fi.setFile(QString::fromLocal8Bit(p.path.constData()), QString::fromLocal8Bit(metaDataFile.constData())); + fi.setFile(QString::fromLocal8Bit(p.path), QString::fromLocal8Bit(metaDataFile)); // try again, maybe there's a file later in the include paths with the same name if (fi.isDir()) { fi = QFileInfo(); @@ -1582,14 +1582,14 @@ void Moc::parsePluginData(ClassDef *def) } } if (!fi.exists()) { - const QByteArray msg = "Plugin Metadata file " + lexem() + const QByteArray msg = "Plugin Metadata file " + lexemView() + " does not exist. Declaration will be ignored"; error(msg.constData()); return; } QFile file(fi.canonicalFilePath()); if (!file.open(QFile::ReadOnly)) { - QByteArray msg = "Plugin Metadata file " + lexem() + " could not be opened: " + QByteArray msg = "Plugin Metadata file " + lexemView() + " could not be opened: " + file.errorString().toUtf8(); error(msg.constData()); return; @@ -1602,7 +1602,7 @@ void Moc::parsePluginData(ClassDef *def) if (!metaData.isEmpty()) { def->pluginData.metaData = QJsonDocument::fromJson(metaData); if (!def->pluginData.metaData.isObject()) { - const QByteArray msg = "Plugin Metadata file " + lexem() + const QByteArray msg = "Plugin Metadata file " + lexemView() + " does not contain a valid JSON object. Declaration will be ignored"; warning(msg.constData()); def->pluginData.iid = QByteArray(); @@ -1628,7 +1628,7 @@ QByteArray Moc::parsePropertyAccessor() ++nesting; if (t == RPAREN) --nesting; - accessor += lexem(); + accessor += lexemView(); } return accessor; } @@ -1654,7 +1654,7 @@ void Moc::parseEnumOrFlag(BaseDef *def, EnumFlags flags) identifier = lexem(); while (test(SCOPE) && test(IDENTIFIER)) { identifier += "::"; - identifier += lexem(); + identifier += lexemView(); } def->enumDeclarations[identifier] = flags; } @@ -1669,7 +1669,7 @@ void Moc::parseFlag(BaseDef *def) flagName = lexem(); while (test(SCOPE) && test(IDENTIFIER)) { flagName += "::"; - flagName += lexem(); + flagName += lexemView(); } } next(COMMA); @@ -1677,7 +1677,7 @@ void Moc::parseFlag(BaseDef *def) enumName = lexem(); while (test(SCOPE) && test(IDENTIFIER)) { enumName += "::"; - enumName += lexem(); + enumName += lexemView(); } } @@ -1725,17 +1725,17 @@ void Moc::parseInterfaces(ClassDef *def) QList<ClassDef::Interface> iface; iface += ClassDef::Interface(lexem()); while (test(SCOPE)) { - iface.last().className += lexem(); + iface.last().className += lexemView(); next(IDENTIFIER); - iface.last().className += lexem(); + iface.last().className += lexemView(); } while (test(COLON)) { next(IDENTIFIER); iface += ClassDef::Interface(lexem()); while (test(SCOPE)) { - iface.last().className += lexem(); + iface.last().className += lexemView(); next(IDENTIFIER); - iface.last().className += lexem(); + iface.last().className += lexemView(); } } // resolve from classnames to interface ids @@ -1756,11 +1756,11 @@ void Moc::parseDeclareInterface() next(LPAREN); QByteArray interface; next(IDENTIFIER); - interface += lexem(); + interface += lexemView(); while (test(SCOPE)) { - interface += lexem(); + interface += lexemView(); next(IDENTIFIER); - interface += lexem(); + interface += lexemView(); } next(COMMA); QByteArray iid; diff --git a/src/tools/moc/parser.h b/src/tools/moc/parser.h index 56e95a3f08c..cbc35284423 100644 --- a/src/tools/moc/parser.h +++ b/src/tools/moc/parser.h @@ -44,6 +44,8 @@ public: inline Token token() { return symbols.at(index-1).token;} inline QByteArray lexem() { return symbols.at(index-1).lexem();} inline QByteArray unquotedLexem() { return symbols.at(index-1).unquotedLexem();} + inline QByteArrayView lexemView() { return symbols.at(index-1).lexemView();} + inline QByteArrayView unquotedLexemView() { return symbols.at(index-1).unquotedLexemView();} inline const Symbol &symbol() { return symbols.at(index-1);} inline const Symbol &symbolAt(qsizetype idx) { return symbols.at(idx); } diff --git a/src/tools/moc/preprocessor.cpp b/src/tools/moc/preprocessor.cpp index fd2d196a7a5..77c2c66ecdd 100644 --- a/src/tools/moc/preprocessor.cpp +++ b/src/tools/moc/preprocessor.cpp @@ -190,7 +190,7 @@ Symbols Preprocessor::tokenize(const QByteArray& input, int lineNum, Preprocesso const QByteArray newString = '\"' - + symbols.constLast().unquotedLexem() + + symbols.constLast().unquotedLexemView() + input.mid(lexem - begin + 1, data - lexem - 2) + '\"'; symbols.last() = Symbol(symbols.constLast().lineNum, @@ -650,7 +650,7 @@ Symbols Preprocessor::macroExpandIdentifier(Preprocessor *that, SymbolStack &sym const Symbols &arg = arguments.at(index); QByteArray stringified; for (const Symbol &sym : arg) - stringified += sym.lexem(); + stringified += sym.lexemView(); stringified.replace('"', "\\\""); stringified.prepend('"'); @@ -967,9 +967,8 @@ int PP_Expression::primary_expression() test(PP_RPAREN); } else { next(); - const QByteArray &lex = lexem(); - auto lexView = QByteArrayView(lex); - if (lex.endsWith('L')) + auto lexView = lexemView(); + if (lexView.endsWith('L')) lexView.chop(1); value = lexView.toInt(nullptr, 0); } @@ -1120,7 +1119,7 @@ void Preprocessor::preprocess(const QByteArray &filename, Symbols &preprocessed) QByteArray include; bool local = false; if (test(PP_STRING_LITERAL)) { - local = lexem().startsWith('\"'); + local = lexemView().startsWith('\"'); include = unquotedLexem(); } else continue; @@ -1322,7 +1321,7 @@ void Preprocessor::parseDefineArguments(Macro *m) if (t == PP_RPAREN) break; if (t != PP_IDENTIFIER) { - QByteArray l = lexem(); + QByteArrayView l = lexemView(); if (l == "...") { m->isVariadic = true; arguments += Symbol(symbol().lineNum, PP_IDENTIFIER, "__VA_ARGS__"); @@ -1346,7 +1345,7 @@ void Preprocessor::parseDefineArguments(Macro *m) break; if (t == PP_COMMA) continue; - if (lexem() == "...") { + if (lexemView() == "...") { //GCC extension: #define FOO(x, y...) x(y) // The last argument was already parsed. Just mark the macro as variadic. m->isVariadic = true; diff --git a/src/tools/moc/symbols.h b/src/tools/moc/symbols.h index 9c7b9e26d9e..f83e37de677 100644 --- a/src/tools/moc/symbols.h +++ b/src/tools/moc/symbols.h @@ -58,6 +58,8 @@ struct Symbol Token token = NOTOKEN; inline QByteArray lexem() const { return lex.mid(from, len); } inline QByteArray unquotedLexem() const { return lex.mid(from+1, len-2); } + inline QByteArrayView lexemView() const { return QByteArrayView{lex}.mid(from, len); } + inline QByteArrayView unquotedLexemView() const { return QByteArrayView{lex}.mid(from+1, len-2); } inline operator SubArray() const { return SubArray(lex, from, len); } bool operator==(const Symbol& o) const { |
