patterns: Fix boolean operations and cast syntax
This commit is contained in:
parent
93c1fbd65e
commit
71be77c54b
@ -203,25 +203,25 @@ namespace hex::pl {
|
|||||||
case Token::Operator::BitNot:
|
case Token::Operator::BitNot:
|
||||||
return new ASTNodeLiteral(bitNot(left, right));
|
return new ASTNodeLiteral(bitNot(left, right));
|
||||||
case Token::Operator::BoolEquals:
|
case Token::Operator::BoolEquals:
|
||||||
return new ASTNodeLiteral(left == right);
|
return new ASTNodeLiteral(bool(left == right));
|
||||||
case Token::Operator::BoolNotEquals:
|
case Token::Operator::BoolNotEquals:
|
||||||
return new ASTNodeLiteral(left != right);
|
return new ASTNodeLiteral(bool(left != right));
|
||||||
case Token::Operator::BoolGreaterThan:
|
case Token::Operator::BoolGreaterThan:
|
||||||
return new ASTNodeLiteral(left > right);
|
return new ASTNodeLiteral(bool(left > right));
|
||||||
case Token::Operator::BoolLessThan:
|
case Token::Operator::BoolLessThan:
|
||||||
return new ASTNodeLiteral(left < right);
|
return new ASTNodeLiteral(bool(left < right));
|
||||||
case Token::Operator::BoolGreaterThanOrEquals:
|
case Token::Operator::BoolGreaterThanOrEquals:
|
||||||
return new ASTNodeLiteral(left >= right);
|
return new ASTNodeLiteral(bool(left >= right));
|
||||||
case Token::Operator::BoolLessThanOrEquals:
|
case Token::Operator::BoolLessThanOrEquals:
|
||||||
return new ASTNodeLiteral(left <= right);
|
return new ASTNodeLiteral(bool(left <= right));
|
||||||
case Token::Operator::BoolAnd:
|
case Token::Operator::BoolAnd:
|
||||||
return new ASTNodeLiteral(left && right);
|
return new ASTNodeLiteral(bool(left && right));
|
||||||
case Token::Operator::BoolXor:
|
case Token::Operator::BoolXor:
|
||||||
return new ASTNodeLiteral(left && !right || !left && right);
|
return new ASTNodeLiteral(bool(left && !right || !left && right));
|
||||||
case Token::Operator::BoolOr:
|
case Token::Operator::BoolOr:
|
||||||
return new ASTNodeLiteral(left || right);
|
return new ASTNodeLiteral(bool(left || right));
|
||||||
case Token::Operator::BoolNot:
|
case Token::Operator::BoolNot:
|
||||||
return new ASTNodeLiteral(!right);
|
return new ASTNodeLiteral(bool(!right));
|
||||||
default:
|
default:
|
||||||
LogConsole::abortEvaluation("invalid operand used in mathematical expression", this);
|
LogConsole::abortEvaluation("invalid operand used in mathematical expression", this);
|
||||||
}
|
}
|
||||||
|
@ -170,14 +170,11 @@ namespace hex::pl {
|
|||||||
if (builtinType == nullptr)
|
if (builtinType == nullptr)
|
||||||
throwParseError("invalid type used for pointer size", -1);
|
throwParseError("invalid type used for pointer size", -1);
|
||||||
|
|
||||||
if (!MATCHES(sequence(SEPARATOR_ROUNDBRACKETOPEN)))
|
if (!peek(SEPARATOR_ROUNDBRACKETOPEN))
|
||||||
throwParseError("expected '(' before cast expression", -1);
|
throwParseError("expected '(' before cast expression", -1);
|
||||||
|
|
||||||
auto node = parseFactor();
|
auto node = parseFactor();
|
||||||
|
|
||||||
if (!MATCHES(sequence(SEPARATOR_ROUNDBRACKETCLOSE)))
|
|
||||||
throwParseError("expected ')' after cast expression", -1);
|
|
||||||
|
|
||||||
return new ASTNodeCast(node, type);
|
return new ASTNodeCast(node, type);
|
||||||
} else return parseFactor();
|
} else return parseFactor();
|
||||||
}
|
}
|
||||||
@ -327,7 +324,7 @@ namespace hex::pl {
|
|||||||
auto nodeCleanup = SCOPE_GUARD { delete node; };
|
auto nodeCleanup = SCOPE_GUARD { delete node; };
|
||||||
|
|
||||||
while (MATCHES(sequence(OPERATOR_BOOLAND))) {
|
while (MATCHES(sequence(OPERATOR_BOOLAND))) {
|
||||||
node = create(new ASTNodeMathematicalExpression(node, this->parseBinaryOrExpression(), Token::Operator::BitOr));
|
node = create(new ASTNodeMathematicalExpression(node, this->parseBinaryOrExpression(), Token::Operator::BoolAnd));
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeCleanup.release();
|
nodeCleanup.release();
|
||||||
@ -342,7 +339,7 @@ namespace hex::pl {
|
|||||||
auto nodeCleanup = SCOPE_GUARD { delete node; };
|
auto nodeCleanup = SCOPE_GUARD { delete node; };
|
||||||
|
|
||||||
while (MATCHES(sequence(OPERATOR_BOOLXOR))) {
|
while (MATCHES(sequence(OPERATOR_BOOLXOR))) {
|
||||||
node = create(new ASTNodeMathematicalExpression(node, this->parseBooleanAnd(), Token::Operator::BitOr));
|
node = create(new ASTNodeMathematicalExpression(node, this->parseBooleanAnd(), Token::Operator::BoolXor));
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeCleanup.release();
|
nodeCleanup.release();
|
||||||
@ -357,7 +354,7 @@ namespace hex::pl {
|
|||||||
auto nodeCleanup = SCOPE_GUARD { delete node; };
|
auto nodeCleanup = SCOPE_GUARD { delete node; };
|
||||||
|
|
||||||
while (MATCHES(sequence(OPERATOR_BOOLOR))) {
|
while (MATCHES(sequence(OPERATOR_BOOLOR))) {
|
||||||
node = create(new ASTNodeMathematicalExpression(node, this->parseBooleanXor(), Token::Operator::BitOr));
|
node = create(new ASTNodeMathematicalExpression(node, this->parseBooleanXor(), Token::Operator::BoolOr));
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeCleanup.release();
|
nodeCleanup.release();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user