|
21 | 21 | #include <unordered_map> |
22 | 22 | #include <vector> |
23 | 23 |
|
| 24 | +#if (__cplusplus >= 201703L) && (__cplusplus < 202002L) |
| 25 | +#include <string_view> |
| 26 | +#endif |
| 27 | +#if __cplusplus >= 202002L |
| 28 | +#include <span> |
| 29 | +#endif |
| 30 | + |
24 | 31 | #ifdef _WIN32 |
25 | 32 | # ifdef SIMPLECPP_EXPORT |
26 | 33 | # define SIMPLECPP_LIB __declspec(dllexport) |
|
46 | 53 | # pragma warning(disable : 4244) |
47 | 54 | #endif |
48 | 55 |
|
| 56 | +// provide unsafe (i.e. raw pointer) API for TokenList |
| 57 | +// note: std::istream has an overhead compared to raw pointers |
| 58 | +#ifndef SIMPLECPP_UNSAFE_API |
| 59 | +// still provide the unsafe API for standards which lack the performant wrappers |
| 60 | +# if __cplusplus < 201703L |
| 61 | +# define SIMPLECPP_UNSAFE_API |
| 62 | +# endif |
| 63 | +#endif |
| 64 | + |
49 | 65 | namespace simplecpp { |
50 | 66 | /** C code standard */ |
51 | 67 | enum cstd_t { CUnknown=-1, C89, C99, C11, C17, C23 }; |
@@ -217,10 +233,34 @@ namespace simplecpp { |
217 | 233 | explicit TokenList(std::vector<std::string> &filenames); |
218 | 234 | /** generates a token list from the given std::istream parameter */ |
219 | 235 | TokenList(std::istream &istr, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr); |
| 236 | +#ifdef SIMPLECPP_UNSAFE_API |
220 | 237 | /** generates a token list from the given buffer */ |
221 | | - TokenList(const unsigned char* data, std::size_t size, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr); |
| 238 | + TokenList(const unsigned char* data, std::size_t size, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr) |
| 239 | + : TokenList(data, size, filenames, filename, outputList, 0) |
| 240 | + {} |
| 241 | + /** generates a token list from the given buffer */ |
| 242 | + TokenList(const char* data, std::size_t size, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr) |
| 243 | + : TokenList(reinterpret_cast<const unsigned char*>(data), size, filenames, filename, outputList, 0) |
| 244 | + {} |
| 245 | +#endif |
| 246 | +#if (__cplusplus >= 201703L) && (__cplusplus < 202002L) |
222 | 247 | /** generates a token list from the given buffer */ |
223 | | - TokenList(const char* data, std::size_t size, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr); |
| 248 | + TokenList(std::string_view data, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr) |
| 249 | + : TokenList(reinterpret_cast<const unsigned char*>(data.data()), data.size(), filenames, filename, outputList, 0) |
| 250 | + {} |
| 251 | +#endif |
| 252 | +#if __cplusplus >= 202002L |
| 253 | + /** generates a token list from the given buffer */ |
| 254 | + TokenList(std::span<char> data, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr) |
| 255 | + : TokenList(data.data(), data.size(), filenames, filename, outputList, 0) |
| 256 | + {} |
| 257 | + |
| 258 | + /** generates a token list from the given buffer */ |
| 259 | + TokenList(std::span<unsigned char> data, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr) |
| 260 | + : TokenList(data.data(), data.size(), filenames, filename, outputList, 0) |
| 261 | + {} |
| 262 | +#endif |
| 263 | + |
224 | 264 | /** generates a token list from the given filename parameter */ |
225 | 265 | TokenList(const std::string &filename, std::vector<std::string> &filenames, OutputList *outputList = nullptr); |
226 | 266 | TokenList(const TokenList &other); |
@@ -296,6 +336,8 @@ namespace simplecpp { |
296 | 336 | } |
297 | 337 |
|
298 | 338 | private: |
| 339 | + TokenList(const unsigned char* data, std::size_t size, std::vector<std::string> &filenames, const std::string &filename, OutputList *outputList, int unused); |
| 340 | + |
299 | 341 | void combineOperators(); |
300 | 342 |
|
301 | 343 | void constFoldUnaryNotPosNeg(Token *tok); |
|
0 commit comments