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

This commit is contained in:
Robert Reif 2010-12-03 08:14:09 +01:00 committed by Daniel Marjamäki
parent 2cd8bc74cc
commit b29568c81d
2 changed files with 59 additions and 28 deletions

View File

@ -8745,16 +8745,17 @@ void Tokenizer::simplifyQtSignalsSlots()
{
tok2->deleteNext();
}
else if (Token::Match(tok2->next(), "public|protected|private slots :"))
else if (Token::Match(tok2->next(), "public|protected|private slots|Q_SLOTS :"))
{
tok2 = tok2->next();
tok2->str(tok2->str() + ":");
tok2->deleteNext();
tok2->deleteNext();
}
else if (Token::simpleMatch(tok2->next(), "signals :"))
else if (Token::Match(tok2->next(), "signals|Q_SIGNALS :"))
{
tok2->deleteNext();
tok2 = tok2->next();
tok2->str("protected:");
tok2->deleteNext();
}
}

View File

@ -4774,7 +4774,7 @@ private:
void Qt()
{
const char code[] = "class Counter : public QObject "
const char code1[] = "class Counter : public QObject "
"{ "
" Q_OBJECT "
"public: "
@ -4788,19 +4788,49 @@ private:
" int m_value; "
"};";
const char result [] = "class Counter : public QObject "
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 ; "
"} ;";
ASSERT_EQUALS(result, tokenizeAndStringify(code,false));
ASSERT_EQUALS(result1, tokenizeAndStringify(code1,false));
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; "
"};";
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 ; "
"} ;";
ASSERT_EQUALS(result2, tokenizeAndStringify(code2,false));
}
void sql()