diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index a2049bd02..ac977c288 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9970,7 +9970,13 @@ void Tokenizer::simplifyQtSignalsSlots() { for (Token *tok = _tokens; tok; tok = tok->next()) { - if (!Token::Match(tok, "class %var% :")) + // check for emit which can be outside of class + if (Token::Match(tok, "emit|Q_EMIT %var% (") && + Token::simpleMatch(tok->tokAt(2)->link(), ") ;")) + { + tok->deleteThis(); + } + else if (!Token::Match(tok, "class %var% :")) continue; if (tok->previous() && tok->previous()->str() == "enum") @@ -10015,6 +10021,11 @@ void Tokenizer::simplifyQtSignalsSlots() tok2->str("protected:"); tok2->deleteNext(); } + else if (Token::Match(tok2->next(), "emit|Q_EMIT %var% (") && + Token::simpleMatch(tok2->tokAt(3)->link(), ") ;")) + { + tok2->deleteNext(); + } } } } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index c2607ab12..c546b664b 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -5537,7 +5537,14 @@ private: " 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 " "{ " @@ -5550,7 +5557,14 @@ private: "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,false)); @@ -5566,7 +5580,14 @@ private: " 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 " "{ " @@ -5579,7 +5600,14 @@ private: "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,false)); }