Skip to content

Commit

Permalink
testrunner: small PreprocessorHelper cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Apr 10, 2024
1 parent 838bb4f commit cfc88fb
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 34 deletions.
20 changes: 3 additions & 17 deletions test/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +146,10 @@ std::string PreprocessorHelper::getcode(Preprocessor &preprocessor, const std::s

void PreprocessorHelper::preprocess(const char code[], std::vector<std::string> &files, Tokenizer& tokenizer)
{
// Raw Tokens..
std::istringstream istr(code);
const simplecpp::TokenList tokens1(istr, files, files[0]);

// Preprocess..
simplecpp::TokenList tokens2(files);
std::map<std::string, simplecpp::TokenList*> filedata;
simplecpp::preprocess(tokens2, tokens1, files, filedata, simplecpp::DUI());

// Tokenizer..
tokenizer.list.createTokens(std::move(tokens2));
}

void PreprocessorHelper::preprocess(Preprocessor &preprocessor, const char code[], std::vector<std::string> &files, Tokenizer& tokenizer)
{
preprocess(preprocessor, code, files, tokenizer, simplecpp::DUI());
preprocess(code, files, tokenizer, simplecpp::DUI());
}

void PreprocessorHelper::preprocess(Preprocessor &preprocessor, const char code[], std::vector<std::string> &files, Tokenizer& tokenizer, const simplecpp::DUI& dui)
void PreprocessorHelper::preprocess(const char code[], std::vector<std::string> &files, Tokenizer& tokenizer, const simplecpp::DUI& dui)
{
std::istringstream istr(code);
const simplecpp::TokenList tokens1(istr, files, files[0]);
Expand All @@ -177,6 +162,7 @@ void PreprocessorHelper::preprocess(Preprocessor &preprocessor, const char code[
// Tokenizer..
tokenizer.list.createTokens(std::move(tokens2));

const Preprocessor preprocessor(tokenizer.getSettings());
std::list<Directive> directives = preprocessor.createDirectives(tokens1);
tokenizer.setDirectives(std::move(directives));
}
3 changes: 1 addition & 2 deletions test/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ class PreprocessorHelper
static std::string getcode(Preprocessor &preprocessor, const std::string &filedata, const std::string &cfg, const std::string &filename, SuppressionList *inlineSuppression = nullptr);

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

namespace cppcheck {
Expand Down
4 changes: 1 addition & 3 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "fixture.h"
#include "helpers.h"
#include "platform.h"
#include "preprocessor.h"
#include "settings.h"
#include "tokenize.h"

Expand Down Expand Up @@ -127,10 +126,9 @@ class TestCondition : public TestFixture {

#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
void check_(const char* file, int line, const char code[], const Settings &settings, const char* filename = "test.cpp") {
Preprocessor preprocessor(settings);
std::vector<std::string> files(1, filename);
Tokenizer tokenizer(settings, this);
PreprocessorHelper::preprocess(preprocessor, code, files, tokenizer);
PreprocessorHelper::preprocess(code, files, tokenizer);

// Tokenizer..
ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line);
Expand Down
4 changes: 1 addition & 3 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "fixture.h"
#include "helpers.h"
#include "platform.h"
#include "preprocessor.h"
#include "settings.h"
#include "standards.h"
#include "tokenize.h"
Expand Down Expand Up @@ -331,10 +330,9 @@ class TestOther : public TestFixture {
settings->standards.cpp = Standards::CPPLatest;
settings->certainty.enable(Certainty::inconclusive);

Preprocessor preprocessor(*settings);
std::vector<std::string> files(1, filename);
Tokenizer tokenizer(*settings, this);
PreprocessorHelper::preprocess(preprocessor, code, files, tokenizer);
PreprocessorHelper::preprocess(code, files, tokenizer);

// Tokenizer..
ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line);
Expand Down
3 changes: 1 addition & 2 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7674,10 +7674,9 @@ class TestTokenizer : public TestFixture {
std::string checkHdrs_(const char* file, int line, const char code[], bool checkHeadersFlag) {
const Settings settings = settingsBuilder().checkHeaders(checkHeadersFlag).build();

Preprocessor preprocessor(settings0);
std::vector<std::string> files(1, "test.cpp");
Tokenizer tokenizer(settings, this);
PreprocessorHelper::preprocess(preprocessor, code, files, tokenizer);
PreprocessorHelper::preprocess(code, files, tokenizer);

// Tokenizer..
ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line);
Expand Down
4 changes: 1 addition & 3 deletions test/testtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "fixture.h"
#include "helpers.h"
#include "platform.h"
#include "preprocessor.h"
#include "settings.h"
#include "standards.h"
#include "tokenize.h"
Expand Down Expand Up @@ -65,10 +64,9 @@ class TestType : public TestFixture {
void checkP_(const char* file, int line, const char code[], const Settings& settings, const char filename[] = "test.cpp", const simplecpp::DUI& dui = simplecpp::DUI()) {
const Settings settings1 = settingsBuilder(settings).severity(Severity::warning).severity(Severity::portability).build();

Preprocessor preprocessor(settings1);
std::vector<std::string> files(1, filename);
Tokenizer tokenizer(settings1, this);
PreprocessorHelper::preprocess(preprocessor, code, files, tokenizer, dui);
PreprocessorHelper::preprocess(code, files, tokenizer, dui);

// Tokenizer..
ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line);
Expand Down
6 changes: 2 additions & 4 deletions test/testunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,8 @@ class TestUnusedVar : public TestFixture {
#define checkStructMemberUsageP(...) checkStructMemberUsageP_(__FILE__, __LINE__, __VA_ARGS__)
void checkStructMemberUsageP_(const char* file, int line, const char code[]) {
std::vector<std::string> files(1, "test.cpp");
Preprocessor preprocessor(settings);
Tokenizer tokenizer(settings, this);
PreprocessorHelper::preprocess(preprocessor, code, files, tokenizer);
PreprocessorHelper::preprocess(code, files, tokenizer);

// Tokenizer..
ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line);
Expand All @@ -290,10 +289,9 @@ class TestUnusedVar : public TestFixture {

#define checkFunctionVariableUsageP(...) checkFunctionVariableUsageP_(__FILE__, __LINE__, __VA_ARGS__)
void checkFunctionVariableUsageP_(const char* file, int line, const char code[], const char* filename = "test.cpp") {
Preprocessor preprocessor(settings);
std::vector<std::string> files(1, filename);
Tokenizer tokenizer(settings, this);
PreprocessorHelper::preprocess(preprocessor, code, files, tokenizer);
PreprocessorHelper::preprocess(code, files, tokenizer);

// Tokenizer..
ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line);
Expand Down

0 comments on commit cfc88fb

Please sign in to comment.