Fixed #1030 (wrong line number with goto)

This commit is contained in:
Daniel Marjamäki 2009-12-02 19:47:35 +01:00
parent f5c81429cb
commit 96268b4caf
2 changed files with 39 additions and 24 deletions

View File

@ -3918,6 +3918,7 @@ void Tokenizer::simplifyGoto()
ret = true;
token->insertToken(tok2->str().c_str());
token = token->next();
token->linenr(tok2->linenr());
if (token->str() == "(")
{
links.push_back(token);

View File

@ -1847,18 +1847,25 @@ private:
" c();\n"
"}";
const char expect[] = "void foo ( ) "
"{ "
"if ( a ( ) ) "
"{ "
"c ( ) ; "
"return ; "
"} "
"b ( ) ; "
"c ( ) ; "
"}";
std::istringstream istr(code);
Tokenizer tokenizer;
tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList();
tokenizer.validate();
ASSERT_EQUALS(expect, tok(code));
const char expect[] = "\n\n##file 0\n"
"1: void foo ( )\n"
"2: {\n"
"3: if ( a ( ) )\n"
"4: {\n"
"5:\n6:\n7:\n8:\n"
"9: c ( ) ; return ; }\n"
"7: b ( ) ;\n"
"8:\n"
"9: c ( ) ;\n"
"10: }\n";
ASSERT_EQUALS(expect, tokenizer.tokens()->stringifyList(""));
}
{
@ -1872,20 +1879,27 @@ private:
" d();\n"
"}";
const char expect[] = "void foo ( ) "
"{ "
"if ( a ( ) ) "
"{ "
"if ( c ( ) ) "
"{ d ( ) ; } "
"return ; "
"} "
"b ( ) ; "
"if ( c ( ) ) "
"{ d ( ) ; } "
"}";
ASSERT_EQUALS(expect, tok(code));
std::istringstream istr(code);
Tokenizer tokenizer;
tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList();
tokenizer.validate();
const char expect[] = "\n\n##file 0\n"
"1: void foo ( )\n"
"2: {\n"
"3: if ( a ( ) ) {\n"
"4:\n5:\n6:\n"
"7: if ( c ( ) ) {\n"
"8: d ( ) ; } return ; }\n"
"5: b ( ) ;\n"
"6:\n"
"7: if ( c ( ) ) {\n"
"8: d ( ) ; }\n"
"9: }\n";
ASSERT_EQUALS(expect, tokenizer.tokens()->stringifyList(""));
}
{