|
27 | 27 |
|
28 | 28 | #include <cerrno> |
29 | 29 | #include <cstdio> |
30 | | -#include <cstring> |
31 | 30 | #include <iostream> |
32 | 31 | #include <fstream> |
33 | 32 | #include <list> |
34 | | -#include <map> |
35 | 33 | #include <stdexcept> |
36 | 34 | #include <utility> |
37 | 35 | #include <vector> |
|
47 | 45 |
|
48 | 46 | #include "xml.h" |
49 | 47 |
|
50 | | -class SuppressionList; |
51 | | - |
52 | 48 | const Settings SimpleTokenizer::s_settings; |
53 | 49 |
|
54 | 50 | // TODO: better path-only usage |
@@ -115,53 +111,6 @@ ScopedFile::~ScopedFile() { |
115 | 111 | } |
116 | 112 | } |
117 | 113 |
|
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 | | - |
165 | 114 | void SimpleTokenizer2::preprocess(const char* code, std::size_t size, std::vector<std::string> &files, const std::string& file0, Tokenizer& tokenizer, ErrorLogger& errorlogger) |
166 | 115 | { |
167 | 116 | const simplecpp::TokenList tokens1(code, size, files, file0); |
|
0 commit comments