Fixed #2271 (Tokenizer: simplify Qt signals and slots)

This commit is contained in:
Robert Reif 2010-12-02 17:41:49 +01:00 committed by Daniel Marjamäki
parent 1bc8a2b6ba
commit eda4bcae29
3 changed files with 83 additions and 0 deletions

View File

@ -2154,6 +2154,9 @@ bool Tokenizer::tokenize(std::istream &code,
// remove Microsoft MFC..
simplifyMicrosoftMFC();
// Remove Qt signals and slots
simplifyQtSignalsSlots();
// remove Borland stuff..
simplifyBorland();
@ -8714,4 +8717,46 @@ void Tokenizer::simplifyBorland()
}
}
// Remove Qt signals and slots
void Tokenizer::simplifyQtSignalsSlots()
{
Token *tok = _tokens;
while ((tok = const_cast<Token *>(Token::findmatch(tok, "class %var% :"))))
{
unsigned 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() == "}")
{
indentlevel--;
if (indentlevel == 0)
break;
}
if (Token::simpleMatch(tok2->next(), "Q_OBJECT"))
{
tok2->deleteNext();
}
else if (Token::Match(tok2->next(), "public|protected|private slots :"))
{
tok2 = tok2->next();
tok2->str(tok2->str() + ":");
tok2->deleteNext();
tok2->deleteNext();
}
else if (Token::simpleMatch(tok2->next(), "signals :"))
{
tok2->deleteNext();
tok2->deleteNext();
}
}
}
}

View File

@ -489,6 +489,11 @@ public:
*/
void simplifyBorland();
/**
* Remove Qt signals and slots
*/
void simplifyQtSignalsSlots();
/**
* This will return a short name describing function parameters
* e.g. parameters: (int a, char b) should get name "int,char,".

View File

@ -265,6 +265,8 @@ private:
TEST_CASE(borland);
TEST_CASE(Qt);
TEST_CASE(sql);
TEST_CASE(simplifyLogicalOperators);
@ -4770,6 +4772,37 @@ private:
tokenizeAndStringify("class Fred { __property int x = { } };", false));
}
void Qt()
{
const char code[] = "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; "
"};";
const char result [] = "class Counter : public QObject "
"{ "
"public: "
"Counter ( ) { m_value = 0 ; } "
"int value ( ) const { return m_value ; } "
"public: "
"void setValue ( int value ) ; "
"void valueChanged ( int newValue ) ; "
"private: "
"int m_value ; "
"} ;";
ASSERT_EQUALS(result, tokenizeAndStringify(code,false));
}
void sql()
{
// Oracle PRO*C extensions for inline SQL. Just replace the SQL with "asm()" to fix wrong error messages