@@ -249,6 +249,7 @@ namespace simplecpp {
249249 SYNTAX_ERROR ,
250250 DIRECTIVE_AS_MACRO_PARAMETER ,
251251 PORTABILITY_BACKSLASH ,
252+ PORTABILITY_LINE_DIRECTIVE ,
252253 PORTABILITY_NO_EOF_NEWLINE ,
253254 UNHANDLED_CHAR_ERROR ,
254255 EXPLICIT_INCLUDE_NOT_FOUND ,
@@ -262,52 +263,67 @@ namespace simplecpp {
262263
263264 using OutputList = std::list<Output>;
264265
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+
265281 /* * List of tokens. */
266282 class SIMPLECPP_LIB TokenList {
267283 public:
268284 class Stream ;
269285
270286 explicit TokenList (std::vector<std::string> &filenames);
271287 /* * generates a token list from the given std::istream parameter */
272- 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 );
273289 /* * generates a token list from the given buffer */
274290 template <size_t size>
275- TokenList (const char (&data)[size], std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr)
276- : 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 )
277293 {}
278294 /* * generates a token list from the given buffer */
279295 template <size_t size>
280- TokenList (const unsigned char (&data)[size], std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr)
281- : 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 )
282298 {}
283299#if SIMPLECPP_TOKENLIST_ALLOW_PTR
284300 /* * generates a token list from the given buffer */
285- TokenList (const unsigned char * data, std::size_t size, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr)
286- : 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 )
287303 {}
288304 /* * generates a token list from the given buffer */
289- TokenList (const char * data, std::size_t size, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr)
290- : 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 )
291307 {}
292308#endif // SIMPLECPP_TOKENLIST_ALLOW_PTR
293309 /* * generates a token list from the given buffer */
294- TokenList (View data, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr)
295- : 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 )
296312 {}
297313#ifdef __cpp_lib_span
298314 /* * generates a token list from the given buffer */
299- TokenList (std::span<const char > data, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr)
300- : 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 )
301317 {}
302318
303319 /* * generates a token list from the given buffer */
304- TokenList (std::span<const unsigned char > data, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr)
305- : 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 )
306322 {}
307323#endif // __cpp_lib_span
308324
309325 /* * generates a token list from the given filename parameter */
310- 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 );
311327 TokenList (const TokenList &other);
312328 TokenList (TokenList &&other);
313329 ~TokenList ();
@@ -323,7 +339,7 @@ namespace simplecpp {
323339 void dump (bool linenrs = false ) const ;
324340 std::string stringify (bool linenrs = false ) const ;
325341
326- 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 );
327343 /* *
328344 * @throws std::overflow_error thrown on overflow or division by zero
329345 * @throws std::runtime_error thrown on invalid expressions
@@ -387,7 +403,7 @@ namespace simplecpp {
387403 const std::string& file (const Location& loc) const ;
388404
389405 private:
390- 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*/ );
391407
392408 void combineOperators ();
393409
@@ -436,21 +452,6 @@ namespace simplecpp {
436452 long long result; // condition result
437453 };
438454
439- /* *
440- * Command line preprocessor settings.
441- * On the command line these are configured by -D, -U, -I, --include, -std
442- */
443- struct SIMPLECPP_LIB DUI {
444- DUI () = default ;
445- std::list<std::string> defines;
446- std::set<std::string> undefined;
447- std::list<std::string> includePaths;
448- std::list<std::string> includes;
449- std::string std;
450- bool clearIncludeCache{};
451- bool removeComments{}; /* * remove comment tokens from included files */
452- };
453-
454455 struct SIMPLECPP_LIB FileData {
455456 /* * The canonical filename associated with this data */
456457 std::string filename;
0 commit comments