MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / TestPreprocessor

Class TestPreprocessor

test/testpreprocessor.cpp:48–3159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46class ErrorLogger;
47
48class TestPreprocessor : public TestFixture {
49public:
50 TestPreprocessor() : TestFixture("TestPreprocessor") {}
51
52private:
53 template<size_t size>
54 std::string expandMacros(const char (&code)[size], ErrorLogger &errorLogger) const {
55 simplecpp::OutputList outputList;
56 std::vector<std::string> files;
57 simplecpp::TokenList tokens1 = simplecpp::TokenList(code, files, "file.cpp", &outputList);
58 Preprocessor p(tokens1, settingsDefault, errorLogger, Path::identify(tokens1.getFiles()[0], false));
59 ASSERT(p.loadFiles(files));
60 simplecpp::TokenList tokens2 = p.preprocess("", files, outputList);
61 (void)p.reportOutput(outputList, true);
62 return tokens2.stringify();
63 }
64
65 template<size_t size>
66 void preprocess(const char (&code)[size], std::vector<std::string> &files, const std::string& file0, TokenList& tokenlist, const simplecpp::DUI& dui)
67 {
68 if (!files.empty())
69 throw std::runtime_error("file list not empty");
70
71 if (tokenlist.front())
72 throw std::runtime_error("token list not empty");
73
74 simplecpp::OutputList outputList;
75 const simplecpp::TokenList tokens1(code, files, file0, &outputList);
76
77 // Preprocess..
78 simplecpp::TokenList tokens2(files);
79 simplecpp::FileDataCache cache;
80 simplecpp::preprocess(tokens2, tokens1, files, cache, dui, &outputList);
81 Preprocessor preprocessor(tokens2, settingsDefault, *this, Standards::Language::C);
82 (void)preprocessor.reportOutput(outputList, true);
83
84 // Tokenizer..
85 tokenlist.createTokens(std::move(tokens2));
86 }
87
88 template<size_t size>
89 std::vector<RemarkComment> getRemarkComments(const char (&code)[size], ErrorLogger& errorLogger) const
90 {
91 std::vector<std::string> files;
92 simplecpp::TokenList tokens1(code, files, "test.cpp");
93
94 const Preprocessor preprocessor(tokens1, settingsDefault, errorLogger, Path::identify(tokens1.getFiles()[0], false));
95 return preprocessor.getRemarkComments();
96 }
97
98 static std::string getcodeforcfg(const Settings& settings, ErrorLogger& errorlogger, const char* code, std::size_t size, const std::string &cfg, const std::string &filename, SuppressionList *inlineSuppression = nullptr)
99 {
100 std::map<std::string, std::string> cfgcode = getcode(settings, errorlogger, code, size, std::set<std::string>{cfg}, filename, inlineSuppression);
101 const auto it = cfgcode.find(cfg);
102 if (it == cfgcode.end())
103 return "";
104 return it->second;
105 }

Callers

nothing calls this directly

Calls 1

buildMethod · 0.80

Tested by

no test coverage detected