add support for simplifying Qt emit in tokenizer
This commit is contained in:
parent
dfe89f395a
commit
423a1ff64e
|
@ -9970,7 +9970,13 @@ void Tokenizer::simplifyQtSignalsSlots()
|
||||||
{
|
{
|
||||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
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;
|
continue;
|
||||||
|
|
||||||
if (tok->previous() && tok->previous()->str() == "enum")
|
if (tok->previous() && tok->previous()->str() == "enum")
|
||||||
|
@ -10015,6 +10021,11 @@ void Tokenizer::simplifyQtSignalsSlots()
|
||||||
tok2->str("protected:");
|
tok2->str("protected:");
|
||||||
tok2->deleteNext();
|
tok2->deleteNext();
|
||||||
}
|
}
|
||||||
|
else if (Token::Match(tok2->next(), "emit|Q_EMIT %var% (") &&
|
||||||
|
Token::simpleMatch(tok2->tokAt(3)->link(), ") ;"))
|
||||||
|
{
|
||||||
|
tok2->deleteNext();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5537,7 +5537,14 @@ private:
|
||||||
" void valueChanged(int newValue); "
|
" void valueChanged(int newValue); "
|
||||||
"private: "
|
"private: "
|
||||||
" int m_value; "
|
" 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 "
|
const char result1 [] = "class Counter : public QObject "
|
||||||
"{ "
|
"{ "
|
||||||
|
@ -5550,7 +5557,14 @@ private:
|
||||||
"void valueChanged ( int newValue ) ; "
|
"void valueChanged ( int newValue ) ; "
|
||||||
"private: "
|
"private: "
|
||||||
"int m_value ; "
|
"int m_value ; "
|
||||||
"} ;";
|
"} ; "
|
||||||
|
"void Counter :: setValue ( int value ) "
|
||||||
|
"{ "
|
||||||
|
"if ( value != m_value ) { "
|
||||||
|
"m_value = value ; "
|
||||||
|
"valueChanged ( value ) ; "
|
||||||
|
"} "
|
||||||
|
"}";
|
||||||
|
|
||||||
ASSERT_EQUALS(result1, tokenizeAndStringify(code1,false));
|
ASSERT_EQUALS(result1, tokenizeAndStringify(code1,false));
|
||||||
|
|
||||||
|
@ -5566,7 +5580,14 @@ private:
|
||||||
" void valueChanged(int newValue); "
|
" void valueChanged(int newValue); "
|
||||||
"private: "
|
"private: "
|
||||||
" int m_value; "
|
" 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 "
|
const char result2 [] = "class Counter : public QObject "
|
||||||
"{ "
|
"{ "
|
||||||
|
@ -5579,7 +5600,14 @@ private:
|
||||||
"void valueChanged ( int newValue ) ; "
|
"void valueChanged ( int newValue ) ; "
|
||||||
"private: "
|
"private: "
|
||||||
"int m_value ; "
|
"int m_value ; "
|
||||||
"} ;";
|
"} ; "
|
||||||
|
"void Counter :: setValue ( int value ) "
|
||||||
|
"{ "
|
||||||
|
"if ( value != m_value ) { "
|
||||||
|
"m_value = value ; "
|
||||||
|
"valueChanged ( value ) ; "
|
||||||
|
"} "
|
||||||
|
"}";
|
||||||
|
|
||||||
ASSERT_EQUALS(result2, tokenizeAndStringify(code2,false));
|
ASSERT_EQUALS(result2, tokenizeAndStringify(code2,false));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue