diff --git a/src/main/java/avatartranslator/tosysmlv2/AvatarFromSysML.java b/src/main/java/avatartranslator/tosysmlv2/AvatarFromSysML.java index 8a0791b99e9db9d00d7e34bd886b2e9eafb8731a..2bf3a6767ef7dcde6d1655a0595bbf69e2b955de 100644 --- a/src/main/java/avatartranslator/tosysmlv2/AvatarFromSysML.java +++ b/src/main/java/avatartranslator/tosysmlv2/AvatarFromSysML.java @@ -77,6 +77,7 @@ public class AvatarFromSysML { new ComplexSymbolFactory()); stxSpec = parser.parseModel(); buildDataTypes(); + buildBlocks(); } // BUILDING DATATYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% private class BuildDataType implements BiConsumer<String, StxDataType> { @@ -174,10 +175,103 @@ public class AvatarFromSysML { } } } - + // add Timers + size = blk.getNbTimers(); + for (int i = 0; i < size; i++) { + AvatarAttribute aa = new AvatarAttribute(blk.getTimer(i).getName(), AvatarType.TIMER, theBlock, null); + theBlock.addAttribute(aa); + aa.setAsConstant(false); + } + // add Methods + size = blk.getNbMethods(); + for (int i = 0; i < size; i++) { + StxMethod sm = blk.getMethod(i); + AvatarMethod am = new AvatarMethod(sm.getName(),null); + theBlock.addMethod(am); + buildProfile(sm, am, theBlock); + String returnType = sm.getReturnType(); + if (returnType == null) continue; + if (returnType.equals("Integer")) + am.addReturnParameter(new AvatarAttribute("return__0", AvatarType.INTEGER, theBlock, null)); + else if (returnType.equals("Boolean")) + am.addReturnParameter(new AvatarAttribute("return__0", AvatarType.BOOLEAN, theBlock, null)); + else { + AvatarDataType adt = AvatarDataType.dataTypeMap.get(returnType); + int nbFields = adt.getNbFields(); + for (int j = 0; j < nbFields; j++) { + AvatarType type = (adt.getFieldStringType(j) == AvatarDataType.INTEGER ? AvatarType.INTEGER : AvatarType.BOOLEAN); + am.addReturnParameter(new AvatarAttribute("return__" + j, type, theBlock, null)); + } + } + } + // add Signals (build profile delayed) + size = blk.getNbSignals(); + for (int i = 0; i < size; i++) { + StxSignal ss = blk.getSignal(i); + AvatarSignal as = getSignal(ss); + theBlock.addSignal(as); + } } } private void buildBlocks(){ stxSpec.getBlockMap().forEach(new BuildBlock()); } + private void buildProfile(StxStructure ss, AvatarMethod am, AvatarBlock b) { + AvatarAttribute aa; + int size = ss.getSize(); + for (int i = 0; i < size; i++) { + String type = ss.getFieldType(i); + if (type.equals("Integer")){ + aa = new AvatarAttribute(ss.getFieldName(i), AvatarType.INTEGER, b, null); + am.addParameter(aa); + aa.setAsConstant(false); + } else if (type.equals("Boolean")) { + aa = new AvatarAttribute(ss.getFieldName(i), AvatarType.BOOLEAN, b, null); + am.addParameter(aa); + aa.setAsConstant(false); + } else { + AvatarDataType adt = AvatarDataType.dataTypeMap.get(type); + int tsize = adt.getFullSize(); + for(int j = 0; j < tsize; j++) { + aa = new AvatarAttribute( + ss.getFieldName(i) + "__" + adt.getFieldString(j), + (adt.getFieldStringType(j) == AvatarDataType.BOOLEAN ? AvatarType.BOOLEAN : AvatarType.INTEGER), + b, null); + am.addParameter(aa); + aa.setAsConstant(false); + if (j == 0) aa.setDataType(adt); + } + } + } + } + private String getStxAttributeType(String name, StxBlock blk){ + int size = blk.getNbAttributes(); + for (int i = 0; i < size; i++) { + if (blk.getAttribute(i).getName().equals(name)) return blk.getAttribute(i).getType(); + } + return null; + } + private String getStxPathType(String s, StxBlock b) { + String[] path = s.split("__"); + String type = getStxAttributeType(path[0], b); + int size = path.length; + for (int i = 1; i < size; i++) { + AvatarDataType adt = AvatarDataType.dataTypeMap.get(type); + if (adt == null) return null; + int nbFields = adt.getNbFields(); + int j; + for (j = 0; j < nbFields; j++) + if (adt.getFieldName(j).equals(path[i])) break; + if (j == nbFields) return null; + int adtType = adt.getFieldType(j); + if (adtType == AvatarDataType.INTEGER) + type = "Integer"; + else if (adtType == AvatarDataType.BOOLEAN) + type = "Boolean"; + else + type = adt.getDataTypeName(j); + } + return type; + } + } diff --git a/src/main/java/avatartranslator/tosysmlv2/AvatarFromSysMLSyntax.java b/src/main/java/avatartranslator/tosysmlv2/AvatarFromSysMLSyntax.java index 95145e6108888c73c9d2c62cb8d50fe8c9293049..9b67ffd9f176811cadaeccc56b0ca8aa48714c93 100644 --- a/src/main/java/avatartranslator/tosysmlv2/AvatarFromSysMLSyntax.java +++ b/src/main/java/avatartranslator/tosysmlv2/AvatarFromSysMLSyntax.java @@ -336,12 +336,12 @@ public class AvatarFromSysMLSyntax { public int getNbConstants() { return constants.size(); } public int getNbMethods() { return methods.size(); } public int getNbSignals() { return signals.size(); } - public int getNbTimerss() { return timers.size(); } + public int getNbTimers() { return timers.size(); } public StxAttribute getAttribute(int i) { return attributes.get(i); } public StxAttribute getConstant(int i) { return constants.get(i); } public StxMethod getMethod(int i) { return methods.get(i); } public StxSignal getSignal(int i) { return signals.get(i); } - public StxTimer getTimers(int i) { return timers.get(i); } + public StxTimer getTimer(int i) { return timers.get(i); } } public static class StxChannel extends StxElement { private StxInMessage inProfile;