Fix #680: Add option to keep comments in preprocessed code by ludviggunne · Pull Request #681 · cppcheck-opensource/simplecpp · GitHub
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
3 changes: 2 additions & 1 deletion main.cpp
10 changes: 5 additions & 5 deletions simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3341,7 +3341,7 @@ simplecpp::FileDataCache simplecpp::load(const simplecpp::TokenList &rawtokens,
return cache;
}

static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token *&tok1, simplecpp::MacroMap &macros, std::vector<std::string> &files, simplecpp::OutputList *outputList)
static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token *&tok1, simplecpp::MacroMap &macros, std::vector<std::string> &files, simplecpp::OutputList *outputList, const simplecpp::DUI &dui)
{
const simplecpp::Token * const tok = tok1;
const simplecpp::MacroMap::const_iterator it = tok->name ? macros.find(tok->str()) : macros.end();
Expand Down Expand Up @@ -3372,7 +3372,7 @@ static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token
}
output.takeTokens(value);
} else {
if (!tok->comment)
if (!tok->comment || !dui.removeComments)
output.push_back(new simplecpp::Token(*tok));
tok1 = tok->next;
}
Expand Down Expand Up @@ -3647,7 +3647,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
TokenList inc2(files);
if (!inc1.empty() && inc1.cfront()->name) {
const Token *inctok = inc1.cfront();
if (!preprocessToken(inc2, inctok, macros, files, outputList)) {
if (!preprocessToken(inc2, inctok, macros, files, outputList, dui)) {
output.clear();
return;
}
Expand Down Expand Up @@ -3817,7 +3817,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
maybeUsedMacros[rawtok->next->str()].emplace_back(rawtok->next->location);

const Token *tmp = tok;
if (!preprocessToken(expr, tmp, macros, files, outputList)) {
if (!preprocessToken(expr, tmp, macros, files, outputList, dui)) {
output.clear();
return;
}
Expand Down Expand Up @@ -3915,7 +3915,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
const Location loc(rawtok->location);
TokenList tokens(files);

if (!preprocessToken(tokens, rawtok, macros, files, outputList)) {
if (!preprocessToken(tokens, rawtok, macros, files, outputList, dui)) {
output.clear();
return;
}
Expand Down
37 changes: 33 additions & 4 deletions test.cpp
Loading