From 8f8747a7892ebaaebee3fac68ffe8dc2d6ef711d Mon Sep 17 00:00:00 2001 From: Alexandre Bique Date: Tue, 3 Mar 2009 00:08:39 +0000 Subject: [PATCH] fix the type of comparaison to bool --- src/ast/type-checker-visitor.cc | 42 +++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/src/ast/type-checker-visitor.cc b/src/ast/type-checker-visitor.cc index c1f8869..5ad7f12 100644 --- a/src/ast/type-checker-visitor.cc +++ b/src/ast/type-checker-visitor.cc @@ -149,12 +149,42 @@ namespace ast VISIT(AShrExp) VISIT(LShrExp) - VISIT(EqExp) - VISIT(NeqExp) - VISIT(LtExp) - VISIT(LtEqExp) - VISIT(GtExp) - VISIT(GtEqExp) + +#define VISIT_BINARY_CMP_EXP(Type) \ + void \ + TypeCheckerVisitor::visit(Type & node) \ + { \ + node.type = new BoolType; \ + \ + node.left->accept(*this); \ + node.right->accept(*this); \ + \ + CastExp * castExp = findCast(node.left->type, node.right->type); \ + \ + if (!castExp) \ + { \ + node.type = node.left->type; \ + return; \ + } \ + \ + if (castExp->type == node.left->type) \ + { \ + castExp->exp = node.right; \ + node.right = castExp; \ + } \ + else \ + { \ + castExp->exp = node.left; \ + node.left = castExp; \ + } \ + } + + VISIT_BINARY_CMP_EXP(EqExp) + VISIT_BINARY_CMP_EXP(NeqExp) + VISIT_BINARY_CMP_EXP(LtExp) + VISIT_BINARY_CMP_EXP(LtEqExp) + VISIT_BINARY_CMP_EXP(GtExp) + VISIT_BINARY_CMP_EXP(GtEqExp) CastExp * TypeCheckerVisitor::findCast(Type * type1, -- 2.11.4.GIT