From 1f418c1675abab36366b8b04a4e908eefd5713d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 1 Apr 2018 09:06:13 +0200 Subject: [PATCH] bump simplecpp --- externals/simplecpp/simplecpp.cpp | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/externals/simplecpp/simplecpp.cpp b/externals/simplecpp/simplecpp.cpp index edb9f1804..da181a876 100644 --- a/externals/simplecpp/simplecpp.cpp +++ b/externals/simplecpp/simplecpp.cpp @@ -658,7 +658,26 @@ static bool isFloatSuffix(const simplecpp::Token *tok) void simplecpp::TokenList::combineOperators() { + std::stack executableScope; + executableScope.push(false); for (Token *tok = front(); tok; tok = tok->next) { + if (tok->op == '{') { + if (executableScope.top()) { + executableScope.push(true); + continue; + } + const Token *prev = tok->previous; + while (prev && prev->isOneOf(";{}()")) + prev = prev->previous; + executableScope.push(prev && prev->op == ')'); + continue; + } + if (tok->op == '}') { + if (executableScope.size() > 1) + executableScope.pop(); + continue; + } + if (tok->op == '.') { if (tok->previous && tok->previous->op == '.') continue; @@ -694,6 +713,39 @@ void simplecpp::TokenList::combineOperators() continue; if (tok->next->op == '=' && tok->isOneOf("=!<>+-*/%&|^")) { + if (tok->op == '&' && !executableScope.top()) { + // don't combine &= if it is a anonymous reference parameter with default value: + // void f(x&=2) + int indentlevel = 0; + const Token *start = tok; + while (indentlevel >= 0 && start) { + if (start->op == ')') + ++indentlevel; + else if (start->op == '(') + --indentlevel; + else if (start->isOneOf(";{}")) + break; + start = start->previous; + } + if (indentlevel == -1 && start) { + const Token *ftok = start; + bool isFuncDecl = ftok->name; + while (isFuncDecl) { + if (!start->name && start->str != "::" && start->op != '*' && start->op != '&') + isFuncDecl = false; + if (!start->previous) + break; + if (start->previous->isOneOf(";{}:")) + break; + start = start->previous; + } + isFuncDecl &= start != ftok && start->name; + if (isFuncDecl) { + // TODO: we could loop through the parameters here and check if they are correct. + continue; + } + } + } tok->setstr(tok->str + "="); deleteToken(tok->next); } else if ((tok->op == '|' || tok->op == '&') && tok->op == tok->next->op) {