diff --git a/externals/simplecpp/simplecpp.cpp b/externals/simplecpp/simplecpp.cpp index 599ffdfe408..a471190abc0 100755 --- a/externals/simplecpp/simplecpp.cpp +++ b/externals/simplecpp/simplecpp.cpp @@ -4,8 +4,10 @@ */ #if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) -#define SIMPLECPP_WINDOWS -#define NOMINMAX +# define _WIN32_WINNT 0x0602 +# define NOMINMAX +# include +# undef ERROR #endif #include "simplecpp.h" @@ -31,36 +33,17 @@ #include #include #include -#if __cplusplus >= 201103L #ifdef SIMPLECPP_WINDOWS -#include +# include #endif #include -#endif #include #include #ifdef _WIN32 -#include -#else -#include -#endif - -#ifdef SIMPLECPP_WINDOWS -#include -#undef ERROR -#endif - -#if __cplusplus >= 201103L -#define OVERRIDE override -#define EXPLICIT explicit +# include #else -#define OVERRIDE -#define EXPLICIT -#endif - -#if (__cplusplus < 201103L) && !defined(__APPLE__) -#define nullptr NULL +# include #endif static bool isHex(const std::string &s) @@ -153,12 +136,6 @@ static unsigned long long stringToULL(const std::string &s) return ret; } -// TODO: added an undercore since this conflicts with a function of the same name in utils.h from Cppcheck source when building Cppcheck with MSBuild -static bool startsWith_(const std::string &s, const std::string &p) -{ - return (s.size() >= p.size()) && std::equal(p.begin(), p.end(), s.begin()); -} - static bool endsWith(const std::string &s, const std::string &e) { return (s.size() >= e.size()) && std::equal(e.rbegin(), e.rend(), s.rbegin()); @@ -368,22 +345,22 @@ class simplecpp::TokenList::Stream { class StdIStream : public simplecpp::TokenList::Stream { public: // cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members - EXPLICIT StdIStream(std::istream &istr) + explicit StdIStream(std::istream &istr) : istr(istr) { assert(istr.good()); init(); } - virtual int get() OVERRIDE { + virtual int get() override { return istr.get(); } - virtual int peek() OVERRIDE { + virtual int peek() override { return istr.peek(); } - virtual void unget() OVERRIDE { + virtual void unget() override { istr.unget(); } - virtual bool good() OVERRIDE { + virtual bool good() override { return istr.good(); } @@ -402,20 +379,20 @@ class StdCharBufStream : public simplecpp::TokenList::Stream { init(); } - virtual int get() OVERRIDE { + virtual int get() override { if (pos >= size) return lastStatus = EOF; return str[pos++]; } - virtual int peek() OVERRIDE { + virtual int peek() override { if (pos >= size) return lastStatus = EOF; return str[pos]; } - virtual void unget() OVERRIDE { + virtual void unget() override { --pos; } - virtual bool good() OVERRIDE { + virtual bool good() override { return lastStatus != EOF; } @@ -429,7 +406,7 @@ class StdCharBufStream : public simplecpp::TokenList::Stream { class FileStream : public simplecpp::TokenList::Stream { public: // cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members - EXPLICIT FileStream(const std::string &filename, std::vector &files) + explicit FileStream(const std::string &filename, std::vector &files) : file(fopen(filename.c_str(), "rb")) , lastCh(0) , lastStatus(0) { @@ -440,25 +417,25 @@ class FileStream : public simplecpp::TokenList::Stream { init(); } - ~FileStream() OVERRIDE { + ~FileStream() override { fclose(file); file = nullptr; } - virtual int get() OVERRIDE { + virtual int get() override { lastStatus = lastCh = fgetc(file); return lastCh; } - virtual int peek() OVERRIDE{ + virtual int peek() override { // keep lastCh intact const int ch = fgetc(file); unget_internal(ch); return ch; } - virtual void unget() OVERRIDE { + virtual void unget() override { unget_internal(lastCh); } - virtual bool good() OVERRIDE { + virtual bool good() override { return lastStatus != EOF; } @@ -519,12 +496,10 @@ simplecpp::TokenList::TokenList(const TokenList &other) : frontToken(nullptr), b *this = other; } -#if __cplusplus >= 201103L simplecpp::TokenList::TokenList(TokenList &&other) : frontToken(nullptr), backToken(nullptr), files(other.files) { *this = std::move(other); } -#endif simplecpp::TokenList::~TokenList() { @@ -543,7 +518,6 @@ simplecpp::TokenList &simplecpp::TokenList::operator=(const TokenList &other) return *this; } -#if __cplusplus >= 201103L simplecpp::TokenList &simplecpp::TokenList::operator=(TokenList &&other) { if (this != &other) { @@ -557,7 +531,6 @@ simplecpp::TokenList &simplecpp::TokenList::operator=(TokenList &&other) } return *this; } -#endif void simplecpp::TokenList::clear() { @@ -1477,15 +1450,11 @@ unsigned int simplecpp::TokenList::fileIndex(const std::string &filename) namespace simplecpp { class Macro; -#if __cplusplus >= 201103L using MacroMap = std::unordered_map; -#else - typedef std::map MacroMap; -#endif class Macro { public: - explicit Macro(std::vector &f) : nameTokDef(nullptr), valueToken(nullptr), endToken(nullptr), files(f), tokenListDefine(f), variadic(false), valueDefinedInCode_(false) {} + explicit Macro(std::vector &f) : nameTokDef(nullptr), valueToken(nullptr), endToken(nullptr), files(f), tokenListDefine(f), variadic(false), variadicOpt(false), optExpandValue(nullptr), optNoExpandValue(nullptr), valueDefinedInCode_(false) {} Macro(const Token *tok, std::vector &f) : nameTokDef(nullptr), files(f), tokenListDefine(f), valueDefinedInCode_(true) { if (sameline(tok->previousSkipComments(), tok)) @@ -1515,6 +1484,11 @@ namespace simplecpp { *this = other; } + ~Macro() { + delete optExpandValue; + delete optNoExpandValue; + } + Macro &operator=(const Macro &other) { if (this != &other) { files = other.files; @@ -1707,6 +1681,9 @@ namespace simplecpp { bool parseDefine(const Token *nametoken) { nameTokDef = nametoken; variadic = false; + variadicOpt = false; + optExpandValue = nullptr; + optNoExpandValue = nullptr; if (!nameTokDef) { valueToken = endToken = nullptr; args.clear(); @@ -1744,8 +1721,49 @@ namespace simplecpp { if (!sameline(valueToken, nameTokDef)) valueToken = nullptr; endToken = valueToken; - while (sameline(endToken, nameTokDef)) + while (sameline(endToken, nameTokDef)) { + if (variadic && endToken->str() == "__VA_OPT__") + variadicOpt = true; endToken = endToken->next; + } + + if (variadicOpt) { + TokenList expandValue(files); + TokenList noExpandValue(files); + for (const Token *tok = valueToken; tok && tok != endToken;) { + if (tok->str() == "__VA_OPT__") { + if (!sameline(tok, tok->next) || tok->next->op != '(') + throw Error(tok->location, "In definition of '" + nameTokDef->str() + "': Missing opening parenthesis for __VA_OPT__"); + tok = tok->next->next; + int par = 1; + while (tok && tok != endToken) { + if (tok->op == '(') + par++; + else if (tok->op == ')') + par--; + else if (tok->str() == "__VA_OPT__") + throw Error(tok->location, "In definition of '" + nameTokDef->str() + "': __VA_OPT__ cannot be nested"); + if (par == 0) { + tok = tok->next; + break; + } + expandValue.push_back(new Token(*tok)); + tok = tok->next; + } + if (par != 0) { + const Token *const lastTok = expandValue.back() ? expandValue.back() : valueToken->next; + throw Error(lastTok->location, "In definition of '" + nameTokDef->str() + "': Missing closing parenthesis for __VA_OPT__"); + } + } else { + expandValue.push_back(new Token(*tok)); + noExpandValue.push_back(new Token(*tok)); + tok = tok->next; + } + } + optExpandValue = new TokenList(std::move(expandValue)); + optNoExpandValue = new TokenList(std::move(noExpandValue)); + } + return true; } @@ -1900,8 +1918,22 @@ namespace simplecpp { Token * const output_end_1 = output->back(); + const Token *valueToken2; + const Token *endToken2; + + if (variadicOpt) { + if (parametertokens2.size() > args.size() && parametertokens2[args.size() - 1]->next->op != ')') + valueToken2 = optExpandValue->cfront(); + else + valueToken2 = optNoExpandValue->cfront(); + endToken2 = nullptr; + } else { + valueToken2 = valueToken; + endToken2 = endToken; + } + // expand - for (const Token *tok = valueToken; tok != endToken;) { + for (const Token *tok = valueToken2; tok != endToken2;) { if (tok->op != '#') { // A##B => AB if (sameline(tok, tok->next) && tok->next && tok->next->op == '#' && tok->next->next && tok->next->next->op == '#') { @@ -1950,7 +1982,7 @@ namespace simplecpp { } tok = tok->next; - if (tok == endToken) { + if (tok == endToken2) { output->push_back(new Token(*tok->previous)); break; } @@ -2020,24 +2052,6 @@ namespace simplecpp { // Macro parameter.. { TokenList temp(files); - if (tok->str() == "__VA_OPT__") { - if (sameline(tok, tok->next) && tok->next->str() == "(") { - tok = tok->next; - int paren = 1; - while (sameline(tok, tok->next)) { - if (tok->next->str() == "(") - ++paren; - else if (tok->next->str() == ")") - --paren; - if (paren == 0) - return tok->next->next; - tok = tok->next; - if (parametertokens.size() > args.size() && parametertokens.front()->next->str() != ")") - tok = expandToken(output, loc, tok, macros, expandedmacros, parametertokens)->previous; - } - } - throw Error(tok->location, "Missing parenthesis for __VA_OPT__(content)"); - } if (expandArg(&temp, tok, loc, macros, expandedmacros, parametertokens)) { if (tok->str() == "__VA_ARGS__" && temp.empty() && output->cback() && output->cback()->str() == "," && tok->nextSkipComments() && tok->nextSkipComments()->str() == ")") @@ -2338,6 +2352,13 @@ namespace simplecpp { /** is macro variadic? */ bool variadic; + /** does the macro expansion have __VA_OPT__? */ + bool variadicOpt; + + /** Expansion value for varadic macros with __VA_OPT__ expanded and discarded respectively */ + const TokenList *optExpandValue; + const TokenList *optNoExpandValue; + /** was the value of this macro actually defined in the code? */ bool valueDefinedInCode_; }; @@ -2379,170 +2400,6 @@ namespace simplecpp { } #ifdef SIMPLECPP_WINDOWS - -#if __cplusplus >= 201103L -using MyMutex = std::mutex; -template -using MyLock = std::lock_guard; -#else -class MyMutex { -public: - MyMutex() { - InitializeCriticalSection(&m_criticalSection); - } - - ~MyMutex() { - DeleteCriticalSection(&m_criticalSection); - } - - CRITICAL_SECTION* lock() { - return &m_criticalSection; - } -private: - CRITICAL_SECTION m_criticalSection; -}; - -template -class MyLock { -public: - explicit MyLock(T& m) - : m_mutex(m) { - EnterCriticalSection(m_mutex.lock()); - } - - ~MyLock() { - LeaveCriticalSection(m_mutex.lock()); - } - -private: - MyLock& operator=(const MyLock&); - MyLock(const MyLock&); - - T& m_mutex; -}; -#endif - -class RealFileNameMap { -public: - RealFileNameMap() {} - - bool getCacheEntry(const std::string& path, std::string& returnPath) { - MyLock lock(m_mutex); - - const std::map::iterator it = m_fileMap.find(path); - if (it != m_fileMap.end()) { - returnPath = it->second; - return true; - } - return false; - } - - void addToCache(const std::string& path, const std::string& actualPath) { - MyLock lock(m_mutex); - m_fileMap[path] = actualPath; - } - -private: - std::map m_fileMap; - MyMutex m_mutex; -}; - -static RealFileNameMap realFileNameMap; - -static bool realFileName(const std::string &f, std::string &result) -{ - // are there alpha characters in last subpath? - bool alpha = false; - for (std::string::size_type pos = 1; pos <= f.size(); ++pos) { - const unsigned char c = f[f.size() - pos]; - if (c == '/' || c == '\\') - break; - if (std::isalpha(c)) { - alpha = true; - break; - } - } - - // do not convert this path if there are no alpha characters (either pointless or cause wrong results for . and ..) - if (!alpha) - return false; - - // Lookup filename or foldername on file system - if (!realFileNameMap.getCacheEntry(f, result)) { - - WIN32_FIND_DATAA FindFileData; - -#ifdef __CYGWIN__ - const std::string fConverted = simplecpp::convertCygwinToWindowsPath(f); - const HANDLE hFind = FindFirstFileExA(fConverted.c_str(), FindExInfoBasic, &FindFileData, FindExSearchNameMatch, NULL, 0); -#else - HANDLE hFind = FindFirstFileExA(f.c_str(), FindExInfoBasic, &FindFileData, FindExSearchNameMatch, NULL, 0); -#endif - - if (INVALID_HANDLE_VALUE == hFind) - return false; - result = FindFileData.cFileName; - realFileNameMap.addToCache(f, result); - FindClose(hFind); - } - return true; -} - -static RealFileNameMap realFilePathMap; - -/** Change case in given path to match filesystem */ -static std::string realFilename(const std::string &f) -{ - std::string ret; - ret.reserve(f.size()); // this will be the final size - if (realFilePathMap.getCacheEntry(f, ret)) - return ret; - - // Current subpath - std::string subpath; - - for (std::string::size_type pos = 0; pos < f.size(); ++pos) { - const unsigned char c = f[pos]; - - // Separator.. add subpath and separator - if (c == '/' || c == '\\') { - // if subpath is empty just add separator - if (subpath.empty()) { - ret += c; - continue; - } - - const bool isDriveSpecification = - (pos == 2 && subpath.size() == 2 && std::isalpha(subpath[0]) && subpath[1] == ':'); - - // Append real filename (proper case) - std::string f2; - if (!isDriveSpecification && realFileName(f.substr(0, pos), f2)) - ret += f2; - else - ret += subpath; - - subpath.clear(); - - // Append separator - ret += c; - } else { - subpath += c; - } - } - - if (!subpath.empty()) { - std::string f2; - if (realFileName(f,f2)) - ret += f2; - else - ret += subpath; - } - - realFilePathMap.addToCache(f, ret); - return ret; -} - static bool isAbsolutePath(const std::string &path) { if (path.length() >= 3 && path[0] > 0 && std::isalpha(path[0]) && path[1] == ':' && (path[2] == '\\' || path[2] == '/')) @@ -2550,8 +2407,6 @@ static bool isAbsolutePath(const std::string &path) return path.length() > 1U && (path[0] == '/' || path[0] == '\\'); } #else -#define realFilename(f) f - static bool isAbsolutePath(const std::string &path) { return path.length() > 1U && path[0] == '/'; @@ -2629,8 +2484,7 @@ namespace simplecpp { if (unc) path = '/' + path; - // cppcheck-suppress duplicateExpressionTernary - platform-dependent implementation - return strpbrk(path.c_str(), "*?") == nullptr ? realFilename(path) : path; + return path; } } @@ -2689,37 +2543,8 @@ static bool isCpp17OrLater(const simplecpp::DUI &dui) } -static std::string currentDirectoryOSCalc() { - const std::size_t size = 4096; - char currentPath[size]; - -#ifndef _WIN32 - if (getcwd(currentPath, size) != nullptr) -#else - if (_getcwd(currentPath, size) != nullptr) -#endif - return std::string(currentPath); - - return ""; -} - -static const std::string& currentDirectory() { - static const std::string curdir = simplecpp::simplifyPath(currentDirectoryOSCalc()); - return curdir; -} - -static std::string toAbsolutePath(const std::string& path) { - if (path.empty()) { - return path;// preserve error file path that is indicated by an empty string - } - if (!isAbsolutePath(path)) { - return simplecpp::simplifyPath(currentDirectory() + "/" + path); - } - // otherwise - return simplecpp::simplifyPath(path); -} - -static std::string dirPath(const std::string& path, bool withTrailingSlash=true) { +static std::string dirPath(const std::string& path, bool withTrailingSlash=true) +{ const std::size_t lastSlash = path.find_last_of("\\/"); if (lastSlash == std::string::npos) { return ""; @@ -2727,36 +2552,6 @@ static std::string dirPath(const std::string& path, bool withTrailingSlash=true) return path.substr(0, lastSlash + (withTrailingSlash ? 1U : 0U)); } -static std::string omitPathTrailingSlash(const std::string& path) { - if (endsWith(path, "/")) { - return path.substr(0, path.size() - 1U); - } - return path; -} - -static std::string extractRelativePathFromAbsolute(const std::string& absoluteSimplifiedPath, const std::string& prefixSimplifiedAbsoluteDir = currentDirectory()) { - const std::string normalizedAbsolutePath = omitPathTrailingSlash(absoluteSimplifiedPath); - std::string currentPrefix = omitPathTrailingSlash(prefixSimplifiedAbsoluteDir); - std::string leadingParenting; - while (!startsWith_(normalizedAbsolutePath, currentPrefix)) { - leadingParenting = "../" + leadingParenting; - currentPrefix = dirPath(currentPrefix, false); - } - const std::size_t size = currentPrefix.size(); - std::string relativeFromMeetingPath = normalizedAbsolutePath.substr(size, normalizedAbsolutePath.size() - size); - if (currentPrefix.empty() && !(startsWith_(absoluteSimplifiedPath, "/") && startsWith_(prefixSimplifiedAbsoluteDir, "/"))) { - // In the case that there is no common prefix path, - // and at not both of the paths start with `/` (can happen only in Windows paths on distinct partitions), - // return the absolute simplified path as is because no relative path can match. - return absoluteSimplifiedPath; - } - if (startsWith_(relativeFromMeetingPath, "/")) { - // omit the leading slash - relativeFromMeetingPath = relativeFromMeetingPath.substr(1, relativeFromMeetingPath.size()); - } - return leadingParenting + relativeFromMeetingPath; -} - static std::string openHeader(std::ifstream &f, const simplecpp::DUI &dui, const std::string &sourcefile, const std::string &header, bool systemheader); static void simplifyHasInclude(simplecpp::TokenList &expr, const simplecpp::DUI &dui) { @@ -2801,10 +2596,8 @@ static void simplifyHasInclude(simplecpp::TokenList &expr, const simplecpp::DUI for (simplecpp::Token *headerToken = tok1->next; headerToken != tok3; headerToken = headerToken->next) header += headerToken->str(); - // cppcheck-suppress selfAssignment - platform-dependent implementation - header = realFilename(header); } else { - header = realFilename(tok1->str().substr(1U, tok1->str().size() - 2U)); + header = tok1->str().substr(1U, tok1->str().size() - 2U); } std::ifstream f; const std::string header2 = openHeader(f,dui,sourcefile,header,systemheader); @@ -3134,206 +2927,185 @@ class NonExistingFilesCache { NonExistingFilesCache() {} bool contains(const std::string& path) { - MyLock lock(m_mutex); + std::lock_guard lock(m_mutex); return (m_pathSet.find(path) != m_pathSet.end()); } void add(const std::string& path) { - MyLock lock(m_mutex); + std::lock_guard lock(m_mutex); m_pathSet.insert(path); } void clear() { - MyLock lock(m_mutex); + std::lock_guard lock(m_mutex); m_pathSet.clear(); } private: std::set m_pathSet; - MyMutex m_mutex; + std::mutex m_mutex; }; static NonExistingFilesCache nonExistingFilesCache; #endif -static std::string openHeader(std::ifstream &f, const std::string &path) +static std::string openHeaderDirect(std::ifstream &f, const std::string &path) { - std::string simplePath = simplecpp::simplifyPath(path); #ifdef SIMPLECPP_WINDOWS - if (nonExistingFilesCache.contains(simplePath)) + if (nonExistingFilesCache.contains(path)) return ""; // file is known not to exist, skip expensive file open call #endif - f.open(simplePath.c_str()); + f.open(path.c_str()); if (f.is_open()) - return simplePath; + return path; #ifdef SIMPLECPP_WINDOWS - nonExistingFilesCache.add(simplePath); + nonExistingFilesCache.add(path); #endif return ""; } -static std::string getRelativeFileName(const std::string &baseFile, const std::string &header, bool returnAbsolutePath) -{ - const std::string baseFileSimplified = simplecpp::simplifyPath(baseFile); - const std::string baseFileAbsolute = isAbsolutePath(baseFileSimplified) ? - baseFileSimplified : - simplecpp::simplifyPath(currentDirectory() + "/" + baseFileSimplified); - - const std::string headerSimplified = simplecpp::simplifyPath(header); - const std::string path = isAbsolutePath(headerSimplified) ? - headerSimplified : - simplecpp::simplifyPath(dirPath(baseFileAbsolute) + headerSimplified); - - return returnAbsolutePath ? toAbsolutePath(path) : extractRelativePathFromAbsolute(path); -} - -static std::string openHeaderRelative(std::ifstream &f, const std::string &sourcefile, const std::string &header) -{ - return openHeader(f, getRelativeFileName(sourcefile, header, isAbsolutePath(sourcefile))); -} - -// returns the simplified header path: -// * If the header path is absolute, returns it in absolute path -// * Otherwise, returns it in relative path with respect to the current directory -static std::string getIncludePathFileName(const std::string &includePath, const std::string &header) +static std::string openHeader(std::ifstream &f, const simplecpp::DUI &dui, const std::string &sourcefile, const std::string &header, bool systemheader) { - std::string simplifiedHeader = simplecpp::simplifyPath(header); + if (isAbsolutePath(header)) + return openHeaderDirect(f, simplecpp::simplifyPath(header)); - if (isAbsolutePath(simplifiedHeader)) { - return simplifiedHeader; + // prefer first to search the header relatively to source file if found, when not a system header + if (!systemheader) { + std::string path = openHeaderDirect(f, simplecpp::simplifyPath(dirPath(sourcefile) + header)); + if (!path.empty()) { + return path; + } } - std::string basePath = toAbsolutePath(includePath); - if (!basePath.empty() && basePath[basePath.size()-1U]!='/' && basePath[basePath.size()-1U]!='\\') - basePath += '/'; - const std::string absoluteSimplifiedHeaderPath = simplecpp::simplifyPath(basePath + simplifiedHeader); - // preserve absoluteness/relativieness of the including dir - return isAbsolutePath(includePath) ? absoluteSimplifiedHeaderPath : extractRelativePathFromAbsolute(absoluteSimplifiedHeaderPath); -} - -static std::string openHeaderIncludePath(std::ifstream &f, const simplecpp::DUI &dui, const std::string &header) -{ - for (std::list::const_iterator it = dui.includePaths.begin(); it != dui.includePaths.end(); ++it) { - std::string path = openHeader(f, getIncludePathFileName(*it, header)); + // search the header on the include paths (provided by the flags "-I...") + for (const auto &includePath : dui.includePaths) { + std::string path = openHeaderDirect(f, simplecpp::simplifyPath(includePath + "/" + header)); if (!path.empty()) return path; } return ""; } -static std::string openHeader(std::ifstream &f, const simplecpp::DUI &dui, const std::string &sourcefile, const std::string &header, bool systemheader) +std::pair simplecpp::FileDataCache::tryload(FileDataCache::name_map_type::iterator &name_it, const simplecpp::DUI &dui, std::vector &filenames, simplecpp::OutputList *outputList) { - if (isAbsolutePath(header)) - return openHeader(f, header); + const std::string &path = name_it->first; + FileID fileId; - // prefer first to search the header relatively to source file if found, when not a system header - if (!systemheader) { - std::string relativeHeader = openHeaderRelative(f, sourcefile, header); - if (!relativeHeader.empty()) { - return relativeHeader; - } + if (!getFileId(path, fileId)) + return {nullptr, false}; + + const auto id_it = mIdMap.find(fileId); + if (id_it != mIdMap.end()) { + name_it->second = id_it->second; + return {id_it->second, false}; } - // search the header on the include paths (provided by the flags "-I...") - return openHeaderIncludePath(f, dui, header); -} + std::ifstream f(path); + FileData *const data = new FileData {path, TokenList(f, filenames, path, outputList)}; -static std::string findPathInMapBothRelativeAndAbsolute(const std::map &filedata, const std::string& path) { - // here there are two possibilities - either we match this from absolute path or from a relative one - if (filedata.find(path) != filedata.end()) {// try first to respect the exact match - return path; - } + if (dui.removeComments) + data->tokens.removeComments(); - // otherwise - try to use the normalize to the correct representation - std::string alternativePath; - if (isAbsolutePath(path)) { - alternativePath = extractRelativePathFromAbsolute(simplecpp::simplifyPath(path)); - } else { - alternativePath = toAbsolutePath(path); - } + name_it->second = data; + mIdMap.emplace(fileId, data); + mData.emplace_back(data); - if (filedata.find(alternativePath) != filedata.end()) { - return alternativePath; - } - return ""; + return {data, true}; } -static std::string getFileIdPath(const std::map &filedata, const std::string &sourcefile, const std::string &header, const simplecpp::DUI &dui, bool systemheader) +std::pair simplecpp::FileDataCache::get(const std::string &sourcefile, const std::string &header, const simplecpp::DUI &dui, bool systemheader, std::vector &filenames, simplecpp::OutputList *outputList) { - if (filedata.empty()) { - return ""; - } if (isAbsolutePath(header)) { - const std::string simplifiedHeaderPath = simplecpp::simplifyPath(header); - const std::string match = findPathInMapBothRelativeAndAbsolute(filedata, simplifiedHeaderPath); - if (!match.empty()) { - return match; + auto ins = mNameMap.emplace(simplecpp::simplifyPath(header), nullptr); + + if (ins.second) { + const auto ret = tryload(ins.first, dui, filenames, outputList); + if (ret.first != nullptr) { + return ret; + } + } else { + return {ins.first->second, false}; } + + return {nullptr, false}; } if (!systemheader) { - const std::string relativeFilename = getRelativeFileName(sourcefile, header, true); - const std::string match = findPathInMapBothRelativeAndAbsolute(filedata, relativeFilename); - if (!match.empty()) { - return match; - } - // if the file exists but hasn't been loaded yet then we need to stop searching here or we could get a false match - std::ifstream f; - openHeader(f, relativeFilename); - if (f.is_open()) { - f.close(); - return ""; + auto ins = mNameMap.emplace(simplecpp::simplifyPath(dirPath(sourcefile) + header), nullptr); + + if (ins.second) { + const auto ret = tryload(ins.first, dui, filenames, outputList); + if (ret.first != nullptr) { + return ret; + } + } else if (ins.first->second != nullptr) { + return {ins.first->second, false}; } - } else if (filedata.find(header) != filedata.end()) { - return header;// system header that its file is already in the filedata - return that as is } - for (std::list::const_iterator it = dui.includePaths.begin(); it != dui.includePaths.end(); ++it) { - const std::string match = findPathInMapBothRelativeAndAbsolute(filedata, getIncludePathFileName(*it, header)); - if (!match.empty()) { - return match; + for (const auto &includePath : dui.includePaths) { + auto ins = mNameMap.emplace(simplecpp::simplifyPath(includePath + "/" + header), nullptr); + + if (ins.second) { + const auto ret = tryload(ins.first, dui, filenames, outputList); + if (ret.first != nullptr) { + return ret; + } + } else if (ins.first->second != nullptr) { + return {ins.first->second, false}; } } - return ""; + return {nullptr, false}; } -static bool hasFile(const std::map &filedata, const std::string &sourcefile, const std::string &header, const simplecpp::DUI &dui, bool systemheader) +bool simplecpp::FileDataCache::getFileId(const std::string &path, FileID &id) { - return !getFileIdPath(filedata, sourcefile, header, dui, systemheader).empty(); -} +#ifdef SIMPLECPP_WINDOWS + HANDLE hFile = CreateFileA(path.c_str(), 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); -static void safeInsertTokenListToMap(std::map &filedata, const std::string &header2, simplecpp::TokenList *tokens, const std::string &header, const std::string &sourcefile, bool systemheader, const char* contextDesc) -{ - const bool inserted = filedata.insert(std::make_pair(header2, tokens)).second; - if (!inserted) { - std::cerr << "error in " << contextDesc << " - attempt to add a tokenized file to the file map, but this file is already in the map! Details:" << - "header: " << header << " header2: " << header2 << " source: " << sourcefile << " systemheader: " << systemheader << std::endl; - std::abort(); - } + if (hFile == INVALID_HANDLE_VALUE) + return false; + + const BOOL ret = GetFileInformationByHandleEx(hFile, FileIdInfo, &id.fileIdInfo, sizeof(id.fileIdInfo)); + + CloseHandle(hFile); + + return ret == TRUE; +#else + struct stat statbuf; + + if (stat(path.c_str(), &statbuf) != 0) + return false; + + id.dev = statbuf.st_dev; + id.ino = statbuf.st_ino; + + return true; +#endif } -std::map simplecpp::load(const simplecpp::TokenList &rawtokens, std::vector &filenames, const simplecpp::DUI &dui, simplecpp::OutputList *outputList) +simplecpp::FileDataCache 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; + FileDataCache cache; std::list filelist; // -include files for (std::list::const_iterator it = dui.includes.begin(); it != dui.includes.end(); ++it) { - const std::string &filename = realFilename(*it); + const std::string &filename = *it; - if (ret.find(filename) != ret.end()) - continue; + const auto loadResult = cache.get("", filename, dui, false, filenames, outputList); + const bool loaded = loadResult.second; + FileData *const filedata = loadResult.first; - std::ifstream fin(filename.c_str()); - if (!fin.is_open()) { + if (filedata == nullptr) { if (outputList) { simplecpp::Output err(filenames); err.type = simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND; @@ -3343,18 +3115,17 @@ std::map simplecpp::load(const simplecpp::To } continue; } - fin.close(); - TokenList *tokenlist = new TokenList(filename, filenames, outputList); - if (!tokenlist->front()) { - delete tokenlist; + if (!loaded) + continue; + + if (!filedata->tokens.front()) continue; - } if (dui.removeComments) - tokenlist->removeComments(); - ret[filename] = tokenlist; - filelist.push_back(tokenlist->front()); + filedata->tokens.removeComments(); + + filelist.push_back(filedata->tokens.front()); } for (const Token *rawtok = rawtokens.cfront(); rawtok || !filelist.empty(); rawtok = rawtok ? rawtok->next : nullptr) { @@ -3377,25 +3148,20 @@ std::map simplecpp::load(const simplecpp::To continue; const bool systemheader = (htok->str()[0] == '<'); - const std::string header(realFilename(htok->str().substr(1U, htok->str().size() - 2U))); - if (hasFile(ret, sourcefile, header, dui, systemheader)) - continue; + const std::string header(htok->str().substr(1U, htok->str().size() - 2U)); - std::ifstream f; - const std::string header2 = openHeader(f,dui,sourcefile,header,systemheader); - if (!f.is_open()) + FileData *const filedata = cache.get(sourcefile, header, dui, systemheader, filenames, outputList).first; + if (!filedata) continue; - f.close(); - TokenList *tokens = new TokenList(header2, filenames, outputList); if (dui.removeComments) - tokens->removeComments(); - safeInsertTokenListToMap(ret, header2, tokens, header, rawtok->location.file(), systemheader, "simplecpp::load"); - if (tokens->front()) - filelist.push_back(tokens->front()); + filedata->tokens.removeComments(); + + if (filedata->tokens.front()) + filelist.push_back(filedata->tokens.front()); } - return ret; + return cache; } static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token **tok1, simplecpp::MacroMap ¯os, std::vector &files, simplecpp::OutputList *outputList) @@ -3451,7 +3217,7 @@ static std::string getTimeDefine(const struct tm *timep) return std::string("\"").append(buf).append("\""); } -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) +void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenList &rawtokens, std::vector &files, simplecpp::FileDataCache &cache, const simplecpp::DUI &dui, simplecpp::OutputList *outputList, std::list *macroUsage, std::list *ifCond) { #ifdef SIMPLECPP_WINDOWS if (dui.clearIncludeCache) @@ -3543,9 +3309,9 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL includetokenstack.push(rawtokens.cfront()); for (std::list::const_iterator it = dui.includes.begin(); it != dui.includes.end(); ++it) { - const std::map::const_iterator f = filedata.find(*it); - if (f != filedata.end()) - includetokenstack.push(f->second->cfront()); + const FileData *const filedata = cache.get("", *it, dui, false, files, outputList).first; + if (filedata != nullptr && filedata->tokens.cfront() != nullptr) + includetokenstack.push(filedata->tokens.cfront()); } std::map > maybeUsedMacros; @@ -3621,6 +3387,16 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL } output.clear(); return; + } catch (simplecpp::Macro::Error &err) { + if (outputList) { + simplecpp::Output out(files); + out.type = simplecpp::Output::SYNTAX_ERROR; + out.location = err.location; + out.msg = "Failed to parse #define, " + err.what; + outputList->push_back(out); + } + output.clear(); + return; } } else if (ifstates.top() == True && rawtok->str() == INCLUDE) { TokenList inc1(files); @@ -3666,21 +3442,9 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL const Token * const inctok = inc2.cfront(); const bool systemheader = (inctok->str()[0] == '<'); - const std::string header(realFilename(inctok->str().substr(1U, inctok->str().size() - 2U))); - std::string header2 = getFileIdPath(filedata, rawtok->location.file(), header, dui, systemheader); - if (header2.empty()) { - // try to load file.. - std::ifstream f; - header2 = openHeader(f, dui, rawtok->location.file(), header, systemheader); - if (f.is_open()) { - f.close(); - TokenList * const tokens = new TokenList(header2, files, outputList); - if (dui.removeComments) - tokens->removeComments(); - safeInsertTokenListToMap(filedata, header2, tokens, header, rawtok->location.file(), systemheader, "simplecpp::preprocess"); - } - } - if (header2.empty()) { + const std::string header(inctok->str().substr(1U, inctok->str().size() - 2U)); + const FileData *const filedata = cache.get(rawtok->location.file(), header, dui, systemheader, files, outputList).first; + if (filedata == nullptr) { if (outputList) { simplecpp::Output out(files); out.type = Output::MISSING_HEADER; @@ -3696,10 +3460,9 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL out.msg = "#include nested too deeply"; outputList->push_back(out); } - } else if (pragmaOnce.find(header2) == pragmaOnce.end()) { + } else if (pragmaOnce.find(filedata->filename) == pragmaOnce.end()) { includetokenstack.push(gotoNextLine(rawtok)); - const TokenList * const includetokens = filedata.find(header2)->second; - rawtok = includetokens ? includetokens->cfront() : nullptr; + rawtok = filedata->tokens.cfront(); continue; } } else if (rawtok->str() == IF || rawtok->str() == IFDEF || rawtok->str() == IFNDEF || rawtok->str() == ELIF) { @@ -3776,12 +3539,10 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL if (systemheader) { while ((tok = tok->next) && tok->op != '>') header += tok->str(); - // cppcheck-suppress selfAssignment - platform-dependent implementation - header = realFilename(header); if (tok && tok->op == '>') closingAngularBracket = true; } else { - header = realFilename(tok->str().substr(1U, tok->str().size() - 2U)); + header = tok->str().substr(1U, tok->str().size() - 2U); closingAngularBracket = true; } std::ifstream f; @@ -3929,11 +3690,9 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL } } -void simplecpp::cleanup(std::map &filedata) +void simplecpp::cleanup(FileDataCache &cache) { - for (std::map::iterator it = filedata.begin(); it != filedata.end(); ++it) - delete it->second; - filedata.clear(); + cache.clear(); } simplecpp::cstd_t simplecpp::getCStd(const std::string &std) @@ -4032,7 +3791,3 @@ std::string simplecpp::getCppStdString(const std::string &std) { return getCppStdString(getCppStd(std)); } - -#if (__cplusplus < 201103L) && !defined(__APPLE__) -#undef nullptr -#endif diff --git a/externals/simplecpp/simplecpp.h b/externals/simplecpp/simplecpp.h index f5c69593cb1..b69bfee4338 100755 --- a/externals/simplecpp/simplecpp.h +++ b/externals/simplecpp/simplecpp.h @@ -6,13 +6,19 @@ #ifndef simplecppH #define simplecppH +#if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) +# define SIMPLECPP_WINDOWS +#endif + #include #include #include #include #include +#include #include #include +#include #include #ifdef _WIN32 @@ -27,8 +33,10 @@ # define SIMPLECPP_LIB #endif -#if (__cplusplus < 201103L) && !defined(__APPLE__) -#define nullptr NULL +#ifdef SIMPLECPP_WINDOWS +# include +#else +# include #endif #if defined(_MSC_VER) @@ -47,6 +55,7 @@ namespace simplecpp { typedef std::string TokenString; class Macro; + class FileDataCache; /** * Location in source code @@ -214,14 +223,10 @@ namespace simplecpp { /** generates a token list from the given filename parameter */ TokenList(const std::string &filename, std::vector &filenames, OutputList *outputList = nullptr); TokenList(const TokenList &other); -#if __cplusplus >= 201103L TokenList(TokenList &&other); -#endif ~TokenList(); TokenList &operator=(const TokenList &other); -#if __cplusplus >= 201103L TokenList &operator=(TokenList &&other); -#endif void clear(); bool empty() const { @@ -349,7 +354,7 @@ namespace simplecpp { SIMPLECPP_LIB long long characterLiteralToLL(const std::string& str); - SIMPLECPP_LIB std::map load(const TokenList &rawtokens, std::vector &filenames, const DUI &dui, OutputList *outputList = nullptr); + SIMPLECPP_LIB FileDataCache load(const TokenList &rawtokens, std::vector &filenames, const DUI &dui, OutputList *outputList = nullptr); /** * Preprocess @@ -357,18 +362,18 @@ namespace simplecpp { * @param output TokenList that receives the preprocessing output * @param rawtokens Raw tokenlist for top sourcefile * @param files internal data of simplecpp - * @param filedata output from simplecpp::load() + * @param cache output from simplecpp::load() * @param dui defines, undefs, and include paths * @param outputList output: list that will receive output messages * @param macroUsage output: macro usage * @param ifCond output: #if/#elif expressions */ - SIMPLECPP_LIB void preprocess(TokenList &output, const TokenList &rawtokens, std::vector &files, std::map &filedata, const DUI &dui, OutputList *outputList = nullptr, std::list *macroUsage = nullptr, std::list *ifCond = nullptr); + SIMPLECPP_LIB void preprocess(TokenList &output, const TokenList &rawtokens, std::vector &files, FileDataCache &cache, const DUI &dui, OutputList *outputList = nullptr, std::list *macroUsage = nullptr, std::list *ifCond = nullptr); /** * Deallocate data */ - SIMPLECPP_LIB void cleanup(std::map &filedata); + SIMPLECPP_LIB void cleanup(FileDataCache &cache); /** Simplify path */ SIMPLECPP_LIB std::string simplifyPath(std::string path); @@ -389,14 +394,120 @@ namespace simplecpp { /** Returns the __cplusplus value for a given standard */ SIMPLECPP_LIB std::string getCppStdString(const std::string &std); SIMPLECPP_LIB std::string getCppStdString(cppstd_t std); + + struct SIMPLECPP_LIB FileData { + /** The canonical filename associated with this data */ + std::string filename; + /** The tokens associated with this file */ + TokenList tokens; + }; + + class SIMPLECPP_LIB FileDataCache { + public: + FileDataCache() = default; + + FileDataCache(const FileDataCache &) = delete; + FileDataCache(FileDataCache &&) = default; + + FileDataCache &operator=(const FileDataCache &) = delete; + FileDataCache &operator=(FileDataCache &&) = default; + + /** Get the cached data for a file, or load and then return it if it isn't cached. + * returns the file data and true if the file was loaded, false if it was cached. */ + std::pair get(const std::string &sourcefile, const std::string &header, const DUI &dui, bool systemheader, std::vector &filenames, OutputList *outputList); + + void insert(FileData data) { + FileData *const newdata = new FileData(std::move(data)); + + mData.emplace_back(newdata); + mNameMap.emplace(newdata->filename, newdata); + } + + void clear() { + mNameMap.clear(); + mIdMap.clear(); + mData.clear(); + } + + typedef std::vector> container_type; + typedef container_type::iterator iterator; + typedef container_type::const_iterator const_iterator; + typedef container_type::size_type size_type; + + size_type size() const { + return mData.size(); + } + iterator begin() { + return mData.begin(); + } + iterator end() { + return mData.end(); + } + const_iterator begin() const { + return mData.begin(); + } + const_iterator end() const { + return mData.end(); + } + const_iterator cbegin() const { + return mData.cbegin(); + } + const_iterator cend() const { + return mData.cend(); + } + + private: + struct FileID { +#ifdef SIMPLECPP_WINDOWS + struct { + std::uint64_t VolumeSerialNumber; + struct { + std::uint64_t IdentifierHi; + std::uint64_t IdentifierLo; + } FileId; + } fileIdInfo; + + bool operator==(const FileID &that) const noexcept { + return fileIdInfo.VolumeSerialNumber == that.fileIdInfo.VolumeSerialNumber && + fileIdInfo.FileId.IdentifierHi == that.fileIdInfo.FileId.IdentifierHi && + fileIdInfo.FileId.IdentifierLo == that.fileIdInfo.FileId.IdentifierLo; + } +#else + dev_t dev; + ino_t ino; + + bool operator==(const FileID& that) const noexcept { + return dev == that.dev && ino == that.ino; + } +#endif + struct Hasher { + std::size_t operator()(const FileID &id) const { +#ifdef SIMPLECPP_WINDOWS + return static_cast(id.fileIdInfo.FileId.IdentifierHi ^ id.fileIdInfo.FileId.IdentifierLo ^ + id.fileIdInfo.VolumeSerialNumber); +#else + return static_cast(id.dev) ^ static_cast(id.ino); +#endif + } + }; + }; + + using name_map_type = std::unordered_map; + using id_map_type = std::unordered_map; + + static bool getFileId(const std::string &path, FileID &id); + + std::pair tryload(name_map_type::iterator &name_it, const DUI &dui, std::vector &filenames, OutputList *outputList); + + container_type mData; + name_map_type mNameMap; + id_map_type mIdMap; + + }; } #if defined(_MSC_VER) # pragma warning(pop) #endif -#if (__cplusplus < 201103L) && !defined(__APPLE__) -#undef nullptr -#endif - #endif diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 901dc57cffe..3218bd8718d 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -72,12 +72,6 @@ Preprocessor::Preprocessor(const Settings& settings, ErrorLogger &errorLogger, S assert(mLang != Standards::Language::None); } -Preprocessor::~Preprocessor() -{ - for (const std::pair& tokenList : mTokenLists) - delete tokenList.second; -} - namespace { struct BadInlineSuppression { BadInlineSuppression(std::string file, const int line, std::string msg) : file(std::move(file)), line(line), errmsg(std::move(msg)) {} @@ -312,9 +306,8 @@ void Preprocessor::inlineSuppressions(const simplecpp::TokenList &tokens, Suppre return; std::list err; ::addInlineSuppressions(tokens, mSettings, suppressions, err); - for (auto it = mTokenLists.cbegin(); it != mTokenLists.cend(); ++it) { - if (it->second) - ::addInlineSuppressions(*it->second, mSettings, suppressions, err); + for (const auto &filedata : mFileCache) { + ::addInlineSuppressions(filedata->tokens, mSettings, suppressions, err); } for (const BadInlineSuppression &bad : err) { error(bad.file, bad.line, bad.errmsg); @@ -325,9 +318,8 @@ std::vector Preprocessor::getRemarkComments(const simplecpp::Toke { std::vector ret; addRemarkComments(tokens, ret); - for (auto it = mTokenLists.cbegin(); it != mTokenLists.cend(); ++it) { - if (it->second) - addRemarkComments(*it->second, ret); + for (const auto &filedata : mFileCache) { + addRemarkComments(filedata->tokens, ret); } return ret; } @@ -338,11 +330,12 @@ std::list Preprocessor::createDirectives(const simplecpp::TokenList & std::list directives; std::vector list; - list.reserve(1U + mTokenLists.size()); + list.reserve(1U + mFileCache.size()); list.push_back(&tokens); - for (auto it = mTokenLists.cbegin(); it != mTokenLists.cend(); ++it) { - list.push_back(it->second); - } + std::transform(mFileCache.cbegin(), mFileCache.cend(), std::back_inserter(list), + [](const std::unique_ptr &filedata) { + return &filedata->tokens; + }); for (const simplecpp::TokenList *tokenList : list) { for (const simplecpp::Token *tok = tokenList->cfront(); tok; tok = tok->next) { @@ -672,9 +665,9 @@ std::set Preprocessor::getConfigs(const simplecpp::TokenList &token ::getConfigs(tokens, defined, mSettings.userDefines, mSettings.userUndefs, ret); - for (auto it = mTokenLists.cbegin(); it != mTokenLists.cend(); ++it) { - if (!mSettings.configurationExcluded(it->first)) - ::getConfigs(*(it->second), defined, mSettings.userDefines, mSettings.userUndefs, ret); + for (const auto &filedata : mFileCache) { + if (!mSettings.configurationExcluded(filedata->filename)) + ::getConfigs(filedata->tokens, defined, mSettings.userDefines, mSettings.userUndefs, ret); } return ret; @@ -780,17 +773,16 @@ bool Preprocessor::loadFiles(const simplecpp::TokenList &rawtokens, std::vector< const simplecpp::DUI dui = createDUI(mSettings, "", mLang); simplecpp::OutputList outputList; - mTokenLists = simplecpp::load(rawtokens, files, dui, &outputList); + mFileCache = simplecpp::load(rawtokens, files, dui, &outputList); handleErrors(outputList, false); return !hasErrors(outputList); } -void Preprocessor::removeComments(simplecpp::TokenList &tokens) +void Preprocessor::removeComments(simplecpp::TokenList &tokens) const { tokens.removeComments(); - for (std::pair& tokenList : mTokenLists) { - if (tokenList.second) - tokenList.second->removeComments(); + for (const auto &filedata : mFileCache) { + filedata->tokens.removeComments(); } } @@ -822,7 +814,7 @@ simplecpp::TokenList Preprocessor::preprocess(const simplecpp::TokenList &tokens std::list macroUsage; std::list ifCond; simplecpp::TokenList tokens2(files); - simplecpp::preprocess(tokens2, tokens1, files, mTokenLists, dui, &outputList, ¯oUsage, &ifCond); + simplecpp::preprocess(tokens2, tokens1, files, mFileCache, dui, &outputList, ¯oUsage, &ifCond); mMacroUsage = std::move(macroUsage); mIfCond = std::move(ifCond); @@ -983,8 +975,8 @@ std::size_t Preprocessor::calculateHash(const simplecpp::TokenList &tokens1, con hashData += static_cast(tok->location.col); } } - for (auto it = mTokenLists.cbegin(); it != mTokenLists.cend(); ++it) { - for (const simplecpp::Token *tok = it->second->cfront(); tok; tok = tok->next) { + for (const auto &filedata : mFileCache) { + for (const simplecpp::Token *tok = filedata->tokens.cfront(); tok; tok = tok->next) { if (!tok->comment) { hashData += tok->str(); hashData += static_cast(tok->location.line); @@ -998,8 +990,8 @@ std::size_t Preprocessor::calculateHash(const simplecpp::TokenList &tokens1, con void Preprocessor::simplifyPragmaAsm(simplecpp::TokenList &tokenList) const { Preprocessor::simplifyPragmaAsmPrivate(tokenList); - for (const std::pair& list : mTokenLists) { - Preprocessor::simplifyPragmaAsmPrivate(*list.second); + for (const auto &filedata : mFileCache) { + Preprocessor::simplifyPragmaAsmPrivate(filedata->tokens); } } diff --git a/lib/preprocessor.h b/lib/preprocessor.h index 8659cc36fb7..3ab390c22bb 100644 --- a/lib/preprocessor.h +++ b/lib/preprocessor.h @@ -110,7 +110,7 @@ class CPPCHECKLIB WARN_UNUSED Preprocessor { static char macroChar; explicit Preprocessor(const Settings& settings, ErrorLogger &errorLogger, Standards::Language lang); - virtual ~Preprocessor(); + virtual ~Preprocessor() = default; void inlineSuppressions(const simplecpp::TokenList &tokens, SuppressionList &suppressions); @@ -122,7 +122,7 @@ class CPPCHECKLIB WARN_UNUSED Preprocessor { bool loadFiles(const simplecpp::TokenList &rawtokens, std::vector &files); - void removeComments(simplecpp::TokenList &tokens); + void removeComments(simplecpp::TokenList &tokens) const; static void setPlatformInfo(simplecpp::TokenList &tokens, const Settings& settings); @@ -177,7 +177,7 @@ class CPPCHECKLIB WARN_UNUSED Preprocessor { /** list of all directives met while preprocessing file */ - std::map mTokenLists; + simplecpp::FileDataCache mFileCache; /** filename for cpp/c file - useful when reporting errors */ std::string mFile0; diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 91caca5b8af..4f014d3414f 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -74,9 +74,9 @@ class TestPreprocessor : public TestFixture { // Preprocess.. simplecpp::TokenList tokens2(files); - std::map filedata; + simplecpp::FileDataCache cache; // TODO: provide and handle outputList - simplecpp::preprocess(tokens2, tokens1, files, filedata, dui); + simplecpp::preprocess(tokens2, tokens1, files, cache, dui); // Tokenizer.. tokenlist.createTokens(std::move(tokens2));