diff --git a/src/main/java/avatartranslator/AvatarAttribute.java b/src/main/java/avatartranslator/AvatarAttribute.java index 8c1d689e87d92ed87bf2a4d2ffec9b313d9dfd11..113e27929d9632583d73699a320d67b8f3898cb2 100644 --- a/src/main/java/avatartranslator/AvatarAttribute.java +++ b/src/main/java/avatartranslator/AvatarAttribute.java @@ -63,15 +63,6 @@ public class AvatarAttribute extends AvatarLeftHand implements NameChecker.NameS public AvatarAttribute(String _name, AvatarType _type, AvatarStateMachineOwner _block, Object _referenceObject) { super(_name, _referenceObject); - /*if (_type == -1) { - TraceManager.addDev("- - - - - - - - - - - - " + _name + ": " + _type); - try { - int x = 1 / 0; - } catch (Exception e) { - e.printStackTrace(); - System.exit(0); - } - }*/ type = _type; this.block = _block; } diff --git a/src/main/java/avatartranslator/AvatarDataType.java b/src/main/java/avatartranslator/AvatarDataType.java new file mode 100644 index 0000000000000000000000000000000000000000..f01863b5faf6d875350c00279b597bc7c6c20a46 --- /dev/null +++ b/src/main/java/avatartranslator/AvatarDataType.java @@ -0,0 +1,180 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package avatartranslator; + +import avatartranslator.intboolsolver.AvatarIBSolver; +import myutil.NameChecker; +import myutil.TraceManager; +import myutil.intboolsolver.IBSParamComp; +import org.json.JSONArray; +import org.json.JSONObject; + +import java.util.*; + + +/** + * Class AvatarDataType + * Creation: 31/05/2024 + * + * @author Ludovic APVRILLE + */ +public class AvatarDataType extends AvatarElement implements NameChecker.NameStartWithUpperCase, IBSParamComp { + + private List<AvatarAttribute> attributes; + + + public AvatarDataType(String _name, Object _referenceObject) { + super(_name, _referenceObject); + attributes = new LinkedList<AvatarAttribute>(); + } + + + public void clearAttributes() { + attributes.clear(); + } + + + public List<AvatarAttribute> getAttributes() { + return attributes; + } + + + public void addAttribute(AvatarAttribute _aa) { + if (getAvatarAttributeWithName(_aa.getName()) == null) { + //TraceManager.addDevStackTrace("Adding attribute " + _aa.getName() + " to block " + getName()); + attributes.add(_aa); + } + } + + + public String toString() { + //Thread.currentThread().dumpStack(); + StringBuffer sb = new StringBuffer("DataType:" + getName() + " ID=" + getID() + " \n"); + + for (AvatarAttribute attribute : attributes) { + sb.append(" attribute: " + attribute.toString() + " ID=" + attribute.getID() + "\n"); + } + + return sb.toString(); + } + + public String toStringRecursive() { + + return toString(); + } + + + + public String toShortString() { + return toString(); + } + + public int attributeNb() { + return attributes.size(); + } + + + public AvatarAttribute getAttribute(int _index) { + return attributes.get(_index); + } + + public boolean setAttributeValue(int _index, String _value) { + AvatarAttribute aa = attributes.get(_index); + if (aa == null) { + return false; + } + aa.setInitialValue(_value); + return true; + } + + public int getIndexOfAvatarAttributeWithName(String _name) { + int cpt = 0; + for (AvatarAttribute attribute : attributes) { + if (attribute.getName().compareTo(_name) == 0) { + return cpt; + } + cpt++; + } + return -1; + } + + + /** + * Look for an attribute with the provided name. + * + * @param _name The name of the attribute to look for. + * @return The attribute if found, or null otherwise + */ + public AvatarAttribute getAvatarAttributeWithName(String _name) { + if ((attributes == null) || (_name == null)) { + return null; + } + for (AvatarAttribute attribute : attributes) { + if (attribute.getName().compareTo(_name) == 0) { + return attribute; + } + } + return null; + } + + + + public NameChecker.NamedElement[] getSubNamedElements() { + NameChecker.NamedElement[] nes = new NameChecker.NamedElement[attributes.size()]; + int index = 0; + for (AvatarAttribute aa : attributes) { + nes[index] = aa; + index++; + } + return nes; + } + + public AvatarDataType advancedClone() { + AvatarDataType adt = new AvatarDataType(getName(), getReferenceObject()); + for(AvatarAttribute aa: attributes) { + adt.addAttribute(aa.advancedClone(null)); + } + return adt; + } + + + + + +} diff --git a/src/main/java/avatartranslator/AvatarSpecification.java b/src/main/java/avatartranslator/AvatarSpecification.java index ffad9ae0007d83471781075a1348ed09fdd9b370..3de6ca7ae2f6935837c171292fffa16a8a3c7b25 100644 --- a/src/main/java/avatartranslator/AvatarSpecification.java +++ b/src/main/java/avatartranslator/AvatarSpecification.java @@ -43,6 +43,7 @@ import myutil.Conversion; import myutil.NameChecker; import myutil.TraceManager; import myutil.intboolsolver.IBSParamSpec; +import org.apache.derby.iapi.types.DataType; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -67,6 +68,8 @@ public class AvatarSpecification extends AvatarElement implements IBSParamSpec { private final List<AvatarBlock> blocks; private final List<AvatarRelation> relations; private final List<AvatarAMSInterface> interfaces; + private final List<AvatarDataType> dataTypes; + /** * The list of all library functions that can be called. */ @@ -92,6 +95,7 @@ public class AvatarSpecification extends AvatarElement implements IBSParamSpec { blocks = new LinkedList<>(); interfaces = new LinkedList<>(); relations = new LinkedList<>(); + dataTypes = new LinkedList<>(); pragmas = new LinkedList<>(); constants = new LinkedList<>(); safetyPragmas = new LinkedList<>(); @@ -668,6 +672,10 @@ public class AvatarSpecification extends AvatarElement implements IBSParamSpec { return relations; } + public List<AvatarDataType> getDataTypes() { + return dataTypes; + } + public List<AvatarPragma> getPragmas() { return pragmas; } @@ -760,6 +768,10 @@ public class AvatarSpecification extends AvatarElement implements IBSParamSpec { relations.add(_relation); } + public void addDataType(AvatarDataType _adt) { + dataTypes.add(_adt); + } + public void addInterfaceRelation(AvatarInterfaceRelation _irelation) { irelations.add(_irelation); } @@ -806,6 +818,10 @@ public class AvatarSpecification extends AvatarElement implements IBSParamSpec { for (AvatarRelation relation : relations) { sb.append("Relation:" + relation.toString() + "\n"); } + sb.append("\nData types:\n"); + for (AvatarDataType type : dataTypes) { + sb.append("Data type:" + type.toString() + "\n"); + } sb.append("\nPragmas:\n"); for (AvatarPragma pragma : pragmas) { sb.append("Pragma:" + pragma.toString() + "\n"); @@ -1410,6 +1426,13 @@ public class AvatarSpecification extends AvatarElement implements IBSParamSpec { } } + for (AvatarDataType dt : dataTypes) { + AvatarDataType dt2 = dt.advancedClone(); + if (dt2 != null) { + spec.addDataType(dt2); + } + } + /*for(AvatarPragma pragma: pragmas) { AvatarPragma nP = pragma.advancedClone(); spec.addPragma(nP); diff --git a/src/main/java/ui/AvatarDesignPanelTranslator.java b/src/main/java/ui/AvatarDesignPanelTranslator.java index 4e64961bdf4522240a729fbb5ebe9b5e3338a9b1..f0789be5ad6a5484468b350695026f0169607a77 100644 --- a/src/main/java/ui/AvatarDesignPanelTranslator.java +++ b/src/main/java/ui/AvatarDesignPanelTranslator.java @@ -86,6 +86,7 @@ public class AvatarDesignPanelTranslator { public AvatarSpecification generateAvatarSpecification(List<AvatarBDStateMachineOwner> _blocks) { List<AvatarBDBlock> blocks = new LinkedList<AvatarBDBlock>(); List<AvatarBDLibraryFunction> libraryFunctions = new LinkedList<AvatarBDLibraryFunction>(); + List<AvatarBDDataType> listOfDataTypes = new LinkedList<>(); for (AvatarBDStateMachineOwner owner : _blocks) if (owner instanceof AvatarBDBlock) @@ -99,14 +100,26 @@ public class AvatarDesignPanelTranslator { AvatarSpecification as = new AvatarSpecification("avatarspecification", adp); + //TraceManager.addDev("Getting graphical data types"); if (adp != null) { AvatarBDPanel abdp = adp.getAvatarBDPanel(); if (abdp != null) { as.addApplicationCode(abdp.getMainCode()); + for(TGComponent tgc: abdp.getAllComponentList()) { + if (tgc instanceof AvatarBDDataType) { + listOfDataTypes.add((AvatarBDDataType)(tgc)); + } + } + // Find data types + } } + + TraceManager.addDev("Nb of data types: " + listOfDataTypes.size()); + typeAttributesMap = new HashMap<String, List<TAttribute>>(); nameTypeMap = new HashMap<String, String>(); + createDataTypes(as, listOfDataTypes); createLibraryFunctions(as, libraryFunctions); createBlocks(as, blocks); //createInterfaces(as, interfaces); @@ -1049,7 +1062,7 @@ public class AvatarDesignPanelTranslator { aa.setInitialValue(_a.getInitialValue()); aa.setAsConstant(_a.isConstant()); - if ( (originAttribute != null) && (originAttribute.isConstant()) ) { + if ((originAttribute != null) && (originAttribute.isConstant())) { aa.setAsConstant(true); } @@ -1064,6 +1077,23 @@ public class AvatarDesignPanelTranslator { _ai.addAttribute(this.createRegularAttribute(_ai, _a, _preName, originAttribute)); } + private void createDataTypes(AvatarSpecification _as, List<AvatarBDDataType> _dataTypes) { + for(AvatarBDDataType type: _dataTypes) { + AvatarDataType adt = new AvatarDataType(type.getDataTypeName(), type); + for(TAttribute ta: type.getAttributeList()) { + AvatarType ty = AvatarType.UNDEFINED; + if (ta.getType() == TAttribute.INTEGER) { + ty = AvatarType.INTEGER; + } else { + ty = AvatarType.BOOLEAN; + } + AvatarAttribute aa = new AvatarAttribute(ta.getName(), ty, null, type); + adt.addAttribute(aa); + } + _as.addDataType(adt); + } + } + private void createLibraryFunctions(AvatarSpecification _as, List<AvatarBDLibraryFunction> _libraryFunctions) { for (AvatarBDLibraryFunction libraryFunction : _libraryFunctions) { AvatarLibraryFunction alf = new AvatarLibraryFunction(libraryFunction.getFunctionName(), _as, libraryFunction); @@ -2327,6 +2357,7 @@ public class AvatarDesignPanelTranslator { int index2 = actionText.indexOf(";"); if (index2 != -1) { + makeError(error, connector.tdp, block, connector, "transition action", actionText); } @@ -2886,7 +2917,7 @@ public class AvatarDesignPanelTranslator { String s = _input.substring(index0 + 1, index1).trim(); - String end = _input.substring(index1+1).trim(); + String end = _input.substring(index1 + 1).trim(); //TraceManager.addDev("end>" + end + "<"); if (end.length() > 0) { return null; diff --git a/src/main/java/ui/GTURTLEModeling.java b/src/main/java/ui/GTURTLEModeling.java index f775560b3132d02ade7817a922a5daf4715bc504..c34737cf7ab1dd102bb6224df18032b1686b73d8 100644 --- a/src/main/java/ui/GTURTLEModeling.java +++ b/src/main/java/ui/GTURTLEModeling.java @@ -9652,6 +9652,8 @@ public class GTURTLEModeling { } //TraceManager.addDev("Check done. " + checkingErrors.size() + " errors found\nAvatar Spec:\n" + avspec.toString()); + TraceManager.addDev("Avspec to be drawn:" + avspec.toStringRecursive(true)); + // Go for drawing! hasCrypto = false; @@ -9759,6 +9761,9 @@ public class GTURTLEModeling { } } + // Data types + // Put them on the lower part + for (AvatarRelation ar : avspec.getRelations()) { String bl1 = ar.block1.getName(); @@ -9822,7 +9827,35 @@ public class GTURTLEModeling { } } - ypos += 100; + xpos = 50; + ypos = 500; + + for (AvatarDataType adt : avspec.getDataTypes()) { + AvatarBDDataType abdType = new AvatarBDDataType(xpos, ypos, abd.getMinX(), abd.getMaxX(), abd.getMinY(), abd.getMaxY(), false, + null, abd); + // Adding attributes + for (AvatarAttribute attr : adt.getAttributes()) { + int type = 4; + if (attr.getType() == AvatarType.INTEGER) { + type = 0; + } + if (attr.getType() == AvatarType.TIMER) { + type = 9; + } + abdType.addAttribute(new TAttribute(0, attr.getName(), attr.getType().getDefaultInitialValue(), type)); + } + + + // Drawing + if ((adt.getReferenceObject() != null) && (adt.getReferenceObject() instanceof CDElement)) { + CDElement cd = ((CDElement) (adt.getReferenceObject())); + abdType.setUserResize(cd.getX(), cd.getY(), cd.getWidth(), cd.getHeight()); + abd.addComponent(abdType, cd.getX(), cd.getY(), false, true); + } else { + abd.addComponent(abdType, xpos, ypos, false, true); + } + + } //Add Pragmas