Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cfg/qt.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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)"/>
Expand Down Expand Up @@ -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)"/>
Expand Down
62 changes: 0 additions & 62 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4982,9 +4982,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
if (Settings::terminated())
return false;

// Remove Qt signals and slots
simplifyQtSignalsSlots();

// remove Borland stuff..
simplifyBorland();

Expand Down Expand Up @@ -9131,65 +9128,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)
Expand Down
5 changes: 0 additions & 5 deletions lib/tokenize.h
Original file line number Diff line number Diff line change
Expand Up @@ -536,11 +536,6 @@ class CPPCHECKLIB Tokenizer {
*/
void simplifyBorland();

/**
* Remove Qt signals and slots
*/
void simplifyQtSignalsSlots();

/**
* Collapse operator name tokens into single token
* operator = => operator=
Expand Down
69 changes: 69 additions & 0 deletions test/cfg/qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: };
}
16 changes: 0 additions & 16 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ class TestSymbolDatabase : public TestFixture {
TEST_CASE(findFunction8);
TEST_CASE(findFunction9);
TEST_CASE(findFunction10); // #7673
TEST_CASE(findFunction11);
TEST_CASE(findFunction12);
TEST_CASE(findFunction13);
TEST_CASE(findFunction14);
Expand Down Expand Up @@ -6057,21 +6056,6 @@ class TestSymbolDatabase : public TestFixture {
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"
Expand Down
131 changes: 0 additions & 131 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ class TestTokenizer : public TestFixture {
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

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

TEST_CASE(borland);

TEST_CASE(simplifyQtSignalsSlots1);
TEST_CASE(simplifyQtSignalsSlots2);

TEST_CASE(simplifySQL);

TEST_CASE(simplifyCAlternativeTokens);
Expand Down Expand Up @@ -4475,10 +4470,6 @@ class TestTokenizer : public TestFixture {
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"
Expand Down Expand Up @@ -4698,128 +4689,6 @@ class TestTokenizer : public TestFixture {
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
Expand Down