Remove simplifyQtSignalsSlots(), update qt.cfg (#4807)

This commit is contained in:
chrchr-github 2023-02-25 15:58:57 +01:00 committed by GitHub
parent 29b651f264
commit a0cc35e3fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 74 additions and 215 deletions

View File

@ -5165,6 +5165,7 @@
<define name="Q_NULLPTR" value="NULL"/>
<define name="Q_OBJECT" value=""/>
<define name="Q_PRIVATE_SLOT(d, signature)" value=""/>
<define name="Q_SLOTS" value=""/>
<define name="Q_PROPERTY(X)" value=""/>
<define name="Q_Q(Class)" value="Class * const q = q_func()"/>
<define name="Q_RETURN_ARG(type, data)" value="QReturnArgument&lt;type &gt;(#type, data)"/>
@ -5197,7 +5198,10 @@
<define name="Q_FOREACH(A,B)" value="for(A:B)"/>
<define name="foreach(A,B)" value="for(A:B)"/>
<define name="forever" value="for (;;)"/>
<define name="emit(X)" value="(X)"/>
<define name="emit" value=""/>
<define name="slots" value=""/>
<define name="signals" value="protected"/>
<define name="Q_SIGNALS" value="protected"/>
<define name="Q_OVERRIDE(x)" value=""/>
<define name="Q_PLUGIN_METADATA(x)" value=""/>
<define name="Q_ASSERT(condition)" value="assert(condition)"/>

View File

@ -4987,9 +4987,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
if (Settings::terminated())
return false;
// Remove Qt signals and slots
simplifyQtSignalsSlots();
// remove Borland stuff..
simplifyBorland();
@ -9136,65 +9133,6 @@ void Tokenizer::simplifyBorland()
}
}
// Remove Qt signals and slots
void Tokenizer::simplifyQtSignalsSlots()
{
if (isC())
return;
if (std::none_of(mSettings->libraries.cbegin(), mSettings->libraries.cend(), [](const std::string& lib) {
return lib == "qt";
}))
return;
for (Token *tok = list.front(); tok; tok = tok->next()) {
// check for emit which can be outside of class
if (Token::Match(tok, "emit|Q_EMIT %name% (") &&
Token::simpleMatch(tok->linkAt(2), ") ;")) {
tok->deleteThis();
} else if (!Token::Match(tok, "class %name% :|::|{"))
continue;
if (tok->previous() && tok->previous()->str() == "enum") {
tok = tok->tokAt(2);
continue;
}
// count { and } for tok2
int indentlevel = 0;
for (Token *tok2 = tok; tok2; tok2 = tok2->next()) {
if (tok2->str() == "{") {
++indentlevel;
if (indentlevel == 1)
tok = tok2;
else
tok2 = tok2->link();
} else if (tok2->str() == "}") {
if (indentlevel<2)
break;
else
--indentlevel;
} else if (tok2->str() == ";" && indentlevel == 0)
break;
if (tok2->strAt(1) == "Q_OBJECT")
tok2->deleteNext();
if (Token::Match(tok2->next(), "public|protected|private slots|Q_SLOTS :")) {
tok2 = tok2->next();
tok2->str(tok2->str() + ":");
tok2->deleteNext(2);
tok2 = tok2->previous();
} else if (Token::Match(tok2->next(), "signals|Q_SIGNALS :")) {
tok2 = tok2->next();
tok2->str("protected:");
tok2->deleteNext();
} else if (Token::Match(tok2->next(), "emit|Q_EMIT %name% (") &&
Token::simpleMatch(tok2->linkAt(3), ") ;")) {
tok2->deleteNext();
}
}
}
}
void Tokenizer::createSymbolDatabase()
{
if (!mSymbolDatabase)

View File

@ -536,11 +536,6 @@ private:
*/
void simplifyBorland();
/**
* Remove Qt signals and slots
*/
void simplifyQtSignalsSlots();
/**
* Collapse operator name tokens into single token
* operator = => operator=

View File

@ -494,4 +494,73 @@ namespace {
}
void slot() {};
};
// findFunction11
class Fred : public QObject {
Q_OBJECT
private slots:
void foo();
};
void Fred::foo() { }
// bitfields14
class X {
signals:
};
// simplifyQtSignalsSlots1
class Counter1 : public QObject {
Q_OBJECT
public:
Counter1() { m_value = 0; }
int value() const { return m_value; }
public slots:
void setValue(int value);
signals:
void valueChanged(int newValue);
private:
int m_value;
};
void Counter1::setValue(int value) {
if (value != m_value) {
m_value = value;
emit valueChanged(value);
}
}
class Counter2 : public QObject {
Q_OBJECT
public:
Counter2() { m_value = 0; }
int value() const { return m_value; }
public Q_SLOTS:
void setValue(int value);
Q_SIGNALS:
void valueChanged(int newValue);
private:
int m_value;
};
void Counter2::setValue(int value) {
if (value != m_value) {
m_value = value;
emit valueChanged(value);
}
}
class MyObject1 : public QObject {
MyObject1() {}
~MyObject1() {}
public slots:
signals:
void test() {}
};
class MyObject2 : public QObject {
Q_OBJECT
public slots:
};
// simplifyQtSignalsSlots2
namespace Foo { class Bar; }
class Foo::Bar : public QObject { private slots: };
}

View File

@ -407,7 +407,6 @@ private:
TEST_CASE(findFunction8);
TEST_CASE(findFunction9);
TEST_CASE(findFunction10); // #7673
TEST_CASE(findFunction11);
TEST_CASE(findFunction12);
TEST_CASE(findFunction13);
TEST_CASE(findFunction14);
@ -6074,21 +6073,6 @@ private:
ASSERT_EQUALS(true, db && f && f->function() && f->function()->tokenDef->linenr() == 2);
}
void findFunction11() {
settings1.libraries.emplace_back("qt");
GET_SYMBOL_DB("class Fred : public QObject {\n"
" Q_OBJECT\n"
"private slots:\n"
" void foo();\n"
"};\n"
"void Fred::foo() { }");
settings1.libraries.pop_back();
ASSERT_EQUALS("", errout.str());
const Token *f = Token::findsimplematch(tokenizer.tokens(), "foo ( ) {");
ASSERT_EQUALS(true, db && f && f->function() && f->function()->tokenDef->linenr() == 4);
}
void findFunction12() {
GET_SYMBOL_DB("void foo(std::string a) { }\n"
"void foo(long long a) { }\n"

View File

@ -304,7 +304,6 @@ private:
TEST_CASE(bitfields10);
TEST_CASE(bitfields12); // ticket #3485 (segmentation fault)
TEST_CASE(bitfields13); // ticket #3502 (segmentation fault)
TEST_CASE(bitfields14); // ticket #4561 (segfault for 'class a { signals: };')
TEST_CASE(bitfields15); // ticket #7747 (enum Foo {A,B}:4;)
TEST_CASE(bitfields16); // Save bitfield bit count
@ -314,10 +313,6 @@ private:
TEST_CASE(microsoftString);
TEST_CASE(borland);
TEST_CASE(simplifyQtSignalsSlots1);
TEST_CASE(simplifyQtSignalsSlots2);
TEST_CASE(simplifySQL);
TEST_CASE(simplifyCAlternativeTokens);
@ -4475,10 +4470,6 @@ private:
ASSERT_EQUALS("x y ;", tokenizeAndStringify("struct{x y:};\n"));
}
void bitfields14() { // #4561 - crash for 'signals:'
ASSERT_EQUALS("class x { protected: } ;", tokenizeAndStringify("class x { signals: };\n"));
}
void bitfields15() { // #7747 - enum Foo {A,B}:4;
ASSERT_EQUALS("struct AB {\n"
"enum Foo { A , B } ; enum Foo Anonymous ;\n"
@ -4698,128 +4689,6 @@ private:
tokenizeAndStringify("class Fred { __property int x = { } };", true, Settings::Win32A));
}
void simplifyQtSignalsSlots1() {
const char code1[] = "class Counter : public QObject "
"{ "
" Q_OBJECT "
"public: "
" Counter() { m_value = 0; } "
" int value() const { return m_value; } "
"public slots: "
" void setValue(int value); "
"signals: "
" void valueChanged(int newValue); "
"private: "
" int m_value; "
"}; "
"void Counter::setValue(int value) "
"{ "
" if (value != m_value) { "
" m_value = value; "
" emit valueChanged(value); "
" } "
"}";
const char result1[] = "class Counter : public QObject "
"{ "
"public: "
"Counter ( ) { m_value = 0 ; } "
"int value ( ) const { return m_value ; } "
"public: "
"void setValue ( int value ) ; "
"protected: "
"void valueChanged ( int newValue ) ; "
"private: "
"int m_value ; "
"} ; "
"void Counter :: setValue ( int value ) "
"{ "
"if ( value != m_value ) { "
"m_value = value ; "
"valueChanged ( value ) ; "
"} "
"}";
ASSERT_EQUALS(result1, tokenizeAndStringify(code1));
const char code2[] = "class Counter : public QObject "
"{ "
" Q_OBJECT "
"public: "
" Counter() { m_value = 0; } "
" int value() const { return m_value; } "
"public Q_SLOTS: "
" void setValue(int value); "
"Q_SIGNALS: "
" void valueChanged(int newValue); "
"private: "
" int m_value; "
"};"
"void Counter::setValue(int value) "
"{ "
" if (value != m_value) { "
" m_value = value; "
" emit valueChanged(value); "
" } "
"}";
const char result2[] = "class Counter : public QObject "
"{ "
"public: "
"Counter ( ) { m_value = 0 ; } "
"int value ( ) const { return m_value ; } "
"public: "
"void setValue ( int value ) ; "
"protected: "
"void valueChanged ( int newValue ) ; "
"private: "
"int m_value ; "
"} ; "
"void Counter :: setValue ( int value ) "
"{ "
"if ( value != m_value ) { "
"m_value = value ; "
"valueChanged ( value ) ; "
"} "
"}";
ASSERT_EQUALS(result2, tokenizeAndStringify(code2));
const char code3[] = "class MyObject : public QObject {"
" MyObject() {}"
" ~MyObject() {}"
" public slots:"
" signals:"
" void test() {}"
"};";
const char result3[] = "class MyObject : public QObject { "
"MyObject ( ) { } "
"~ MyObject ( ) { } "
"public: "
"protected: "
"void test ( ) { } "
"} ;";
ASSERT_EQUALS(result3, tokenizeAndStringify(code3));
ASSERT_EQUALS("", errout.str());
const char code4[] = "class MyObject : public QObject {"
" Q_OBJECT "
"public slots:"
"};";
const char result4[] = "class MyObject : public QObject { "
"public: "
"} ;";
ASSERT_EQUALS(result4, tokenizeAndStringify(code4));
}
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));
}
void simplifySQL() {
// Oracle PRO*C extensions for inline SQL. Just replace the SQL with "asm()" to fix wrong error messages
// ticket: #1959