From d1406d51e5c52b9da405799f3df74e3f63519473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 6 Aug 2016 13:01:39 +0200 Subject: [PATCH] bump simplecpp (fixing problem with newlines in macro calls) --- externals/simplecpp/simplecpp.cpp | 35 +++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/externals/simplecpp/simplecpp.cpp b/externals/simplecpp/simplecpp.cpp index 14706b24d..5444a79a3 100644 --- a/externals/simplecpp/simplecpp.cpp +++ b/externals/simplecpp/simplecpp.cpp @@ -796,7 +796,7 @@ std::string simplecpp::TokenList::readUntil(std::istream &istr, const Location & clear(); if (outputList) { Output err(files); - err.type = Output::ERROR; + err.type = Output::SYNTAX_ERROR; err.location = location; err.msg = std::string("No pair for character (") + start + "). Can't process file. File is either invalid or unicode, which is currently not supported."; outputList->push_back(err); @@ -887,8 +887,31 @@ public: const std::map ¯os, std::vector &files) const { std::set expandedmacros; + TokenList output2(files); - rawtok = expand(&output2, rawtok->location, rawtok, macros, expandedmacros); + + if (functionLike() && rawtok->next && rawtok->next->op == '(') { + // Copy macro call to a new tokenlist with no linebreaks + const Token * const rawtok1 = rawtok; + TokenList rawtokens2(files); + rawtokens2.push_back(new Token(rawtok->str, rawtok1->location)); + rawtok = rawtok->next; + rawtokens2.push_back(new Token(rawtok->str, rawtok1->location)); + rawtok = rawtok->next; + int par = 1; + while (rawtok && par > 0) { + if (rawtok->op == '(') + ++par; + else if (rawtok->op == ')') + --par; + rawtokens2.push_back(new Token(rawtok->str, rawtok1->location)); + rawtok = rawtok->next; + } + if (expand(&output2, rawtok1->location, rawtokens2.cfront(), macros, expandedmacros)) + rawtok = rawtok1->next; + } else { + rawtok = expand(&output2, rawtok->location, rawtok, macros, expandedmacros); + } while (output2.cback() && rawtok) { unsigned int par = 0; Token* macro2tok = output2.back(); @@ -977,12 +1000,12 @@ public: /** Struct that is thrown when macro is expanded with wrong number of parameters */ struct wrongNumberOfParameters : public Error { - wrongNumberOfParameters(const Location &loc, const std::string ¯oName) : Error(loc, "Syntax error. Wrong number of parameters for macro \'" + macroName + "\'.") {} + wrongNumberOfParameters(const Location &loc, const std::string ¯oName) : Error(loc, "Wrong number of parameters for macro \'" + macroName + "\'.") {} }; /** Struct that is thrown when there is invalid ## usage */ struct invalidHashHash : public Error { - invalidHashHash(const Location &loc, const std::string ¯oName) : Error(loc, "Syntax error. Invalid ## usage when expanding \'" + macroName + "\'.") {} + invalidHashHash(const Location &loc, const std::string ¯oName) : Error(loc, "Invalid ## usage when expanding \'" + macroName + "\'.") {} }; private: /** Create new token where Token::macro is set for replaced tokens */ @@ -1885,7 +1908,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL conditionIsTrue = (evaluate(expr, sizeOfType) != 0); } catch (const std::exception &) { Output out(rawtok->location.files); - out.type = Output::ERROR; + out.type = Output::SYNTAX_ERROR; out.location = rawtok->location; out.msg = "failed to evaluate " + std::string(rawtok->str == IF ? "#if" : "#elif") + " condition"; if (outputList) @@ -1953,7 +1976,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL rawtok = macro->second.expand(&tokens, rawtok, macros, files); } catch (const simplecpp::Macro::Error &err) { Output out(err.location.files); - out.type = Output::ERROR; + out.type = Output::SYNTAX_ERROR; out.location = err.location; out.msg = err.what; if (outputList)