6060# endif
6161#endif
6262
63+ #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 9
64+ // Hack to workaround GCC bug.
65+ // Details: https://trac.cppcheck.net/ticket/14850
66+ // seen on g++ before 10.x
67+ #define SIMPLECPP_NOEXCEPT
68+ #else
69+ #define SIMPLECPP_NOEXCEPT noexcept
70+ #endif
71+
6372namespace simplecpp {
6473 /* * C code standard */
6574 enum cstd_t : std::int8_t { CUnknown=-1 , C89 , C99 , C11 , C17 , C23 , C2Y };
@@ -238,7 +247,10 @@ namespace simplecpp {
238247 MISSING_HEADER ,
239248 INCLUDE_NESTED_TOO_DEEPLY ,
240249 SYNTAX_ERROR ,
250+ DIRECTIVE_AS_MACRO_PARAMETER ,
241251 PORTABILITY_BACKSLASH ,
252+ PORTABILITY_LINE_DIRECTIVE ,
253+ PORTABILITY_NO_EOF_NEWLINE ,
242254 UNHANDLED_CHAR_ERROR ,
243255 EXPLICIT_INCLUDE_NOT_FOUND ,
244256 FILE_NOT_FOUND ,
@@ -251,52 +263,67 @@ namespace simplecpp {
251263
252264 using OutputList = std::list<Output>;
253265
266+ /* *
267+ * Command line preprocessor settings.
268+ * On the command line these are configured by -D, -U, -I, --include, -std
269+ */
270+ struct SIMPLECPP_LIB DUI {
271+ DUI () = default ;
272+ std::list<std::string> defines;
273+ std::set<std::string> undefined;
274+ std::list<std::string> includePaths;
275+ std::list<std::string> includes;
276+ std::string std;
277+ bool clearIncludeCache{};
278+ bool removeComments{}; /* * remove comment tokens from included files */
279+ };
280+
254281 /* * List of tokens. */
255282 class SIMPLECPP_LIB TokenList {
256283 public:
257284 class Stream ;
258285
259286 explicit TokenList (std::vector<std::string> &filenames);
260287 /* * generates a token list from the given std::istream parameter */
261- TokenList (std::istream &istr, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr );
288+ TokenList (std::istream &istr, std::vector<std::string> &filenames, const std::string &filename=std::string(), const DUI &dui = {}, OutputList *outputList = nullptr );
262289 /* * generates a token list from the given buffer */
263290 template <size_t size>
264- TokenList (const char (&data)[size], std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr)
265- : TokenList(reinterpret_cast <const unsigned char *>(data), size-1, filenames, filename, outputList, 0)
291+ TokenList (const char (&data)[size], std::vector<std::string> &filenames, const std::string &filename=std::string(), const DUI &dui = {}, OutputList *outputList = nullptr )
292+ : TokenList(reinterpret_cast <const unsigned char *>(data), size-1 , filenames, filename, dui, outputList, 0 )
266293 {}
267294 /* * generates a token list from the given buffer */
268295 template <size_t size>
269- TokenList (const unsigned char (&data)[size], std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr)
270- : TokenList(data, size-1 , filenames, filename, outputList, 0 )
296+ TokenList (const unsigned char (&data)[size], std::vector<std::string> &filenames, const std::string &filename=std::string(), const DUI &dui = {}, OutputList *outputList = nullptr )
297+ : TokenList(data, size-1 , filenames, filename, dui, outputList, 0 )
271298 {}
272299#if SIMPLECPP_TOKENLIST_ALLOW_PTR
273300 /* * generates a token list from the given buffer */
274- TokenList (const unsigned char * data, std::size_t size, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr)
275- : TokenList(data, size, filenames, filename, outputList, 0 )
301+ TokenList (const unsigned char * data, std::size_t size, std::vector<std::string> &filenames, const std::string &filename=std::string(), const DUI &dui = {}, OutputList *outputList = nullptr )
302+ : TokenList(data, size, filenames, filename, dui, outputList, 0 )
276303 {}
277304 /* * generates a token list from the given buffer */
278- TokenList (const char * data, std::size_t size, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr)
279- : TokenList(reinterpret_cast <const unsigned char *>(data), size, filenames, filename, outputList, 0)
305+ TokenList (const char * data, std::size_t size, std::vector<std::string> &filenames, const std::string &filename=std::string(), const DUI &dui = {}, OutputList *outputList = nullptr )
306+ : TokenList(reinterpret_cast <const unsigned char *>(data), size, filenames, filename, dui, outputList, 0 )
280307 {}
281308#endif // SIMPLECPP_TOKENLIST_ALLOW_PTR
282309 /* * generates a token list from the given buffer */
283- TokenList (View data, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr)
284- : TokenList(reinterpret_cast <const unsigned char *>(data.data()), data.size(), filenames, filename, outputList, 0)
310+ TokenList (View data, std::vector<std::string> &filenames, const std::string &filename=std::string(), const DUI &dui = {}, OutputList *outputList = nullptr )
311+ : TokenList(reinterpret_cast <const unsigned char *>(data.data()), data.size(), filenames, filename, dui, outputList, 0 )
285312 {}
286313#ifdef __cpp_lib_span
287314 /* * generates a token list from the given buffer */
288- TokenList (std::span<const char > data, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr)
289- : TokenList(reinterpret_cast <const unsigned char *>(data.data()), data.size(), filenames, filename, outputList, 0)
315+ TokenList (std::span<const char > data, std::vector<std::string> &filenames, const std::string &filename=std::string(), const DUI &dui = {}, OutputList *outputList = nullptr )
316+ : TokenList(reinterpret_cast <const unsigned char *>(data.data()), data.size(), filenames, filename, dui, outputList, 0 )
290317 {}
291318
292319 /* * generates a token list from the given buffer */
293- TokenList (std::span<const unsigned char > data, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr)
294- : TokenList(data.data(), data.size(), filenames, filename, outputList, 0)
320+ TokenList (std::span<const unsigned char > data, std::vector<std::string> &filenames, const std::string &filename=std::string(), const DUI &dui = {}, OutputList *outputList = nullptr )
321+ : TokenList(data.data(), data.size(), filenames, filename, dui, outputList, 0 )
295322 {}
296323#endif // __cpp_lib_span
297324
298325 /* * generates a token list from the given filename parameter */
299- TokenList (const std::string &filename, std::vector<std::string> &filenames, OutputList *outputList = nullptr );
326+ TokenList (const std::string &filename, std::vector<std::string> &filenames, const DUI &dui = {}, OutputList *outputList = nullptr );
300327 TokenList (const TokenList &other);
301328 TokenList (TokenList &&other);
302329 ~TokenList ();
@@ -312,7 +339,7 @@ namespace simplecpp {
312339 void dump (bool linenrs = false ) const ;
313340 std::string stringify (bool linenrs = false ) const ;
314341
315- void readfile (Stream &stream, const std::string &filename=std::string(), OutputList *outputList = nullptr);
342+ void readfile (Stream &stream, const std::string &filename=std::string(), const DUI &dui = {}, OutputList *outputList = nullptr );
316343 /* *
317344 * @throws std::overflow_error thrown on overflow or division by zero
318345 * @throws std::runtime_error thrown on invalid expressions
@@ -376,7 +403,7 @@ namespace simplecpp {
376403 const std::string& file (const Location& loc) const ;
377404
378405 private:
379- TokenList (const unsigned char * data, std::size_t size, std::vector<std::string> &filenames, const std::string &filename, OutputList *outputList, int /* unused*/ );
406+ TokenList (const unsigned char * data, std::size_t size, std::vector<std::string> &filenames, const std::string &filename, const DUI &dui, OutputList *outputList, int /* unused*/ );
380407
381408 void combineOperators ();
382409
@@ -425,21 +452,6 @@ namespace simplecpp {
425452 long long result; // condition result
426453 };
427454
428- /* *
429- * Command line preprocessor settings.
430- * On the command line these are configured by -D, -U, -I, --include, -std
431- */
432- struct SIMPLECPP_LIB DUI {
433- DUI () = default ;
434- std::list<std::string> defines;
435- std::set<std::string> undefined;
436- std::list<std::string> includePaths;
437- std::list<std::string> includes;
438- std::string std;
439- bool clearIncludeCache{};
440- bool removeComments{}; /* * remove comment tokens from included files */
441- };
442-
443455 struct SIMPLECPP_LIB FileData {
444456 /* * The canonical filename associated with this data */
445457 std::string filename;
@@ -453,10 +465,10 @@ namespace simplecpp {
453465 ~FileDataCache ();
454466
455467 FileDataCache (const FileDataCache &) = delete ;
456- FileDataCache (FileDataCache &&) noexcept ;
468+ FileDataCache (FileDataCache &&) SIMPLECPP_NOEXCEPT ;
457469
458470 FileDataCache &operator =(const FileDataCache &) = delete ;
459- FileDataCache &operator =(FileDataCache &&) noexcept ;
471+ FileDataCache &operator =(FileDataCache &&) SIMPLECPP_NOEXCEPT ;
460472
461473 /* * Get the cached data for a file, or load and then return it if it isn't cached.
462474 * returns the file data and true if the file was loaded, false if it was cached. */
@@ -578,9 +590,15 @@ namespace simplecpp {
578590 /* * Returns the C version a given standard */
579591 SIMPLECPP_LIB cstd_t getCStd (const std::string &std);
580592
593+ /* * Returns the name of a C standard */
594+ SIMPLECPP_LIB const char *getCStdName (cstd_t std);
595+
581596 /* * Returns the C++ version a given standard */
582597 SIMPLECPP_LIB cppstd_t getCppStd (const std::string &std);
583598
599+ /* * Returns the name of a C++ standard */
600+ SIMPLECPP_LIB const char *getCppStdName (cppstd_t std);
601+
584602 /* * Returns the __STDC_VERSION__ value for a given standard */
585603 SIMPLECPP_LIB std::string getCStdString (const std::string &std);
586604 SIMPLECPP_LIB std::string getCStdString (cstd_t std);
0 commit comments