@@ -684,47 +684,45 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
684684 const Token * const llNextToken = llTok->next ;
685685 if (!llTok->next )
686686 continue ;
687- // #file "file.c"
688- if (llNextToken->str () == " file" &&
689- llNextToken->next &&
690- llNextToken->next ->str ()[0 ] == ' \" ' )
691- {
692- const Token *strtok = cback ();
693- while (strtok->comment )
694- strtok = strtok->previous ;
695- loc.push (location);
696- location.fileIndex = fileIndex (strtok->str ().substr (1U , strtok->str ().size () - 2U ));
697- location.line = 1U ;
698- }
699- // #3 "file.c"
700- // #line 3 "file.c"
701- else if ((llNextToken->number &&
702- llNextToken->next &&
703- llNextToken->next ->str ()[0 ] == ' \" ' ) ||
704- (llNextToken->str () == " line" &&
705- llNextToken->next &&
706- llNextToken->next ->number &&
707- llNextToken->next ->next &&
708- llNextToken->next ->next ->str ()[0 ] == ' \" ' ))
709- {
710- const Token *strtok = cback ();
711- while (strtok->comment )
712- strtok = strtok->previous ;
713- const Token *numtok = strtok->previous ;
714- while (numtok->comment )
715- numtok = numtok->previous ;
716- lineDirective (fileIndex (replaceAll (strtok->str ().substr (1U , strtok->str ().size () - 2U )," \\\\ " ," \\ " )),
717- std::atol (numtok->str ().c_str ()), &location);
718- }
719- // #line 3
720- else if (llNextToken->str () == " line" &&
721- llNextToken->next &&
722- llNextToken->next ->number )
723- {
724- const Token *numtok = cback ();
725- while (numtok->comment )
726- numtok = numtok->previous ;
727- lineDirective (location.fileIndex , std::atol (numtok->str ().c_str ()), &location);
687+ if (llNextToken->next ) {
688+ // #file "file.c"
689+ if (llNextToken->str () == " file" &&
690+ llNextToken->next ->str ()[0 ] == ' \" ' )
691+ {
692+ const Token *strtok = cback ();
693+ while (strtok->comment )
694+ strtok = strtok->previous ;
695+ loc.push (location);
696+ location.fileIndex = fileIndex (strtok->str ().substr (1U , strtok->str ().size () - 2U ));
697+ location.line = 1U ;
698+ }
699+ // #3 "file.c"
700+ // #line 3 "file.c"
701+ else if ((llNextToken->number &&
702+ llNextToken->next ->str ()[0 ] == ' \" ' ) ||
703+ (llNextToken->str () == " line" &&
704+ llNextToken->next ->number &&
705+ llNextToken->next ->next &&
706+ llNextToken->next ->next ->str ()[0 ] == ' \" ' ))
707+ {
708+ const Token *strtok = cback ();
709+ while (strtok->comment )
710+ strtok = strtok->previous ;
711+ const Token *numtok = strtok->previous ;
712+ while (numtok->comment )
713+ numtok = numtok->previous ;
714+ lineDirective (fileIndex (replaceAll (strtok->str ().substr (1U , strtok->str ().size () - 2U )," \\\\ " ," \\ " )),
715+ std::atol (numtok->str ().c_str ()), &location);
716+ }
717+ // #line 3
718+ else if (llNextToken->str () == " line" &&
719+ llNextToken->next ->number )
720+ {
721+ const Token *numtok = cback ();
722+ while (numtok->comment )
723+ numtok = numtok->previous ;
724+ lineDirective (location.fileIndex , std::atol (numtok->str ().c_str ()), &location);
725+ }
728726 }
729727 // #endfile
730728 else if (llNextToken->str () == " endfile" && !loc.empty ())
0 commit comments