Skip to content

Commit

Permalink
Preprocessor: got rid of unused and test-only preprocess() overloads (
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave authored Apr 6, 2024
1 parent c15004e commit 1707820
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 80 deletions.
36 changes: 0 additions & 36 deletions lib/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <algorithm>
#include <array>
#include <cstddef>
#include <iterator> // back_inserter
#include <sstream>
#include <utility>

Expand Down Expand Up @@ -653,41 +652,6 @@ std::set<std::string> Preprocessor::getConfigs(const simplecpp::TokenList &token
return ret;
}


void Preprocessor::preprocess(std::istream &istr, std::map<std::string, std::string> &result, const std::string &filename, const std::list<std::string> &includePaths)
{
(void)includePaths;

simplecpp::OutputList outputList;
std::vector<std::string> files;
const simplecpp::TokenList tokens1(istr, files, filename, &outputList);

const std::set<std::string> configs = getConfigs(tokens1);

for (const std::string &c : configs) {
if (mSettings.userUndefs.find(c) == mSettings.userUndefs.end()) {
result[c] = getcode(tokens1, c, files, false);
}
}
}

void Preprocessor::preprocess(std::istream &srcCodeStream, std::string &processedFile, std::list<std::string> &resultConfigurations, const std::string &filename, const std::list<std::string> &includePaths)
{
(void)includePaths;

if (mFile0.empty())
mFile0 = filename;

simplecpp::OutputList outputList;
std::vector<std::string> files;
const simplecpp::TokenList tokens1(srcCodeStream, files, filename, &outputList);

const std::set<std::string> configs = getConfigs(tokens1);
std::copy(configs.cbegin(), configs.cend(), std::back_inserter(resultConfigurations));

processedFile = tokens1.stringify();
}

static void splitcfg(const std::string &cfg, std::list<std::string> &defines, const std::string &defaultValue)
{
for (std::string::size_type defineStartPos = 0U; defineStartPos < cfg.size();) {
Expand Down
44 changes: 3 additions & 41 deletions lib/preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ class SuppressionList;
*
*/

class CPPCHECKLIB Directive {
public:
struct CPPCHECKLIB Directive {
/** name of (possibly included) file where directive is defined */
std::string file;

Expand Down Expand Up @@ -110,38 +109,6 @@ class CPPCHECKLIB Preprocessor {

void setPlatformInfo(simplecpp::TokenList *tokens) const;

/**
* Extract the code for each configuration
* @param istr The (file/string) stream to read from.
* @param result The map that will get the results
* @param filename The name of the file to check e.g. "src/main.cpp"
* @param includePaths List of paths where include files should be searched from,
* single path can be e.g. in format "include/".
* There must be a path separator at the end. Default parameter is empty list.
* Note that if path from given filename is also extracted and that is used as
* a last include path if include file was not found from earlier paths.
*/
void preprocess(std::istream &istr, std::map<std::string, std::string> &result, const std::string &filename, const std::list<std::string> &includePaths = std::list<std::string>());

/**
* Extract the code for each configuration. Use this with getcode() to get the
* file data for each individual configuration.
*
* @param srcCodeStream The (file/string) stream to read from.
* @param processedFile Give reference to empty string as a parameter,
* function will fill processed file here. Use this also as a filedata parameter
* to getcode() if you received more than once configurations.
* @param resultConfigurations List of configurations. Pass these one by one
* to getcode() with processedFile.
* @param filename The name of the file to check e.g. "src/main.cpp"
* @param includePaths List of paths where include files should be searched from,
* single path can be e.g. in format "include/".
* There must be a path separator at the end. Default parameter is empty list.
* Note that if path from given filename is also extracted and that is used as
* a last include path if include file was not found from earlier paths.
*/
void preprocess(std::istream &srcCodeStream, std::string &processedFile, std::list<std::string> &resultConfigurations, const std::string &filename, const std::list<std::string> &includePaths);

simplecpp::TokenList preprocess(const simplecpp::TokenList &tokens1, const std::string &cfg, std::vector<std::string> &files, bool throwError = false);

std::string getcode(const simplecpp::TokenList &tokens1, const std::string &cfg, std::vector<std::string> &files, const bool writeLocations);
Expand All @@ -157,13 +124,6 @@ class CPPCHECKLIB Preprocessor {

void simplifyPragmaAsm(simplecpp::TokenList *tokenList) const;

private:

static void simplifyPragmaAsmPrivate(simplecpp::TokenList *tokenList);

public:


static void getErrorMessages(ErrorLogger *errorLogger, const Settings &settings);

/**
Expand All @@ -176,6 +136,8 @@ class CPPCHECKLIB Preprocessor {
static bool hasErrors(const simplecpp::Output &output);

private:
static void simplifyPragmaAsmPrivate(simplecpp::TokenList *tokenList);

void missingInclude(const std::string &filename, unsigned int linenr, const std::string &header, HeaderTypes headerType);
void error(const std::string &filename, unsigned int linenr, const std::string &msg);

Expand Down
7 changes: 4 additions & 3 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6830,10 +6830,11 @@ class TestTokenizer : public TestFixture {

// Preprocess file..
Preprocessor preprocessor(settings0);
std::list<std::string> configurations;
std::string filedata;
std::istringstream fin(raw_code);
preprocessor.preprocess(fin, filedata, configurations, emptyString, settings0.includePaths);
simplecpp::OutputList outputList;
std::vector<std::string> files;
const simplecpp::TokenList tokens1(fin, files, emptyString, &outputList);
const std::string filedata = tokens1.stringify();
const std::string code = PreprocessorHelper::getcode(preprocessor, filedata, emptyString, emptyString);

ASSERT_THROW(tokenizeAndStringify(code.c_str()), InternalError);
Expand Down

0 comments on commit 1707820

Please sign in to comment.