Tokenizer:vardecl: split up reference variables declared in class better

This commit is contained in:
Daniel Marjamäki 2016-01-19 15:27:11 +01:00
parent a434e0fb1a
commit ab441f3fb1
2 changed files with 14 additions and 5 deletions

View File

@ -5393,12 +5393,15 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, Token * tokEnd, bool only_k_r_
if (tok2->strAt(1) == "*")
break;
if (Token::Match(tok2->next(), "& %name% ,"))
break;
tok2 = tok2->next();
++typelen;
}
// strange looking variable declaration => don't split up.
if (Token::Match(tok2, "%type% *| %name% , %type% *| %name%"))
if (Token::Match(tok2, "%type% *|&| %name% , %type% *|&| %name%"))
continue;
if (Token::Match(tok2, "struct|union|class %type%")) {
@ -5470,9 +5473,9 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, Token * tokEnd, bool only_k_r_
else
--typelen;
//skip all the pointer part
bool ispointer = false;
while (varName && varName->str() == "*") {
ispointer = true;
bool isPointerOrRef = false;
while (Token::simpleMatch(varName, "*") || Token::Match(varName, "& %name% ,")) {
isPointerOrRef = true;
varName = varName->next();
}
@ -5487,7 +5490,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, Token * tokEnd, bool only_k_r_
if (varName->str() != "operator") {
tok2 = varName->next(); // The ',' or '=' token
if (tok2->str() == "=" && (isstatic || (isconst && !ispointer))) {
if (tok2->str() == "=" && (isstatic || (isconst && !isPointerOrRef))) {
//do not split const non-pointer variables..
while (tok2 && tok2->str() != "," && tok2->str() != ";") {
if (Token::Match(tok2, "{|(|["))

View File

@ -288,6 +288,7 @@ private:
TEST_CASE(vardecl_par); // #2743 - set links if variable type contains parentheses
TEST_CASE(vardecl_par2); // #3912 - set correct links
TEST_CASE(vardecl_par3); // #6556 - Fred x1(a), x2(b);
TEST_CASE(vardecl_class_ref);
TEST_CASE(volatile_variables);
// unsigned i; => unsigned int i;
@ -3630,6 +3631,11 @@ private:
ASSERT_EQUALS("Fred x1 ( a ) ; Fred x2 ( b ) ;", tokenizeAndStringify(code));
}
void vardecl_class_ref() {
const char code[] = "class A { B &b1,&b2; };";
ASSERT_EQUALS("class A { B & b1 ; B & b2 ; } ;", tokenizeAndStringify(code));
}
void vardec_static() {
{
// don't simplify declarations of static variables