diff --git a/src/main/java/tmltranslator/TMLRandomSequence.java b/src/main/java/tmltranslator/TMLRandomSequence.java index 6329a880b9b020979e999ec72089bcb30e734a95..bd560bc6c1f21b90302a2c239439d3d349115c5f 100755 --- a/src/main/java/tmltranslator/TMLRandomSequence.java +++ b/src/main/java/tmltranslator/TMLRandomSequence.java @@ -1,26 +1,26 @@ /* 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, @@ -31,7 +31,7 @@ * 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. */ @@ -52,53 +52,53 @@ import java.util.Vector; */ public class TMLRandomSequence extends TMLActivityElement{ private Vector<Integer> indexes; - + public TMLRandomSequence(String _name, Object _referenceObject) { super(_name, _referenceObject); indexes = new Vector<Integer>(); } - + public void addIndex(int index) { - indexes.add(new Integer(index)); + indexes.add(new Integer(index)); } - + public void sortNexts() { - if (indexes.size() == 0) { - return; - } - - //System.out.println("Nb of indexes" + indexes.size()); - //System.out.println("Nb of nexts" + nexts.size()); - Vector<TMLActivityElement> nextsbis = new Vector<TMLActivityElement>(); - - // Sort according to index stored in indexes - // The smaller is removed at each step - Integer i0; - int index; - int i; - - while(indexes.size() > 0) { - i0 = new Integer(1000); - index = -1; - for(i=0; i<indexes.size(); i++) { - if ( indexes.elementAt(i).compareTo(i0) < 0 ) { - index = i; - i0 = indexes.elementAt(i); - } - } - nextsbis.addElement(nexts.elementAt(index)); - nexts.removeElementAt(index); - indexes.removeElementAt(index); - } - - nexts = nextsbis; - - //for(i=0; i<nexts.size(); i++){ - // System.out.println("sequence #" + i + " = " + nexts.elementAt(i)); - //} + if (indexes.size() == 0) { + return; + } + + //System.out.println("Nb of indexes" + indexes.size()); + //System.out.println("Nb of nexts" + nexts.size()); + Vector<TMLActivityElement> nextsbis = new Vector<TMLActivityElement>(); + + // Sort according to index stored in indexes + // The smaller is removed at each step + Integer i0; + int index; + int i; + + while(indexes.size() > 0) { + i0 = new Integer(1000); + index = -1; + for(i=0; i<indexes.size(); i++) { + if ( indexes.elementAt(i).compareTo(i0) < 0 ) { + index = i; + i0 = indexes.elementAt(i); + } + } + nextsbis.addElement(nexts.elementAt(index)); + nexts.removeElementAt(index); + indexes.removeElementAt(index); + } + + nexts = nextsbis; + + //for(i=0; i<nexts.size(); i++){ + // System.out.println("sequence #" + i + " = " + nexts.elementAt(i)); + //} } public String customExtraToXML() { - return ""; + return ""; } } diff --git a/src/main/java/ui/window/JDialogCCodeGeneration.java b/src/main/java/ui/window/JDialogCCodeGeneration.java index 0cdf119a2e58873b480f366763ca493cd011a79d..85cf2be607227f5836ff45415eefb45656e55050 100755 --- a/src/main/java/ui/window/JDialogCCodeGeneration.java +++ b/src/main/java/ui/window/JDialogCCodeGeneration.java @@ -80,8 +80,8 @@ public class JDialogCCodeGeneration extends JDialog implements ActionListener, R //"C++ Simulator - LabSoc version" }; private static String DEFAULT_GENERATOR = "TTool integrated C generator"; - - // private static int selectedItem = 1; + + // private static int selectedItem = 1; protected static String pathCode; protected static String pathCompiler; @@ -104,7 +104,7 @@ public class JDialogCCodeGeneration extends JDialog implements ActionListener, R protected JButton stop; protected JButton close; - protected JLabel gen, comp; + protected JLabel gen, comp; protected JTextField code1, code2, compiler1; //exe1, exe2, exe3, exe2int, exe2formal; protected JTabbedPane jp1; @@ -114,7 +114,7 @@ public class JDialogCCodeGeneration extends JDialog implements ActionListener, R protected Vector<String> generators; protected JComboBox<String> generatorsBox; - + private Thread t; private boolean go = false; private boolean hasError = false; @@ -209,18 +209,18 @@ public class JDialogCCodeGeneration extends JDialog implements ActionListener, R jp01.add(new JLabel(" "), c01); c01.gridwidth = GridBagConstraints.REMAINDER; //end row - generators = new Vector<String>(); - generators.add(DEFAULT_GENERATOR); - fillGeneratorsWithPlugins(generators); - - generatorsBox = new JComboBox<>(generators); - if (generators.size() > 1) { - generatorsBox.setSelectedIndex(1); - } - jp01.add(generatorsBox, c01); - c01.gridwidth = GridBagConstraints.REMAINDER; //end row - - jp01.add(new JLabel(" "), c01); + generators = new Vector<String>(); + generators.add(DEFAULT_GENERATOR); + fillGeneratorsWithPlugins(generators); + + generatorsBox = new JComboBox<>(generators); + if (generators.size() > 1) { + generatorsBox.setSelectedIndex(1); + } + jp01.add(generatorsBox, c01); + c01.gridwidth = GridBagConstraints.REMAINDER; //end row + + jp01.add(new JLabel(" "), c01); c01.gridwidth = GridBagConstraints.REMAINDER; //end row removeCppFiles = new JCheckBox("Remove old .h, .c, .o files"); @@ -256,7 +256,7 @@ public class JDialogCCodeGeneration extends JDialog implements ActionListener, R code2 = new JTextField(pathCode, 100); // Issue #57 -// code2.setEnabled(false); + // code2.setEnabled(false); jp02.add(code2, c02); jp02.add(new JLabel("with"), c02); @@ -322,7 +322,7 @@ public class JDialogCCodeGeneration extends JDialog implements ActionListener, R public void actionPerformed(ActionEvent evt) { String command = evt.getActionCommand(); // Compare the action command to the known actions. - + if (command.equals("Start")) { startProcess(); } else if (command.equals("Stop")) { @@ -340,10 +340,10 @@ public class JDialogCCodeGeneration extends JDialog implements ActionListener, R //wasClosed = true; dispose(); } -// -// public boolean wasClosed() { -// return wasClosed; -// } + // + // public boolean wasClosed() { + // return wasClosed; + // } public void stopProcess() { try { @@ -382,8 +382,8 @@ public class JDialogCCodeGeneration extends JDialog implements ActionListener, R @Override public void run() { -// String cmd; -// String data; + // String cmd; + // String data; hasError = false; try { @@ -418,112 +418,112 @@ public class JDialogCCodeGeneration extends JDialog implements ActionListener, R private boolean generateCode() throws InterruptedException { - String list; - // int cycle = 0; - boolean error = false; - - jta.append( "Generating C code...\n\n" ); - if( removeCppFiles.isSelected() ) { - jta.append( "Removing all .h files...\n" ); - list = FileUtils.deleteFiles( code1.getText(), ".h" ); - if( list.length() == 0 ) { - jta.append("No files were deleted\n"); - } - else { - jta.append("Files deleted:\n" + list + "\n"); - } - jta.append("\nRemoving all .c files...\n"); - list = FileUtils.deleteFiles( code1.getText(), ".c" ); - if( list.length() == 0 ) { - jta.append( "No files were deleted\n" ); - } - else { - jta.append("Files deleted:\n" + list + "\n"); - } - jta.append("\nRemoving all .o files...\n"); - list = FileUtils.deleteFiles( code1.getText(), ".o" ); - if( list.length() == 0 ) { - jta.append( "No files were deleted\n" ); - } - else { - jta.append( "Files deleted:\n" + list + "\n" ); - } - } - if (removeXFiles.isSelected()) { - jta.append( "\nRemoving all .x files...\n" ); - list = FileUtils.deleteFiles( code1.getText(), ".x" ); - if( list.length() == 0 ) { - jta.append("No files were deleted\n"); - } - else { - jta.append("Files deleted:\n" + list + "\n"); - } - } - testGo(); - if (generatorsBox.getSelectedIndex() == 0) { - error = gtm.generateCCode( code1.getText() ); - if( !error ) { - File dir = new File( code1.getText() ); - StringBuffer s = new StringBuffer(); - jta.append( "\nSource files successfully generated:\n" ); - for( File f: dir.listFiles() ) { - try { - if( f.getCanonicalPath().contains(".c") || f.getCanonicalPath().contains(".h") ) { - s.append( f.getCanonicalPath() + "\n" ); - } - } - catch( IOException ioe ) { - jta.append("Error: " + ioe.getMessage() + "\n"); - mode = STOPPED; - setButtons(); - return true; - } - } - jta.append( s.toString() ); - } - } else { - // code generation by plugin! - int index = generatorsBox.getSelectedIndex() - 1; - int cpt = 0; - Plugin foundPlugin = null; - LinkedList<Plugin> listP = PluginManager.pluginManager.getPluginDiplodocusCodeGenerator(); - for(Plugin p: listP) { - String desc = p.getDiplodocusCodeGeneratorIdentifier(); - if (desc != null) { - if (index == cpt) { - foundPlugin = p; - break; - } - } - } - - if (foundPlugin == null) { - jta.append("Invalid plugin\n"); - - } else { - // We have a valid plugin - // We first need to get an XML representation of the current mapping - TMLMapping<?> tmap = gtm.getTMLMapping(); - - if (tmap == null) { - jta.append("Invalid mapping\n"); - } else { - String XML = tmap.toXML(); - try { - Object instance = foundPlugin.getClassDiplodocusCodeGenerator().newInstance(); - if (instance == null) { - jta.append("Invalid plugin: could not create an instance\n"); - } else { - boolean ret = Plugin.executeBoolStringMethod(instance, XML, "generateCode"); - } - } catch (Exception e) { - jta.append("Exception when calling plugin:" + e.getMessage()); - } - } - } - - } - return error; + String list; + // int cycle = 0; + boolean error = false; + + jta.append( "Generating C code...\n\n" ); + if( removeCppFiles.isSelected() ) { + jta.append( "Removing all .h files...\n" ); + list = FileUtils.deleteFiles( code1.getText(), ".h" ); + if( list.length() == 0 ) { + jta.append("No files were deleted\n"); + } + else { + jta.append("Files deleted:\n" + list + "\n"); + } + jta.append("\nRemoving all .c files...\n"); + list = FileUtils.deleteFiles( code1.getText(), ".c" ); + if( list.length() == 0 ) { + jta.append( "No files were deleted\n" ); + } + else { + jta.append("Files deleted:\n" + list + "\n"); + } + jta.append("\nRemoving all .o files...\n"); + list = FileUtils.deleteFiles( code1.getText(), ".o" ); + if( list.length() == 0 ) { + jta.append( "No files were deleted\n" ); + } + else { + jta.append( "Files deleted:\n" + list + "\n" ); + } + } + if (removeXFiles.isSelected()) { + jta.append( "\nRemoving all .x files...\n" ); + list = FileUtils.deleteFiles( code1.getText(), ".x" ); + if( list.length() == 0 ) { + jta.append("No files were deleted\n"); + } + else { + jta.append("Files deleted:\n" + list + "\n"); + } + } + testGo(); + if (generatorsBox.getSelectedIndex() == 0) { + error = gtm.generateCCode( code1.getText() ); + if( !error ) { + File dir = new File( code1.getText() ); + StringBuffer s = new StringBuffer(); + jta.append( "\nSource files successfully generated:\n" ); + for( File f: dir.listFiles() ) { + try { + if( f.getCanonicalPath().contains(".c") || f.getCanonicalPath().contains(".h") ) { + s.append( f.getCanonicalPath() + "\n" ); + } + } + catch( IOException ioe ) { + jta.append("Error: " + ioe.getMessage() + "\n"); + mode = STOPPED; + setButtons(); + return true; + } + } + jta.append( s.toString() ); + } + } else { + // code generation by plugin! + int index = generatorsBox.getSelectedIndex() - 1; + int cpt = 0; + Plugin foundPlugin = null; + LinkedList<Plugin> listP = PluginManager.pluginManager.getPluginDiplodocusCodeGenerator(); + for(Plugin p: listP) { + String desc = p.getDiplodocusCodeGeneratorIdentifier(); + if (desc != null) { + if (index == cpt) { + foundPlugin = p; + break; + } + } + } + + if (foundPlugin == null) { + jta.append("Invalid plugin\n"); + + } else { + // We have a valid plugin + // We first need to get an XML representation of the current mapping + TMLMapping<?> tmap = gtm.getTMLMapping(); + + if (tmap == null) { + jta.append("Invalid mapping\n"); + } else { + String XML = tmap.toXML(); + try { + Object instance = foundPlugin.getClassDiplodocusCodeGenerator().newInstance(); + if (instance == null) { + jta.append("Invalid plugin: could not create an instance\n"); + } else { + boolean ret = Plugin.executeBoolStringMethod(instance, XML, "generateCode"); + } + } catch (Exception e) { + jta.append("Exception when calling plugin:" + e.getMessage()); + } + } + } + + } + return error; } //End of method generateCode() public void compileCode() throws InterruptedException { @@ -593,12 +593,12 @@ public class JDialogCCodeGeneration extends JDialog implements ActionListener, R } public void fillGeneratorsWithPlugins(Vector<String> v) { - LinkedList<Plugin> list = PluginManager.pluginManager.getPluginDiplodocusCodeGenerator(); - for(Plugin p: list) { - String desc = p.getDiplodocusCodeGeneratorIdentifier(); - if (desc != null) { - v.add(desc); - } - } + LinkedList<Plugin> list = PluginManager.pluginManager.getPluginDiplodocusCodeGenerator(); + for(Plugin p: list) { + String desc = p.getDiplodocusCodeGeneratorIdentifier(); + if (desc != null) { + v.add(desc); + } + } } } //End of class