From 9610bb242097976f2d28e03459c53b58040a0e4e Mon Sep 17 00:00:00 2001 From: Bastien Sultan <bastien.sultan@telecom-paris.fr> Date: Wed, 29 Nov 2023 11:25:12 +0100 Subject: [PATCH] Improving JURASSIC compiler --- src/main/java/cli/Action.java | 8 +- .../mutations/AddEventConnectionMutation.java | 23 +----- .../AddRequestConnectionMutation.java | 79 +++++++++++++++++++ .../mutations/ConnectionMutation.java | 26 ++++++ .../mutations/RequestConnectionMutation.java | 2 + 5 files changed, 114 insertions(+), 24 deletions(-) diff --git a/src/main/java/cli/Action.java b/src/main/java/cli/Action.java index 595fddd37d..34338f99bc 100644 --- a/src/main/java/cli/Action.java +++ b/src/main/java/cli/Action.java @@ -614,19 +614,23 @@ public class Action extends Command implements ProVerifOutputListener { TMLModeling<?> tmlModel = interpreter.mgui.gtm.getTMLModeling(); TMLMapping tmlMapping = interpreter.mgui.gtm.getTMLMapping(); + DateFormat dateFormat = new SimpleDateFormat("_yyyyMMdd_HHmmss"); + Date date = new Date(); + String dateAndTime = dateFormat.format(date); + if (tmlModel == null && tmlMapping == null) { return "No model"; } else{ if (tmlModel != null){ try { - interpreter.mgui.drawTMLSpecification(tmlModel,"TMLModel"); + interpreter.mgui.drawTMLSpecification(tmlModel,"TMLModel", dateAndTime); } catch (MalformedTMLDesignException e) { TraceManager.addDev("Exception in drawing TML model :" + e.getMessage()); } } if (tmlMapping != null){ try { - interpreter.mgui.drawTMAPSpecification(tmlMapping, "TMLMapping"); + interpreter.mgui.drawTMAPSpecification(tmlMapping, "TMLMapping", dateAndTime); } catch (MalformedTMLDesignException e) { TraceManager.addDev("Exception in drawing TML model :" + e.getMessage()); } diff --git a/src/main/java/tmltranslator/mutations/AddEventConnectionMutation.java b/src/main/java/tmltranslator/mutations/AddEventConnectionMutation.java index a25ab0c059..f1678393e0 100644 --- a/src/main/java/tmltranslator/mutations/AddEventConnectionMutation.java +++ b/src/main/java/tmltranslator/mutations/AddEventConnectionMutation.java @@ -50,6 +50,7 @@ import java.util.List; public class AddEventConnectionMutation extends EventConnectionMutation{ protected List<String> parameters; + protected AddEventConnectionMutation(String _originTaskName, String _destinationTaskName, String _connectionName, String _connectionSemantics) { super(_originTaskName, _destinationTaskName, _connectionName); setConnectionSemantics(_connectionSemantics); @@ -110,28 +111,6 @@ public class AddEventConnectionMutation extends EventConnectionMutation{ _tmlModel.addEvent(event); } - public static List<String> parseParameters(String toParse) throws ParseDiplodocusMutationException{ - List<String> _parameters = new LinkedList<>(); - String[] tokens = MutationParser.tokenise(toParse); - - int endIndex; - int closingBracketIndex = DiplodocusMutationParser.indexOf(tokens,")"); - if (closingBracketIndex == -1){ - throw new ParseDiplodocusMutationException("Missing ) at the end of the parameters list."); - } else { - endIndex = closingBracketIndex ; - } - for(int i = DiplodocusMutationParser.indexOf(tokens,"(") + 1; i < endIndex; i += 2) { - if (!(tokens[i].toUpperCase().equals("INT") || tokens[i].toUpperCase().equals("BOOL"))){ - throw new ParseDiplodocusMutationException("Incorrect type provided in parameters list or incorrect list format. Expected types are" + - " int or bool, and expected list format is (type1,type2,...,typen)."); - } - _parameters.add(tokens[i]); - } - - return _parameters; - } - public static AddEventConnectionMutation createFromString(String toParse) throws ParseDiplodocusMutationException{ AddEventConnectionMutation mutation = null; String[] tokens = DiplodocusMutationParser.tokenise(toParse); diff --git a/src/main/java/tmltranslator/mutations/AddRequestConnectionMutation.java b/src/main/java/tmltranslator/mutations/AddRequestConnectionMutation.java index 49269bb07a..20d81fd55f 100644 --- a/src/main/java/tmltranslator/mutations/AddRequestConnectionMutation.java +++ b/src/main/java/tmltranslator/mutations/AddRequestConnectionMutation.java @@ -38,15 +38,94 @@ package tmltranslator.mutations; +import avatartranslator.mutation.MutationParser; import tmltranslator.TMLModeling; +import tmltranslator.TMLRequest; +import tmltranslator.TMLTask; +import tmltranslator.TMLType; + +import java.util.LinkedList; +import java.util.List; public class AddRequestConnectionMutation extends RequestConnectionMutation { + protected List<String> parameters; + protected AddRequestConnectionMutation(String _originTaskName, String _destinationTaskName, String _connectionName) { super(_originTaskName, _destinationTaskName, _connectionName); } + public TMLRequest createElement(TMLModeling<?> _tmlModel) throws ApplyDiplodocusMutationException { + if (getRequest(_tmlModel) != null){ + throw new ApplyDiplodocusMutationException("An request connection named " + getConnectionName() + " already exists in the current model."); + } + + TMLRequest request = new TMLRequest(getConnectionName(), null); + + TMLTask _originTask = getOriginTask(_tmlModel); + TMLTask _destinationTask = getDestinationTask(_tmlModel); + if (_originTask == null){ + throw new ApplyDiplodocusMutationException("The task named " + getOriginTaskName() + " does not exist in the current model."); + } + if (_destinationTask==null){ + throw new ApplyDiplodocusMutationException("The task named " + getDestinationTaskName() + " does not exist in the current model."); + } + request.addOriginTask(_originTask); + request.setDestinationTask(_destinationTask); + + return request; + } + @Override public void apply(TMLModeling<?> _tmlModel) throws ApplyDiplodocusMutationException { + TMLRequest request = createElement(_tmlModel); + if (parameters != null) { + for (String parameter : parameters) { + int type = 4; + if (parameter.toUpperCase().equals("INT")) { + type = TMLType.NATURAL; + } else if (parameter.toUpperCase().equals("BOOL")) { + type = TMLType.BOOLEAN; + } + request.addParam(new TMLType(type)); + } + } + _tmlModel.addRequest(request); + } + + public static AddRequestConnectionMutation createFromString (String toParse) throws ParseDiplodocusMutationException { + String[] tokens = DiplodocusMutationParser.tokenise(toParse); + + int index = DiplodocusMutationParser.indexOf(tokens,"BETWEEN"); + if (tokens.length <= index + 3) { + throw new ParseDiplodocusMutationException("Missing task name. Expected syntax is add request connection connectionName between " + + "originTaskName and destinationTaskName"); + } + String _originTaskName = tokens[index+1]; + String _destinationTaskName = tokens[index+3]; + + if (tokens[index-1].toUpperCase().equals("CONNECTION")){ + throw new ParseDiplodocusMutationException("Missing or invalid connection name. Expected syntax is add request connection " + + "connectionName between originTaskName and destinationTaskName with connectionName != 'connection'"); + } + boolean hasParameters = false; + String _connectionName; + if (DiplodocusMutationParser.indexOf(tokens,"(") != -1){ + hasParameters = true; + } + if (hasParameters){ + _connectionName = tokens[DiplodocusMutationParser.indexOf(tokens,"(")-1]; + } else { + _connectionName = tokens[index - 1]; + } + + AddRequestConnectionMutation mutation = new AddRequestConnectionMutation(_originTaskName, _destinationTaskName, _connectionName); + if (hasParameters){ + mutation.parameters = parseParameters(toParse); + } + mutation.setMutationType("TMLmutation"); + + return mutation; } + } diff --git a/src/main/java/tmltranslator/mutations/ConnectionMutation.java b/src/main/java/tmltranslator/mutations/ConnectionMutation.java index 2da73fac55..cdb0dc63c3 100644 --- a/src/main/java/tmltranslator/mutations/ConnectionMutation.java +++ b/src/main/java/tmltranslator/mutations/ConnectionMutation.java @@ -38,9 +38,13 @@ package tmltranslator.mutations; +import avatartranslator.mutation.MutationParser; import tmltranslator.TMLModeling; import tmltranslator.TMLTask; +import java.util.LinkedList; +import java.util.List; + public abstract class ConnectionMutation extends DiplodocusMutation{ private String connectionName; private String connectionSemantics; @@ -131,6 +135,28 @@ public abstract class ConnectionMutation extends DiplodocusMutation{ return str.matches("-?\\d+(\\.\\d+)?"); } + public static List<String> parseParameters(String toParse) throws ParseDiplodocusMutationException{ + List<String> _parameters = new LinkedList<>(); + String[] tokens = MutationParser.tokenise(toParse); + + int endIndex; + int closingBracketIndex = DiplodocusMutationParser.indexOf(tokens,")"); + if (closingBracketIndex == -1){ + throw new ParseDiplodocusMutationException("Missing ) at the end of the parameters list."); + } else { + endIndex = closingBracketIndex ; + } + for(int i = DiplodocusMutationParser.indexOf(tokens,"(") + 1; i < endIndex; i += 2) { + if (!(tokens[i].toUpperCase().equals("INT") || tokens[i].toUpperCase().equals("BOOL"))){ + throw new ParseDiplodocusMutationException("Incorrect type provided in parameters list or incorrect list format. Expected types are" + + " int or bool, and expected list format is (type1,type2,...,typen)."); + } + _parameters.add(tokens[i]); + } + + return _parameters; + } + public static ConnectionMutation createFromString(String toParse) throws ParseDiplodocusMutationException{ switch (DiplodocusMutationParser.findConnectionTypeToken(toParse)) { case "DATA": diff --git a/src/main/java/tmltranslator/mutations/RequestConnectionMutation.java b/src/main/java/tmltranslator/mutations/RequestConnectionMutation.java index 77f0e6ae05..8fc736fc0c 100644 --- a/src/main/java/tmltranslator/mutations/RequestConnectionMutation.java +++ b/src/main/java/tmltranslator/mutations/RequestConnectionMutation.java @@ -38,6 +38,7 @@ package tmltranslator.mutations; +import org.apache.commons.math3.analysis.function.Add; import tmltranslator.TMLModeling; import tmltranslator.TMLRequest; import tmltranslator.TMLTask; @@ -74,6 +75,7 @@ public abstract class RequestConnectionMutation extends ConnectionMutation { public static RequestConnectionMutation createFromString(String toParse) throws ParseDiplodocusMutationException{ switch (DiplodocusMutationParser.findMutationToken(toParse)) { case "ADD": + return AddRequestConnectionMutation.createFromString(toParse); case "RM": case "REMOVE": return RemoveRequestConnectionMutation.createFromString(toParse); -- GitLab