Search in sources :

Example 1 with EnumType

use of jkind.lustre.EnumType in project AGREE by loonwerks.

the class AgreeASTPrettyprinter method visit.

@Override
public Void visit(AgreeProgram program) {
    if (program.containsRealTimePatterns) {
        write("-- Program contains real-time patterns");
        newline();
        newline();
    }
    write("-- Program top-level node is: " + program.topNode.id);
    newline();
    newline();
    if (!program.globalTypes.isEmpty()) {
        for (Type type : program.globalTypes) {
            String name = "dummy";
            if (type instanceof RecordType) {
                name = ((RecordType) type).id;
            } else if (type instanceof EnumType) {
                name = ((EnumType) type).id;
            }
            TypeDef typeDef = new TypeDef(Location.NULL, name, type);
            typeDef.accept(this);
            newline();
        }
        newline();
    }
    if (!program.globalLustreNodes.isEmpty()) {
        Iterator<Node> iterator = program.globalLustreNodes.iterator();
        while (iterator.hasNext()) {
            iterator.next().accept(this);
            newline();
            if (iterator.hasNext()) {
                newline();
            }
        }
        newline();
    }
    if (!program.uninterpretedFunctions.isEmpty()) {
        Iterator<Function> iterator = program.uninterpretedFunctions.iterator();
        while (iterator.hasNext()) {
            iterator.next().accept(this);
            newline();
            if (iterator.hasNext()) {
                newline();
            }
        }
        newline();
    }
    Iterator<AgreeNode> iterator = program.agreeNodes.iterator();
    while (iterator.hasNext()) {
        iterator.next().accept(this);
        newline();
        if (iterator.hasNext()) {
            newline();
        }
    }
    newline();
    return null;
}
Also used : Function(jkind.lustre.Function) RecordType(jkind.lustre.RecordType) Type(jkind.lustre.Type) EnumType(jkind.lustre.EnumType) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) RecordType(jkind.lustre.RecordType) TypeDef(jkind.lustre.TypeDef) EnumType(jkind.lustre.EnumType) Node(jkind.lustre.Node) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)

Example 2 with EnumType

use of jkind.lustre.EnumType in project AGREE by loonwerks.

the class PrettyPrintVisitor method writeType.

private void writeType(Type type) {
    if (type instanceof RecordType) {
        RecordType recordType = (RecordType) type;
        write("struct {");
        Iterator<Entry<String, Type>> iterator = recordType.fields.entrySet().iterator();
        while (iterator.hasNext()) {
            Entry<String, Type> entry = iterator.next();
            write(entry.getKey());
            write(" : ");
            write(entry.getValue());
            if (iterator.hasNext()) {
                write("; ");
            }
        }
        write("}");
    } else if (type instanceof EnumType) {
        EnumType enumType = (EnumType) type;
        write("enum {");
        Iterator<String> iterator = enumType.values.iterator();
        while (iterator.hasNext()) {
            write(iterator.next());
            if (iterator.hasNext()) {
                write(", ");
            }
        }
        write("}");
    } else {
        write(type);
    }
}
Also used : Entry(java.util.Map.Entry) RecordType(jkind.lustre.RecordType) Type(jkind.lustre.Type) EnumType(jkind.lustre.EnumType) NamedType(jkind.lustre.NamedType) RecordType(jkind.lustre.RecordType) EnumType(jkind.lustre.EnumType) Iterator(java.util.Iterator)

Example 3 with EnumType

use of jkind.lustre.EnumType in project AGREE by loonwerks.

the class TypeTable method getLustreType.

