@@ -699,17 +699,20 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
699
699
700
700
TokenString currentToken;
701
701
702
- if (cback () && cback ()->location .line == location.line && cback ()->previous && cback ()->previous ->op == ' #' && isLastLinePreprocessor () && (lastLine () == " # error" || lastLine () == " # warning" )) {
703
- char prev = ' ' ;
704
- while (stream.good () && (prev == ' \\ ' || (ch != ' \r ' && ch != ' \n ' ))) {
705
- currentToken += ch;
706
- prev = ch;
707
- ch = stream.readChar ();
702
+ if (cback () && cback ()->location .line == location.line && cback ()->previous && cback ()->previous ->op == ' #' ) {
703
+ const Token* const llTok = lastLineTok ();
704
+ if (llTok && llTok->op == ' #' && llTok->next && (llTok->next ->str () == " error" || llTok->next ->str () == " warning" )) {
705
+ char prev = ' ' ;
706
+ while (stream.good () && (prev == ' \\ ' || (ch != ' \r ' && ch != ' \n ' ))) {
707
+ currentToken += ch;
708
+ prev = ch;
709
+ ch = stream.readChar ();
710
+ }
711
+ stream.ungetChar ();
712
+ push_back (new Token (currentToken, location));
713
+ location.adjust (currentToken);
714
+ continue ;
708
715
}
709
- stream.ungetChar ();
710
- push_back (new Token (currentToken, location));
711
- location.adjust (currentToken);
712
- continue ;
713
716
}
714
717
715
718
// number or name
@@ -841,23 +844,30 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
841
844
else
842
845
back ()->setstr (prefix + s);
843
846
844
- if (newlines > 0 && isLastLinePreprocessor () && lastLine ().compare (0 ,9 ," # define " ) == 0 ) {
845
- multiline += newlines;
846
- location.adjust (s);
847
- } else {
848
- location.adjust (currentToken);
847
+ if (newlines > 0 ) {
848
+ const Token * const llTok = lastLineTok ();
849
+ if (llTok && llTok->op == ' #' && llTok->next && llTok->next ->str () == " define" && llTok->next ->next ) {
850
+ multiline += newlines;
851
+ location.adjust (s);
852
+ continue ;
853
+ }
849
854
}
855
+
856
+ location.adjust (currentToken);
850
857
continue ;
851
858
}
852
859
853
860
else {
854
861
currentToken += ch;
855
862
}
856
863
857
- if (*currentToken.begin () == ' <' && isLastLinePreprocessor () && lastLine () == " # include" ) {
858
- currentToken = readUntil (stream, location, ' <' , ' >' , outputList);
859
- if (currentToken.size () < 2U )
860
- return ;
864
+ if (*currentToken.begin () == ' <' ) {
865
+ const Token * const llTok = lastLineTok ();
866
+ if (llTok && llTok->op == ' #' && llTok->next && llTok->next ->str () == " include" ) {
867
+ currentToken = readUntil (stream, location, ' <' , ' >' , outputList);
868
+ if (currentToken.size () < 2U )
869
+ return ;
870
+ }
861
871
}
862
872
863
873
push_back (new Token (currentToken, location));
@@ -1377,7 +1387,7 @@ std::string simplecpp::TokenList::lastLine(int maxsize) const
1377
1387
return ret;
1378
1388
}
1379
1389
1380
- bool simplecpp::TokenList::isLastLinePreprocessor (int maxsize) const
1390
+ const simplecpp::Token* simplecpp:: TokenList::lastLineTok (int maxsize) const
1381
1391
{
1382
1392
const Token* prevTok = nullptr ;
1383
1393
int count = 0 ;
@@ -1387,10 +1397,16 @@ bool simplecpp::TokenList::isLastLinePreprocessor(int maxsize) const
1387
1397
if (tok->comment )
1388
1398
continue ;
1389
1399
if (++count > maxsize)
1390
- return false ;
1400
+ return nullptr ;
1391
1401
prevTok = tok;
1392
1402
}
1393
- return prevTok && prevTok->str ()[0 ] == ' #' ;
1403
+ return prevTok;
1404
+ }
1405
+
1406
+ bool simplecpp::TokenList::isLastLinePreprocessor (int maxsize) const
1407
+ {
1408
+ const Token * const prevTok = lastLineTok (maxsize);
1409
+ return prevTok && prevTok->op == ' #' ;
1394
1410
}
1395
1411
1396
1412
unsigned int simplecpp::TokenList::fileIndex (const std::string &filename)
0 commit comments