@@ -182,8 +182,6 @@ static std::string replaceAll(std::string s, const std::string& from, const std:
182182 return s;
183183}
184184
185- const std::string simplecpp::Location::emptyFileName;
186-
187185void simplecpp::Location::adjust (const std::string &str)
188186{
189187 if (strpbrk (str.c_str (), " \r\n " ) == nullptr ) {
@@ -568,7 +566,7 @@ std::string simplecpp::TokenList::stringify(bool linenrs) const
568566 bool filechg = true ;
569567 for (const Token *tok = cfront (); tok; tok = tok->next ) {
570568 if (tok->location .line < loc.line || tok->location .fileIndex != loc.fileIndex ) {
571- ret << " \n #line " << tok->location .line << " \" " << tok->location . file (files ) << " \"\n " ;
569+ ret << " \n #line " << tok->location .line << " \" " << file ( tok->location ) << " \"\n " ;
572570 loc = tok->location ;
573571 filechg = true ;
574572 }
@@ -1474,6 +1472,12 @@ unsigned int simplecpp::TokenList::fileIndex(const std::string &filename)
14741472 return files.size () - 1U ;
14751473}
14761474
1475+ const std::string& simplecpp::TokenList::file (const Location& loc) const
1476+ {
1477+ static const std::string s_emptyFileName;
1478+ return loc.fileIndex < files.size () ? files[loc.fileIndex ] : s_emptyFileName;
1479+ }
1480+
14771481
14781482namespace simplecpp {
14791483 class Macro ;
@@ -1881,7 +1885,7 @@ namespace simplecpp {
18811885 usageList.push_back (loc);
18821886
18831887 if (nameTokInst->str () == " __FILE__" ) {
1884- output.push_back (new Token (' \" ' +loc .file (output. getFiles () )+' \" ' , loc));
1888+ output.push_back (new Token (' \" ' +output .file (loc )+' \" ' , loc));
18851889 return nameTokInst->next ;
18861890 }
18871891 if (nameTokInst->str () == " __LINE__" ) {
@@ -2633,7 +2637,7 @@ static void simplifyHasInclude(simplecpp::TokenList &expr, const simplecpp::DUI
26332637 }
26342638 }
26352639
2636- const std::string &sourcefile = tok->location . file (expr. getFiles () );
2640+ const std::string &sourcefile = expr. file ( tok->location );
26372641 const bool systemheader = (tok1 && tok1->op == ' <' );
26382642 std::string header;
26392643 if (systemheader) {
@@ -3195,7 +3199,7 @@ simplecpp::FileDataCache simplecpp::load(const simplecpp::TokenList &rawtokens,
31953199 if (!rawtok || rawtok->str () != INCLUDE)
31963200 continue ;
31973201
3198- const std::string &sourcefile = rawtok->location . file (filenames );
3202+ const std::string &sourcefile = rawtokens. file ( rawtok->location );
31993203
32003204 const Token * const htok = rawtok->nextSkipComments ();
32013205 if (!sameline (rawtok, htok))
@@ -3522,7 +3526,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
35223526
35233527 const bool systemheader = (inctok->str ()[0 ] == ' <' );
35243528 const std::string header (inctok->str ().substr (1U , inctok->str ().size () - 2U ));
3525- const FileData *const filedata = cache.get (rawtok->location . file (files ), header, dui, systemheader, files, outputList).first ;
3529+ const FileData *const filedata = cache.get (rawtokens. file ( rawtok->location ), header, dui, systemheader, files, outputList).first ;
35263530 if (filedata == nullptr ) {
35273531 if (outputList) {
35283532 simplecpp::Output out = {
@@ -3615,7 +3619,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
36153619 tok = tok->next ;
36163620 bool closingAngularBracket = false ;
36173621 if (tok) {
3618- const std::string &sourcefile = rawtok->location . file (files );
3622+ const std::string &sourcefile = rawtokens. file ( rawtok->location );
36193623 const bool systemheader = (tok && tok->op == ' <' );
36203624 std::string header;
36213625
@@ -3724,7 +3728,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
37243728 macros.erase (tok->str ());
37253729 }
37263730 } else if (ifstates.top () == True && rawtok->str () == PRAGMA && rawtok->next && rawtok->next ->str () == ONCE && sameline (rawtok,rawtok->next )) {
3727- pragmaOnce.insert (rawtok->location . file (files ));
3731+ pragmaOnce.insert (rawtokens. file ( rawtok->location ));
37283732 }
37293733 if (ifstates.top () != True && rawtok->nextcond )
37303734 rawtok = rawtok->nextcond ->previous ;
0 commit comments