Skip to content
Snippets Groups Projects
AvatarFromSysML.java 62.2 KiB
Newer Older
            extendPrimitiveType = AvatarType.INTEGER;
            return path;
        }
        if (extendString.equals("Boolean")) {
            extendDataType = null;
            extendPrimitiveType = AvatarType.BOOLEAN;
        extendPrimitiveType = null;
        extendDataType = avSpec.getDataTypeByName(extendString);
        if (extendDataType != null)
            return extendName(path, extendDataType);
        else return null;
    }
    private String extendName(String name, AvatarDataType adt) {
        if (adt != null) {
            AvatarDataTypePrimitiveFields primitiveFields = primitiveFieldsMap.get(adt);
Sophie Coudert's avatar
Sophie Coudert committed
            int size = primitiveFields.size() -1;
            StringBuffer res = new StringBuffer();
            int i;
            for (i = 0; i < size; i++)
                res.append(name + "__" + primitiveFields.getName(i) + ", ");
            res.append(name + "__" + primitiveFields.getName(i));
            return res.toString();
        }
        else return null;
    }
    private String extendIdent (String path, StxBlock b) {
        String result = extendPath(path, b);
        return (result.indexOf(',') == -1 ? result : "(" + result + ")");
    }
     private String extendCall (StxCall call, StxBlock b) {
        StringBuffer result = new StringBuffer();
        int size = call.getNbIdents();
        int i;
        for (i =0 ; i < size; i++) {
            result.append(call.getSegment(i));
            result.append(extendPath(call.getIdent(i).replaceAll("\\.", "__"), b));
        }
        result.append(call.getSegment(i));
        return result.toString().replaceAll("\\.", "__");
     }
     private String extendOriginalCall (StxCall call, StxBlock b) {
        StringBuffer result = new StringBuffer();
        int size = call.getNbIdents();
        int i;
        for (i =0 ; i < size; i++) {
            result.append(call.getSegment(i));
Sophie Coudert's avatar
Sophie Coudert committed
            result.append(call.getIdent(i));
        }
        result.append(call.getSegment(i));
        return result.toString();
     }
     // BUILD RELATIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    private void buildRelations(){
        stxSpec.getRelationMap().forEach(new BuildRelation());
    }
    private class BuildRelation implements BiConsumer<String, StxRelation> {
        public BuildRelation() {
        }
        public void accept(String n, StxRelation r) {
            if (!r.isDeclared()) {
                addError(new AvatarFromSysMLError(AvatarFromSysMLError.LOWERROR,
                        "relation " + r.getName() +" has been used but has not been declared"));
                int size = r.getSize();
                if (size == 0) {
                    addError(new AvatarFromSysMLError(AvatarFromSysMLError.LOWWARNING, r.getLeft(),
                     "relation is empty"));
                    return;
                } else {
                    int i = 0;
                    while (i < size && (r.getChannel(i).getBlockA() == null || r.getChannel(i).getBlockB() == null)) i++;
                    if (i == size) {
                        addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR,
                     "cannot determine blocs of relation " + r.getName()));
                        return;
                    }
                    r.setBlock1(stxSpec.getBlockMap().get(r.getChannel(i).getBlockA()));
                    r.setBlock2(stxSpec.getBlockMap().get(r.getChannel(i).getBlockB()));
                    if (r.getBlock1() == null || r.getBlock2() == null) {
                        addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR,
                     "cannot determine blocs of relation " + r.getName()));
                        return;
                    }
               }
            }
            AvatarBlock blk1 = getBlock(r.getBlock1());
            AvatarBlock blk2 = getBlock(r.getBlock2());
            AvatarRelation theRelation = new AvatarRelation(n, blk1, blk2, null);
            avSpec.addRelation(theRelation);
            theRelation.setAsynchronous(r.getAsynchronous());
            theRelation.setPrivate(r.getPrivate());
            theRelation.setLossy(r.getLossy());
            theRelation.setBlocking(r.getBlocking());
            theRelation.setSizeOfFIFO(r.getFifoSize());
            int size = r.getSize();
Sophie Coudert's avatar
Sophie Coudert committed
            if (size == 0) {
                addError(new AvatarFromSysMLError(AvatarFromSysMLError.LOWWARNING, r.getLeft(),
                 "relation " + r.getName() + " is empty"));
Sophie Coudert's avatar
Sophie Coudert committed
            }
            for (int i = 0; i < size; i++) {
                StxChannel c = r.getChannel(i);
                c.commuteSignals(r.getBlock1().getName());
                if (!blk1.getName().equals(c.getBlockA()) || !blk2.getName().equals(c.getBlockB())) {
                 addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, c.getLeft(),
                 "inconsistency between blocs of channel " + c.getName() + " and relation " + r.getName()));
                 continue;
                }
                if (c.getSignalA() != null && c.getSignalB() != null)
                    theRelation.addSignals(getSignal(c.getSignalA()),getSignal(c.getSignalB()));
                else
                 addError(new AvatarFromSysMLError(AvatarFromSysMLError.LOWERROR, c.getLeft(),
                 "missing signal binding for channel"));
           }