From c02dd5bf2360e89eafb76a4933e7ebaa2de61633 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 16 Dec 2021 21:18:05 +0100 Subject: [PATCH] bump simplecpp --- externals/simplecpp/simplecpp.cpp | 40 +++++++++++++++++++++---------- externals/simplecpp/simplecpp.h | 10 ++++++++ 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/externals/simplecpp/simplecpp.cpp b/externals/simplecpp/simplecpp.cpp index 52a82f905..852a5b892 100644 --- a/externals/simplecpp/simplecpp.cpp +++ b/externals/simplecpp/simplecpp.cpp @@ -501,14 +501,26 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen oldLastToken = cback(); const std::string lastline(lastLine()); if (lastline == "# file %str%") { + const Token *strtok = cback(); + while (strtok->comment) + strtok = strtok->previous; loc.push(location); - location.fileIndex = fileIndex(cback()->str().substr(1U, cback()->str().size() - 2U)); + location.fileIndex = fileIndex(strtok->str().substr(1U, strtok->str().size() - 2U)); location.line = 1U; } else if (lastline == "# line %num%") { - lineDirective(location.fileIndex, std::atol(cback()->str().c_str()), &location); + const Token *numtok = cback(); + while (numtok->comment) + numtok = numtok->previous; + lineDirective(location.fileIndex, std::atol(numtok->str().c_str()), &location); } else if (lastline == "# %num% %str%" || lastline == "# line %num% %str%") { - lineDirective(fileIndex(replaceAll(cback()->str().substr(1U, cback()->str().size() - 2U),"\\\\","\\")), - std::atol(cback()->previous->str().c_str()), &location); + const Token *strtok = cback(); + while (strtok->comment) + strtok = strtok->previous; + const Token *numtok = strtok->previous; + while (numtok->comment) + numtok = numtok->previous; + lineDirective(fileIndex(replaceAll(strtok->str().substr(1U, strtok->str().size() - 2U),"\\\\","\\")), + std::atol(numtok->str().c_str()), &location); } // #endfile else if (lastline == "# endfile" && !loc.empty()) { @@ -1393,10 +1405,12 @@ namespace simplecpp { }; private: /** Create new token where Token::macro is set for replaced tokens */ - Token *newMacroToken(const TokenString &str, const Location &loc, bool replaced) const { + Token *newMacroToken(const TokenString &str, const Location &loc, bool replaced, const Token *expandedFromToken=NULL) const { Token *tok = new Token(str,loc); if (replaced) tok->macro = nameTokDef->str(); + if (expandedFromToken) + tok->setExpandedFrom(expandedFromToken, this); return tok; } @@ -1614,12 +1628,12 @@ namespace simplecpp { throw invalidHashHash(tok->location, name()); TokenList new_output(files); if (!expandArg(&new_output, tok, parametertokens2)) - output->push_back(newMacroToken(tok->str(), loc, isReplaced(expandedmacros))); + output->push_back(newMacroToken(tok->str(), loc, isReplaced(expandedmacros), tok)); else if (new_output.empty()) // placemarker token output->push_back(newMacroToken("", loc, isReplaced(expandedmacros))); else for (const Token *tok2 = new_output.cfront(); tok2; tok2 = tok2->next) - output->push_back(newMacroToken(tok2->str(), loc, isReplaced(expandedmacros))); + output->push_back(newMacroToken(tok2->str(), loc, isReplaced(expandedmacros), tok2)); tok = tok->next; } else { tok = expandToken(output, loc, tok, macros, expandedmacros, parametertokens2); @@ -1710,7 +1724,7 @@ namespace simplecpp { const Token *expandToken(TokenList *output, const Location &loc, const Token *tok, const std::map ¯os, const std::set &expandedmacros, const std::vector ¶metertokens) const { // Not name.. if (!tok->name) { - output->push_back(newMacroToken(tok->str(), loc, true)); + output->push_back(newMacroToken(tok->str(), loc, true, tok)); return tok->next; } @@ -1734,14 +1748,14 @@ namespace simplecpp { return recursiveExpandToken(output, temp, loc, tok, macros, expandedmacros2, parametertokens); } if (!sameline(tok, tok->next) || tok->next->op != '(') { - output->push_back(newMacroToken(tok->str(), loc, true)); + output->push_back(newMacroToken(tok->str(), loc, true, tok)); return tok->next; } TokenList tokens(files); tokens.push_back(new Token(*tok)); const Token *tok2 = appendTokens(&tokens, loc, tok->next, macros, expandedmacros, parametertokens); if (!tok2) { - output->push_back(newMacroToken(tok->str(), loc, true)); + output->push_back(newMacroToken(tok->str(), loc, true, tok)); return tok->next; } TokenList temp(files); @@ -1779,7 +1793,7 @@ namespace simplecpp { } } - output->push_back(newMacroToken(tok->str(), loc, true)); + output->push_back(newMacroToken(tok->str(), loc, true, tok)); return tok->next; } @@ -1811,10 +1825,10 @@ namespace simplecpp { return true; for (const Token *partok = parametertokens[argnr]->next; partok != parametertokens[argnr + 1U];) { const std::map::const_iterator it = macros.find(partok->str()); - if (it != macros.end() && (partok->str() == name() || expandedmacros.find(partok->str()) == expandedmacros.end())) + if (it != macros.end() && !partok->isExpandedFrom(&it->second) && (partok->str() == name() || expandedmacros.find(partok->str()) == expandedmacros.end())) partok = it->second.expand(output, loc, partok, macros, expandedmacros); else { - output->push_back(newMacroToken(partok->str(), loc, isReplaced(expandedmacros))); + output->push_back(newMacroToken(partok->str(), loc, isReplaced(expandedmacros), partok)); output->back()->macro = partok->macro; partok = partok->next; } diff --git a/externals/simplecpp/simplecpp.h b/externals/simplecpp/simplecpp.h index 82adad40d..faeb20076 100644 --- a/externals/simplecpp/simplecpp.h +++ b/externals/simplecpp/simplecpp.h @@ -149,11 +149,21 @@ namespace simplecpp { return tok; } + void setExpandedFrom(const Token *tok, const void* m) { + mExpandedFrom = tok->mExpandedFrom; + mExpandedFrom.insert(m); + } + bool isExpandedFrom(const void* m) const { + return mExpandedFrom.find(m) != mExpandedFrom.end(); + } + void printAll() const; void printOut() const; private: TokenString string; + std::set mExpandedFrom; + // Not implemented - prevent assignment Token &operator=(const Token &tok); };