Skip to content

Commit 50357c3

Browse files
authored
testrunner: fold PreprocessorHelper into TestPreprocessor (#7848)
1 parent 5bdfd9d commit 50357c3

File tree

3 files changed

+169
-194
lines changed

3 files changed

+169
-194
lines changed

test/helpers.cpp

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@
2727

2828
#include <cerrno>
2929
#include <cstdio>
30-
#include <cstring>
3130
#include <iostream>
3231
#include <fstream>
3332
#include <list>
34-
#include <map>
3533
#include <stdexcept>
3634
#include <utility>
3735
#include <vector>
@@ -47,8 +45,6 @@
4745

4846
#include "xml.h"
4947

50-
class SuppressionList;
51-
5248
const Settings SimpleTokenizer::s_settings;
5349

5450
// TODO: better path-only usage
@@ -115,53 +111,6 @@ ScopedFile::~ScopedFile() {
115111
}
116112
}
117113

118-
// TODO: we should be using the actual Preprocessor implementation
119-
std::string PreprocessorHelper::getcodeforcfg(const Settings& settings, ErrorLogger& errorlogger, const std::string &filedata, const std::string &cfg, const std::string &filename, SuppressionList *inlineSuppression)
120-
{
121-
std::map<std::string, std::string> cfgcode = getcode(settings, errorlogger, filedata.c_str(), filedata.size(), std::set<std::string>{cfg}, filename, inlineSuppression);
122-
const auto it = cfgcode.find(cfg);
123-
if (it == cfgcode.end())
124-
return "";
125-
return it->second;
126-
}
127-
128-
std::map<std::string, std::string> PreprocessorHelper::getcode(const Settings& settings, ErrorLogger& errorlogger, const char* code, std::size_t size, const std::string &filename)
129-
{
130-
return getcode(settings, errorlogger, code, size, {}, filename, nullptr);
131-
}
132-
133-
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)
134-
{
135-
simplecpp::OutputList outputList;
136-
std::vector<std::string> files;
137-
138-
simplecpp::TokenList tokens(code, size, files, Path::simplifyPath(filename), &outputList);
139-
Preprocessor preprocessor(settings, errorlogger, Path::identify(tokens.getFiles()[0], false));
140-
if (inlineSuppression)
141-
preprocessor.inlineSuppressions(tokens, *inlineSuppression);
142-
preprocessor.removeComments(tokens);
143-
preprocessor.simplifyPragmaAsm(tokens);
144-
145-
preprocessor.reportOutput(outputList, true);
146-
147-
if (Preprocessor::hasErrors(outputList))
148-
return {};
149-
150-
std::map<std::string, std::string> cfgcode;
151-
if (cfgs.empty())
152-
cfgs = preprocessor.getConfigs(tokens);
153-
for (const std::string & config : cfgs) {
154-
try {
155-
const bool writeLocations = (strstr(code, "#file") != nullptr) || (strstr(code, "#include") != nullptr);
156-
cfgcode[config] = preprocessor.getcode(tokens, config, files, writeLocations);
157-
} catch (const simplecpp::Output &) {
158-
cfgcode[config] = "";
159-
}
160-
}
161-
162-
return cfgcode;
163-
}
164-
165114
void SimpleTokenizer2::preprocess(const char* code, std::size_t size, std::vector<std::string> &files, const std::string& file0, Tokenizer& tokenizer, ErrorLogger& errorlogger)
166115
{
167116
const simplecpp::TokenList tokens1(code, size, files, file0);

test/helpers.h

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,12 @@
2727
#include "tokenlist.h"
2828

2929
#include <cstddef>
30-
#include <map>
31-
#include <set>
3230
#include <stdexcept>
3331
#include <sstream>
3432
#include <string>
3533
#include <vector>
3634

3735
class Token;
38-
class SuppressionList;
3936
class ErrorLogger;
4037
namespace tinyxml2 {
4138
class XMLDocument;
@@ -168,31 +165,6 @@ class ScopedFile {
168165
const std::string mFullPath;
169166
};
170167

171-
class PreprocessorHelper
172-
{
173-
public:
174-
/**
175-
* Get preprocessed code for a given configuration
176-
*
177-
* Note: for testing only.
178-
*
179-
* @param filedata file data including preprocessing 'if', 'define', etc
180-
* @param cfg configuration to read out
181-
* @param filename name of source file
182-
* @param inlineSuppression the inline suppressions
183-
*/
184-
static std::string getcodeforcfg(const Settings& settings, ErrorLogger& errorlogger, const std::string &filedata, const std::string &cfg, const std::string &filename, SuppressionList *inlineSuppression = nullptr);
185-
template<size_t size>
186-
static std::map<std::string, std::string> getcode(const Settings& settings, ErrorLogger& errorlogger, const char (&code)[size], const std::string &filename = "file.c")
187-
{
188-
return getcode(settings, errorlogger, code, size-1, filename);
189-
}
190-
191-
private:
192-
static std::map<std::string, std::string> getcode(const Settings& settings, ErrorLogger& errorlogger, const char* code, std::size_t size, const std::string &filename);
193-
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);
194-
};
195-
196168
namespace cppcheck {
197169
template<typename T>
198170
std::size_t count_all_of(const std::string& str, T sub) {

0 commit comments

Comments
 (0)