Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1067,10 +1067,10 @@ void Preprocessor::dump(std::ostream &out) const
for (const simplecpp::MacroUsage &macroUsage: mMacroUsage) {
out << " <macro"
<< " name=\"" << macroUsage.macroName << "\""
<< " file=\"" << ErrorLogger::toxml(mTokens.file(macroUsage.macroLocation)) << "\""
<< " file=\"" << ErrorLogger::toxml(mSettings.relativePaths ? Path::getRelativePath(mTokens.file(macroUsage.macroLocation), mSettings.basePaths) : mTokens.file(macroUsage.macroLocation)) << "\""
<< " line=\"" << macroUsage.macroLocation.line << "\""
<< " column=\"" << macroUsage.macroLocation.col << "\""
<< " usefile=\"" << ErrorLogger::toxml(mTokens.file(macroUsage.useLocation)) << "\""
<< " usefile=\"" << ErrorLogger::toxml(mSettings.relativePaths ? Path::getRelativePath(mTokens.file(macroUsage.useLocation), mSettings.basePaths) : mTokens.file(macroUsage.useLocation)) << "\""
<< " useline=\"" << macroUsage.useLocation.line << "\""
<< " usecolumn=\"" << macroUsage.useLocation.col << "\""
<< " is-known-value=\"" << bool_to_string(macroUsage.macroValueKnown) << "\""
Expand All @@ -1083,7 +1083,7 @@ void Preprocessor::dump(std::ostream &out) const
out << " <simplecpp-if-cond>" << std::endl;
for (const simplecpp::IfCond &ifCond: mIfCond) {
out << " <if-cond"
<< " file=\"" << ErrorLogger::toxml(mTokens.file(ifCond.location)) << "\""
<< " file=\"" << ErrorLogger::toxml(mSettings.relativePaths ? Path::getRelativePath(mTokens.file(ifCond.location), mSettings.basePaths) : mTokens.file(ifCond.location)) << "\""
<< " line=\"" << ifCond.location.line << "\""
<< " column=\"" << ifCond.location.col << "\""
<< " E=\"" << ErrorLogger::toxml(ifCond.E) << "\""
Expand Down
26 changes: 26 additions & 0 deletions test/testpreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ class TestPreprocessor : public TestFixture {
TEST_CASE(writeLocations);

TEST_CASE(pragmaAsm);

TEST_CASE(dumpPreprocessor);
}

template<size_t size>
Expand Down Expand Up @@ -3204,6 +3206,30 @@ class TestPreprocessor : public TestFixture {
const char code[] = "#pragma asm\n";
ASSERT_THROW_INTERNAL(getcodeforcfg(settingsDefault, *this, code, "", "test.cpp"), InternalError::SYNTAX);
}

void dumpPreprocessor() {
const char code[] = "#if M == 0\n"
"#endif\n;\n";
std::vector<std::string> files;
simplecpp::OutputList outputList;

Settings settings;
settings.relativePaths = true;
settings.basePaths.emplace_back("/some/path");

simplecpp::TokenList tokens1(code, files, "/some/path/test.cpp", {}, &outputList);
Preprocessor preprocessor(tokens1, settings, *this, Standards::Language::CPP);
(void)preprocessor.preprocess("", files, outputList);
(void)preprocessor.reportOutput(outputList, true);

std::ostringstream ostr;
preprocessor.dump(ostr);
ASSERT_EQUALS(
" <simplecpp-if-cond>\n"
" <if-cond file=\"test.cpp\" line=\"1\" column=\"2\" E=\"M == 0\" result=\"1\"/>\n"
" </simplecpp-if-cond>\n",
ostr.str());
}
};

REGISTER_TEST(TestPreprocessor)
Loading