@@ -2796,6 +2796,11 @@ class NonExistingFilesCache {
27962796 m_pathSet.insert (path);
27972797 }
27982798
2799+ void clear () {
2800+ ScopedLock lock (m_criticalSection);
2801+ m_pathSet.clear ();
2802+ }
2803+
27992804private:
28002805 std::set<std::string> m_pathSet;
28012806 CRITICAL_SECTION m_criticalSection;
@@ -2807,22 +2812,18 @@ static NonExistingFilesCache nonExistingFilesCache;
28072812
28082813static std::string openHeader (std::ifstream &f, const std::string &path)
28092814{
2810- #ifdef SIMPLECPP_WINDOWS
28112815 std::string simplePath = simplecpp::simplifyPath (path);
2816+ #ifdef SIMPLECPP_WINDOWS
28122817 if (nonExistingFilesCache.contains (simplePath))
28132818 return " " ; // file is known not to exist, skip expensive file open call
2814-
2819+ # endif
28152820 f.open (simplePath.c_str ());
28162821 if (f.is_open ())
28172822 return simplePath;
2818- else {
2819- nonExistingFilesCache.add (simplePath);
2820- return " " ;
2821- }
2822- #else
2823- f.open (path.c_str ());
2824- return f.is_open () ? simplecpp::simplifyPath (path) : " " ;
2823+ #ifdef SIMPLECPP_WINDOWS
2824+ nonExistingFilesCache.add (simplePath);
28252825#endif
2826+ return " " ;
28262827}
28272828
28282829static std::string getRelativeFileName (const std::string &sourcefile, const std::string &header)
@@ -2864,8 +2865,6 @@ static std::string openHeader(std::ifstream &f, const simplecpp::DUI &dui, const
28642865
28652866 if (systemheader) {
28662867 ret = openHeaderIncludePath (f, dui, header);
2867- if (ret.empty ())
2868- return openHeaderRelative (f, sourcefile, header);
28692868 return ret;
28702869 }
28712870
@@ -2894,8 +2893,8 @@ static std::string getFileName(const std::map<std::string, simplecpp::TokenList
28942893 return s;
28952894 }
28962895
2897- if (filedata.find (relativeFilename ) != filedata.end ())
2898- return relativeFilename ;
2896+ if (systemheader && filedata.find (header ) != filedata.end ())
2897+ return header ;
28992898
29002899 return " " ;
29012900}
@@ -2907,6 +2906,11 @@ static bool hasFile(const std::map<std::string, simplecpp::TokenList *> &filedat
29072906
29082907std::map<std::string, simplecpp::TokenList*> simplecpp::load (const simplecpp::TokenList &rawtokens, std::vector<std::string> &filenames, const simplecpp::DUI &dui, simplecpp::OutputList *outputList)
29092908{
2909+ #ifdef SIMPLECPP_WINDOWS
2910+ if (dui.clearIncludeCache )
2911+ nonExistingFilesCache .clear ();
2912+ #endif
2913+
29102914 std::map<std::string, simplecpp::TokenList*> ret;
29112915
29122916 std::list<const Token *> filelist;
@@ -3032,6 +3036,11 @@ static std::string getTimeDefine(struct tm *timep)
30323036
30333037void simplecpp::preprocess (simplecpp::TokenList &output, const simplecpp::TokenList &rawtokens, std::vector<std::string> &files, std::map<std::string, simplecpp::TokenList *> &filedata, const simplecpp::DUI &dui, simplecpp::OutputList *outputList, std::list<simplecpp::MacroUsage> *macroUsage, std::list<simplecpp::IfCond> *ifCond)
30343038{
3039+ #ifdef SIMPLECPP_WINDOWS
3040+ if (dui.clearIncludeCache )
3041+ nonExistingFilesCache.clear ();
3042+ #endif
3043+
30353044 std::map<std::string, std::size_t > sizeOfType (rawtokens.sizeOfType );
30363045 sizeOfType.insert (std::make_pair (" char" , sizeof (char )));
30373046 sizeOfType.insert (std::make_pair (" short" , sizeof (short )));
@@ -3223,7 +3232,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
32233232
32243233 const Token * const inctok = inc2.cfront ();
32253234
3226- const bool systemheader = (inctok->op == ' <' );
3235+ const bool systemheader = (inctok->str ()[ 0 ] == ' <' );
32273236 const std::string header (realFilename (inctok->str ().substr (1U , inctok->str ().size () - 2U )));
32283237 std::string header2 = getFileName (filedata, rawtok->location .file (), header, dui, systemheader);
32293238 if (header2.empty ()) {
0 commit comments