From 8b4b062927d45ab75bb9491f1e3bf59311cac42c Mon Sep 17 00:00:00 2001 From: apvrille <ludovic.apvrille@eurecom.fr> Date: Mon, 29 Jan 2018 17:18:31 +0100 Subject: [PATCH] Update on TTool: select keyword --- .idea/misc.xml | 2 +- .../avatartranslator/AvatarAttribute.java | 78 +++++---- src/main/java/translator/JKeyword.java | 2 +- src/main/java/ui/AvatarMethod.java | 150 +++++++++--------- 4 files changed, 119 insertions(+), 113 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 51e5191ed4..b755d8ca46 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -38,7 +38,7 @@ <property name="caretWidth" class="java.lang.Integer" /> </properties> </component> - <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK"> + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="false" project-jdk-name="1.7" project-jdk-type="JavaSDK"> <output url="file://$PROJECT_DIR$/build" /> </component> </project> \ No newline at end of file diff --git a/src/main/java/avatartranslator/AvatarAttribute.java b/src/main/java/avatartranslator/AvatarAttribute.java index 84b5d3ee1b..1701e29ad4 100644 --- a/src/main/java/avatartranslator/AvatarAttribute.java +++ b/src/main/java/avatartranslator/AvatarAttribute.java @@ -37,9 +37,6 @@ */ - - - package avatartranslator; import myutil.TraceManager; @@ -47,11 +44,12 @@ import myutil.TraceManager; import java.util.HashMap; /** - * Class AvatarAttribute - * Avatar attributes, either of blocks, or manipulated by signals / methods - * Creation: 20/05/2010 - * @version 1.0 20/05/2010 - * @author Ludovic APVRILLE + * Class AvatarAttribute + * Avatar attributes, either of blocks, or manipulated by signals / methods + * Creation: 20/05/2010 + * + * @author Ludovic APVRILLE + * @version 1.0 20/05/2010 */ public class AvatarAttribute extends AvatarLeftHand { @@ -62,7 +60,7 @@ public class AvatarAttribute extends AvatarLeftHand { private AvatarStateMachineOwner block; - public AvatarAttribute (String _name, AvatarType _type, AvatarStateMachineOwner _block, Object _referenceObject) { + public AvatarAttribute(String _name, AvatarType _type, AvatarStateMachineOwner _block, Object _referenceObject) { super(_name, _referenceObject); /*if (_type == -1) { TraceManager.addDev("- - - - - - - - - - - - " + _name + ": " + _type); @@ -77,7 +75,7 @@ public class AvatarAttribute extends AvatarLeftHand { this.block = _block; } - public AvatarStateMachineOwner getBlock () { + public AvatarStateMachineOwner getBlock() { return this.block; } @@ -101,27 +99,27 @@ public class AvatarAttribute extends AvatarLeftHand { public int getInitialValueInInt() { - if ((initialValue == null) || (initialValue.length() == 0)) { + if ((initialValue == null) || (initialValue.length() == 0)) { return getDefaultInitialValueInInt(); } - if (isInt()) { - try { - return Integer.decode(initialValue).intValue(); - } catch (Exception e) { - return -1; - } - } + if (isInt()) { + try { + return Integer.decode(initialValue).intValue(); + } catch (Exception e) { + return -1; + } + } - if (isBool()) { - if (initialValue.charAt(0) == 'f') { - return 0; - } else { - return 1; - } - } + if (isBool()) { + if (initialValue.charAt(0) == 'f') { + return 0; + } else { + return 1; + } + } - return 0; + return 0; } public String getDefaultInitialValue() { @@ -151,58 +149,58 @@ public class AvatarAttribute extends AvatarLeftHand { public boolean isTimer() { return (type == AvatarType.TIMER); } - + public String toString() { String ret = this.type.getStringType() + " " + getName(); - if (initialValue == null) { + if (initialValue == null) { return ret; } return ret + " = " + initialValue; } - public String toBasicString() { + public String toBasicString() { String ret = this.type.getStringType() + " " + getName(); return ret; } public String toStringType() { String ret = type.getStringType() + " " + getName() + " typeid= " + getType(); - if (initialValue == null) { + if (initialValue == null) { return ret; } return ret + " = " + initialValue; } - public boolean isLeftHand () { + public boolean isLeftHand() { return true; } @Override - public boolean containsAMethodCall () { + public boolean containsAMethodCall() { return false; } @Override - public AvatarAttribute clone () { + public AvatarAttribute clone() { return this; } @Override - public void replaceAttributes (HashMap<AvatarAttribute, AvatarAttribute> attributesMapping) { + public void replaceAttributes(HashMap<AvatarAttribute, AvatarAttribute> attributesMapping) { TraceManager.addDev("!!! ERROR !!! (replaceAttributes in AvatarAttribute)"); /* !!! We should never arrive here !!! */ } public AvatarAttribute advancedClone(AvatarStateMachineOwner _block) { - AvatarAttribute aa = new AvatarAttribute(getName(), getType(), _block, getReferenceObject()); - if (hasInitialValue()) { - aa.setInitialValue(getInitialValue()); - } + AvatarAttribute aa = new AvatarAttribute(getName(), getType(), _block, getReferenceObject()); + if (hasInitialValue()) { + aa.setInitialValue(getInitialValue()); + } - return aa; + return aa; } - + } diff --git a/src/main/java/translator/JKeyword.java b/src/main/java/translator/JKeyword.java index a1e3b70577..7fd99f77d2 100755 --- a/src/main/java/translator/JKeyword.java +++ b/src/main/java/translator/JKeyword.java @@ -50,7 +50,7 @@ package translator; public class JKeyword { private final static String [] words = {"abstract", "default", "goto", "package", "synchronized", "boolean", "do", "if", "private", "this", "break", "double", "implements", "protected", "throw", "byte", "else", "import", "public", "throws", "case", "enum", "instanceof", "return", "transient", "catch", "extends", "int", "short", "try", "char", "final", - "interface", "static", "void", "class", "finally", "long", "strictfp", "volatile", "const", "float", "native", "super", "while", "continue", "for", "new", "switch"}; + "interface", "static", "void", "class", "finally", "long", "strictfp", "volatile", "const", "float", "native", "super", "while", "continue", "for", "new", "switch", "select"}; public final static String INDENT = " "; public final static String END_OP = ";"; diff --git a/src/main/java/ui/AvatarMethod.java b/src/main/java/ui/AvatarMethod.java index 6c6ca546b1..e5054cedde 100644 --- a/src/main/java/ui/AvatarMethod.java +++ b/src/main/java/ui/AvatarMethod.java @@ -37,49 +37,47 @@ */ - - - package ui; import myutil.Conversion; import myutil.TraceManager; -import translator.RTLOTOSKeyword; import translator.JKeyword; +import translator.RTLOTOSKeyword; import java.util.Vector; /** - * Class AvatarMethod - * Method in Avatar ... - * Creation: 08/04/2010 - * @version 1.0 08/04/2010 - * @author Ludovic APVRILLE + * Class AvatarMethod + * Method in Avatar ... + * Creation: 08/04/2010 + * + * @author Ludovic APVRILLE + * @version 1.0 08/04/2010 */ public class AvatarMethod { public static final String[] cryptoMethods = { - "Message aencrypt(Message msg, Key k)", - "Message adecrypt(Message msg, Key k)", - "Key pk(Key k)", - "Message sign(Message msg, Key k)", - "bool verifySign(Message msg1, Message sig, Key k)", - "Message cert(Key k, Message msg)", - "bool verifyCert(Message cert, Key k)", - "Key getpk(Message cert)", - "Message sencrypt(Message msg, Key k)", - "Message sdecrypt(Message msg, Key k)", - "Key DH(Key pubK, Key privK)", - "Message hash(Message msg)", - "Message MAC(Message msg, Key k)", - "bool verifyMAC(Message msg, Key k, Message macmsg)", - "Message concat2(Message msg1, Message msg2)", - "Message concat3(Message msg1, Message msg2, Message msg3)", - "Message concat4(Message msg1, Message msg2, Message msg3, Message msg4)", - "get2(Message msg, Message msg1, Message msg2)", - "get3(Message msg, Message msg1, Message msg2, Message msg3)", - "get4(Message msg, Message msg1, Message msg2, Message msg3, Message msg4)"}; - + "Message aencrypt(Message msg, Key k)", + "Message adecrypt(Message msg, Key k)", + "Key pk(Key k)", + "Message sign(Message msg, Key k)", + "bool verifySign(Message msg1, Message sig, Key k)", + "Message cert(Key k, Message msg)", + "bool verifyCert(Message cert, Key k)", + "Key getpk(Message cert)", + "Message sencrypt(Message msg, Key k)", + "Message sdecrypt(Message msg, Key k)", + "Key DH(Key pubK, Key privK)", + "Message hash(Message msg)", + "Message MAC(Message msg, Key k)", + "bool verifyMAC(Message msg, Key k, Message macmsg)", + "Message concat2(Message msg1, Message msg2)", + "Message concat3(Message msg1, Message msg2, Message msg3)", + "Message concat4(Message msg1, Message msg2, Message msg3, Message msg4)", + "get2(Message msg, Message msg1, Message msg2)", + "get3(Message msg, Message msg1, Message msg2, Message msg3)", + "get4(Message msg, Message msg1, Message msg2, Message msg3, Message msg4)"}; + // Types of parameters public final static int NATURAL = 0; public final static int BOOLEAN = 1; @@ -156,13 +154,12 @@ public class AvatarMethod { if (index0 != -1) { if (index0 == 0) { return null; - } else if (method.charAt(index0-1) == ' ') { - method = method.substring(0, index0-1) + method.substring(index0, method.length()); + } else if (method.charAt(index0 - 1) == ' ') { + method = method.substring(0, index0 - 1) + method.substring(index0, method.length()); } } - // Check whether there is a return type or not int index2 = method.indexOf(' '); if (index2 != -1) { @@ -171,7 +168,7 @@ public class AvatarMethod { if ((tmp.indexOf('(') == -1) && (tmp.indexOf(')') == -1)) { // So, there is a return type! rt = tmp.trim(); - method = method.substring(index2+1, method.length()).trim(); + method = method.substring(index2 + 1, method.length()).trim(); if (!isAValidId(rt, false, false, false)) { TraceManager.addDev("Unvalid type: " + rt); return null; @@ -198,7 +195,7 @@ public class AvatarMethod { // No parenthesis at all if ((index0 == -1) && (index1 == -1)) { if (isAValidId(method, true, true, true)) { - return new AvatarMethod(method, new String [0], new String[0], rt); + return new AvatarMethod(method, new String[0], new String[0], rt); } else { return null; } @@ -210,11 +207,11 @@ public class AvatarMethod { } // Check that only one parenthesis of each type - tmp = method.substring(Math.min(index0+1, method.length()), method.length()); + tmp = method.substring(Math.min(index0 + 1, method.length()), method.length()); if (tmp.indexOf('(') > -1) { return null; } - tmp = method.substring(Math.min(index1+1, method.length()), method.length()); + tmp = method.substring(Math.min(index1 + 1, method.length()), method.length()); if (tmp.indexOf(')') > -1) { return null; } @@ -233,11 +230,11 @@ public class AvatarMethod { // Between parenthesis: parameters of the form: String space String comma // We replace double space by spaces and then spaces by commas - tmp = method.substring(index0+1, index1).trim(); + tmp = method.substring(index0 + 1, index1).trim(); // no parameter? if (tmp.length() == 0) { - return new AvatarMethod(id, new String [0], new String[0], rt); + return new AvatarMethod(id, new String[0], new String[0], rt); } // Has parameters... @@ -249,7 +246,7 @@ public class AvatarMethod { //TraceManager.addDev("tmp=" + tmp); String splitted[] = tmp.split(","); - int size = splitted.length/2; + int size = splitted.length / 2; // TraceManager.addDev("Nb of parameters=" + size); String types[] = new String[size]; String typeIds[] = new String[size]; @@ -262,24 +259,24 @@ public class AvatarMethod { //} try { - for(i=0; i<splitted.length; i = i + 2){ + for (i = 0; i < splitted.length; i = i + 2) { if (splitted[i].length() == 0) { return null; } - if (splitted[i+1].length() == 0) { + if (splitted[i + 1].length() == 0) { return null; } if (!isAValidId(splitted[i], false, false, false)) { TraceManager.addDev("Unvalid type: " + splitted[i]); return null; } - if (!isAValidId(splitted[i+1], true, true, true)) { - TraceManager.addDev("Unvalid id of parameter " + splitted[i+1]); + if (!isAValidId(splitted[i + 1], true, true, true)) { + TraceManager.addDev("Unvalid id of parameter " + splitted[i + 1]); return null; } //TraceManager.addDev("Adding parameter: " + splitted[i] + " " + splitted[i+1]); - types[i/2] = splitted[i]; - typeIds[i/2] = splitted[i+1]; + types[i / 2] = splitted[i]; + typeIds[i / 2] = splitted[i + 1]; } } catch (Exception e) { TraceManager.addDev("AvatarMethod Exception:" + e.getMessage()); @@ -291,20 +288,31 @@ public class AvatarMethod { return new AvatarMethod(id, types, typeIds, rt); } - public String getId() { return id;} - public String[] getTypes(){ return types;} - public String[] getTypeIds(){ return typeIds;} - public String getReturnType() { return returnType;} + public String getId() { + return id; + } + + public String[] getTypes() { + return types; + } + + public String[] getTypeIds() { + return typeIds; + } + + public String getReturnType() { + return returnType; + } public String getType(int _index) { - if ((_index <0) || (_index>=types.length)) { + if ((_index < 0) || (_index >= types.length)) { return null; } return types[_index]; } public String getTypeId(int _index) { - if ((_index <0) || (_index>=typeIds.length)) { + if ((_index < 0) || (_index >= typeIds.length)) { return null; } return typeIds[_index]; @@ -320,7 +328,7 @@ public class AvatarMethod { String lowerid = id.toLowerCase(); boolean b1, b2, b3, b4, b5; - b1 = (id.substring(0,1)).matches("[a-zA-Z]"); + b1 = (id.substring(0, 1)).matches("[a-zA-Z]"); b2 = id.matches("\\w*"); if (checkKeyword) { b3 = !RTLOTOSKeyword.isAKeyword(lowerid); @@ -349,9 +357,9 @@ public class AvatarMethod { AvatarMethod am; - for(int i= 0; i<forbidden.size(); i++) { - am = (AvatarMethod)(forbidden.elementAt(i)); - if (s.compareTo(am.getId()) ==0) { + for (int i = 0; i < forbidden.size(); i++) { + am = (AvatarMethod) (forbidden.elementAt(i)); + if (s.compareTo(am.getId()) == 0) { return false; } } @@ -361,25 +369,25 @@ public class AvatarMethod { public static int getType(String s) { if (s.equals("nat")) { - return NATURAL; + return NATURAL; } else if (s.equals("bool")) { - return BOOLEAN; + return BOOLEAN; } else if (s.equals("int")) { - return INTEGER; + return INTEGER; } else if (s.equals("Integer")) { - return INTEGER; + return INTEGER; } return OTHER; } public static String getStringType(int type) { - switch(type) { - case NATURAL: - return "nat"; - case BOOLEAN: - return "bool"; - case INTEGER: - return "int"; + switch (type) { + case NATURAL: + return "nat"; + case BOOLEAN: + return "bool"; + case INTEGER: + return "int"; } return ""; } @@ -393,9 +401,9 @@ public class AvatarMethod { } method += id + "("; - for (int i=0; i<types.length; i++) { + for (int i = 0; i < types.length; i++) { method += types[i] + " " + typeIds[i]; - if (i<(types.length - 1)) { + if (i < (types.length - 1)) { method += ", "; } } @@ -418,7 +426,7 @@ public class AvatarMethod { return false; } - AvatarMethod am = (AvatarMethod)o; + AvatarMethod am = (AvatarMethod) o; return getId().equals(am.getId()); } @@ -426,7 +434,7 @@ public class AvatarMethod { public String getUseDescription() { String s = getId() + "("; - for(int i=0; i<typeIds.length; i++) { + for (int i = 0; i < typeIds.length; i++) { s += typeIds[i]; if (i < (typeIds.length - 1)) { s += ", "; -- GitLab