bump simplecpp

This commit is contained in:
Daniel Marjamäki 2016-08-04 22:53:10 +02:00
parent a0624344ce
commit cbfeae0ff7
2 changed files with 30 additions and 14 deletions

View File

@ -1058,16 +1058,26 @@ private:
unsigned int par = 0; unsigned int par = 0;
const Token *tok = lpar; const Token *tok = lpar;
while (sameline(lpar, tok)) { while (sameline(lpar, tok)) {
if (!expandArg(tokens, tok, tok->location, macros, expandedmacros1, expandedmacros, parametertokens)) if (tok->op == '#' && sameline(tok,tok->next) && tok->next->op == '#' && sameline(tok,tok->next->next)) {
tokens->push_back(new Token(*tok)); // A##B => AB
if (tok->op == '(') const std::string strB(expandArgStr(tok->next->next, parametertokens));
++par; if (variadic && strB.empty() && tok->previous->op == ',')
else if (tok->op == ')') { tokens->deleteToken(tokens->back());
--par; else
if (par == 0U) tokens->back()->setstr(tokens->back()->str + strB);
break; tok = tok->next->next->next;
} else {
if (!expandArg(tokens, tok, tok->location, macros, expandedmacros1, expandedmacros, parametertokens))
tokens->push_back(new Token(*tok));
if (tok->op == '(')
++par;
else if (tok->op == ')') {
--par;
if (par == 0U)
break;
}
tok = tok->next;
} }
tok = tok->next;
} }
return sameline(lpar,tok) ? tok : NULL; return sameline(lpar,tok) ? tok : NULL;
} }
@ -1196,10 +1206,16 @@ private:
// #123 => "123" // #123 => "123"
TokenList tokenListHash(files); TokenList tokenListHash(files);
tok = expandToken(&tokenListHash, loc, tok, macros, expandedmacros1, expandedmacros, parametertokens2); tok = expandToken(&tokenListHash, loc, tok, macros, expandedmacros1, expandedmacros, parametertokens2);
std::string s; std::ostringstream ostr;
for (const Token *hashtok = tokenListHash.cfront(); hashtok; hashtok = hashtok->next) for (const Token *hashtok = tokenListHash.cfront(); hashtok; hashtok = hashtok->next) {
s += hashtok->str; for (unsigned int i = 0; i < hashtok->str.size(); i++) {
output->push_back(newMacroToken('\"' + s + '\"', loc, expandedmacros1.empty())); unsigned char c = hashtok->str[i];
if (c == '\"' || c == '\\' || c == '\'')
ostr << '\\';
ostr << c;
}
}
output->push_back(newMacroToken('\"' + ostr.str() + '\"', loc, expandedmacros1.empty()));
} }
} }

View File

@ -1446,7 +1446,7 @@ private:
void stringify5() const { void stringify5() const {
const char filedata[] = "#define A(x) a(#x,x)\n" const char filedata[] = "#define A(x) a(#x,x)\n"
"A(foo(\"\\\"\"))\n"; "A(foo(\"\\\"\"))\n";
ASSERT_EQUALS("\na ( \"foo(\"\\\"\")\" , foo ( \"\\\"\" ) )", OurPreprocessor::expandMacros(filedata)); ASSERT_EQUALS("\na ( \"foo(\\\"\\\\\\\"\\\")\" , foo ( \"\\\"\" ) )", OurPreprocessor::expandMacros(filedata));
} }
void pragma() { void pragma() {