@@ -648,6 +648,8 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
648648
649649 const Token *oldLastToken = nullptr ;
650650
651+ bool locationchange = false ;
652+
651653 Location location (fileIndex (filename), 1 , 1 );
652654 while (stream.good ()) {
653655 unsigned char ch = stream.readChar ();
@@ -716,6 +718,7 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
716718 if (ppTok && ppTok->str ()[0 ] == ' \" ' )
717719 location.fileIndex = fileIndex (replaceAll (ppTok->str ().substr (1U , ppTok->str ().size () - 2U )," \\\\ " ," \\ " ));
718720
721+ locationchange = true ;
719722 }
720723
721724 continue ;
@@ -934,6 +937,11 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
934937
935938 push_back (new Token (currentToken, location, !!std::isspace (stream.peekChar ())));
936939
940+ if (locationchange) {
941+ back ()->locationchange = true ;
942+ locationchange = false ;
943+ }
944+
937945 if (multiline)
938946 location.col += currentToken.size ();
939947 else
@@ -1435,7 +1443,7 @@ const simplecpp::Token* simplecpp::TokenList::lastLineTok(int maxsize) const
14351443 const Token* prevTok = nullptr ;
14361444 int count = 0 ;
14371445 for (const Token *tok = cback (); ; tok = tok->previous ) {
1438- if (!sameline (tok, cback ()))
1446+ if (!sameline (tok, cback ()) || tok-> locationchange )
14391447 break ;
14401448 if (tok->comment )
14411449 continue ;
@@ -2979,7 +2987,9 @@ static const simplecpp::Token *gotoNextLine(const simplecpp::Token *tok)
29792987{
29802988 const unsigned int line = tok->location .line ;
29812989 const unsigned int file = tok->location .fileIndex ;
2982- while (tok && tok->location .line == line && tok->location .fileIndex == file)
2990+ if (tok)
2991+ tok = tok->next ;
2992+ while (tok && tok->location .line == line && tok->location .fileIndex == file && !tok->locationchange )
29832993 tok = tok->next ;
29842994 return tok;
29852995}
0 commit comments