@@ -412,6 +412,23 @@ static bool isStringLiteralPrefix(const std::string &str)
412412 str == " R" || str == " uR" || str == " UR" || str == " LR" || str == " u8R" ;
413413}
414414
415+ void simplecpp::TokenList::lineDirective (unsigned int fileIndex, unsigned int line, Location *location)
416+ {
417+ if (fileIndex != location->fileIndex || line >= location->line ) {
418+ location->fileIndex = fileIndex;
419+ location->line = line;
420+ return ;
421+ }
422+
423+ if (line + 2 >= location->line ) {
424+ location->line = line;
425+ while (cback ()->op != ' #' )
426+ deleteToken (back ());
427+ deleteToken (back ());
428+ return ;
429+ }
430+ }
431+
415432void simplecpp::TokenList::readfile (std::istream &istr, const std::string &filename, OutputList *outputList)
416433{
417434 std::stack<simplecpp::Location> loc;
@@ -468,23 +485,10 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
468485 location.fileIndex = fileIndex (cback ()->str ().substr (1U , cback ()->str ().size () - 2U ));
469486 location.line = 1U ;
470487 } else if (lastline == " # line %num%" ) {
471- const Location loc1 = location;
472- location.line = std::atol (cback ()->str ().c_str ());
473- if (location.line < loc1.line )
474- location.line = loc1.line ;
475- } else if (lastline == " # line %num% %str%" ) {
476- const Location loc1 = location;
477- location.fileIndex = fileIndex (cback ()->str ().substr (1U , cback ()->str ().size () - 2U ));
478- location.line = std::atol (cback ()->previous ->str ().c_str ());
479- if (loc1.fileIndex == location.fileIndex && location.line < loc1.line )
480- location.line = loc1.line ;
481- } else if (lastline == " # %num% %str%" ) {
482- const Location loc1 = location;
483- loc.push (location);
484- location.fileIndex = fileIndex (cback ()->str ().substr (1U , cback ()->str ().size () - 2U ));
485- location.line = std::atol (cback ()->previous ->str ().c_str ());
486- if (loc1.fileIndex == location.fileIndex && location.line < loc1.line )
487- location.line = loc1.line ;
488+ lineDirective (location.fileIndex , std::atol (cback ()->str ().c_str ()), &location);
489+ } else if (lastline == " # %num% %str%" || lastline == " # line %num% %str%" ) {
490+ lineDirective (fileIndex (cback ()->str ().substr (1U , cback ()->str ().size () - 2U )),
491+ std::atol (cback ()->previous ->str ().c_str ()), &location);
488492 }
489493 // #endfile
490494 else if (lastline == " # endfile" && !loc.empty ()) {
0 commit comments