Skip to content

Commit

Permalink
testrunner: moved Preprocessor object into PreprocessorHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Apr 11, 2024
1 parent 1c49488 commit 999bc80
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 120 deletions.
15 changes: 6 additions & 9 deletions test/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,27 +111,28 @@ ScopedFile::~ScopedFile() {
}

// TODO: we should be using the actual Preprocessor implementation
std::string PreprocessorHelper::getcode(Preprocessor &preprocessor, const std::string &filedata, const std::string &cfg, const std::string &filename, SuppressionList *inlineSuppression)
std::string PreprocessorHelper::getcode(const Settings& settings, ErrorLogger& errorlogger, const std::string &filedata, const std::string &cfg, const std::string &filename, SuppressionList *inlineSuppression)
{
std::map<std::string, std::string> cfgcode = getcode(preprocessor, filedata.c_str(), std::set<std::string>{cfg}, filename, inlineSuppression);
std::map<std::string, std::string> cfgcode = getcode(settings, errorlogger, filedata.c_str(), std::set<std::string>{cfg}, filename, inlineSuppression);
const auto it = cfgcode.find(cfg);
if (it == cfgcode.end())
return "";
return it->second;
}

std::map<std::string, std::string> PreprocessorHelper::getcode(Preprocessor &preprocessor, const char code[], const std::string &filename, SuppressionList *inlineSuppression)
std::map<std::string, std::string> PreprocessorHelper::getcode(const Settings& settings, ErrorLogger& errorlogger, const char code[], const std::string &filename, SuppressionList *inlineSuppression)
{
return getcode(preprocessor, code, {}, filename, inlineSuppression);
return getcode(settings, errorlogger, code, {}, filename, inlineSuppression);
}

std::map<std::string, std::string> PreprocessorHelper::getcode(Preprocessor &preprocessor, const char code[], std::set<std::string> cfgs, const std::string &filename, SuppressionList *inlineSuppression)
std::map<std::string, std::string> PreprocessorHelper::getcode(const Settings& settings, ErrorLogger& errorlogger, const char code[], std::set<std::string> cfgs, const std::string &filename, SuppressionList *inlineSuppression)
{
simplecpp::OutputList outputList;
std::vector<std::string> files;

std::istringstream istr(code);
simplecpp::TokenList tokens(istr, files, Path::simplifyPath(filename), &outputList);
Preprocessor preprocessor(settings, errorlogger);
if (inlineSuppression)
preprocessor.inlineSuppressions(tokens, *inlineSuppression);
tokens.removeComments();
Expand All @@ -155,10 +156,6 @@ std::map<std::string, std::string> PreprocessorHelper::getcode(Preprocessor &pre
}
}

// Since "files" is a local variable the tracking info must be cleared..
preprocessor.mMacroUsage.clear();
preprocessor.mIfCond.clear();

return cfgcode;
}

Expand Down
6 changes: 3 additions & 3 deletions test/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ class PreprocessorHelper
* @param filename name of source file
* @param inlineSuppression the inline suppressions
*/
static std::string getcode(Preprocessor &preprocessor, const std::string &filedata, const std::string &cfg, const std::string &filename, SuppressionList *inlineSuppression = nullptr);
static std::map<std::string, std::string> getcode(Preprocessor &preprocessor, const char code[], const std::string &filename = "file.c", SuppressionList *inlineSuppression = nullptr);
static std::string getcode(const Settings& settings, ErrorLogger& errorlogger, const std::string &filedata, const std::string &cfg, const std::string &filename, SuppressionList *inlineSuppression = nullptr);
static std::map<std::string, std::string> getcode(const Settings& settings, ErrorLogger& errorlogger, const char code[], const std::string &filename = "file.c", SuppressionList *inlineSuppression = nullptr);

static void preprocess(const char code[], std::vector<std::string> &files, Tokenizer& tokenizer, ErrorLogger& errorlogger);
static void preprocess(const char code[], std::vector<std::string> &files, Tokenizer& tokenizer, ErrorLogger& errorlogger, const simplecpp::DUI& dui);

private:
static std::map<std::string, std::string> getcode(Preprocessor &preprocessor, const char code[], std::set<std::string> cfgs, const std::string &filename = "file.c", SuppressionList *inlineSuppression = nullptr);
static std::map<std::string, std::string> getcode(const Settings& settings, ErrorLogger& errorlogger, const char code[], std::set<std::string> cfgs, const std::string &filename = "file.c", SuppressionList *inlineSuppression = nullptr);
};

namespace cppcheck {
Expand Down
Loading

0 comments on commit 999bc80

Please sign in to comment.