Skip to content

Commit a0cc35e

Browse files
Remove simplifyQtSignalsSlots(), update qt.cfg (#4807)
1 parent 29b651f commit a0cc35e

6 files changed

Lines changed: 74 additions & 215 deletions

File tree

cfg/qt.cfg

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5165,6 +5165,7 @@
51655165
<define name="Q_NULLPTR" value="NULL"/>
51665166
<define name="Q_OBJECT" value=""/>
51675167
<define name="Q_PRIVATE_SLOT(d, signature)" value=""/>
5168+
<define name="Q_SLOTS" value=""/>
51685169
<define name="Q_PROPERTY(X)" value=""/>
51695170
<define name="Q_Q(Class)" value="Class * const q = q_func()"/>
51705171
<define name="Q_RETURN_ARG(type, data)" value="QReturnArgument&lt;type &gt;(#type, data)"/>
@@ -5197,7 +5198,10 @@
51975198
<define name="Q_FOREACH(A,B)" value="for(A:B)"/>
51985199
<define name="foreach(A,B)" value="for(A:B)"/>
51995200
<define name="forever" value="for (;;)"/>
5200-
<define name="emit(X)" value="(X)"/>
5201+
<define name="emit" value=""/>
5202+
<define name="slots" value=""/>
5203+
<define name="signals" value="protected"/>
5204+
<define name="Q_SIGNALS" value="protected"/>
52015205
<define name="Q_OVERRIDE(x)" value=""/>
52025206
<define name="Q_PLUGIN_METADATA(x)" value=""/>
52035207
<define name="Q_ASSERT(condition)" value="assert(condition)"/>

lib/tokenize.cpp

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4987,9 +4987,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
49874987
if (Settings::terminated())
49884988
return false;
49894989

4990-
// Remove Qt signals and slots
4991-
simplifyQtSignalsSlots();
4992-
49934990
// remove Borland stuff..
49944991
simplifyBorland();
49954992

@@ -9136,65 +9133,6 @@ void Tokenizer::simplifyBorland()
91369133
}
91379134
}
91389135

