Skip to content

Commit 84595f8

Browse files
committed
Add correct column number to enum tokens
1 parent 1ca1246 commit 84595f8

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/tokenize.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9222,15 +9222,18 @@ void Tokenizer::simplifyStructDecl()
92229222
while (!Token::Match(start, "struct|class|union|enum")) {
92239223
after->insertToken(start->str());
92249224
after = after->next();
9225+
after->column(start->column());
92259226
start->deleteThis();
92269227
}
92279228
tok = start;
92289229
if (!after)
92299230
break; // see #4869 segmentation fault in Tokenizer::simplifyStructDecl (invalid code)
92309231
after->insertToken(type->str());
9232+
after->next()->column(type->column());
92319233
if (start->str() != "class") {
92329234
after->insertToken(start->str());
92339235
after = after->next();
9236+
after->column(start->column());
92349237
}
92359238

92369239
after = after->tokAt(2);

test/testtokenize.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,10 @@ class TestTokenizer : public TestFixture {
506506
TEST_CASE(dumpFallthrough);
507507

508508
TEST_CASE(simplifyRedundantParentheses);
509+
510+
TEST_CASE(simplifyEnum1);
511+
512+
TEST_CASE(simplifyEnum2);
509513
}
510514

511515
class TokenizerTest : public Tokenizer
@@ -8810,6 +8814,30 @@ class TestTokenizer : public TestFixture {
88108814
SimpleTokenizer tokenizer(settingsDefault, *this, false);
88118815
ASSERT_NO_THROW(tokenizer.tokenize(code));
88128816
}
8817+
8818+
void simplifyEnum1() {
8819+
const char code[] = "static enum {A,B} ab;";
8820+
ASSERT_EQUALS("enum Anonymous0 { A , B } ; static enum Anonymous0 ab ;", tokenizeAndStringify(code));
8821+
SimpleTokenizer tokenizer(settingsDefault, *this);
8822+
tokenizer.tokenize(code);
8823+
const Token* tok = Token::findsimplematch(tokenizer.tokens(), "static");
8824+
ASSERT(tok);
8825+
ASSERT_EQUALS(tok->column(), 1);
8826+
ASSERT_EQUALS(tok->next()->column(), 8);
8827+
ASSERT_EQUALS(tok->tokAt(2)->column(), 0);
8828+
}
8829+
8830+
void simplifyEnum2() {
8831+
const char code[] = "enum static E {A,B} ab;";
8832+
ASSERT_EQUALS("enum E { A , B } ; static enum E ab ;", tokenizeAndStringify(code));
8833+
SimpleTokenizer tokenizer(settingsDefault, *this);
8834+
tokenizer.tokenize(code);
8835+
const Token* tok = Token::findsimplematch(tokenizer.tokens(), "static");
8836+
ASSERT(tok);
8837+
ASSERT_EQUALS(tok->column(), 0);
8838+
ASSERT_EQUALS(tok->next()->column(), 1);
8839+
ASSERT_EQUALS(tok->tokAt(2)->column(), 13);
8840+
}
88138841
};
88148842

88158843
REGISTER_TEST(TestTokenizer)

0 commit comments

Comments
 (0)