|
20 | 20 | #define helpersH |
21 | 21 |
|
22 | 22 | #include "library.h" |
23 | | -#include "preprocessor.h" |
24 | 23 | #include "settings.h" |
25 | 24 | #include "standards.h" |
26 | 25 | #include "tokenize.h" |
|
37 | 36 | class Token; |
38 | 37 | class SuppressionList; |
39 | 38 | class ErrorLogger; |
40 | | -namespace simplecpp { |
41 | | - struct DUI; |
42 | | -} |
43 | 39 | namespace tinyxml2 { |
44 | 40 | class XMLDocument; |
45 | 41 | } |
@@ -69,39 +65,59 @@ class SimpleTokenizer : public Tokenizer { |
69 | 65 | } |
70 | 66 | */ |
71 | 67 |
|
72 | | - /** |
73 | | - * Tokenize code |
74 | | - * @param code The code |
75 | | - * @param cpp Indicates if the code is C++ |
76 | | - * @param configuration E.g. "A" for code where "#ifdef A" is true |
77 | | - * @return false if source code contains syntax errors |
78 | | - */ |
| 68 | + template<size_t size> |
| 69 | + bool tokenize(const char (&code)[size], |
| 70 | + const std::string& filename, |
| 71 | + const std::string &configuration = "") |
| 72 | + { |
| 73 | + std::istringstream istr(code); |
| 74 | + return tokenize(istr, filename, configuration); |
| 75 | + } |
| 76 | + |
79 | 77 | template<size_t size> |
80 | 78 | bool tokenize(const char (&code)[size], |
81 | 79 | bool cpp = true, |
82 | 80 | const std::string &configuration = "") |
83 | 81 | { |
84 | 82 | std::istringstream istr(code); |
85 | | - if (!list.createTokens(istr, cpp ? "test.cpp" : "test.c")) |
86 | | - return false; |
| 83 | + return tokenize(istr, std::string(cpp ? "test.cpp" : "test.c"), configuration); |
| 84 | + } |
87 | 85 |
|
88 | | - return simplifyTokens1(configuration); |
| 86 | + bool tokenize(const std::string& code, |
| 87 | + const std::string& filename, |
| 88 | + const std::string &configuration = "") |
| 89 | + { |
| 90 | + std::istringstream istr(code); |
| 91 | + return tokenize(istr, filename, configuration); |
89 | 92 | } |
90 | 93 |
|
91 | | - // TODO: get rid of this |
92 | 94 | bool tokenize(const std::string& code, |
93 | 95 | bool cpp = true, |
94 | 96 | const std::string &configuration = "") |
95 | 97 | { |
96 | 98 | std::istringstream istr(code); |
97 | | - if (!list.createTokens(istr, cpp ? "test.cpp" : "test.c")) |
| 99 | + return tokenize(istr, std::string(cpp ? "test.cpp" : "test.c"), configuration); |
| 100 | + } |
| 101 | + |
| 102 | +private: |
| 103 | + /** |
| 104 | + * Tokenize code |
| 105 | + * @param istr The code as stream |
| 106 | + * @param filename Indicates if the code is C++ |
| 107 | + * @param configuration E.g. "A" for code where "#ifdef A" is true |
| 108 | + * @return false if source code contains syntax errors |
| 109 | + */ |
| 110 | + bool tokenize(std::istream& istr, |
| 111 | + const std::string& filename, |
| 112 | + const std::string &configuration = "") |
| 113 | + { |
| 114 | + if (!list.createTokens(istr, filename)) |
98 | 115 | return false; |
99 | 116 |
|
100 | 117 | return simplifyTokens1(configuration); |
101 | 118 | } |
102 | 119 |
|
103 | | -private: |
104 | | - // TODO. find a better solution |
| 120 | + // TODO: find a better solution |
105 | 121 | static const Settings s_settings; |
106 | 122 | }; |
107 | 123 |
|
@@ -171,12 +187,6 @@ class PreprocessorHelper |
171 | 187 | static std::string getcode(const Settings& settings, ErrorLogger& errorlogger, const std::string &filedata, const std::string &cfg, const std::string &filename, SuppressionList *inlineSuppression = nullptr); |
172 | 188 | static std::map<std::string, std::string> getcode(const Settings& settings, ErrorLogger& errorlogger, const char code[], const std::string &filename = "file.c", SuppressionList *inlineSuppression = nullptr); |
173 | 189 |
|
174 | | - static void preprocess(const char code[], std::vector<std::string> &files, Tokenizer& tokenizer, ErrorLogger& errorlogger); |
175 | | - static void preprocess(const char code[], std::vector<std::string> &files, Tokenizer& tokenizer, ErrorLogger& errorlogger, const simplecpp::DUI& dui); |
176 | | - |
177 | | - /** get remark comments */ |
178 | | - static std::vector<RemarkComment> getRemarkComments(const char code[], ErrorLogger& errorLogger); |
179 | | - |
180 | 190 | private: |
181 | 191 | static std::map<std::string, std::string> getcode(const Settings& settings, ErrorLogger& errorlogger, const char code[], std::set<std::string> cfgs, const std::string &filename = "file.c", SuppressionList *inlineSuppression = nullptr); |
182 | 192 | }; |
@@ -246,4 +256,26 @@ struct LibraryHelper |
246 | 256 | static Library::Error loadxmldoc(Library &lib, const tinyxml2::XMLDocument& doc); |
247 | 257 | }; |
248 | 258 |
|
| 259 | +class SimpleTokenizer2 : public Tokenizer { |
| 260 | +public: |
| 261 | + template<size_t size> |
| 262 | + SimpleTokenizer2(const Settings &settings, ErrorLogger &errorlogger, const char (&code)[size], const std::string& file0) |
| 263 | + : Tokenizer{settings, errorlogger} |
| 264 | + { |
| 265 | + preprocess(code, mFiles, file0, *this, errorlogger); |
| 266 | + } |
| 267 | + |
| 268 | + // TODO: get rid of this |
| 269 | + SimpleTokenizer2(const Settings &settings, ErrorLogger &errorlogger, const char code[], const std::string& file0) |
| 270 | + : Tokenizer{settings, errorlogger} |
| 271 | + { |
| 272 | + preprocess(code, mFiles, file0, *this, errorlogger); |
| 273 | + } |
| 274 | + |
| 275 | +private: |
| 276 | + static void preprocess(const char code[], std::vector<std::string> &files, const std::string& file0, Tokenizer& tokenizer, ErrorLogger& errorlogger); |
| 277 | + |
| 278 | + std::vector<std::string> mFiles; |
| 279 | +}; |
| 280 | + |
249 | 281 | #endif // helpersH |
0 commit comments