From 87b08fd405f553275d1ad408f1d010d33314ea66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 6 Nov 2016 12:29:13 +0100 Subject: [PATCH] bump simplecpp to rev a6124eec2bdab9eb6c06c87e024a94709ce6e9ee --- externals/simplecpp/simplecpp.cpp | 29 +++++++++++++++++++++++++---- externals/simplecpp/simplecpp.h | 8 ++++---- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/externals/simplecpp/simplecpp.cpp b/externals/simplecpp/simplecpp.cpp index 9068de106..63a4418f5 100644 --- a/externals/simplecpp/simplecpp.cpp +++ b/externals/simplecpp/simplecpp.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -32,6 +33,7 @@ #include #include #include +#include #if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) #include @@ -392,8 +394,14 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen loc.push(location); location.fileIndex = fileIndex(cback()->str.substr(1U, cback()->str.size() - 2U)); location.line = 1U; + } else if (lastline == "# line %num%") { + loc.push(location); + location.line = std::atol(cback()->str.c_str()); + } else if (lastline == "# line %num% %str%") { + loc.push(location); + location.fileIndex = fileIndex(cback()->str.substr(1U, cback()->str.size() - 2U)); + location.line = std::atol(cback()->previous->str.c_str()); } - // #endfile else if (lastline == "# endfile" && !loc.empty()) { location = loc.top(); @@ -870,7 +878,8 @@ std::string simplecpp::TokenList::lastLine(int maxsize) const { continue; if (!ret.empty()) ret = ' ' + ret; - ret = (tok->str[0] == '\"' ? std::string("%str%") : tok->str) + ret; + ret = (tok->str[0] == '\"' ? std::string("%str%") + : std::isdigit(static_cast(tok->str[0])) ? std::string("%num%") : tok->str) + ret; if (++count > maxsize) return ""; } @@ -1567,6 +1576,14 @@ namespace simplecpp { #ifdef SIMPLECPP_WINDOWS static bool realFileName(const std::vector &buf, std::ostream &ostr) { + // Detect root directory, see simplecpp:realFileName returns the wrong root path #45 + if ((buf.size()==2 || (buf.size()>2 && buf[2]=='\0')) + && std::isalpha(buf[0]) && buf[1]==':') + { + ostr << (char)buf[0]; + ostr << (char)buf[1]; + return true; + } WIN32_FIND_DATA FindFileData; HANDLE hFind = FindFirstFile(&buf[0], &FindFileData); if (hFind == INVALID_HANDLE_VALUE) @@ -1640,7 +1657,13 @@ void simplifySizeof(simplecpp::TokenList &expr, const std::mapstr != "sizeof") continue; simplecpp::Token *tok1 = tok->next; + if (!tok1) { + throw std::runtime_error("missed sizeof argument"); + } simplecpp::Token *tok2 = tok1->next; + if (!tok2) { + throw std::runtime_error("missed sizeof argument"); + } if (tok1->op == '(') { tok1 = tok1->next; while (tok2->op != ')') @@ -1838,8 +1861,6 @@ std::map simplecpp::load(const simplecpp::To if (!f.is_open()) continue; - ret[header2] = 0; - TokenList *tokens = new TokenList(f, fileNumbers, header2, outputList); ret[header2] = tokens; if (tokens->front()) diff --git a/externals/simplecpp/simplecpp.h b/externals/simplecpp/simplecpp.h index af9e0d077..8fe9b1b59 100644 --- a/externals/simplecpp/simplecpp.h +++ b/externals/simplecpp/simplecpp.h @@ -50,7 +50,7 @@ typedef std::string TokenString; */ class SIMPLECPP_LIB Location { public: - Location(const std::vector &f) : files(f), fileIndex(0), line(1U), col(0U) {} + explicit Location(const std::vector &f) : files(f), fileIndex(0), line(1U), col(0U) {} Location &operator=(const Location &other) { if (this != &other) { @@ -152,7 +152,7 @@ private: /** Output from preprocessor */ struct SIMPLECPP_LIB Output { - Output(const std::vector &files) : type(ERROR), location(files) {} + explicit Output(const std::vector &files) : type(ERROR), location(files) {} enum Type { ERROR, /* #error */ WARNING, /* #warning */ @@ -170,7 +170,7 @@ typedef std::list OutputList; /** List of tokens. */ class SIMPLECPP_LIB TokenList { public: - TokenList(std::vector &filenames); + explicit TokenList(std::vector &filenames); TokenList(std::istream &istr, std::vector &filenames, const std::string &filename=std::string(), OutputList *outputList = 0); TokenList(const TokenList &other); ~TokenList(); @@ -262,7 +262,7 @@ private: /** Tracking how macros are used */ struct SIMPLECPP_LIB MacroUsage { - MacroUsage(const std::vector &f) : macroLocation(f), useLocation(f) {} + explicit MacroUsage(const std::vector &f) : macroLocation(f), useLocation(f) {} std::string macroName; Location macroLocation; Location useLocation;