Skip to content

bumped simplecpp to https://github.com/danmar/simplecpp/commit/9dc2c3df53ee0caf76906e596306f7ad70fc2a78 #4726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions externals/simplecpp/simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2796,6 +2796,11 @@ class NonExistingFilesCache {
m_pathSet.insert(path);
}

void clear() {
ScopedLock lock(m_criticalSection);
m_pathSet.clear();
}

private:
std::set<std::string> m_pathSet;
CRITICAL_SECTION m_criticalSection;
Expand All @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -2894,8 +2893,8 @@ static std::string getFileName(const std::map<std::string, simplecpp::TokenList
return s;
}

if (filedata.find(relativeFilename) != filedata.end())
return relativeFilename;
if (systemheader && filedata.find(header) != filedata.end())
return header;

return "";
}
Expand All @@ -2907,6 +2906,11 @@ static bool hasFile(const std::map<std::string, simplecpp::TokenList *> &filedat

std::map<std::string, simplecpp::TokenList*> simplecpp::load(const simplecpp::TokenList &rawtokens, std::vector<std::string> &filenames, const simplecpp::DUI &dui, simplecpp::OutputList *outputList)
{
#ifdef SIMPLECPP_WINDOWS
if (dui.clearIncludeCache)
nonExistingFilesCache .clear();
#endif

std::map<std::string, simplecpp::TokenList*> ret;

std::list<const Token *> filelist;
Expand Down Expand Up @@ -3032,6 +3036,11 @@ static std::string getTimeDefine(struct tm *timep)

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)
{
#ifdef SIMPLECPP_WINDOWS
if (dui.clearIncludeCache)
nonExistingFilesCache.clear();
#endif

std::map<std::string, std::size_t> sizeOfType(rawtokens.sizeOfType);
sizeOfType.insert(std::make_pair("char", sizeof(char)));
sizeOfType.insert(std::make_pair("short", sizeof(short)));
Expand Down Expand Up @@ -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()) {
Expand Down
3 changes: 2 additions & 1 deletion externals/simplecpp/simplecpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> defines;
std::set<std::string> undefined;
std::list<std::string> includePaths;
std::list<std::string> includes;
std::string std;
bool clearIncludeCache;
};

SIMPLECPP_LIB long long characterLiteralToLL(const std::string& str);
Expand Down
1 change: 1 addition & 0 deletions test/testpreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2483,6 +2483,7 @@ class TestPreprocessor : public TestFixture {
ASSERT_EQUALS(true, Preprocessor::missingSystemIncludeFlag);

ASSERT_EQUALS("[test.c:1]: (information) Include file: \"missing.h\" not found.\n"
"[test.c:2]: (information) Include file: <header.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.\n"
"[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());

Preprocessor::missingIncludeFlag = false;
Expand Down