1
0
Fork 0

DBG: finally have "<<" and ">>" for shl and shr

This commit is contained in:
mrexodia 2016-02-18 03:43:29 +01:00
parent c0e41aed15
commit d9f0639b0d
3 changed files with 33 additions and 14 deletions

View File

@ -305,23 +305,27 @@ static void specialformat(char* string)
char str[deflen] = "";
char backup[deflen] = "";
strcpy_s(backup, string); //create a backup of the string
if(found) //contains =
if(found && found != string) //contains =
{
char* a = (found - 1);
*found = 0;
auto a = found - 1;
*found = '\0';
found++;
if(!*found)
{
*found = '=';
return;
}
if(mathisoperator(*a)) //x*=3 -> x=x*3
{
char op = *a;
*a = 0;
if(isvalidexpression(string))
sprintf_s(str, "mov %s,%s%c%s", string, string, op, found);
if(isvalidexpression(found))
{
len = int(strlen(string));
if(len > 1 && string[len - 1] == '<' || string[len - 1] == '>') //TODO: never look at this again, ever (used for x<<=1 and x>>=1)
{
string[len - 1] = '\0';
sprintf_s(str, "mov %s,%s%c%c%s", string, string, op, op, found);
}
else
sprintf_s(str, "mov %s,%s%c%s", string, string, op, found);
}
else
strcpy_s(str, backup);
}

View File

@ -158,7 +158,7 @@ void ExpressionParser::tokenize(const String & expression)
addOperatorToken(ch, Token::Type::OperatorMod);
break;
case '+':
if(!isUnaryOperator()) //skip all unary add operators
if(!isUnaryOperator()) //skip all unary add operators
addOperatorToken(ch, Token::Type::OperatorAdd);
break;
case '-':
@ -168,10 +168,22 @@ void ExpressionParser::tokenize(const String & expression)
addOperatorToken(ch, Token::Type::OperatorSub);
break;
case '<':
addOperatorToken(ch, Token::Type::OperatorShl);
if(i + 1 < len && expression[i + 1] == ch)
{
addOperatorToken(ch, Token::Type::OperatorShl);
i++;
}
else
addOperatorToken(ch, Token::Type::Error);
break;
case '>':
addOperatorToken(ch, Token::Type::OperatorShr);
if(i + 1 < len && expression[i + 1] == ch)
{
addOperatorToken(ch, Token::Type::OperatorShr);
i++;
}
else
addOperatorToken(ch, Token::Type::Error);
break;
case '&':
addOperatorToken(ch, Token::Type::OperatorAnd);
@ -434,6 +446,8 @@ bool ExpressionParser::calculate(duint & value, bool signedcalc, bool silent, bo
unsignedoperation(token.type(), op1, op2, result);
stack.push(result);
break;
case Token::Type::Error:
return false;
default: //do nothing
break;
}

View File

@ -29,7 +29,8 @@ public:
OperatorShr,
OperatorAnd,
OperatorXor,
OperatorOr
OperatorOr,
Error
};
enum class Associativity