From c31df0a2d7c0132a0f33e1c7302b160f86e90f69 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 15 Dec 2025 14:03:39 +0100 Subject: [PATCH 1/2] refs #1059 - extract configurations for `#if x <=` and `#if x >=` --- lib/preprocessor.cpp | 2 +- test/testpreprocessor.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 636e5a848a1..a23c6d20589 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -410,7 +410,7 @@ static std::string readcondition(const simplecpp::Token *iftok, const std::setstr(); } - if (len == 3 && cond->name && next1->str() == "==" && next2->number) { + if (len == 3 && cond->name && (next1->str() == "==" || next1->str() == "<=" || next1->str() == ">=") && next2->number) { if (defined.find(cond->str()) == defined.end()) return cond->str() + '=' + cond->next->next->str(); } diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 369de0d2640..b6aa5dd9639 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -316,6 +316,8 @@ class TestPreprocessor : public TestFixture { TEST_CASE(getConfigs11); // #9832 - include guards TEST_CASE(getConfigs12); // #14222 TEST_CASE(getConfigs13); // #14222 + TEST_CASE(getConfigs14); // #1059 + TEST_CASE(getConfigs15); // #1059 TEST_CASE(getConfigsError); TEST_CASE(getConfigsD1); @@ -2289,6 +2291,20 @@ class TestPreprocessor : public TestFixture { ASSERT_EQUALS("\n", getConfigsStr(filedata, nullptr, "gnu.cfg")); } + void getConfigs14() { // #1059 + const char filedata[] = "#if A >= 1\n" + "1\n" + "#endif\n"; + ASSERT_EQUALS("\nA=1\n", getConfigsStr(filedata)); + } + + void getConfigs15() { // #1059 + const char filedata[] = "#if A <= 1\n" + "1\n" + "#endif\n"; + ASSERT_EQUALS("\nA=1\n", getConfigsStr(filedata)); + } + void getConfigsError() { const char filedata1[] = "#ifndef X\n" "#error \"!X\"\n" From 73c16c6dfa921d7e825ae897b485de974643b7dc Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 15 Dec 2025 15:16:49 +0100 Subject: [PATCH 2/2] refs #1059 - extract configurations for `#if x < y` and `#if x > y` [skip ci] --- lib/preprocessor.cpp | 11 +++++++++++ test/testpreprocessor.cpp | 18 +++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index a23c6d20589..6101c7b5ce1 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -415,6 +415,17 @@ static std::string readcondition(const simplecpp::Token *iftok, const std::setstr() + '=' + cond->next->next->str(); } + if (len == 3 && cond->name && (next1->op == '<' || next1->op == '>') && next2->number) { + if (defined.find(cond->str()) == defined.end()) { + int v = strToInt(cond->next->next->str()); + if (next1->op == '<') + v -= 1; + else + v += 1; + return cond->str() + '=' + std::to_string(v); + } + } + std::set configset; for (; sameline(iftok,cond); cond = cond->next) { if (cond->op == '!') { diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index b6aa5dd9639..b38c71823f4 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -318,6 +318,8 @@ class TestPreprocessor : public TestFixture { TEST_CASE(getConfigs13); // #14222 TEST_CASE(getConfigs14); // #1059 TEST_CASE(getConfigs15); // #1059 + TEST_CASE(getConfigs16); // #1059 + TEST_CASE(getConfigs17); // #1059 TEST_CASE(getConfigsError); TEST_CASE(getConfigsD1); @@ -654,7 +656,7 @@ class TestPreprocessor : public TestFixture { "#else\n" " B\n" "#endif\n"; - TODO_ASSERT_EQUALS("\nLIBVER=101\n", "\n", getConfigsStr(filedata)); + ASSERT_EQUALS("\nLIBVER=101\n", getConfigsStr(filedata)); } void if_cond2() { @@ -2305,6 +2307,20 @@ class TestPreprocessor : public TestFixture { ASSERT_EQUALS("\nA=1\n", getConfigsStr(filedata)); } + void getConfigs16() { // #1059 + const char filedata[] = "#if A > 1\n" + "1\n" + "#endif\n"; + ASSERT_EQUALS("\nA=2\n", getConfigsStr(filedata)); + } + + void getConfigs17() { // #1059 + const char filedata[] = "#if A < 1\n" + "1\n" + "#endif\n"; + ASSERT_EQUALS("\nA=0\n", getConfigsStr(filedata)); + } + void getConfigsError() { const char filedata1[] = "#ifndef X\n" "#error \"!X\"\n"