Skip to content

Commit 99acd31

Browse files
authored
bumped simplecpp to danmar/simplecpp@9dc2c3d (#4726)
1 parent a8fd5cb commit 99acd31

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

externals/simplecpp/simplecpp.cpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
27992804
private:
28002805
std::set<std::string> m_pathSet;
28012806
CRITICAL_SECTION m_criticalSection;
@@ -2807,22 +2812,18 @@ static NonExistingFilesCache nonExistingFilesCache;
28072812

28082813
static 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

28282829
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
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

29082907
std::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

30333037
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)
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()) {

externals/simplecpp/simplecpp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,13 @@ namespace simplecpp {
314314
* On the command line these are configured by -D, -U, -I, --include, -std
315315
*/
316316
struct SIMPLECPP_LIB DUI {
317-
DUI() {}
317+
DUI() : clearIncludeCache(false) {}
318318
std::list<std::string> defines;
319319
std::set<std::string> undefined;
320320
std::list<std::string> includePaths;
321321
std::list<std::string> includes;
322322
std::string std;
323+
bool clearIncludeCache;
323324
};
324325

325326
SIMPLECPP_LIB long long characterLiteralToLL(const std::string& str);

test/testpreprocessor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2483,6 +2483,7 @@ class TestPreprocessor : public TestFixture {
24832483
ASSERT_EQUALS(true, Preprocessor::missingSystemIncludeFlag);
24842484

24852485
ASSERT_EQUALS("[test.c:1]: (information) Include file: \"missing.h\" not found.\n"
2486+
"[test.c:2]: (information) Include file: <header.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.\n"
24862487
"[test.c:3]: (information) Include file: <missing2.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.\n", errout.str());
24872488

24882489
Preprocessor::missingIncludeFlag = false;

0 commit comments

Comments
 (0)