From 9c27211bb6fa61f3330721b467e9871706a8d667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 24 Aug 2016 20:27:29 +0200 Subject: [PATCH] bump simplecpp to 403708c --- externals/simplecpp/simplecpp.cpp | 45 +++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/externals/simplecpp/simplecpp.cpp b/externals/simplecpp/simplecpp.cpp index 1927a39a8..94b1357f0 100644 --- a/externals/simplecpp/simplecpp.cpp +++ b/externals/simplecpp/simplecpp.cpp @@ -1146,8 +1146,20 @@ private: } else if (tok->op == '#' && sameline(tok, tok->next) && tok->next->op != '#') { tok = expandHash(tokens, tok->location, tok, macros, expandedmacros, parametertokens); } else { - if (!expandArg(tokens, tok, tok->location, macros, expandedmacros, parametertokens)) - tokens->push_back(new Token(*tok)); + if (!expandArg(tokens, tok, tok->location, macros, expandedmacros, parametertokens)) { + bool expanded = false; + if (macros.find(tok->str) != macros.end() && expandedmacros.find(tok->str) == expandedmacros.end()) { + const std::map::const_iterator it = macros.find(tok->str); + const Macro &m = it->second; + if (!m.functionLike()) { + m.expand(tokens, tok, macros, files); + expanded = true; + } + } + if (!expanded) + tokens->push_back(new Token(*tok)); + } + if (tok->op == '(') ++par; else if (tok->op == ')') { @@ -1243,6 +1255,8 @@ private: if (tok->op != '#') { // A##B => AB if (tok->next && tok->next->op == '#' && tok->next->next && tok->next->next->op == '#') { + if (!sameline(tok, tok->next->next->next)) + throw invalidHashHash(tok->location, name()); output->push_back(newMacroToken(expandArgStr(tok, parametertokens2), loc, isReplaced(expandedmacros))); tok = tok->next; } else { @@ -1441,7 +1455,19 @@ private: throw invalidHashHash(tok->location, name()); Token *B = tok->next->next; - const std::string strAB = A->str + expandArgStr(B, parametertokens); + std::string strAB; + + TokenList tokensB(files); + if (expandArg(&tokensB, B, parametertokens)) { + if (tokensB.empty()) + strAB = A->str; + else { + strAB = A->str + tokensB.cfront()->str; + tokensB.deleteToken(tokensB.front()); + } + } else { + strAB = A->str + B->str; + } bool removeComma = false; if (variadic && strAB == "," && tok->previous->str == "," && args.size() >= 1U && B->str == args[args.size()-1U]) @@ -1454,6 +1480,9 @@ private: tokens.push_back(new Token(strAB, tok->location)); // TODO: For functionLike macros, push the (...) expandToken(output, loc, tokens.cfront(), macros, expandedmacros, parametertokens); + for (Token *b = tokensB.front(); b; b = b->next) + b->location = loc; + output->takeTokens(tokensB); } return B->next; @@ -1498,11 +1527,11 @@ private: namespace simplecpp { #ifdef SIMPLECPP_WINDOWS std::string realFilename(const std::string &f) { - WIN32_FIND_DATA FindFileData; - TCHAR buf[4096] = {0}; - for (unsigned int i = 0; i < f.size(); ++i) - buf[i] = f[i]; - HANDLE hFind = FindFirstFile(buf, &FindFileData); + WIN32_FIND_DATA FindFileData; + TCHAR buf[4096] = {0}; + for (unsigned int i = 0; i < f.size(); ++i) + buf[i] = f[i]; + HANDLE hFind = FindFirstFile(buf, &FindFileData); if (hFind == INVALID_HANDLE_VALUE) return f; std::ostringstream ostr;