diff options
Diffstat (limited to 'sources/shiboken6/ApiExtractor/typeparser.cpp')
-rw-r--r-- | sources/shiboken6/ApiExtractor/typeparser.cpp | 88 |
1 files changed, 34 insertions, 54 deletions
diff --git a/sources/shiboken6/ApiExtractor/typeparser.cpp b/sources/shiboken6/ApiExtractor/typeparser.cpp index 38c556d41..11d7bf641 100644 --- a/sources/shiboken6/ApiExtractor/typeparser.cpp +++ b/sources/shiboken6/ApiExtractor/typeparser.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt for Python. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "typeparser.h" #include <typeinfo.h> @@ -33,6 +8,8 @@ #include <QtCore/QStack> #include <QtCore/QTextStream> +using namespace Qt::StringLiterals; + class Scanner { public: @@ -60,7 +37,7 @@ public: { } - Token nextToken(QString *errorMessage = Q_NULLPTR); + Token nextToken(QString *errorMessage = nullptr); QString identifier() const; QString msgParseError(const QString &why) const; @@ -82,7 +59,7 @@ Scanner::Token Scanner::nextToken(QString *errorMessage) Token tok = NoToken; // remove whitespace - while (m_pos < m_length && m_chars[m_pos] == QLatin1Char(' ')) + while (m_pos < m_length && m_chars[m_pos] == u' ') ++m_pos; m_tokenStart = m_pos; @@ -108,7 +85,7 @@ Scanner::Token Scanner::nextToken(QString *errorMessage) ++m_pos; break; default: - if (c.isLetterOrNumber() || c == QLatin1Char('_')) { + if (c.isLetterOrNumber() || c == u'_') { tok = Identifier; } else { QString message; @@ -131,7 +108,7 @@ Scanner::Token Scanner::nextToken(QString *errorMessage) } if (tok == Identifier) { - if (c.isLetterOrNumber() || c == QLatin1Char('_')) + if (c.isLetterOrNumber() || c == u'_') ++m_pos; else break; @@ -141,23 +118,23 @@ Scanner::Token Scanner::nextToken(QString *errorMessage) if (tok == Identifier) { switch (m_pos - m_tokenStart) { case 5: - if (m_chars[m_tokenStart] == QLatin1Char('c') - && m_chars[m_tokenStart + 1] == QLatin1Char('o') - && m_chars[m_tokenStart + 2] == QLatin1Char('n') - && m_chars[m_tokenStart + 3] == QLatin1Char('s') - && m_chars[m_tokenStart + 4] == QLatin1Char('t')) { + if (m_chars[m_tokenStart] == u'c' + && m_chars[m_tokenStart + 1] == u'o' + && m_chars[m_tokenStart + 2] == u'n' + && m_chars[m_tokenStart + 3] == u's' + && m_chars[m_tokenStart + 4] == u't') { tok = ConstToken; } break; case 8: - if (m_chars[m_tokenStart] == QLatin1Char('v') - && m_chars[m_tokenStart + 1] == QLatin1Char('o') - && m_chars[m_tokenStart + 2] == QLatin1Char('l') - && m_chars[m_tokenStart + 3] == QLatin1Char('a') - && m_chars[m_tokenStart + 4] == QLatin1Char('t') - && m_chars[m_tokenStart + 5] == QLatin1Char('i') - && m_chars[m_tokenStart + 6] == QLatin1Char('l') - && m_chars[m_tokenStart + 7] == QLatin1Char('e')) { + if (m_chars[m_tokenStart] == u'v' + && m_chars[m_tokenStart + 1] == u'o' + && m_chars[m_tokenStart + 2] == u'l' + && m_chars[m_tokenStart + 3] == u'a' + && m_chars[m_tokenStart + 4] == u't' + && m_chars[m_tokenStart + 5] == u'i' + && m_chars[m_tokenStart + 6] == u'l' + && m_chars[m_tokenStart + 7] == u'e') { tok = VolatileToken; } break; @@ -170,8 +147,8 @@ Scanner::Token Scanner::nextToken(QString *errorMessage) QString Scanner::msgParseError(const QString &why) const { - return QStringLiteral("TypeParser: Unable to parse \"") - + QString(m_chars, m_length) + QStringLiteral("\": ") + why; + return "TypeParser: Unable to parse \""_L1 + + QString(m_chars, m_length) + "\": "_L1 + why; } TypeInfo TypeParser::parse(const QString &str, QString *errorMessage) @@ -189,7 +166,7 @@ TypeInfo TypeParser::parse(const QString &str, QString *errorMessage) Scanner::Token tok = scanner.nextToken(errorMessage); while (tok != Scanner::NoToken) { if (tok == Scanner::InvalidToken) - return TypeInfo(); + return {}; // switch (tok) { // case Scanner::StarToken: printf(" - *\n"); break; @@ -222,12 +199,12 @@ TypeInfo TypeParser::parse(const QString &str, QString *errorMessage) stack.top().setReferenceType(RValueReference); break; case RValueReference: - const QString message = scanner.msgParseError(QStringLiteral("Too many '&' qualifiers")); + const QString message = scanner.msgParseError("Too many '&' qualifiers"_L1); if (errorMessage) *errorMessage = message; else qWarning().noquote().nospace() << message; - return TypeInfo(); + return {}; } break; case Scanner::LessThanToken: @@ -269,12 +246,12 @@ TypeInfo TypeParser::parse(const QString &str, QString *errorMessage) case Scanner::OpenParenToken: // function pointers not supported case Scanner::CloseParenToken: { - const QString message = scanner.msgParseError(QStringLiteral("Function pointers are not supported")); + const QString message = scanner.msgParseError("Function pointers are not supported"_L1); if (errorMessage) *errorMessage = message; else qWarning().noquote().nospace() << message; - return TypeInfo(); + return {}; } case Scanner::Identifier: @@ -285,7 +262,7 @@ TypeInfo TypeParser::parse(const QString &str, QString *errorMessage) colon_prefix = false; } else { QStringList qualifiedName = stack.top().qualifiedName(); - qualifiedName.last().append(QLatin1Char(' ') + scanner.identifier()); + qualifiedName.last().append(u' ' + scanner.identifier()); stack.top().setQualifiedName(qualifiedName); } break; @@ -304,9 +281,12 @@ TypeInfo TypeParser::parse(const QString &str, QString *errorMessage) break; } - tok = scanner.nextToken(); + tok = scanner.nextToken(errorMessage); } - Q_ASSERT(!stack.isEmpty()); + if (stack.isEmpty() || stack.constFirst().qualifiedName().isEmpty()) { + *errorMessage = u"Unable to parse type \""_s + str + u"\"."_s; + return {}; + } return stack.constFirst(); } |