Beispiel #1
0
	AllocaInsn::AllocaInsn(const VariablePtr& variable, const ValuePtr& size, const ValueList& dimensions) :
		Insn(IC_Stack, IT_Alloca), size(size), variable(variable), dimensions(dimensions) {
		assert(variable && "variable must not be null");
		assert(variable->getValueType() == Value::VT_Memory && "variable must not be a temporary");
		assert(size && "size must not be null");
		assert(size->getType()->isInt() && "size must be of type int");

		if (analysis::types::isArray(variable->getType())) {
			auto type = cast<ArrayType>(variable->getType());
			assert(type->getNumOfDimensions() == dimensions.size() && "dimension information mismatch with type");
		}
	}
Beispiel #2
0
    ValuePtr FloatValue::Promote(const ValuePtr another) const {

        const TypeSpecifier another_type = another->getType();

        // case 1. Exactly same type
        if (getType() == another_type) {
            return this->Copy();
        }

        switch (another_type) {

            case F32:
            case F64: {
                DataTypePtr return_type = getSize() > another->getSize()
                                     ? data_type_
                                     : another->getDataType();

                return FloatValue::Create(return_type, this->getFloatValue());
            }

            case S8:
            case S16:
            case S32:
            case S64:
            case U8:
            case U16:
            case U32:
            case U64:  {

                return this->Copy();

            }

            case STR8: {
                std::string val = std::to_string(this->getFloatValue());
                return StringValue::Create(another->getDataType(), val);
            }
            case STR16: {
                std::u16string val;
                val += this->getFloatValue();
                return StringValue::CreateU16(another->getDataType(), val);
            }
            case STR32: {
                std::u32string val;
                val += this->getFloatValue();
                return StringValue::CreateU32(another->getDataType(), val);
            }

            default:
                return nullptr;
        }
        
    }
Beispiel #3
0
void Zone::setProperty (string key, ValuePtr value) {
	lock_guard<recursive_mutex> lock(value_m);

	if (key == "color") {
		if (value->getType() != Type::COLOR)
			return;

		auto val = dynamic_pointer_cast<Color>(value);
		setColor(*val);
		return;
	}

	if (key == "parent")
		return;

	if (key == "world")
		return;

	Agent::setProperty(key, value);
}
Beispiel #4
0
    ValuePtr FloatValue::OperateBinary(
            const Expression::Type expression_type,
            const ValuePtr &right_promoted) const {

        ValuePtr result = nullptr;

        // 'right' value MUST be same type with this's type;
        if (right_promoted->getType() == this->getType()) {

            double epsilon = std::numeric_limits<double>::epsilon();

            std::shared_ptr<FloatValue> right_dynamic = std::dynamic_pointer_cast<FloatValue>(right_promoted);

            double left_value = this->getFloatValue();
            double right_value = right_dynamic->getFloatValue();

            double result_value = 0;

            switch (expression_type) {

                case Expression::Type::EXP_OR :
                    return nullptr;
                case Expression::Type::EXP_AND :
                    return nullptr;

                case Expression::Type::EXP_EQL :
                    result_value = this->NearlyEqual(right_value);
                    break;
                case Expression::Type::EXP_NEQ :
                    result_value = !this->NearlyEqual(right_value);
                    break;
                case Expression::Type::EXP_LSS :
                    result_value = left_value < right_value;
                    break;
                case Expression::Type::EXP_GTR :
                    result_value = left_value > right_value;
                    break;
                case Expression::Type::EXP_LEQ :
                    result_value = (left_value < right_value) || this->NearlyEqual(right_value);
                    break;
                case Expression::Type::EXP_GEQ :
                    result_value = (left_value > right_value) || this->NearlyEqual(right_value);
                    break;

                case Expression::Type::EXP_ASSIGN :
                    result_value = right_value;
                    break;

                case Expression::Type::EXP_LSHIFT :
                case Expression::Type::EXP_LSASSIGN :
                    return nullptr;
                case Expression::Type::EXP_RSHIFT :
                case Expression::Type::EXP_RSASSIGN :
                    return nullptr;

                case Expression::Type::EXP_ADD :
                case Expression::Type::EXP_ADDASSIGN :
                    result_value = left_value + right_value;
                    break;
                case Expression::Type::EXP_SUB :
                case Expression::Type::EXP_SUBASSIGN :
                    result_value = left_value - right_value;
                    break;
                case Expression::Type::EXP_MUL :
                case Expression::Type::EXP_MULASSIGN :
                    result_value = left_value * right_value;
                    break;
                case Expression::Type::EXP_DIV :
                case Expression::Type::EXP_DIVASSIGN :
                    result_value = left_value / right_value;
                    break;
                case Expression::Type::EXP_MOD :
                case Expression::Type::EXP_MODASSIGN :
                    result_value = fmod(left_value, right_value);
                    break;
                case Expression::Type::EXP_XOR :
                case Expression::Type::EXP_XORASSIGN :
                    return nullptr;

                case Expression::Type::EXP_LOR :
                    result_value = left_value || right_value;
                    break;
                case Expression::Type::EXP_LAND :
                    result_value = left_value && right_value;
                    break;

                default:
                    return nullptr;
            }

            result = FloatValue::Create(data_type_, result_value);
        }

        return result;
    }