void VisitorNodeTyper::visit(ExprOP2 *n){ n->getLeft()->accept(*this); TypeClass* tc = dynamic_cast<TypeClass*>(n->getLeft()->getType()); Class* old_cur_class = this->cur_class; this->cur_class = tc ? tc->getClass() : 0; n->getRight()->accept(*this); // Type of binary operator is type of operands (with promotion), except for comparison operators if ( n->getOperator() == ExprOP2::LT || n->getOperator() == ExprOP2::LTE || n->getOperator() == ExprOP2::GT || n->getOperator() == ExprOP2::GTE || n->getOperator() == ExprOP2::EQ || n->getOperator() == ExprOP2::NEQ ) { n->setType(TypePrimary::getBool()); } else if (n->getOperator() == ExprOP2::DOT) { if (!tc) throw __FILE__ "(" QUOTE(__LINE__) "): Left hand side of . operator must be an object / class."; n->setType(n->getRight()->getType()); } else if (n->getOperator() == ExprOP2::ARRAY) { // TODO Check rhs type TypeArray* ta = dynamic_cast<TypeArray*>(n->getLeft()->getType()); if (!ta) throw __FILE__ "(" QUOTE(__LINE__) "): Left hand side of [] operator must be an array."; n->setType(ta->getType()); } else // All other operators { n->setType(n->getLeft()->getType()); } this->cur_class = old_cur_class; }