diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2023-05-18 23:11:31 +0300 |
---|---|---|
committer | Ahmad Samir <a.samirh78@gmail.com> | 2023-06-22 02:20:29 +0300 |
commit | a993510c9eb2da86a24a0c42ce13fbe3a9fa062b (patch) | |
tree | 40c34721b0db1e77fd3969a9e6376808a4bab731 /src/tools/moc | |
parent | 39882a1354cb06d2b0b0a0d5b41a168041df0476 (diff) |
Moc: simplify showing a warning
Instead of changing the "index" member then restoring it, add a
symbolAt() method to get the Symbol in question, and pass it to
new warning() overload.
Change-Id: Ie84a6cf4d837f4ed694f617100e9556c2fc2eea3
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/tools/moc')
-rw-r--r-- | src/tools/moc/moc.cpp | 7 | ||||
-rw-r--r-- | src/tools/moc/parser.cpp | 9 | ||||
-rw-r--r-- | src/tools/moc/parser.h | 2 |
3 files changed, 11 insertions, 7 deletions
diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index e067158784..b6671f6e12 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -1931,13 +1931,10 @@ void Moc::checkProperties(ClassDef *cdef) } if (p.read.isEmpty() && p.member.isEmpty() && p.bind.isEmpty()) { - const qsizetype rewind = index; - if (p.location >= 0) - index = p.location; QByteArray msg = "Property declaration " + p.name + " has neither an associated QProperty<> member" ", nor a READ accessor function nor an associated MEMBER variable. The property will be invalid."; - warning(msg.constData()); - index = rewind; + const auto &sym = p.location >= 0 ? symbolAt(p.location) : Symbol(); + warning(sym, msg.constData()); if (p.write.isEmpty()) { cdef->propertyList.removeAt(i); --i; diff --git a/src/tools/moc/parser.cpp b/src/tools/moc/parser.cpp index f1493518f8..ab3131f732 100644 --- a/src/tools/moc/parser.cpp +++ b/src/tools/moc/parser.cpp @@ -73,9 +73,14 @@ void Parser::error(const char *msg) exit(EXIT_FAILURE); } +void Parser::warning(const Symbol &sym, QByteArrayView msg) +{ + if (displayWarnings) + printMsg("warning: %s\n", msg, sym); +} + void Parser::warning(const char *msg) { - if (displayWarnings && msg) - printMsg("warning: %s\n", msg, index > 0 ? symbol() : Symbol{}); + warning(index > 0 ? symbol() : Symbol{}, msg); } void Parser::note(const char *msg) { diff --git a/src/tools/moc/parser.h b/src/tools/moc/parser.h index 7b5c604a71..6fe982a1ce 100644 --- a/src/tools/moc/parser.h +++ b/src/tools/moc/parser.h @@ -44,10 +44,12 @@ public: inline QByteArray lexem() { return symbols.at(index-1).lexem();} inline QByteArray unquotedLexem() { return symbols.at(index-1).unquotedLexem();} inline const Symbol &symbol() { return symbols.at(index-1);} + inline const Symbol &symbolAt(qsizetype idx) { return symbols.at(idx); } Q_NORETURN void error(const Symbol &symbol); Q_NORETURN void error(const char *msg = nullptr); void warning(const char * = nullptr); + void warning(const Symbol &sym, QByteArrayView msg); void note(const char * = nullptr); void defaultErrorMsg(const Symbol &sym); void printMsg(QByteArrayView formatStringSuffix, QByteArrayView msg, const Symbol &sym); |