Skip to content

Commit 73c16c6

Browse files
committed
refs #1059 - extract configurations for #if x < y and #if x > y [skip ci]
1 parent c31df0a commit 73c16c6

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

lib/preprocessor.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,17 @@ static std::string readcondition(const simplecpp::Token *iftok, const std::set<s
415415
return cond->str() + '=' + cond->next->next->str();
416416
}
417417

418+
if (len == 3 && cond->name && (next1->op == '<' || next1->op == '>') && next2->number) {
419+
if (defined.find(cond->str()) == defined.end()) {
420+
int v = strToInt<int>(cond->next->next->str());
421+
if (next1->op == '<')
422+
v -= 1;
423+
else
424+
v += 1;
425+
return cond->str() + '=' + std::to_string(v);
426+
}
427+
}
428+
418429
std::set<std::string> configset;
419430
for (; sameline(iftok,cond); cond = cond->next) {
420431
if (cond->op == '!') {

test/testpreprocessor.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ class TestPreprocessor : public TestFixture {
318318
TEST_CASE(getConfigs13); // #14222
319319
TEST_CASE(getConfigs14); // #1059
320320
TEST_CASE(getConfigs15); // #1059
321+
TEST_CASE(getConfigs16); // #1059
322+
TEST_CASE(getConfigs17); // #1059
321323
TEST_CASE(getConfigsError);
322324

323325
TEST_CASE(getConfigsD1);
@@ -654,7 +656,7 @@ class TestPreprocessor : public TestFixture {
654656
"#else\n"
655657
" B\n"
656658
"#endif\n";
657-
TODO_ASSERT_EQUALS("\nLIBVER=101\n", "\n", getConfigsStr(filedata));
659+
ASSERT_EQUALS("\nLIBVER=101\n", getConfigsStr(filedata));
658660
}
659661

660662
void if_cond2() {
@@ -2305,6 +2307,20 @@ class TestPreprocessor : public TestFixture {
23052307
ASSERT_EQUALS("\nA=1\n", getConfigsStr(filedata));
23062308
}
23072309

2310+
void getConfigs16() { // #1059
2311+
const char filedata[] = "#if A > 1\n"
2312+
"1\n"
2313+
"#endif\n";
2314+
ASSERT_EQUALS("\nA=2\n", getConfigsStr(filedata));
2315+
}
2316+
2317+
void getConfigs17() { // #1059
2318+
const char filedata[] = "#if A < 1\n"
2319+
"1\n"
2320+
"#endif\n";
2321+
ASSERT_EQUALS("\nA=0\n", getConfigsStr(filedata));
2322+
}
2323+
23082324
void getConfigsError() {
23092325
const char filedata1[] = "#ifndef X\n"
23102326
"#error \"!X\"\n"

0 commit comments

Comments
 (0)