Skip to content
Open
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
51 changes: 0 additions & 51 deletions test/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@

#include <cerrno>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <fstream>
#include <list>
#include <map>
#include <stdexcept>
#include <utility>
#include <vector>
Expand All @@ -47,8 +45,6 @@

#include "xml.h"

class SuppressionList;

const Settings SimpleTokenizer::s_settings;

// TODO: better path-only usage
Expand Down Expand Up @@ -115,53 +111,6 @@ ScopedFile::~ScopedFile() {
}
}

// TODO: we should be using the actual Preprocessor implementation
std::string PreprocessorHelper::getcodeforcfg(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(settings, errorlogger, filedata.c_str(), filedata.size(), 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(const Settings& settings, ErrorLogger& errorlogger, const char* code, std::size_t size, const std::string &filename)
{
return getcode(settings, errorlogger, code, size, {}, filename, nullptr);
}

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

simplecpp::TokenList tokens(code, size, files, Path::simplifyPath(filename), &outputList);
Preprocessor preprocessor(settings, errorlogger, Path::identify(tokens.getFiles()[0], false));
if (inlineSuppression)
preprocessor.inlineSuppressions(tokens, *inlineSuppression);
preprocessor.removeComments(tokens);
preprocessor.simplifyPragmaAsm(tokens);

preprocessor.reportOutput(outputList, true);

if (Preprocessor::hasErrors(outputList))
return {};

std::map<std::string, std::string> cfgcode;
if (cfgs.empty())
cfgs = preprocessor.getConfigs(tokens);
for (const std::string & config : cfgs) {
try {
const bool writeLocations = (strstr(code, "#file") != nullptr) || (strstr(code, "#include") != nullptr);
cfgcode[config] = preprocessor.getcode(tokens, config, files, writeLocations);
} catch (const simplecpp::Output &) {
cfgcode[config] = "";
}
}

return cfgcode;
}

void SimpleTokenizer2::preprocess(const char* code, std::size_t size, std::vector<std::string> &files, const std::string& file0, Tokenizer& tokenizer, ErrorLogger& errorlogger)
{
const simplecpp::TokenList tokens1(code, size, files, file0);
Expand Down
28 changes: 0 additions & 28 deletions test/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,12 @@
#include "tokenlist.h"

#include <cstddef>
#include <map>
#include <set>
#include <stdexcept>
#include <sstream>
#include <string>
#include <vector>

class Token;
class SuppressionList;
class ErrorLogger;
namespace tinyxml2 {
class XMLDocument;
Expand Down Expand Up @@ -168,31 +165,6 @@ class ScopedFile {
const std::string mFullPath;
};

class PreprocessorHelper
{
public:
/**
* Get preprocessed code for a given configuration
*
* Note: for testing only.
*
* @param filedata file data including preprocessing 'if', 'define', etc
* @param cfg configuration to read out
* @param filename name of source file
* @param inlineSuppression the inline suppressions
*/
static std::string getcodeforcfg(const Settings& settings, ErrorLogger& errorlogger, const std::string &filedata, const std::string &cfg, const std::string &filename, SuppressionList *inlineSuppression = nullptr);
template<size_t size>
static std::map<std::string, std::string> getcode(const Settings& settings, ErrorLogger& errorlogger, const char (&code)[size], const std::string &filename = "file.c")
{
return getcode(settings, errorlogger, code, size-1, filename);
}

private:
static std::map<std::string, std::string> getcode(const Settings& settings, ErrorLogger& errorlogger, const char* code, std::size_t size, const std::string &filename);
static std::map<std::string, std::string> getcode(const Settings& settings, ErrorLogger& errorlogger, const char* code, std::size_t size, std::set<std::string> cfgs, const std::string &filename, SuppressionList *inlineSuppression);
};

namespace cppcheck {
template<typename T>
std::size_t count_all_of(const std::string& str, T sub) {
Expand Down
Loading