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>
bb10
Ahmad Samir 2023-05-18 23:11:31 +03:00
parent 39882a1354
commit a993510c9e
3 changed files with 11 additions and 7 deletions

View File

@ -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;

View File

@ -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) {

View File

@ -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);