public Type getLustreType(AgreeTypeSystem.TypeDef agreeType) {
    if (agreeType == AgreeTypeSystem.Prim.IntTypeDef) {
        return NamedType.INT;
    } else if (agreeType == AgreeTypeSystem.Prim.RealTypeDef) {
        return NamedType.REAL;
    } else if (agreeType == AgreeTypeSystem.Prim.BoolTypeDef) {
        return NamedType.BOOL;
    } else if (agreeType instanceof AgreeTypeSystem.RangeIntTypeDef) {
        return NamedType.INT;
    } else if (agreeType instanceof AgreeTypeSystem.RangeRealTypeDef) {
        return NamedType.REAL;
    } else if (agreeType instanceof AgreeTypeSystem.RecordTypeDef) {
        String name = ((AgreeTypeSystem.RecordTypeDef) agreeType).name.replace("::", "__").replace(".", "__");
        Map<String, AgreeTypeSystem.TypeDef> agreeFields = ((AgreeTypeSystem.RecordTypeDef) agreeType).fields;
        Map<String, Type> lustreFields = new HashMap<>();
        for (Entry<String, AgreeTypeSystem.TypeDef> entry : agreeFields.entrySet()) {
            String key = entry.getKey();
            Type lt = updateLustreTypeMap(entry.getValue());
            if (lt != null) {
                lustreFields.put(key, lt);
            }
        }
        RecordType lustreRecType = new RecordType(name, lustreFields);
        return lustreRecType;
    } else if (agreeType instanceof AgreeTypeSystem.EnumTypeDef) {
        String name = ((AgreeTypeSystem.EnumTypeDef) agreeType).name.replace("::", "__").replace(".", "__");
        List<String> enumValues = new ArrayList<String>();
        for (String raw : ((AgreeTypeSystem.EnumTypeDef) agreeType).values) {
            String enumValue = raw.replace("::", "__").replace(".", "__");
            enumValues.add(enumValue);
        }
        EnumType lustreEnumType = new EnumType(name, enumValues);
        return lustreEnumType;
    } else if (agreeType instanceof AgreeTypeSystem.ArrayTypeDef) {
        AgreeTypeSystem.TypeDef agreeBaseType = ((AgreeTypeSystem.ArrayTypeDef) agreeType).stemType;
        int dimension = ((AgreeTypeSystem.ArrayTypeDef) agreeType).size;
        Type lustreBaseType = updateLustreTypeMap(agreeBaseType);
        if (lustreBaseType != null) {
            ArrayType lustreArrayType = new ArrayType(lustreBaseType, dimension);
            return lustreArrayType;
        }
    }
    // Jkind does not reason over this.
    return null;
}
Also used : ArrayList(java.util.ArrayList) ArrayType(jkind.lustre.ArrayType) AgreeTypeSystem(com.rockwellcollins.atc.agree.AgreeTypeSystem) Entry(java.util.Map.Entry) EnumType(jkind.lustre.EnumType) NamedType(jkind.lustre.NamedType) ArrayType(jkind.lustre.ArrayType) RecordType(jkind.lustre.RecordType) Type(jkind.lustre.Type) RecordType(jkind.lustre.RecordType) EnumType(jkind.lustre.EnumType) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with EnumType

use of jkind.lustre.EnumType in project AGREE by loonwerks.

the class AgreeUtils method getLustreTypes.

public static List<TypeDef> getLustreTypes(AgreeProgram agreeProgram) {
    List<TypeDef> types = new ArrayList<>();
    for (Type type : agreeProgram.globalTypes) {
        String typeName;
        if (type instanceof RecordType) {
            typeName = ((RecordType) type).id;
        } else if (type instanceof EnumType) {
            typeName = ((EnumType) type).id;
        } else {
            throw new AgreeException("Unable to handle type of type '" + type.getClass() + "'");
        }
        types.add(new TypeDef(typeName, type));
    }
    // add synonym types
    types.addAll(getTypeSynonmyms());
    return types;
}
Also used : RecordType(jkind.lustre.RecordType) EnumType(jkind.lustre.EnumType) ComponentType(org.osate.aadl2.ComponentType) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) TypeDef(jkind.lustre.TypeDef) RecordType(jkind.lustre.RecordType) EnumType(jkind.lustre.EnumType) ArrayList(java.util.ArrayList)

Aggregations

EnumType (jkind.lustre.EnumType)4 RecordType (jkind.lustre.RecordType)4 Type (jkind.lustre.Type)4 NamedType (jkind.lustre.NamedType)3 ArrayList (java.util.ArrayList)2 Entry (java.util.Map.Entry)2 TypeDef (jkind.lustre.TypeDef)2 AgreeTypeSystem (com.rockwellcollins.atc.agree.AgreeTypeSystem)1 AgreeNode (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 ArrayType (jkind.lustre.ArrayType)1 Function (jkind.lustre.Function)1 Node (jkind.lustre.Node)1 ComponentType (org.osate.aadl2.ComponentType)1