Skip to content

Commit f48ea28

Browse files
committed
PreprocessorHelper: write locations in getcode() when #include is encountered
1 parent 723282d commit f48ea28

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

test/helpers.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include <cerrno>
2929
#include <cstdio>
30+
#include <cstring>
3031
#include <iostream>
3132
#include <fstream>
3233
#include <list>
@@ -152,8 +153,8 @@ std::map<std::string, std::string> PreprocessorHelper::getcode(const Settings& s
152153
cfgs = preprocessor.getConfigs(tokens);
153154
for (const std::string & config : cfgs) {
154155
try {
155-
// TODO: also preserve location information when #include exists - enabling that will fail since #line is treated like a regular token
156-
cfgcode[config] = preprocessor.getcode(tokens, config, files, std::string(code).find("#file") != std::string::npos);
156+
const bool writeLocations = (strstr(code, "#file") != nullptr) || (strstr(code, "#include") != nullptr);
157+
cfgcode[config] = preprocessor.getcode(tokens, config, files, writeLocations);
157158
} catch (const simplecpp::Output &) {
158159
cfgcode[config] = "";
159160
}

test/testpreprocessor.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2658,7 +2658,6 @@ class TestPreprocessor : public TestFixture {
26582658
}
26592659
}
26602660

2661-
// TODO: fails because the location information is not be preserved by PreprocessorHelper::getcode()
26622661
void writeLocations()
26632662
{
26642663
const char inc[] = "class A {\n"
@@ -2668,17 +2667,13 @@ class TestPreprocessor : public TestFixture {
26682667
const char code[] = R"(#include "test.h")";
26692668
ScopedFile header("test.h", inc);
26702669
const std::string processed = PreprocessorHelper::getcodeforcfg(settingsDefault, *this, code, "", "test.cpp");
2671-
TODO_ASSERT_EQUALS(
2670+
ASSERT_EQUALS(
26722671
"\n"
26732672
"#line 1 \"test.h\"\n"
26742673
"class A {\n"
26752674
"public :\n"
26762675
"void f ( ) { }\n"
26772676
"} ;",
2678-
"class A {\n"
2679-
"public :\n"
2680-
"void f ( ) { }\n"
2681-
"} ;",
26822677
processed);
26832678
}
26842679
};

0 commit comments

Comments
 (0)