9139-
// Remove Qt signals and slots
9140-
void Tokenizer::simplifyQtSignalsSlots()
9141-
{
9142-
if (isC())
9143-
return;
9144-
if (std::none_of(mSettings->libraries.cbegin(), mSettings->libraries.cend(), [](const std::string& lib) {
9145-
return lib == "qt";
9146-
}))
9147-
return;
9148-
for (Token *tok = list.front(); tok; tok = tok->next()) {
9149-
// check for emit which can be outside of class
9150-
if (Token::Match(tok, "emit|Q_EMIT %name% (") &&
9151-
Token::simpleMatch(tok->linkAt(2), ") ;")) {
9152-
tok->deleteThis();
9153-
} else if (!Token::Match(tok, "class %name% :|::|{"))
9154-
continue;
9155-
9156-
if (tok->previous() && tok->previous()->str() == "enum") {
9157-
tok = tok->tokAt(2);
9158-
continue;
9159-
}
9160-
9161-
// count { and } for tok2
9162-
int indentlevel = 0;
9163-
for (Token *tok2 = tok; tok2; tok2 = tok2->next()) {
9164-
if (tok2->str() == "{") {
9165-
++indentlevel;
9166-
if (indentlevel == 1)
9167-
tok = tok2;
9168-
else
9169-
tok2 = tok2->link();
9170-
} else if (tok2->str() == "}") {
9171-
if (indentlevel<2)
9172-
break;
9173-
else
9174-
--indentlevel;
9175-
} else if (tok2->str() == ";" && indentlevel == 0)
9176-
break;
9177-
9178-
if (tok2->strAt(1) == "Q_OBJECT")
9179-
tok2->deleteNext();
9180-
9181-
if (Token::Match(tok2->next(), "public|protected|private slots|Q_SLOTS :")) {
9182-
tok2 = tok2->next();
9183-
tok2->str(tok2->str() + ":");
9184-
tok2->deleteNext(2);
9185-
tok2 = tok2->previous();
9186-
} else if (Token::Match(tok2->next(), "signals|Q_SIGNALS :")) {
9187-
tok2 = tok2->next();
9188-
tok2->str("protected:");
9189-
tok2->deleteNext();
9190-
} else if (Token::Match(tok2->next(), "emit|Q_EMIT %name% (") &&
9191-
Token::simpleMatch(tok2->linkAt(3), ") ;")) {
9192-
tok2->deleteNext();
9193-
}
9194-
}
9195-
}
9196-
}
9197-
91989136
void Tokenizer::createSymbolDatabase()
91999137
{
92009138
if (!mSymbolDatabase)

lib/tokenize.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,6 @@ class CPPCHECKLIB Tokenizer {
536536
*/
537537
void simplifyBorland();
538538

539-
/**
540-
* Remove Qt signals and slots
541-
*/
542-
void simplifyQtSignalsSlots();
543-
544539
/**
545540
* Collapse operator name tokens into single token
546541
* operator = => operator=

test/cfg/qt.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,4 +494,73 @@ namespace {
494494
}
495495
void slot() {};
496496
};
497+
498+
// findFunction11
499+
class Fred : public QObject {
500+
Q_OBJECT
501+
private slots:
502+
void foo();
503+
};
504+
void Fred::foo() { }
505+
506+
// bitfields14
507+
class X {
508+
signals:
509+
};
510+
511+
// simplifyQtSignalsSlots1
512+
class Counter1 : public QObject {
513+
Q_OBJECT
514+
public:
515+
Counter1() { m_value = 0; }
516+
int value() const { return m_value; }
517+
public slots:
518+
void setValue(int value);
519+
signals:
520+
void valueChanged(int newValue);
521+
private:
522+
int m_value;
523+
};
524+
void Counter1::setValue(int value) {
525+
if (value != m_value) {
526+
m_value = value;
527+
emit valueChanged(value);
528+
}
529+
}
530+
531+
class Counter2 : public QObject {
532+
Q_OBJECT
533+
public:
534+
Counter2() { m_value = 0; }
535+
int value() const { return m_value; }
536+
public Q_SLOTS:
537+
void setValue(int value);
538+
Q_SIGNALS:
539+
void valueChanged(int newValue);
540+
private:
541+
int m_value;
542+
};
543+
void Counter2::setValue(int value) {
544+
if (value != m_value) {
545+
m_value = value;
546+
emit valueChanged(value);
547+
}
548+
}
549+
550+
class MyObject1 : public QObject {
551+
MyObject1() {}
552+
~MyObject1() {}
553+
public slots:
554+
signals:
555+
void test() {}
556+
};
557+
558+
class MyObject2 : public QObject {
559+
Q_OBJECT
560+
public slots:
561+
};
562+
563+
// simplifyQtSignalsSlots2
564+
namespace Foo { class Bar; }
565+
class Foo::Bar : public QObject { private slots: };
497566
}

test/testsymboldatabase.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,6 @@ class TestSymbolDatabase : public TestFixture {
407407
TEST_CASE(findFunction8);
408408
TEST_CASE(findFunction9);
409409
TEST_CASE(findFunction10); // #7673
410-
TEST_CASE(findFunction11);
411410
TEST_CASE(findFunction12);
412411
TEST_CASE(findFunction13);
413412
TEST_CASE(findFunction14);
@@ -6074,21 +6073,6 @@ class TestSymbolDatabase : public TestFixture {
60746073
ASSERT_EQUALS(true, db && f && f->function() && f->function()->tokenDef->linenr() == 2);
60756074
}
60766075

6077-
void findFunction11() {
6078-
settings1.libraries.emplace_back("qt");
6079-
GET_SYMBOL_DB("class Fred : public QObject {\n"
6080-
" Q_OBJECT\n"
6081-
"private slots:\n"
6082-
" void foo();\n"
6083-
"};\n"
6084-
"void Fred::foo() { }");
6085-
settings1.libraries.pop_back();
6086-
ASSERT_EQUALS("", errout.str());
6087-
6088-
const Token *f = Token::findsimplematch(tokenizer.tokens(), "foo ( ) {");
6089-
ASSERT_EQUALS(true, db && f && f->function() && f->function()->tokenDef->linenr() == 4);
6090-
}
6091-
60926076
void findFunction12() {
60936077
GET_SYMBOL_DB("void foo(std::string a) { }\n"
60946078
"void foo(long long a) { }\n"

test/testtokenize.cpp

Lines changed: 0 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ class TestTokenizer : public TestFixture {
304304
TEST_CASE(bitfields10);
305305
TEST_CASE(bitfields12); // ticket #3485 (segmentation fault)
306306
TEST_CASE(bitfields13); // ticket #3502 (segmentation fault)
307-
TEST_CASE(bitfields14); // ticket #4561 (segfault for 'class a { signals: };')
308307
TEST_CASE(bitfields15); // ticket #7747 (enum Foo {A,B}:4;)
309308
TEST_CASE(bitfields16); // Save bitfield bit count
310309

@@ -314,10 +313,6 @@ class TestTokenizer : public TestFixture {
314313
TEST_CASE(microsoftString);
315314

316315
TEST_CASE(borland);
317-
318-
TEST_CASE(simplifyQtSignalsSlots1);
319-
TEST_CASE(simplifyQtSignalsSlots2);
320-
321316
TEST_CASE(simplifySQL);
322317

323318
TEST_CASE(simplifyCAlternativeTokens);
@@ -4475,10 +4470,6 @@ class TestTokenizer : public TestFixture {
44754470
ASSERT_EQUALS("x y ;", tokenizeAndStringify("struct{x y:};\n"));
44764471
}
44774472

4478-
void bitfields14() { // #4561 - crash for 'signals:'
4479-
ASSERT_EQUALS("class x { protected: } ;", tokenizeAndStringify("class x { signals: };\n"));
4480-
}
4481-
44824473
void bitfields15() { // #7747 - enum Foo {A,B}:4;
44834474
ASSERT_EQUALS("struct AB {\n"
44844475
"enum Foo { A , B } ; enum Foo Anonymous ;\n"
@@ -4698,128 +4689,6 @@ class TestTokenizer : public TestFixture {
46984689
tokenizeAndStringify("class Fred { __property int x = { } };", true, Settings::Win32A));
46994690
}
47004691

4701-
void simplifyQtSignalsSlots1() {
4702-
const char code1[] = "class Counter : public QObject "
4703-
"{ "
4704-
" Q_OBJECT "
4705-
"public: "
4706-
" Counter() { m_value = 0; } "
4707-
" int value() const { return m_value; } "
4708-
"public slots: "
4709-
" void setValue(int value); "
4710-
"signals: "
4711-
" void valueChanged(int newValue); "
4712-
"private: "
4713-
" int m_value; "
4714-
"}; "
4715-
"void Counter::setValue(int value) "
4716-
"{ "
4717-
" if (value != m_value) { "
4718-
" m_value = value; "
4719-
" emit valueChanged(value); "
4720-
" } "
4721-
"}";
4722-
4723-
const char result1[] = "class Counter : public QObject "
4724-
"{ "
4725-
"public: "
4726-
"Counter ( ) { m_value = 0 ; } "
4727-
"int value ( ) const { return m_value ; } "
4728-
"public: "
4729-
"void setValue ( int value ) ; "
4730-
"protected: "
4731-
"void valueChanged ( int newValue ) ; "
4732-
"private: "
4733-
"int m_value ; "
4734-
"} ; "
4735-
"void Counter :: setValue ( int value ) "
4736-
"{ "
4737-
"if ( value != m_value ) { "
4738-
"m_value = value ; "
4739-
"valueChanged ( value ) ; "
4740-
"} "
4741-
"}";
4742-
4743-
ASSERT_EQUALS(result1, tokenizeAndStringify(code1));
4744-
4745-
const char code2[] = "class Counter : public QObject "
4746-
"{ "
4747-
" Q_OBJECT "
4748-
"public: "
4749-
" Counter() { m_value = 0; } "
4750-
" int value() const { return m_value; } "
4751-
"public Q_SLOTS: "
4752-
" void setValue(int value); "
4753-
"Q_SIGNALS: "
4754-
" void valueChanged(int newValue); "
4755-
"private: "
4756-
" int m_value; "
4757-
"};"
4758-
"void Counter::setValue(int value) "
4759-
"{ "
4760-
" if (value != m_value) { "
4761-
" m_value = value; "
4762-
" emit valueChanged(value); "
4763-
" } "
4764-
"}";
4765-
4766-
const char result2[] = "class Counter : public QObject "
4767-
"{ "
4768-
"public: "
4769-
"Counter ( ) { m_value = 0 ; } "
4770-
"int value ( ) const { return m_value ; } "
4771-
"public: "
4772-
"void setValue ( int value ) ; "
4773-
"protected: "
4774-
"void valueChanged ( int newValue ) ; "
4775-
"private: "
4776-
"int m_value ; "
4777-
"} ; "
4778-
"void Counter :: setValue ( int value ) "
4779-
"{ "
4780-
"if ( value != m_value ) { "
4781-
"m_value = value ; "
4782-
"valueChanged ( value ) ; "
4783-
"} "
4784-
"}";
4785-
4786-
ASSERT_EQUALS(result2, tokenizeAndStringify(code2));
4787-
4788-
const char code3[] = "class MyObject : public QObject {"
4789-
" MyObject() {}"
4790-
" ~MyObject() {}"
4791-
" public slots:"
4792-
" signals:"
4793-
" void test() {}"
4794-
"};";
4795-
const char result3[] = "class MyObject : public QObject { "
4796-
"MyObject ( ) { } "
4797-
"~ MyObject ( ) { } "
4798-
"public: "
4799-
"protected: "
4800-
"void test ( ) { } "
4801-
"} ;";
4802-
4803-
ASSERT_EQUALS(result3, tokenizeAndStringify(code3));
4804-
ASSERT_EQUALS("", errout.str());
4805-
4806-
const char code4[] = "class MyObject : public QObject {"
4807-
" Q_OBJECT "
4808-
"public slots:"
4809-
"};";
4810-
const char result4[] = "class MyObject : public QObject { "
4811-
"public: "
4812-
"} ;";
4813-
4814-
ASSERT_EQUALS(result4, tokenizeAndStringify(code4));
4815-
}
4816-
4817-
void simplifyQtSignalsSlots2() {
4818-
const char code1[] = "class Foo::Bar: public QObject { private slots: };";
4819-
const char result1[] = "class Foo :: Bar : public QObject { private: } ;";
4820-
ASSERT_EQUALS(result1, tokenizeAndStringify(code1));
4821-
}
4822-
48234692
void simplifySQL() {
48244693
// Oracle PRO*C extensions for inline SQL. Just replace the SQL with "asm()" to fix wrong error messages
48254694
// ticket: #1959

0 commit comments

Comments
 (0)