Debugger: Simplify expression parser.

- Remove handling of the power token, as it's not actually valid C/C++ syntax,
  and causes problems when parsing more complex pointer types/dereferences.
This commit is contained in:
Rene Gollent 2014-12-09 22:53:35 -05:00
parent d621fb88d7
commit 194d85f4a3
5 changed files with 15 additions and 64 deletions

View File

@ -72,10 +72,6 @@ static BString TokenTypeToString(int32 type)
token = "%";
break;
case TOKEN_POWER:
token = "**";
break;
case TOKEN_OPENING_PAREN:
token = "(";
break;
@ -1521,17 +1517,17 @@ CLanguageExpressionEvaluator::_ParseProduct()
{
static Operand zero(int64(0LL));
Operand value = _ParsePower();
Operand value = _ParseUnary();
while (true) {
Token token = fTokenizer->NextToken();
switch (token.type) {
case TOKEN_STAR:
value *= _ParsePower();
value *= _ParseUnary();
break;
case TOKEN_SLASH:
{
Operand rhs = _ParsePower();
Operand rhs = _ParseUnary();
if (rhs == zero)
throw ParseException("division by zero", token.position);
value /= rhs;
@ -1540,7 +1536,7 @@ CLanguageExpressionEvaluator::_ParseProduct()
case TOKEN_MODULO:
{
Operand rhs = _ParsePower();
Operand rhs = _ParseUnary();
if (rhs == zero)
throw ParseException("modulo by zero", token.position);
value %= rhs;
@ -1550,7 +1546,7 @@ CLanguageExpressionEvaluator::_ParseProduct()
case TOKEN_LOGICAL_AND:
{
value.SetTo((value != zero)
&& (_ParsePower() != zero));
&& (_ParseUnary() != zero));
break;
}
@ -1558,44 +1554,44 @@ CLanguageExpressionEvaluator::_ParseProduct()
case TOKEN_LOGICAL_OR:
{
value.SetTo((value != zero)
|| (_ParsePower() != zero));
|| (_ParseUnary() != zero));
break;
}
case TOKEN_BITWISE_AND:
value &= _ParsePower();
value &= _ParseUnary();
break;
case TOKEN_BITWISE_OR:
value |= _ParsePower();
value |= _ParseUnary();
break;
case TOKEN_BITWISE_XOR:
value ^= _ParsePower();
value ^= _ParseUnary();
break;
case TOKEN_EQ:
value.SetTo((int64)(value == _ParsePower()));
value.SetTo((int64)(value == _ParseUnary()));
break;
case TOKEN_NE:
value.SetTo((int64)(value != _ParsePower()));
value.SetTo((int64)(value != _ParseUnary()));
break;
case TOKEN_GT:
value.SetTo((int64)(value > _ParsePower()));
value.SetTo((int64)(value > _ParseUnary()));
break;
case TOKEN_GE:
value.SetTo((int64)(value >= _ParsePower()));
value.SetTo((int64)(value >= _ParseUnary()));
break;
case TOKEN_LT:
value.SetTo((int64)(value < _ParsePower()));
value.SetTo((int64)(value < _ParseUnary()));
break;
case TOKEN_LE:
value.SetTo((int64)(value <= _ParsePower()));
value.SetTo((int64)(value <= _ParseUnary()));
break;
default:
@ -1606,43 +1602,6 @@ CLanguageExpressionEvaluator::_ParseProduct()
}
CLanguageExpressionEvaluator::Operand
CLanguageExpressionEvaluator::_ParsePower()
{
Operand value = _ParseUnary();
while (true) {
Token token = fTokenizer->NextToken();
if (token.type != TOKEN_POWER) {
fTokenizer->RewindToken();
return value;
}
Operand power = _ParseUnary();
Operand temp = value;
int64 powerValue = power.PrimitiveValue().ToInt64();
bool handleNegativePower = false;
if (powerValue < 0) {
powerValue = abs(powerValue);
handleNegativePower = true;
}
if (powerValue == 0)
value.SetTo((int64)1);
else {
for (; powerValue > 1; powerValue--)
value *= temp;
}
if (handleNegativePower) {
temp.SetTo((int64)1);
temp /= value;
value = temp;
}
}
}
CLanguageExpressionEvaluator::Operand
CLanguageExpressionEvaluator::_ParseUnary()
{

View File

@ -62,7 +62,6 @@ private:
private:
Operand _ParseSum();
Operand _ParseProduct();
Operand _ParsePower();
Operand _ParseUnary();
Operand _ParseIdentifier(ValueNode* parentNode = NULL);
Operand _ParseAtom();

View File

@ -326,7 +326,6 @@ CLanguageFamilySyntaxHighlightInfo::_MapTokenToSyntaxType(const Token& token)
case TOKEN_STAR:
case TOKEN_SLASH:
case TOKEN_MODULO:
case TOKEN_POWER:
case TOKEN_OPENING_PAREN:
case TOKEN_CLOSING_PAREN:
case TOKEN_OPENING_SQUARE_BRACKET:

View File

@ -273,10 +273,6 @@ Tokenizer::_ParseOperator()
case '*':
switch (_Peek()) {
case '*':
type = TOKEN_POWER;
length = 2;
break;
case '/':
type = TOKEN_END_COMMENT_BLOCK;
length = 2;

View File

@ -33,8 +33,6 @@ enum {
TOKEN_SLASH,
TOKEN_MODULO,
TOKEN_POWER,
TOKEN_OPENING_PAREN,
TOKEN_CLOSING_PAREN,