@@ -2796,6 +2796,11 @@ class NonExistingFilesCache {
2796
2796
m_pathSet.insert (path);
2797
2797
}
2798
2798
2799
+ void clear () {
2800
+ ScopedLock lock (m_criticalSection);
2801
+ m_pathSet.clear ();
2802
+ }
2803
+
2799
2804
private:
2800
2805
std::set<std::string> m_pathSet;
2801
2806
CRITICAL_SECTION m_criticalSection;
@@ -2807,22 +2812,18 @@ static NonExistingFilesCache nonExistingFilesCache;
2807
2812
2808
2813
static std::string openHeader (std::ifstream &f, const std::string &path)
2809
2814
{
2810
- #ifdef SIMPLECPP_WINDOWS
2811
2815
std::string simplePath = simplecpp::simplifyPath (path);
2816
+ #ifdef SIMPLECPP_WINDOWS
2812
2817
if (nonExistingFilesCache.contains (simplePath))
2813
2818
return " " ; // file is known not to exist, skip expensive file open call
2814
-
2819
+ # endif
2815
2820
f.open (simplePath.c_str ());
2816
2821
if (f.is_open ())
2817
2822
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);
2825
2825
#endif
2826
+ return " " ;
2826
2827
}
2827
2828
2828
2829
static 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
2864
2865
2865
2866
if (systemheader) {
2866
2867
ret = openHeaderIncludePath (f, dui, header);
2867
- if (ret.empty ())
2868
- return openHeaderRelative (f, sourcefile, header);
2869
2868
return ret;
2870
2869
}
2871
2870
@@ -2894,8 +2893,8 @@ static std::string getFileName(const std::map<std::string, simplecpp::TokenList
2894
2893
return s;
2895
2894
}
2896
2895
2897
- if (filedata.find (relativeFilename ) != filedata.end ())
2898
- return relativeFilename ;
2896
+ if (systemheader && filedata.find (header ) != filedata.end ())
2897
+ return header ;
2899
2898
2900
2899
return " " ;
2901
2900
}
@@ -2907,6 +2906,11 @@ static bool hasFile(const std::map<std::string, simplecpp::TokenList *> &filedat
2907
2906
2908
2907
std::map<std::string, simplecpp::TokenList*> simplecpp::load (const simplecpp::TokenList &rawtokens, std::vector<std::string> &filenames, const simplecpp::DUI &dui, simplecpp::OutputList *outputList)
2909
2908
{
2909
+ #ifdef SIMPLECPP_WINDOWS
2910
+ if (dui.clearIncludeCache )
2911
+ nonExistingFilesCache .clear ();
2912
+ #endif
2913
+
2910
2914
std::map<std::string, simplecpp::TokenList*> ret;
2911
2915
2912
2916
std::list<const Token *> filelist;
@@ -3032,6 +3036,11 @@ static std::string getTimeDefine(struct tm *timep)
3032
3036
3033
3037
void 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)
3034
3038
{
3039
+ #ifdef SIMPLECPP_WINDOWS
3040
+ if (dui.clearIncludeCache )
3041
+ nonExistingFilesCache.clear ();
3042
+ #endif
3043
+
3035
3044
std::map<std::string, std::size_t > sizeOfType (rawtokens.sizeOfType );
3036
3045
sizeOfType.insert (std::make_pair (" char" , sizeof (char )));
3037
3046
sizeOfType.insert (std::make_pair (" short" , sizeof (short )));
@@ -3223,7 +3232,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
3223
3232
3224
3233
const Token * const inctok = inc2.cfront ();
3225
3234
3226
- const bool systemheader = (inctok->op == ' <' );
3235
+ const bool systemheader = (inctok->str ()[ 0 ] == ' <' );
3227
3236
const std::string header (realFilename (inctok->str ().substr (1U , inctok->str ().size () - 2U )));
3228
3237
std::string header2 = getFileName (filedata, rawtok->location .file (), header, dui, systemheader);
3229
3238
if (header2.empty ()) {
0 commit comments