8000 Eclipse parser should enforce type safety when adding values to arrays · Issue #132 · orcc/orcc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Eclipse parser should enforce type safety when adding values to arrays #132
Open
@robstewart57

Description

@robstewart57

Eclipse does not complain about this code:

float foo[10];
foo[0] := 0;

This code fails when executed with the Orcc simulator

caused by: net.sf.orcc.OrccRuntimeException: unexpected type in set
    at net.sf.orcc.ir.util.ValueUtil.set(ValueUtil.java:889)

Because the simulator type checks the element type in CAL with the actual type of the value, at runtime (see here )

if (type.isBool() && isBool(value) || type.isString()
                && isString(value)) {
            valueToSet = value;
        } else if (type.isFloat() && isFloat(value)) {
            BigDecimal floatVal = (BigDecimal) value;
            valueToSet = floatVal.floatValue();
        } else if ((type.isInt() || type.isUint()) && isInt(value)) {
            BigInteger intVal = (BigInteger) value;
            int size = type.getSizeInBits();
            if (size <= 8) {
                valueToSet = intVal.byteValue();
            } else if (size <= 16) {
                valueToSet = intVal.shortValue();
            } else if (size <= 32) {
                valueToSet = intVal.intValue();
            } else if (size <= 64) {
                valueToSet = intVal.longValue();
            } else {
                valueToSet = value;
            }
        } else {
            throw new OrccRuntimeException("unexpected type in set");
        }

Would it be better to avoid this, by enforcing 4F66 these checks within the frontend Eclipse editor?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0