Esempio n. 1
0
	Node::ReturnType WhileNode::typeCheck() const
	{
		expectType(TYPE_BOOL, children[0]->typeCheck());
		expectType(TYPE_UNIT, children[1]->typeCheck());
		
		BinaryArithmeticNode* binaryOp = dynamic_cast<BinaryArithmeticNode*>(children[0]);
		UnaryArithmeticNode* unaryOp = dynamic_cast<UnaryArithmeticNode*>(children[0]);
		bool ok(false);
		if (binaryOp && binaryOp->op >= ASEBA_OP_EQUAL && binaryOp->op <= ASEBA_OP_AND)
			ok = true;
		if (unaryOp && unaryOp->op == ASEBA_UNARY_OP_NOT)
			ok = true;
		
		if (!ok)
			throw TranslatableError(children[0]->sourcePos, ERROR_EXPECTING_CONDITION).arg(children[0]->toNodeName());
		return TYPE_UNIT;
	}
Esempio n. 2
0
	Node::ReturnType UnaryArithmeticNode::typeCheck() const
	{
		switch (op)
		{
			case ASEBA_UNARY_OP_SUB:
			case ASEBA_UNARY_OP_ABS:
			case ASEBA_UNARY_OP_BIT_NOT:
				expectType(TYPE_INT, children[0]->typeCheck());
				return TYPE_INT;
			
			case ASEBA_UNARY_OP_NOT:
				expectType(TYPE_BOOL, children[0]->typeCheck());
				return TYPE_BOOL;
			
			default:
				abort();
				return TYPE_UNIT;
		}
	}
Esempio n. 3
0
	Node::ReturnType BinaryArithmeticNode::typeCheck() const
	{
		switch (op)
		{
			case ASEBA_OP_SHIFT_LEFT:
			case ASEBA_OP_SHIFT_RIGHT:
			case ASEBA_OP_ADD:
			case ASEBA_OP_SUB:
			case ASEBA_OP_MULT:
			case ASEBA_OP_DIV:
			case ASEBA_OP_MOD:
			case ASEBA_OP_BIT_OR:
			case ASEBA_OP_BIT_XOR:
			case ASEBA_OP_BIT_AND:
				expectType(TYPE_INT, children[0]->typeCheck());
				expectType(TYPE_INT, children[1]->typeCheck());
				return TYPE_INT;
			
			case ASEBA_OP_EQUAL:
			case ASEBA_OP_NOT_EQUAL:
			case ASEBA_OP_BIGGER_THAN:
			case ASEBA_OP_BIGGER_EQUAL_THAN:
			case ASEBA_OP_SMALLER_THAN:
			case ASEBA_OP_SMALLER_EQUAL_THAN:
				expectType(TYPE_INT, children[0]->typeCheck());
				expectType(TYPE_INT, children[1]->typeCheck());
				return TYPE_BOOL;
			
			case ASEBA_OP_OR:
			case ASEBA_OP_AND:
				expectType(TYPE_BOOL, children[0]->typeCheck());
				expectType(TYPE_BOOL, children[1]->typeCheck());
				return TYPE_BOOL;
				
			default:
				abort();
				return TYPE_UNIT;
		}
	}
NBodyCtx* expectNBodyCtx(lua_State* luaSt, int idx)
{
    return (NBodyCtx*) expectType(luaSt, idx, NBODYCTX_TYPE);
}
Esempio n. 5
0
	Node::ReturnType AssignmentNode::typeCheck() const
	{
		expectType(TYPE_UNIT, children[0]->typeCheck());
		expectType(TYPE_INT, children[1]->typeCheck());
		return TYPE_UNIT;
	}