Improved Qt simplification

This commit is contained in:
Daniel Marjamäki 2020-02-21 19:04:21 +01:00
parent 388b5118df
commit ec8c733afb
2 changed files with 14 additions and 5 deletions

View File

@ -10837,7 +10837,7 @@ void Tokenizer::simplifyQtSignalsSlots()
if (Token::Match(tok, "emit|Q_EMIT %name% (") &&
Token::simpleMatch(tok->linkAt(2), ") ;")) {
tok->deleteThis();
} else if (!Token::Match(tok, "class %name% :"))
} else if (!Token::Match(tok, "class %name% :|::|{"))
continue;
if (tok->previous() && tok->previous()->str() == "enum") {
@ -10859,7 +10859,9 @@ void Tokenizer::simplifyQtSignalsSlots()
break;
else
--indentlevel;
}
} else if (tok2->str() == ";" && indentlevel == 0)
break;
if (tok2->strAt(1) == "Q_OBJECT")
tok2->deleteNext();

View File

@ -375,7 +375,8 @@ private:
TEST_CASE(borland);
TEST_CASE(Qt);
TEST_CASE(simplifyQtSignalsSlots1);
TEST_CASE(simplifyQtSignalsSlots2);
TEST_CASE(simplifySQL);
@ -5802,7 +5803,7 @@ private:
}
void bitfields14() { // #4561 - crash for 'signals:'
ASSERT_EQUALS("class x { signals : } ;", tokenizeAndStringify("class x { signals: };\n",false));
ASSERT_EQUALS("class x { protected: } ;", tokenizeAndStringify("class x { signals: };\n",false));
}
void bitfields15() { // #7747 - enum Foo {A,B}:4;
@ -6018,7 +6019,7 @@ private:
tokenizeAndStringify("class Fred { __property int x = { } };", false, true, Settings::Win32A));
}
void Qt() {
void simplifyQtSignalsSlots1() {
const char code1[] = "class Counter : public QObject "
"{ "
" Q_OBJECT "
@ -6134,6 +6135,12 @@ private:
ASSERT_EQUALS(result4, tokenizeAndStringify(code4,false));
}
void simplifyQtSignalsSlots2() {
const char code1[] = "class Foo::Bar: public QObject { private slots: };";
const char result1[] = "class Foo :: Bar : public QObject { private: } ;";
ASSERT_EQUALS(result1, tokenizeAndStringify(code1,false));
}
void simplifySQL() {
// Oracle PRO*C extensions for inline SQL. Just replace the SQL with "asm()" to fix wrong error messages
// ticket: #1959