Tokenizer:vardecl: split up reference variables declared in class better
This commit is contained in:
parent
a434e0fb1a
commit
ab441f3fb1
|
@ -5393,12 +5393,15 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, Token * tokEnd, bool only_k_r_
|
||||||
if (tok2->strAt(1) == "*")
|
if (tok2->strAt(1) == "*")
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if (Token::Match(tok2->next(), "& %name% ,"))
|
||||||
|
break;
|
||||||
|
|
||||||
tok2 = tok2->next();
|
tok2 = tok2->next();
|
||||||
++typelen;
|
++typelen;
|
||||||
}
|
}
|
||||||
|
|
||||||
// strange looking variable declaration => don't split up.
|
// 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;
|
continue;
|
||||||
|
|
||||||
if (Token::Match(tok2, "struct|union|class %type%")) {
|
if (Token::Match(tok2, "struct|union|class %type%")) {
|
||||||
|
@ -5470,9 +5473,9 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, Token * tokEnd, bool only_k_r_
|
||||||
else
|
else
|
||||||
--typelen;
|
--typelen;
|
||||||
//skip all the pointer part
|
//skip all the pointer part
|
||||||
bool ispointer = false;
|
bool isPointerOrRef = false;
|
||||||
while (varName && varName->str() == "*") {
|
while (Token::simpleMatch(varName, "*") || Token::Match(varName, "& %name% ,")) {
|
||||||
ispointer = true;
|
isPointerOrRef = true;
|
||||||
varName = varName->next();
|
varName = varName->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5487,7 +5490,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, Token * tokEnd, bool only_k_r_
|
||||||
if (varName->str() != "operator") {
|
if (varName->str() != "operator") {
|
||||||
tok2 = varName->next(); // The ',' or '=' token
|
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..
|
//do not split const non-pointer variables..
|
||||||
while (tok2 && tok2->str() != "," && tok2->str() != ";") {
|
while (tok2 && tok2->str() != "," && tok2->str() != ";") {
|
||||||
if (Token::Match(tok2, "{|(|["))
|
if (Token::Match(tok2, "{|(|["))
|
||||||
|
|
|
@ -288,6 +288,7 @@ private:
|
||||||
TEST_CASE(vardecl_par); // #2743 - set links if variable type contains parentheses
|
TEST_CASE(vardecl_par); // #2743 - set links if variable type contains parentheses
|
||||||
TEST_CASE(vardecl_par2); // #3912 - set correct links
|
TEST_CASE(vardecl_par2); // #3912 - set correct links
|
||||||
TEST_CASE(vardecl_par3); // #6556 - Fred x1(a), x2(b);
|
TEST_CASE(vardecl_par3); // #6556 - Fred x1(a), x2(b);
|
||||||
|
TEST_CASE(vardecl_class_ref);
|
||||||
TEST_CASE(volatile_variables);
|
TEST_CASE(volatile_variables);
|
||||||
|
|
||||||
// unsigned i; => unsigned int i;
|
// unsigned i; => unsigned int i;
|
||||||
|
@ -3630,6 +3631,11 @@ private:
|
||||||
ASSERT_EQUALS("Fred x1 ( a ) ; Fred x2 ( b ) ;", tokenizeAndStringify(code));
|
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() {
|
void vardec_static() {
|
||||||
{
|
{
|
||||||
// don't simplify declarations of static variables
|
// don't simplify declarations of static variables
|
||||||
|
|
Loading…
Reference in New Issue