Bump simplecpp
This commit is contained in:
parent
8ab305d3c9
commit
d606eb5ed9
|
@ -1026,15 +1026,15 @@ void simplecpp::TokenList::constFoldBitwise(Token *tok)
|
||||||
{
|
{
|
||||||
Token * const tok1 = tok;
|
Token * const tok1 = tok;
|
||||||
for (const char *op = "&^|"; *op; op++) {
|
for (const char *op = "&^|"; *op; op++) {
|
||||||
const std::string* altop;
|
const std::string* alternativeOp;
|
||||||
if (*op == '&')
|
if (*op == '&')
|
||||||
altop = &BITAND;
|
alternativeOp = &BITAND;
|
||||||
else if (*op == '|')
|
else if (*op == '|')
|
||||||
altop = &BITOR;
|
alternativeOp = &BITOR;
|
||||||
else
|
else
|
||||||
altop = &XOR;
|
alternativeOp = &XOR;
|
||||||
for (tok = tok1; tok && tok->op != ')'; tok = tok->next) {
|
for (tok = tok1; tok && tok->op != ')'; tok = tok->next) {
|
||||||
if (tok->op != *op && !isAlternativeBinaryOp(tok, *altop))
|
if (tok->op != *op && !isAlternativeBinaryOp(tok, *alternativeOp))
|
||||||
continue;
|
continue;
|
||||||
if (!tok->previous || !tok->previous->number)
|
if (!tok->previous || !tok->previous->number)
|
||||||
continue;
|
continue;
|
||||||
|
@ -1472,7 +1472,8 @@ namespace simplecpp {
|
||||||
}
|
}
|
||||||
|
|
||||||
const Token *appendTokens(TokenList *tokens,
|
const Token *appendTokens(TokenList *tokens,
|
||||||
const Token *lpar,
|
const Location &rawloc,
|
||||||
|
const Token * const lpar,
|
||||||
const std::map<TokenString,Macro> ¯os,
|
const std::map<TokenString,Macro> ¯os,
|
||||||
const std::set<TokenString> &expandedmacros,
|
const std::set<TokenString> &expandedmacros,
|
||||||
const std::vector<const Token*> ¶metertokens) const {
|
const std::vector<const Token*> ¶metertokens) const {
|
||||||
|
@ -1483,17 +1484,17 @@ namespace simplecpp {
|
||||||
while (sameline(lpar, tok)) {
|
while (sameline(lpar, tok)) {
|
||||||
if (tok->op == '#' && sameline(tok,tok->next) && tok->next->op == '#' && sameline(tok,tok->next->next)) {
|
if (tok->op == '#' && sameline(tok,tok->next) && tok->next->op == '#' && sameline(tok,tok->next->next)) {
|
||||||
// A##B => AB
|
// A##B => AB
|
||||||
tok = expandHashHash(tokens, tok->location, tok, macros, expandedmacros, parametertokens);
|
tok = expandHashHash(tokens, rawloc, tok, macros, expandedmacros, parametertokens);
|
||||||
} else if (tok->op == '#' && sameline(tok, tok->next) && tok->next->op != '#') {
|
} else if (tok->op == '#' && sameline(tok, tok->next) && tok->next->op != '#') {
|
||||||
tok = expandHash(tokens, tok->location, tok, macros, expandedmacros, parametertokens);
|
tok = expandHash(tokens, rawloc, tok, macros, expandedmacros, parametertokens);
|
||||||
} else {
|
} else {
|
||||||
if (!expandArg(tokens, tok, tok->location, macros, expandedmacros, parametertokens)) {
|
if (!expandArg(tokens, tok, rawloc, macros, expandedmacros, parametertokens)) {
|
||||||
bool expanded = false;
|
bool expanded = false;
|
||||||
const std::map<TokenString, Macro>::const_iterator it = macros.find(tok->str());
|
const std::map<TokenString, Macro>::const_iterator it = macros.find(tok->str());
|
||||||
if (it != macros.end() && expandedmacros.find(tok->str()) == expandedmacros.end()) {
|
if (it != macros.end() && expandedmacros.find(tok->str()) == expandedmacros.end()) {
|
||||||
const Macro &m = it->second;
|
const Macro &m = it->second;
|
||||||
if (!m.functionLike()) {
|
if (!m.functionLike()) {
|
||||||
m.expand(tokens, tok->location, tok, macros, expandedmacros);
|
m.expand(tokens, rawloc, tok, macros, expandedmacros);
|
||||||
expanded = true;
|
expanded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1511,6 +1512,8 @@ namespace simplecpp {
|
||||||
tok = tok->next;
|
tok = tok->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (Token *tok2 = tokens->front(); tok2; tok2 = tok2->next)
|
||||||
|
tok2->location = lpar->location;
|
||||||
return sameline(lpar,tok) ? tok : NULL;
|
return sameline(lpar,tok) ? tok : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1612,13 +1615,19 @@ namespace simplecpp {
|
||||||
hashToken = hashToken->next;
|
hashToken = hashToken->next;
|
||||||
++numberOfHash;
|
++numberOfHash;
|
||||||
}
|
}
|
||||||
if (numberOfHash == 4) {
|
if (numberOfHash == 4 && tok->next->location.col + 1 == tok->next->next->location.col) {
|
||||||
// # ## # => ##
|
// # ## # => ##
|
||||||
output->push_back(newMacroToken("##", loc, isReplaced(expandedmacros)));
|
output->push_back(newMacroToken("##", loc, isReplaced(expandedmacros)));
|
||||||
tok = hashToken;
|
tok = hashToken;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (numberOfHash >= 2 && tok->location.col + 1 < tok->next->location.col) {
|
||||||
|
output->push_back(new Token(*tok));
|
||||||
|
tok = tok->next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
tok = tok->next;
|
tok = tok->next;
|
||||||
if (tok == endToken) {
|
if (tok == endToken) {
|
||||||
output->push_back(new Token(*tok->previous));
|
output->push_back(new Token(*tok->previous));
|
||||||
|
@ -1645,17 +1654,7 @@ namespace simplecpp {
|
||||||
return functionLike() ? parametertokens2.back()->next : nameTokInst->next;
|
return functionLike() ? parametertokens2.back()->next : nameTokInst->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Token *expandToken(TokenList *output, const Location &loc, const Token *tok, const std::map<TokenString,Macro> ¯os, const std::set<TokenString> &expandedmacros, const std::vector<const Token*> ¶metertokens) const {
|
const Token *recursiveExpandToken(TokenList *output, TokenList &temp, const Location &loc, const Token *tok, const std::map<TokenString,Macro> ¯os, const std::set<TokenString> &expandedmacros, const std::vector<const Token*> ¶metertokens) const {
|
||||||
// Not name..
|
|
||||||
if (!tok->name) {
|
|
||||||
output->push_back(newMacroToken(tok->str(), loc, true));
|
|
||||||
return tok->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Macro parameter..
|
|
||||||
{
|
|
||||||
TokenList temp(files);
|
|
||||||
if (expandArg(&temp, tok, loc, macros, expandedmacros, parametertokens)) {
|
|
||||||
if (!(temp.cback() && temp.cback()->name && tok->next && tok->next->op == '(')) {
|
if (!(temp.cback() && temp.cback()->name && tok->next && tok->next->op == '(')) {
|
||||||
output->takeTokens(temp);
|
output->takeTokens(temp);
|
||||||
return tok->next;
|
return tok->next;
|
||||||
|
@ -1681,37 +1680,55 @@ namespace simplecpp {
|
||||||
TokenList temp2(files);
|
TokenList temp2(files);
|
||||||
temp2.push_back(new Token(temp.cback()->str(), tok->location));
|
temp2.push_back(new Token(temp.cback()->str(), tok->location));
|
||||||
|
|
||||||
const Token *tok2 = appendTokens(&temp2, tok->next, macros, expandedmacros, parametertokens);
|
const Token *tok2 = appendTokens(&temp2, loc, tok->next, macros, expandedmacros, parametertokens);
|
||||||
if (!tok2)
|
if (!tok2)
|
||||||
return tok->next;
|
return tok->next;
|
||||||
|
|
||||||
output->takeTokens(temp);
|
output->takeTokens(temp);
|
||||||
output->deleteToken(output->back());
|
output->deleteToken(output->back());
|
||||||
calledMacro.expand(output, loc, temp2.cfront(), macros, expandedmacros);
|
calledMacro.expand(output, loc, temp2.cfront(), macros, expandedmacros);
|
||||||
|
|
||||||
return tok2->next;
|
return tok2->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Token *expandToken(TokenList *output, const Location &loc, const Token *tok, const std::map<TokenString,Macro> ¯os, const std::set<TokenString> &expandedmacros, const std::vector<const Token*> ¶metertokens) const {
|
||||||
|
// Not name..
|
||||||
|
if (!tok->name) {
|
||||||
|
output->push_back(newMacroToken(tok->str(), loc, true));
|
||||||
|
return tok->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Macro parameter..
|
||||||
|
{
|
||||||
|
TokenList temp(files);
|
||||||
|
if (expandArg(&temp, tok, loc, macros, expandedmacros, parametertokens))
|
||||||
|
return recursiveExpandToken(output, temp, loc, tok, macros, expandedmacros, parametertokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Macro..
|
// Macro..
|
||||||
const std::map<TokenString, Macro>::const_iterator it = macros.find(tok->str());
|
const std::map<TokenString, Macro>::const_iterator it = macros.find(tok->str());
|
||||||
if (it != macros.end() && expandedmacros.find(tok->str()) == expandedmacros.end()) {
|
if (it != macros.end() && expandedmacros.find(tok->str()) == expandedmacros.end()) {
|
||||||
|
std::set<std::string> expandedmacros2(expandedmacros);
|
||||||
|
expandedmacros2.insert(tok->str());
|
||||||
|
|
||||||
const Macro &calledMacro = it->second;
|
const Macro &calledMacro = it->second;
|
||||||
if (!calledMacro.functionLike())
|
if (!calledMacro.functionLike()) {
|
||||||
return calledMacro.expand(output, loc, tok, macros, expandedmacros);
|
TokenList temp(files);
|
||||||
|
calledMacro.expand(&temp, loc, tok, macros, expandedmacros);
|
||||||
|
return recursiveExpandToken(output, temp, loc, tok, macros, expandedmacros2, parametertokens);
|
||||||
|
}
|
||||||
if (!sameline(tok, tok->next) || tok->next->op != '(') {
|
if (!sameline(tok, tok->next) || tok->next->op != '(') {
|
||||||
output->push_back(newMacroToken(tok->str(), loc, true));
|
output->push_back(newMacroToken(tok->str(), loc, true));
|
||||||
return tok->next;
|
return tok->next;
|
||||||
}
|
}
|
||||||
TokenList tokens(files);
|
TokenList tokens(files);
|
||||||
tokens.push_back(new Token(*tok));
|
tokens.push_back(new Token(*tok));
|
||||||
const Token *tok2 = appendTokens(&tokens, tok->next, macros, expandedmacros, parametertokens);
|
const Token *tok2 = appendTokens(&tokens, loc, tok->next, macros, expandedmacros, parametertokens);
|
||||||
if (!tok2) {
|
if (!tok2) {
|
||||||
output->push_back(newMacroToken(tok->str(), loc, true));
|
output->push_back(newMacroToken(tok->str(), loc, true));
|
||||||
return tok->next;
|
return tok->next;
|
||||||
}
|
}
|
||||||
calledMacro.expand(output, loc, tokens.cfront(), macros, expandedmacros);
|
TokenList temp(files);
|
||||||
return tok2->next;
|
calledMacro.expand(&temp, loc, tokens.cfront(), macros, expandedmacros);
|
||||||
|
return recursiveExpandToken(output, temp, loc, tok2, macros, expandedmacros2, parametertokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (tok->str() == DEFINED) {
|
else if (tok->str() == DEFINED) {
|
||||||
|
@ -1879,7 +1896,7 @@ namespace simplecpp {
|
||||||
if (tokensB.empty() && sameline(B,B->next) && B->next->op=='(') {
|
if (tokensB.empty() && sameline(B,B->next) && B->next->op=='(') {
|
||||||
const std::map<TokenString,Macro>::const_iterator it = macros.find(strAB);
|
const std::map<TokenString,Macro>::const_iterator it = macros.find(strAB);
|
||||||
if (it != macros.end() && expandedmacros.find(strAB) == expandedmacros.end() && it->second.functionLike()) {
|
if (it != macros.end() && expandedmacros.find(strAB) == expandedmacros.end() && it->second.functionLike()) {
|
||||||
const Token *tok2 = appendTokens(&tokens, B->next, macros, expandedmacros, parametertokens);
|
const Token *tok2 = appendTokens(&tokens, loc, B->next, macros, expandedmacros, parametertokens);
|
||||||
if (tok2)
|
if (tok2)
|
||||||
nextTok = tok2->next;
|
nextTok = tok2->next;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue