@@ -275,8 +275,10 @@ class simplecpp::TokenList::Stream {
275275 return ch;
276276 }
277277
278- unsigned char peekChar () {
279- auto ch = static_cast <unsigned char >(peek ());
278+ int peekChar () {
279+ int ch = peek ();
280+ if (ch == EOF)
281+ return ch;
280282
281283 // For UTF-16 encoded files the BOM is 0xfeff/0xfffe. If the
282284 // character is non-ASCII character then replace it with 0xff
@@ -285,7 +287,7 @@ class simplecpp::TokenList::Stream {
285287 const auto ch2 = static_cast <unsigned char >(peek ());
286288 unget ();
287289 const int ch16 = makeUtf16Char (ch, ch2);
288- ch = static_cast < unsigned char >((( ch16 >= 0x80 ) ? 0xff : ch16)) ;
290+ ch = ( ch16 >= 0x80 ) ? 0xff : ch16;
289291 }
290292
291293 // Handling of newlines..
@@ -598,7 +600,7 @@ std::string simplecpp::TokenList::stringify(bool linenrs) const
598600 return ret.str ();
599601}
600602
601- static bool isNameChar (unsigned char ch)
603+ static bool isNameChar (int ch)
602604{
603605 return std::isalnum (ch) || ch == ' _' || ch == ' $' ;
604606}
@@ -635,10 +637,10 @@ static bool isStringLiteralPrefix(const std::string &str)
635637 str == " R" || str == " uR" || str == " UR" || str == " LR" || str == " u8R" ;
636638}
637639
638- void simplecpp::TokenList::lineDirective (unsigned int fileIndex , unsigned int line, Location &location)
640+ void simplecpp::TokenList::lineDirective (unsigned int fileIndex_ , unsigned int line, Location &location)
639641{
640- if (fileIndex != location.fileIndex || line >= location.line ) {
641- location.fileIndex = fileIndex ;
642+ if (fileIndex_ != location.fileIndex || line >= location.line ) {
643+ location.fileIndex = fileIndex_ ;
642644 location.line = line;
643645 return ;
644646 }
@@ -771,8 +773,21 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
771773 ch = stream.readChar ();
772774 }
773775 stream.ungetChar ();
774- push_back (new Token (currentToken, location));
775- location.adjust (currentToken);
776+ std::string::size_type pos = 0 ;
777+ unsigned int spliced = 0 ;
778+ while ((pos = currentToken.find (' \\ ' , pos)) != std::string::npos) {
779+ if (pos + 1 < currentToken.size () && currentToken[pos + 1 ] == ' \n ' ) {
780+ currentToken.erase (pos, 2 );
781+ ++spliced;
782+ } else {
783+ ++pos;
784+ }
785+ }
786+ if (!currentToken.empty ()) {
787+ push_back (new Token (currentToken, location));
788+ location.adjust (currentToken);
789+ }
790+ location.line += spliced;
776791 continue ;
777792 }
778793 }
@@ -1739,6 +1754,9 @@ namespace simplecpp {
17391754 return tok;
17401755 }
17411756
1757+ /* *
1758+ * @throws Error thrown in case of __VA_OPT__ issues
1759+ */
17421760 bool parseDefine (const Token *nametoken) {
17431761 nameTokDef = nametoken;
17441762 variadic = false ;
@@ -2201,6 +2219,8 @@ namespace simplecpp {
22012219 }
22022220
22032221 output.push_back (newMacroToken (tok->str (), loc, true , tok));
2222+ if (it != macros.end ())
2223+ output.back ()->markExpandedFrom (&it->second );
22042224 return tok->next ;
22052225 }
22062226
@@ -3379,6 +3399,17 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
33793399 }
33803400 output.clear ();
33813401 return ;
3402+ } catch (const simplecpp::Macro::Error& e) {
3403+ if (outputList) {
3404+ simplecpp::Output err{
3405+ Output::DUI_ERROR,
3406+ {},
3407+ e.what
3408+ };
3409+ outputList->emplace_back (std::move (err));
3410+ }
3411+ output.clear ();
3412+ return ;
33823413 }
33833414 }
33843415
@@ -3507,14 +3538,14 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
35073538 else
35083539 it->second = macro;
35093540 }
3510- } catch (const std::runtime_error &) {
3541+ } catch (const std::runtime_error &err ) {
35113542 if (outputList) {
3512- simplecpp::Output err {
3543+ simplecpp::Output out {
35133544 Output::SYNTAX_ERROR,
35143545 rawtok->location ,
3515- " Failed to parse #define"
3546+ std::string ( " Failed to parse #define, " ) + err. what ()
35163547 };
3517- outputList->emplace_back (std::move (err ));
3548+ outputList->emplace_back (std::move (out ));
35183549 }
35193550 output.clear ();
35203551 return ;
@@ -3671,7 +3702,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
36713702 bool closingAngularBracket = false ;
36723703 if (tok) {
36733704 const std::string &sourcefile = rawtokens.file (rawtok->location );
3674- const bool systemheader = ( tok && tok ->op == ' <' ) ;
3705+ const bool systemheader = tok->op == ' <' ;
36753706 std::string header;
36763707
36773708 if (systemheader) {
0 commit comments