diff --git a/src/avatartranslator/AvatarMethod.java b/src/avatartranslator/AvatarMethod.java index d1022f2d5a9e059bb8b572f41bfe206666344d30..f4eb21eb04f11828e2aaffe5ad1e52cab5f51007 100644 --- a/src/avatartranslator/AvatarMethod.java +++ b/src/avatartranslator/AvatarMethod.java @@ -54,17 +54,23 @@ import myutil.*; public class AvatarMethod extends AvatarElement{ protected LinkedList<AvatarAttribute> parameters; + protected LinkedList<AvatarAttribute> returnParameters; public AvatarMethod(String _name, Object _referenceObject) { super(_name, _referenceObject); parameters = new LinkedList<AvatarAttribute>(); + returnParameters = new LinkedList<AvatarAttribute>(); } public void addParameter(AvatarAttribute _attribute) { parameters.add(_attribute); } + public void addReturnParameter(AvatarAttribute _attribute) { + returnParameters.add(_attribute); + } + public LinkedList<AvatarAttribute> getListOfAttributes() { return parameters; } @@ -75,7 +81,27 @@ public class AvatarMethod extends AvatarElement{ public String toString() { int cpt = 0; - String ret = getName() + "("; + String ret = ""; + + if (returnParameters.size() != 0) { + if (returnParameters.size() == 1) { + ret += AvatarType.getStringType(returnParameters.get(0).getType()) + " "; + } else { + int index = 0; + for(AvatarAttribute aa: returnParameters) { + if (index == 0) { + index ++; + } else { + ret = ret + ","; + } + ret += AvatarType.getStringType(aa.getType()); + } + ret = "(" + ret + ") "; + } + + } + + ret += getName() + "("; for(AvatarAttribute attribute: parameters) { if (cpt != 0) { diff --git a/src/avatartranslator/toproverif/AVATAR2ProVerif.java b/src/avatartranslator/toproverif/AVATAR2ProVerif.java index 5dd03ce9f783d24d63875599a7c86304eab249cd..b78bc0f8fa2e3b88903046922aea6b5b70fcb31c 100755 --- a/src/avatartranslator/toproverif/AVATAR2ProVerif.java +++ b/src/avatartranslator/toproverif/AVATAR2ProVerif.java @@ -209,7 +209,7 @@ public class AVATAR2ProVerif { terminateProcess(_p); return; - + // Action on signal } else if (_asme instanceof AvatarActionOnSignal){ aaos = (AvatarActionOnSignal)_asme; as = aaos.getSignal(); diff --git a/src/ui/AvatarDesignPanelTranslator.java b/src/ui/AvatarDesignPanelTranslator.java index 11c7b984f8c5305f84688706d1dc7735956faf2d..daad97be35c21234dc0477459acf6e359875a82d 100644 --- a/src/ui/AvatarDesignPanelTranslator.java +++ b/src/ui/AvatarDesignPanelTranslator.java @@ -169,6 +169,7 @@ public class AvatarDesignPanelTranslator { atam = new avatartranslator.AvatarMethod(uiam.getId(), uiam); ab.addMethod(atam); makeParameters(atam, uiam); + makeReturnParameters(ab, block, atam, uiam); } // Create signals v = block.getSignalList(); @@ -205,6 +206,48 @@ public class AvatarDesignPanelTranslator { } + public void makeReturnParameters(AvatarBlock _ab, AvatarBDBlock _block, avatartranslator.AvatarMethod _atam, ui.AvatarMethod _uiam) { + String rt = _uiam.getReturnType().trim(); + AvatarAttribute aa; + Vector types; + TAttribute ta; + int type; + + if (rt.length() == 0) { + return; + } + + if ((rt.compareTo("int") == 0) || (rt.compareTo("bool") == 0)) { + aa = new AvatarAttribute("return__0", AvatarType.getType(rt), _block); + _atam.addReturnParameter(aa); + } else { + types = adp.getAvatarBDPanel().getAttributesOfDataType(rt); + if (types == null) { + CheckingError ce = new CheckingError(CheckingError.STRUCTURE_ERROR, "Unknown data type: " + rt + " declared as a return parameter of a method of " + _block.getName()); + ce.setAvatarBlock(_ab); + ce.setTDiagramPanel(adp.getAvatarBDPanel()); + addCheckingError(ce); + return; + } else { + for(int j=0; j<types.size(); j++) { + ta = (TAttribute)(types.elementAt(j)); + if (ta.getType() == TAttribute.INTEGER){ + type = AvatarType.INTEGER; + } else if (ta.getType() == TAttribute.NATURAL){ + type = AvatarType.INTEGER; + } else if (ta.getType() == TAttribute.BOOLEAN) { + type = AvatarType.BOOLEAN; + } else { + type = AvatarType.INTEGER; + } + aa = new AvatarAttribute("return__" + j, type, _block); + _atam.addReturnParameter(aa); + } + } + } + + } + public void makeParameters(avatartranslator.AvatarMethod _atam, ui.AvatarMethod _uiam) { String typeIds[] = _uiam.getTypeIds(); String types[] = _uiam.getTypes(); @@ -726,8 +769,10 @@ public class AvatarDesignPanelTranslator { if (s.trim().length() > 0) { s = modifyString(s.trim()); // Variable assignation or method call? - error = s.indexOf("="); - if (error == -1) { + + TraceManager.addDev("IsAVariable Assignation: " + s + " -> " + isAVariableAssignation(s)); + + if (!isAVariableAssignation(s)) { // Method call s = modifyStringMethodCall(s, _ab.getName()); if(!_ab.isAValidMethodCall(s)) { @@ -872,6 +917,7 @@ public class AvatarDesignPanelTranslator { } private String modifyStringMethodCall(String _input, String _blockName) { + int index0 = _input.indexOf('('); int index1 = _input.indexOf(')'); @@ -886,7 +932,7 @@ public class AvatarDesignPanelTranslator { return _input; } - //TraceManager.addDev("Analyzing method call " + s); + TraceManager.addDev("-> -> Analyzing method call " + s); TAttribute ta, tatmp; String [] actions = s.split(","); @@ -916,11 +962,44 @@ public class AvatarDesignPanelTranslator { s = _input.substring(0, index0) + "(" + s + ")"; - //TraceManager.addDev("Returning method call " + s); + // Managing output parameters + index0 = s.indexOf("="); + if (index0 != -1) { + String param = s.substring(0, index0); + } + + TraceManager.addDev("-> -> Returning method call " + s); return s; } + public boolean isAVariableAssignation (String _input) { + int index = _input.indexOf('='); + if (index == -1) { + return false; + } + + // Must check whether what follows the '=' is a function or not. + String tmp = _input.substring(index+1, _input.length()).trim(); + + index = tmp.indexOf('('); + if (index == -1) { + return true; + } + + tmp = tmp.substring(0, index); + + TraceManager.addDev("rest= >" + tmp + "<"); + int length = tmp.length(); + tmp = tmp.trim(); + if (tmp.length() != length) { + TraceManager.addDev("pb of length"); + return true; + } + + return !(TAttribute.isAValidId(tmp, false, false)); + } + /*public TURTLEModeling generateTURTLEModeling() { LinkedList<AvatarBDBlock> blocks = adp.getAvatarBDPanel().getFullBlockList(); return generateTURTLEModeling(blocks, ""); diff --git a/src/ui/AvatarMethod.java b/src/ui/AvatarMethod.java index 4af5c492820cb687cb630f104ed07635ac2a72a6..9040553043cac60990c078edb79f0ae62072213e 100644 --- a/src/ui/AvatarMethod.java +++ b/src/ui/AvatarMethod.java @@ -64,18 +64,35 @@ public class AvatarMethod { protected String id; protected String typeIds[]; protected String types[]; + + protected String returnType; public AvatarMethod(String _id, String _types[], String _typeIds[]) { id = _id; types = _types; typeIds = _typeIds; + returnType = ""; + } + + public AvatarMethod(String _id, String _types[], String _typeIds[], String _returnType) { + id = _id; + types = _types; + typeIds = _typeIds; + returnType = _returnType; } - // An operation must be of the form: "id(type id0, type id1, ...) + + + // An operation must be of the form: "id(type id0, type id1, ...)" + // Or 'returntype id(type id0, type id1, ...)' // Returns null in case the method is not valid public static AvatarMethod isAValidMethod(String _method) { + + TraceManager.addDev("Is a valid method? " + _method); + String method, tmp, id; + String rt = ""; if (_method == null) { return null; @@ -87,8 +104,27 @@ public class AvatarMethod { return null; } - int index0 = _method.indexOf('('); - int index1 = _method.indexOf(')'); + // Check whether there is a return type or not + int index2 = method.indexOf(' '); + if (index2 != -1) { + tmp = method.substring(0, index2); + // No parenthesis? + if ((tmp.indexOf('(') == -1) && (tmp.indexOf(')') == -1)) { + // So, there is a return type! + rt = tmp.trim(); + method = method.substring(index2+1, method.length()).trim(); + if (!isAValidId(rt, false, false, false)) { + TraceManager.addDev("Unvalid type: " + rt); + return null; + } + TraceManager.addDev("Found a return type: " + rt); + TraceManager.addDev("Now working with method: " + method); + } + } + + int index0 = method.indexOf('('); + int index1 = method.indexOf(')'); + // Only one of the two parenthesis if ((index0 == -1) && (index1 > -1)) { @@ -99,10 +135,12 @@ public class AvatarMethod { return null; } + + // 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]); + return new AvatarMethod(method, new String [0], new String[0], rt); } else { return null; } @@ -125,6 +163,8 @@ public class AvatarMethod { // And so: parenthesis are in the right order, and are used only one for each + + //TraceManager.addDev("Checking for an id before parenthesis"); // Before parenthesis -> id tmp = method.substring(0, index0).trim(); if (!isAValidId(tmp, true, true, true)) { @@ -138,7 +178,7 @@ public class AvatarMethod { // no parameter? if (tmp.length() == 0) { - return new AvatarMethod(id, new String [0], new String[0]); + return new AvatarMethod(id, new String [0], new String[0], rt); } // Has parameters... @@ -157,9 +197,10 @@ public class AvatarMethod { boolean b0, b1; int i; - /*for(i=0; i<splitted.length; i++) { - TraceManager.addDev("splitted[" + i + "]: " + splitted[i]); - }*/ + //TraceManager.addDev("splitted"); + //for(i=0; i<splitted.length; i++) { + // TraceManager.addDev("splitted[" + i + "]: " + splitted[i]); + //} try { for(i=0; i<splitted.length; i = i + 2){ @@ -170,14 +211,14 @@ public class AvatarMethod { return null; } if (!isAValidId(splitted[i], false, false, false)) { - //TraceManager.addDev("Unvalid type: " + splitted[i]); + 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]); + TraceManager.addDev("Unvalid id of parameter " + splitted[i+1]); return null; } - //TraceManager.addDev("Adding parameter: " + splitted[i] + " " + splitted[i+1]); + TraceManager.addDev("Adding parameter: " + splitted[i] + " " + splitted[i+1]); types[i/2] = splitted[i]; typeIds[i/2] = splitted[i+1]; } @@ -186,12 +227,15 @@ public class AvatarMethod { return null; } - return new AvatarMethod(id, types, typeIds); + TraceManager.addDev("Returning method"); + + 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 getType(int _index) { if ((_index <0) || (_index>=types.length)) { @@ -286,7 +330,12 @@ public class AvatarMethod { public String toString() { int cpt = 0; - String method = id + "("; + String method = ""; + if (returnType.length() > 0) { + method += returnType + " "; + } + + method += id + "("; for (int i=0; i<types.length; i++) { method += types[i] + " " + typeIds[i]; if (i<(types.length - 1)) {