Skip to content
Extraits de code Groupes Projets
Valider cbf5417c rédigé par Kubat's avatar Kubat
Parcourir les fichiers

FIX: Check the left member of binary expression where we can

parent 20cbd79c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!25Draft: New Vivy module spec
Pipeline #2842 en échec
...@@ -30,28 +30,28 @@ auto updateExprWithInfixOperator = [throwUnexpectedToken, createOpElement]( ...@@ -30,28 +30,28 @@ auto updateExprWithInfixOperator = [throwUnexpectedToken, createOpElement](
}; };
auto updateLeft = []<typename IrT>(IrExpression *current, IrExpression *newLeft) -> void { auto updateLeft = []<typename IrT>(IrExpression *current, IrExpression *newLeft) -> void {
dynamic_cast<IrT *>(current)->left = newLeft; IrT *typpedCurrent = dynamic_cast<IrT *>(current);
if (typpedCurrent->left != nullptr)
throw std::runtime_error("Unexpected token in expression parsing: " + tok.toString());
typpedCurrent->left = newLeft;
newLeft->setParent(current); newLeft->setParent(current);
}; };
auto updateExprWithConstExpr = [updateLeft](IrExpression *&current, Token tok) -> void { auto updateExprWithConstExpr = [updateLeft](IrExpression *&current, Token tok) -> void {
IrExpression *newLeft = IrElement::create<IrEConstExpr>(current, tok); IrExpression *newLeft = IrElement::create<IrEConstExpr>(current, tok);
/* (... `op` <- currentExpression) newLeft -> currentExpression */ /* (... `op` <- currentExpression) newLeft -> currentExpression */
if (current != nullptr && current->left == nullptr) { if (current != nullptr) {
switch (current->type()) { switch (current->type()) {
case Type::CompOp: updateLeft<IrECompOp>(current, newLeft); return; case Type::CompOp: return <IrECompOp>(current, newLeft);
case Type::ArithmeticOp: updateLeft<IrEArithmeticOp>(current, newLeft); return; case Type::ArithmeticOp: return updateLeft<IrEArithmeticOp>(current, newLeft);
case Type::LogicOp: updateLeft<IrELogicOp>(current, newLeft); return; case Type::LogicOp: return updateLeft<IrELogicOp>(current, newLeft);
case Type::ConstExpr: case Type::ConstExpr:
case Type::Call: case Type::Call:
case Type::VariableRef: throw std::runtime_error("Invalid expression"); case Type::VariableRef: throw std::runtime_error("Invalid expression");
} }
} }
/* Can be the case for `1 + 2 2` which is invalid */
else if (current != nullptr && current->left != nullptr)
throw std::runtime_error("Unexpected token in expression parsing: " + tok.toString());
/* newLeft -> currentExpression */ /* newLeft -> currentExpression */
else else
current = newLeft; current = newLeft;
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter