From 99acd3145e1bd7a7bd722cf0f93fd1f6f458409e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Fri, 20 Jan 2023 15:41:32 +0100 Subject: [PATCH] bumped simplecpp to https://github.com/danmar/simplecpp/commit/9dc2c3df53ee0caf76906e596306f7ad70fc2a78 (#4726) --- externals/simplecpp/simplecpp.cpp | 37 +++++++++++++++++++------------ externals/simplecpp/simplecpp.h | 3 ++- test/testpreprocessor.cpp | 1 + 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/externals/simplecpp/simplecpp.cpp b/externals/simplecpp/simplecpp.cpp index 2b7b8b00e..95d721363 100644 --- a/externals/simplecpp/simplecpp.cpp +++ b/externals/simplecpp/simplecpp.cpp @@ -2796,6 +2796,11 @@ public: m_pathSet.insert(path); } + void clear() { + ScopedLock lock(m_criticalSection); + m_pathSet.clear(); + } + private: std::set m_pathSet; CRITICAL_SECTION m_criticalSection; @@ -2807,22 +2812,18 @@ static NonExistingFilesCache nonExistingFilesCache; static std::string openHeader(std::ifstream &f, const std::string &path) { -#ifdef SIMPLECPP_WINDOWS std::string simplePath = simplecpp::simplifyPath(path); +#ifdef SIMPLECPP_WINDOWS if (nonExistingFilesCache.contains(simplePath)) return ""; // file is known not to exist, skip expensive file open call - +#endif f.open(simplePath.c_str()); if (f.is_open()) return simplePath; - else { - nonExistingFilesCache.add(simplePath); - return ""; - } -#else - f.open(path.c_str()); - return f.is_open() ? simplecpp::simplifyPath(path) : ""; +#ifdef SIMPLECPP_WINDOWS + nonExistingFilesCache.add(simplePath); #endif + return ""; } 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 if (systemheader) { ret = openHeaderIncludePath(f, dui, header); - if (ret.empty()) - return openHeaderRelative(f, sourcefile, header); return ret; } @@ -2894,8 +2893,8 @@ static std::string getFileName(const std::map &filedat std::map simplecpp::load(const simplecpp::TokenList &rawtokens, std::vector &filenames, const simplecpp::DUI &dui, simplecpp::OutputList *outputList) { +#ifdef SIMPLECPP_WINDOWS + if (dui.clearIncludeCache) + nonExistingFilesCache .clear(); +#endif + std::map ret; std::list filelist; @@ -3032,6 +3036,11 @@ static std::string getTimeDefine(struct tm *timep) void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenList &rawtokens, std::vector &files, std::map &filedata, const simplecpp::DUI &dui, simplecpp::OutputList *outputList, std::list *macroUsage, std::list *ifCond) { +#ifdef SIMPLECPP_WINDOWS + if (dui.clearIncludeCache) + nonExistingFilesCache.clear(); +#endif + std::map sizeOfType(rawtokens.sizeOfType); sizeOfType.insert(std::make_pair("char", sizeof(char))); sizeOfType.insert(std::make_pair("short", sizeof(short))); @@ -3223,7 +3232,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL const Token * const inctok = inc2.cfront(); - const bool systemheader = (inctok->op == '<'); + const bool systemheader = (inctok->str()[0] == '<'); const std::string header(realFilename(inctok->str().substr(1U, inctok->str().size() - 2U))); std::string header2 = getFileName(filedata, rawtok->location.file(), header, dui, systemheader); if (header2.empty()) { diff --git a/externals/simplecpp/simplecpp.h b/externals/simplecpp/simplecpp.h index 24443b074..7f4b3c63e 100644 --- a/externals/simplecpp/simplecpp.h +++ b/externals/simplecpp/simplecpp.h @@ -314,12 +314,13 @@ namespace simplecpp { * On the command line these are configured by -D, -U, -I, --include, -std */ struct SIMPLECPP_LIB DUI { - DUI() {} + DUI() : clearIncludeCache(false) {} std::list defines; std::set undefined; std::list includePaths; std::list includes; std::string std; + bool clearIncludeCache; }; SIMPLECPP_LIB long long characterLiteralToLL(const std::string& str); diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index ff5613c9b..f709d33d7 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -2483,6 +2483,7 @@ private: ASSERT_EQUALS(true, Preprocessor::missingSystemIncludeFlag); ASSERT_EQUALS("[test.c:1]: (information) Include file: \"missing.h\" not found.\n" + "[test.c:2]: (information) Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.\n" "[test.c:3]: (information) Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.\n", errout.str()); Preprocessor::missingIncludeFlag = false;