update simplecpp
This commit is contained in:
parent
b9b47809f9
commit
e7f469c4ba
|
@ -449,9 +449,12 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
|
||||||
|
|
||||||
// number or name
|
// number or name
|
||||||
if (isNameChar(ch)) {
|
if (isNameChar(ch)) {
|
||||||
|
const bool num = std::isdigit(ch);
|
||||||
while (istr.good() && isNameChar(ch)) {
|
while (istr.good() && isNameChar(ch)) {
|
||||||
currentToken += ch;
|
currentToken += ch;
|
||||||
ch = readChar(istr,bom);
|
ch = readChar(istr,bom);
|
||||||
|
if (num && ch=='\'' && isNameChar(peekChar(istr,bom)))
|
||||||
|
ch = readChar(istr,bom);
|
||||||
}
|
}
|
||||||
|
|
||||||
ungetChar(istr,bom);
|
ungetChar(istr,bom);
|
||||||
|
@ -586,6 +589,7 @@ void simplecpp::TokenList::constFold()
|
||||||
constFoldUnaryNotPosNeg(tok);
|
constFoldUnaryNotPosNeg(tok);
|
||||||
constFoldMulDivRem(tok);
|
constFoldMulDivRem(tok);
|
||||||
constFoldAddSub(tok);
|
constFoldAddSub(tok);
|
||||||
|
constFoldShift(tok);
|
||||||
constFoldComparison(tok);
|
constFoldComparison(tok);
|
||||||
constFoldBitwise(tok);
|
constFoldBitwise(tok);
|
||||||
constFoldLogicalOp(tok);
|
constFoldLogicalOp(tok);
|
||||||
|
@ -766,6 +770,29 @@ void simplecpp::TokenList::constFoldAddSub(Token *tok)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void simplecpp::TokenList::constFoldShift(Token *tok)
|
||||||
|
{
|
||||||
|
for (; tok && tok->op != ')'; tok = tok->next) {
|
||||||
|
if (!tok->previous || !tok->previous->number)
|
||||||
|
continue;
|
||||||
|
if (!tok->next || !tok->next->number)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
long long result;
|
||||||
|
if (tok->str == "<<")
|
||||||
|
result = stringToLL(tok->previous->str) << stringToLL(tok->next->str);
|
||||||
|
else if (tok->str == ">>")
|
||||||
|
result = stringToLL(tok->previous->str) >> stringToLL(tok->next->str);
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
|
||||||
|
tok = tok->previous;
|
||||||
|
tok->setstr(toString(result));
|
||||||
|
deleteToken(tok->next);
|
||||||
|
deleteToken(tok->next);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static const std::string NOTEQ("not_eq");
|
static const std::string NOTEQ("not_eq");
|
||||||
void simplecpp::TokenList::constFoldComparison(Token *tok)
|
void simplecpp::TokenList::constFoldComparison(Token *tok)
|
||||||
{
|
{
|
||||||
|
@ -1193,6 +1220,7 @@ namespace simplecpp {
|
||||||
}
|
}
|
||||||
if (!sameline(nametoken, argtok)) {
|
if (!sameline(nametoken, argtok)) {
|
||||||
endToken = argtok ? argtok->previous : argtok;
|
endToken = argtok ? argtok->previous : argtok;
|
||||||
|
valueToken = NULL;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
valueToken = argtok ? argtok->next : NULL;
|
valueToken = argtok ? argtok->next : NULL;
|
||||||
|
@ -1259,8 +1287,8 @@ namespace simplecpp {
|
||||||
} else {
|
} else {
|
||||||
if (!expandArg(tokens, tok, tok->location, macros, expandedmacros, parametertokens)) {
|
if (!expandArg(tokens, tok, tok->location, macros, expandedmacros, parametertokens)) {
|
||||||
bool expanded = false;
|
bool expanded = false;
|
||||||
if (macros.find(tok->str) != macros.end() && expandedmacros.find(tok->str) == expandedmacros.end()) {
|
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()) {
|
||||||
const Macro &m = it->second;
|
const Macro &m = it->second;
|
||||||
if (!m.functionLike()) {
|
if (!m.functionLike()) {
|
||||||
m.expand(tokens, tok, macros, files);
|
m.expand(tokens, tok, macros, files);
|
||||||
|
|
|
@ -249,6 +249,7 @@ namespace simplecpp {
|
||||||
void constFoldUnaryNotPosNeg(Token *tok);
|
void constFoldUnaryNotPosNeg(Token *tok);
|
||||||
void constFoldMulDivRem(Token *tok);
|
void constFoldMulDivRem(Token *tok);
|
||||||
void constFoldAddSub(Token *tok);
|
void constFoldAddSub(Token *tok);
|
||||||
|
void constFoldShift(Token *tok);
|
||||||
void constFoldComparison(Token *tok);
|
void constFoldComparison(Token *tok);
|
||||||
void constFoldBitwise(Token *tok);
|
void constFoldBitwise(Token *tok);
|
||||||
void constFoldLogicalOp(Token *tok);
|
void constFoldLogicalOp(Token *tok);
|
||||||
|
|
Loading…
Reference in New Issue