Search in sources :

Example 1 with ArrayType

use of com.rockwellcollins.atc.agree.agree.ArrayType in project AGREE by loonwerks.

the class AgreeTypeSystem method typeDefFromType.

public static TypeDef typeDefFromType(Type t) {
    if (t instanceof PrimType) {
        int lowSign = ((PrimType) t).getLowNeg() == null ? 1 : -1;
        int highSign = ((PrimType) t).getHighNeg() == null ? 1 : -1;
        String lowStr = ((PrimType) t).getRangeLow();
        String highStr = ((PrimType) t).getRangeHigh();
        if (((PrimType) t).getName().equals("int")) {
            if (lowStr == null || highStr == null) {
                return Prim.IntTypeDef;
            } else {
                long low = Long.valueOf(lowStr) * lowSign;
                long high = Long.valueOf(highStr) * highSign;
                return new RangeIntTypeDef(low, high);
            }
        } else if (((PrimType) t).getName().equals("real")) {
            if (lowStr == null || highStr == null) {
                return Prim.RealTypeDef;
            } else {
                double low = Double.valueOf(lowStr) * lowSign;
                double high = Double.valueOf(highStr) * highSign;
                return new RangeRealTypeDef(low, high);
            }
        } else if (((PrimType) t).getName().equals("bool")) {
            return Prim.BoolTypeDef;
        } else {
            return Prim.ErrorTypeDef;
        }
    } else if (t instanceof ArrayType) {
        String size = ((ArrayType) t).getSize();
        TypeDef baseTypeDef = typeDefFromType(((ArrayType) t).getStem());
        return new ArrayTypeDef(baseTypeDef, Integer.parseInt(size), Optional.empty());
    } else if (t instanceof DoubleDotRef) {
        return typeDefFromNE(((DoubleDotRef) t).getElm());
    } else {
        return Prim.ErrorTypeDef;
    }
}
Also used : ArrayType(com.rockwellcollins.atc.agree.agree.ArrayType) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) PrimType(com.rockwellcollins.atc.agree.agree.PrimType) AadlString(org.osate.aadl2.AadlString)

Aggregations

ArrayType (com.rockwellcollins.atc.agree.agree.ArrayType)1 DoubleDotRef (com.rockwellcollins.atc.agree.agree.DoubleDotRef)1 PrimType (com.rockwellcollins.atc.agree.agree.PrimType)1 AadlString (org.osate.aadl2.AadlString)1