Skip to content
Snippets Groups Projects
Commit bd33ec6a authored by Ludovic Apvrille's avatar Ludovic Apvrille
Browse files

Update on AVATAR: method can return parameters (draft)

parent 617be5fa
No related branches found
No related tags found
No related merge requests found
...@@ -54,17 +54,23 @@ import myutil.*; ...@@ -54,17 +54,23 @@ import myutil.*;
public class AvatarMethod extends AvatarElement{ public class AvatarMethod extends AvatarElement{
protected LinkedList<AvatarAttribute> parameters; protected LinkedList<AvatarAttribute> parameters;
protected LinkedList<AvatarAttribute> returnParameters;
public AvatarMethod(String _name, Object _referenceObject) { public AvatarMethod(String _name, Object _referenceObject) {
super(_name, _referenceObject); super(_name, _referenceObject);
parameters = new LinkedList<AvatarAttribute>(); parameters = new LinkedList<AvatarAttribute>();
returnParameters = new LinkedList<AvatarAttribute>();
} }
public void addParameter(AvatarAttribute _attribute) { public void addParameter(AvatarAttribute _attribute) {
parameters.add(_attribute); parameters.add(_attribute);
} }
public void addReturnParameter(AvatarAttribute _attribute) {
returnParameters.add(_attribute);
}
public LinkedList<AvatarAttribute> getListOfAttributes() { public LinkedList<AvatarAttribute> getListOfAttributes() {
return parameters; return parameters;
} }
...@@ -75,7 +81,27 @@ public class AvatarMethod extends AvatarElement{ ...@@ -75,7 +81,27 @@ public class AvatarMethod extends AvatarElement{
public String toString() { public String toString() {
int cpt = 0; 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) { for(AvatarAttribute attribute: parameters) {
if (cpt != 0) { if (cpt != 0) {
......
...@@ -209,7 +209,7 @@ public class AVATAR2ProVerif { ...@@ -209,7 +209,7 @@ public class AVATAR2ProVerif {
terminateProcess(_p); terminateProcess(_p);
return; return;
// Action on signal
} else if (_asme instanceof AvatarActionOnSignal){ } else if (_asme instanceof AvatarActionOnSignal){
aaos = (AvatarActionOnSignal)_asme; aaos = (AvatarActionOnSignal)_asme;
as = aaos.getSignal(); as = aaos.getSignal();
......
...@@ -169,6 +169,7 @@ public class AvatarDesignPanelTranslator { ...@@ -169,6 +169,7 @@ public class AvatarDesignPanelTranslator {
atam = new avatartranslator.AvatarMethod(uiam.getId(), uiam); atam = new avatartranslator.AvatarMethod(uiam.getId(), uiam);
ab.addMethod(atam); ab.addMethod(atam);
makeParameters(atam, uiam); makeParameters(atam, uiam);
makeReturnParameters(ab, block, atam, uiam);
} }
// Create signals // Create signals
v = block.getSignalList(); v = block.getSignalList();
...@@ -205,6 +206,48 @@ public class AvatarDesignPanelTranslator { ...@@ -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) { public void makeParameters(avatartranslator.AvatarMethod _atam, ui.AvatarMethod _uiam) {
String typeIds[] = _uiam.getTypeIds(); String typeIds[] = _uiam.getTypeIds();
String types[] = _uiam.getTypes(); String types[] = _uiam.getTypes();
...@@ -726,8 +769,10 @@ public class AvatarDesignPanelTranslator { ...@@ -726,8 +769,10 @@ public class AvatarDesignPanelTranslator {
if (s.trim().length() > 0) { if (s.trim().length() > 0) {
s = modifyString(s.trim()); s = modifyString(s.trim());
// Variable assignation or method call? // Variable assignation or method call?
error = s.indexOf("=");
if (error == -1) { TraceManager.addDev("IsAVariable Assignation: " + s + " -> " + isAVariableAssignation(s));
if (!isAVariableAssignation(s)) {
// Method call // Method call
s = modifyStringMethodCall(s, _ab.getName()); s = modifyStringMethodCall(s, _ab.getName());
if(!_ab.isAValidMethodCall(s)) { if(!_ab.isAValidMethodCall(s)) {
...@@ -872,6 +917,7 @@ public class AvatarDesignPanelTranslator { ...@@ -872,6 +917,7 @@ public class AvatarDesignPanelTranslator {
} }
private String modifyStringMethodCall(String _input, String _blockName) { private String modifyStringMethodCall(String _input, String _blockName) {
int index0 = _input.indexOf('('); int index0 = _input.indexOf('(');
int index1 = _input.indexOf(')'); int index1 = _input.indexOf(')');
...@@ -886,7 +932,7 @@ public class AvatarDesignPanelTranslator { ...@@ -886,7 +932,7 @@ public class AvatarDesignPanelTranslator {
return _input; return _input;
} }
//TraceManager.addDev("Analyzing method call " + s); TraceManager.addDev("-> -> Analyzing method call " + s);
TAttribute ta, tatmp; TAttribute ta, tatmp;
String [] actions = s.split(","); String [] actions = s.split(",");
...@@ -916,11 +962,44 @@ public class AvatarDesignPanelTranslator { ...@@ -916,11 +962,44 @@ public class AvatarDesignPanelTranslator {
s = _input.substring(0, index0) + "(" + s + ")"; 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; 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() { /*public TURTLEModeling generateTURTLEModeling() {
LinkedList<AvatarBDBlock> blocks = adp.getAvatarBDPanel().getFullBlockList(); LinkedList<AvatarBDBlock> blocks = adp.getAvatarBDPanel().getFullBlockList();
return generateTURTLEModeling(blocks, ""); return generateTURTLEModeling(blocks, "");
......
...@@ -64,18 +64,35 @@ public class AvatarMethod { ...@@ -64,18 +64,35 @@ public class AvatarMethod {
protected String id; protected String id;
protected String typeIds[]; protected String typeIds[];
protected String types[]; protected String types[];
protected String returnType;
public AvatarMethod(String _id, String _types[], String _typeIds[]) { public AvatarMethod(String _id, String _types[], String _typeIds[]) {
id = _id; id = _id;
types = _types; types = _types;
typeIds = _typeIds; 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 // Returns null in case the method is not valid
public static AvatarMethod isAValidMethod(String _method) { public static AvatarMethod isAValidMethod(String _method) {
TraceManager.addDev("Is a valid method? " + _method);
String method, tmp, id; String method, tmp, id;
String rt = "";
if (_method == null) { if (_method == null) {
return null; return null;
...@@ -87,8 +104,27 @@ public class AvatarMethod { ...@@ -87,8 +104,27 @@ public class AvatarMethod {
return null; return null;
} }
int index0 = _method.indexOf('('); // Check whether there is a return type or not
int index1 = _method.indexOf(')'); 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 // Only one of the two parenthesis
if ((index0 == -1) && (index1 > -1)) { if ((index0 == -1) && (index1 > -1)) {
...@@ -99,10 +135,12 @@ public class AvatarMethod { ...@@ -99,10 +135,12 @@ public class AvatarMethod {
return null; return null;
} }
// No parenthesis at all // No parenthesis at all
if ((index0 == -1) && (index1 == -1)) { if ((index0 == -1) && (index1 == -1)) {
if (isAValidId(method, true, true, true)) { 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 { } else {
return null; return null;
} }
...@@ -125,6 +163,8 @@ public class AvatarMethod { ...@@ -125,6 +163,8 @@ public class AvatarMethod {
// And so: parenthesis are in the right order, and are used only one for each // 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 // Before parenthesis -> id
tmp = method.substring(0, index0).trim(); tmp = method.substring(0, index0).trim();
if (!isAValidId(tmp, true, true, true)) { if (!isAValidId(tmp, true, true, true)) {
...@@ -138,7 +178,7 @@ public class AvatarMethod { ...@@ -138,7 +178,7 @@ public class AvatarMethod {
// no parameter? // no parameter?
if (tmp.length() == 0) { 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... // Has parameters...
...@@ -157,9 +197,10 @@ public class AvatarMethod { ...@@ -157,9 +197,10 @@ public class AvatarMethod {
boolean b0, b1; boolean b0, b1;
int i; int i;
/*for(i=0; i<splitted.length; i++) { //TraceManager.addDev("splitted");
TraceManager.addDev("splitted[" + i + "]: " + splitted[i]); //for(i=0; i<splitted.length; i++) {
}*/ // TraceManager.addDev("splitted[" + i + "]: " + splitted[i]);
//}
try { try {
for(i=0; i<splitted.length; i = i + 2){ for(i=0; i<splitted.length; i = i + 2){
...@@ -170,14 +211,14 @@ public class AvatarMethod { ...@@ -170,14 +211,14 @@ public class AvatarMethod {
return null; return null;
} }
if (!isAValidId(splitted[i], false, false, false)) { if (!isAValidId(splitted[i], false, false, false)) {
//TraceManager.addDev("Unvalid type: " + splitted[i]); TraceManager.addDev("Unvalid type: " + splitted[i]);
return null; return null;
} }
if (!isAValidId(splitted[i+1], true, true, true)) { 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; 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]; types[i/2] = splitted[i];
typeIds[i/2] = splitted[i+1]; typeIds[i/2] = splitted[i+1];
} }
...@@ -186,12 +227,15 @@ public class AvatarMethod { ...@@ -186,12 +227,15 @@ public class AvatarMethod {
return null; 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 getId() { return id;}
public String[] getTypes(){ return types;} public String[] getTypes(){ return types;}
public String[] getTypeIds(){ return typeIds;} public String[] getTypeIds(){ return typeIds;}
public String getReturnType() { return returnType;}
public String getType(int _index) { public String getType(int _index) {
if ((_index <0) || (_index>=types.length)) { if ((_index <0) || (_index>=types.length)) {
...@@ -286,7 +330,12 @@ public class AvatarMethod { ...@@ -286,7 +330,12 @@ public class AvatarMethod {
public String toString() { public String toString() {
int cpt = 0; int cpt = 0;
String method = id + "("; String method = "";
if (returnType.length() > 0) {
method += returnType + " ";
}
method += id + "(";
for (int i=0; i<types.length; i++) { for (int i=0; i<types.length; i++) {
method += types[i] + " " + typeIds[i]; method += types[i] + " " + typeIds[i];
if (i<(types.length - 1)) { if (i<(types.length - 1)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment