bump simplecpp
This commit is contained in:
parent
8253a18646
commit
d220573fa5
|
@ -213,6 +213,11 @@ std::string simplecpp::TokenList::stringify() const {
|
||||||
std::ostringstream ret;
|
std::ostringstream ret;
|
||||||
Location loc(files);
|
Location loc(files);
|
||||||
for (const Token *tok = cfront(); tok; tok = tok->next) {
|
for (const Token *tok = cfront(); tok; tok = tok->next) {
|
||||||
|
if (tok->location.line < loc.line || tok->location.fileIndex != loc.fileIndex) {
|
||||||
|
ret << "\n#line " << tok->location.line << " \"" << tok->location.file() << "\"\n";
|
||||||
|
loc = tok->location;
|
||||||
|
}
|
||||||
|
|
||||||
while (tok->location.line > loc.line) {
|
while (tok->location.line > loc.line) {
|
||||||
ret << '\n';
|
ret << '\n';
|
||||||
loc.line++;
|
loc.line++;
|
||||||
|
@ -315,6 +320,19 @@ bool isNameChar(unsigned char ch) {
|
||||||
return std::isalnum(ch) || ch == '_' || ch == '$';
|
return std::isalnum(ch) || ch == '_' || ch == '$';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::string escapeString(const std::string &str) {
|
||||||
|
std::ostringstream ostr;
|
||||||
|
ostr << '\"';
|
||||||
|
for (std::size_t i = 1U; i < str.size() - 1; ++i) {
|
||||||
|
char c = str[i];
|
||||||
|
if (c == '\\' || c == '\"' || c == '\'')
|
||||||
|
ostr << '\\';
|
||||||
|
ostr << c;
|
||||||
|
}
|
||||||
|
ostr << '\"';
|
||||||
|
return ostr.str();
|
||||||
|
}
|
||||||
|
|
||||||
void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filename, OutputList *outputList)
|
void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filename, OutputList *outputList)
|
||||||
{
|
{
|
||||||
std::stack<simplecpp::Location> loc;
|
std::stack<simplecpp::Location> loc;
|
||||||
|
@ -444,7 +462,7 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
|
||||||
// TODO report
|
// TODO report
|
||||||
return;
|
return;
|
||||||
currentToken.erase(currentToken.size() - endOfRawString.size(), endOfRawString.size() - 1U);
|
currentToken.erase(currentToken.size() - endOfRawString.size(), endOfRawString.size() - 1U);
|
||||||
back()->setstr(currentToken);
|
back()->setstr(escapeString(currentToken));
|
||||||
location.col += currentToken.size() + 2U + 2 * delim.size();
|
location.col += currentToken.size() + 2U + 2 * delim.size();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -536,6 +554,11 @@ void simplecpp::TokenList::combineOperators() {
|
||||||
|
|
||||||
if (tok->op == '\0' || !tok->next || tok->next->op == '\0')
|
if (tok->op == '\0' || !tok->next || tok->next->op == '\0')
|
||||||
continue;
|
continue;
|
||||||
|
if (!sameline(tok,tok->next))
|
||||||
|
continue;
|
||||||
|
if (tok->location.col + 1U != tok->next->location.col)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (tok->next->op == '=' && tok->isOneOf("=!<>+-*/%&|^")) {
|
if (tok->next->op == '=' && tok->isOneOf("=!<>+-*/%&|^")) {
|
||||||
tok->setstr(tok->str + "=");
|
tok->setstr(tok->str + "=");
|
||||||
deleteToken(tok->next);
|
deleteToken(tok->next);
|
||||||
|
@ -1382,15 +1405,11 @@ private:
|
||||||
TokenList tokenListHash(files);
|
TokenList tokenListHash(files);
|
||||||
tok = expandToken(&tokenListHash, loc, tok->next, macros, expandedmacros, parametertokens);
|
tok = expandToken(&tokenListHash, loc, tok->next, macros, expandedmacros, parametertokens);
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
for (const Token *hashtok = tokenListHash.cfront(); hashtok; hashtok = hashtok->next) {
|
ostr << '\"';
|
||||||
for (unsigned int i = 0; i < hashtok->str.size(); i++) {
|
for (const Token *hashtok = tokenListHash.cfront(); hashtok; hashtok = hashtok->next)
|
||||||
unsigned char c = hashtok->str[i];
|
ostr << hashtok->str;
|
||||||
if (c == '\"' || c == '\\' || c == '\'')
|
ostr << '\"';
|
||||||
ostr << '\\';
|
output->push_back(newMacroToken(escapeString(ostr.str()), loc, isReplaced(expandedmacros)));
|
||||||
ostr << c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
output->push_back(newMacroToken('\"' + ostr.str() + '\"', loc, isReplaced(expandedmacros)));
|
|
||||||
return tok;
|
return tok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1807,9 +1826,11 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
|
||||||
err.msg = '#' + rawtok->str + ' ' + err.msg;
|
err.msg = '#' + rawtok->str + ' ' + err.msg;
|
||||||
outputList->push_back(err);
|
outputList->push_back(err);
|
||||||
}
|
}
|
||||||
|
if (rawtok->str == ERROR) {
|
||||||
output.clear();
|
output.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (rawtok->str == DEFINE) {
|
if (rawtok->str == DEFINE) {
|
||||||
if (ifstates.top() != TRUE)
|
if (ifstates.top() != TRUE)
|
||||||
|
|
Loading…
Reference in New Issue