Skip to content

Commit 12d0391

Browse files
authored
Fix #14286 : Add correct column number to tokens of enum in dump file (danmar#7974)
1 parent 9486fde commit 12d0391

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/tokenize.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7631,16 +7631,20 @@ void Tokenizer::simplifyStaticConst()
76317631
}
76327632

76337633
// Move the qualifier to the left-most position in the declaration
7634+
const int column = tok->next()->column();
76347635
tok->deleteNext();
76357636
if (!leftTok) {
76367637
list.front()->insertToken(qualifiers[i]);
76377638
list.front()->swapWithNext();
7639+
list.front()->column(column);
76387640
tok = list.front();
76397641
} else if (leftTok->next()) {
76407642
leftTok->next()->insertTokenBefore(qualifiers[i]);
7643+
leftTok->next()->column(column);
76417644
tok = leftTok->next();
76427645
} else {
76437646
leftTok->insertToken(qualifiers[i]);
7647+
leftTok->next()->column(column);
76447648
tok = leftTok;
76457649
}
76467650
}
@@ -9222,15 +9226,18 @@ void Tokenizer::simplifyStructDecl()
92229226
while (!Token::Match(start, "struct|class|union|enum")) {
92239227
after->insertToken(start->str());
92249228
after = after->next();
9229+
after->column(start->column());
92259230
start->deleteThis();
92269231
}
92279232
tok = start;
92289233
if (!after)
92299234
break; // see #4869 segmentation fault in Tokenizer::simplifyStructDecl (invalid code)
92309235
after->insertToken(type->str());
9236+
after->next()->column(type->column());
92319237
if (start->str() != "class") {
92329238
after->insertToken(start->str());
92339239
after = after->next();
9240+
after->column(start->column());
92349241
}
92359242

92369243
after = after->tokAt(2);

test/testtokenize.cpp

Lines changed: 26 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,28 @@ 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+
}
8828+
8829+
void simplifyEnum2() {
8830+
const char code[] = "enum AB {A,B}; enum AB static ab; ";
8831+
ASSERT_EQUALS("enum AB { A , B } ; static enum AB ab ;", tokenizeAndStringify(code));
8832+
SimpleTokenizer tokenizer(settingsDefault, *this);
8833+
tokenizer.tokenize(code);
8834+
const Token* tok = Token::findsimplematch(tokenizer.tokens(), "static");
8835+
ASSERT(tok);
8836+
ASSERT_EQUALS(tok->column(), 24);
8837+
ASSERT_EQUALS(tok->next()->column(), 16);
8838+
}
88138839
};
88148840

88158841
REGISTER_TEST(TestTokenizer)

0 commit comments

Comments
 (0)