diff --git a/main.cpp b/main.cpp index ecbe062f..6b5b0d0e 100644 --- a/main.cpp +++ b/main.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include int main(int argc, char **argv) @@ -110,6 +109,8 @@ int main(int argc, char **argv) std::exit(0); } + dui.removeComments = true; + // Perform preprocessing simplecpp::OutputList outputList; std::vector files; @@ -126,11 +127,10 @@ int main(int argc, char **argv) rawtokens = new simplecpp::TokenList(filename,files,&outputList); } rawtokens->removeComments(); - std::map included = simplecpp::load(*rawtokens, files, dui, &outputList); - for (std::pair i : included) - i.second->removeComments(); simplecpp::TokenList outputTokens(files); - simplecpp::preprocess(outputTokens, *rawtokens, files, included, dui, &outputList); + std::map filedata; + simplecpp::preprocess(outputTokens, *rawtokens, files, filedata, dui, &outputList); + simplecpp::cleanup(filedata); delete rawtokens; rawtokens = nullptr; @@ -174,8 +174,5 @@ int main(int argc, char **argv) } } - // cleanup included tokenlists - simplecpp::cleanup(included); - return 0; } diff --git a/simplecpp.cpp b/simplecpp.cpp index 43d8ac4c..1de36a52 100755 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -3145,6 +3145,8 @@ std::map simplecpp::load(const simplecpp::To continue; } + if (dui.removeComments) + tokenlist->removeComments(); ret[filename] = tokenlist; filelist.push_back(tokenlist->front()); } @@ -3180,6 +3182,8 @@ std::map simplecpp::load(const simplecpp::To f.close(); TokenList *tokens = new TokenList(header2, filenames, outputList); + if (dui.removeComments) + tokens->removeComments(); ret[header2] = tokens; if (tokens->front()) filelist.push_back(tokens->front()); @@ -3448,6 +3452,8 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL header2 = openHeader(f, dui, rawtok->location.file(), header, systemheader); if (f.is_open()) { TokenList * const tokens = new TokenList(f, files, header2, outputList); + if (dui.removeComments) + tokens->removeComments(); filedata[header2] = tokens; } } diff --git a/simplecpp.h b/simplecpp.h index 7ef0740c..87238378 100755 --- a/simplecpp.h +++ b/simplecpp.h @@ -320,13 +320,14 @@ namespace simplecpp { * On the command line these are configured by -D, -U, -I, --include, -std */ struct SIMPLECPP_LIB DUI { - DUI() : clearIncludeCache(false) {} + DUI() : clearIncludeCache(false), removeComments(false) {} std::list defines; std::set undefined; std::list includePaths; std::list includes; std::string std; bool clearIncludeCache; + bool removeComments; /** remove comment tokens from included files */ }; SIMPLECPP_LIB long long characterLiteralToLL(const std::string& str);