diff --git a/src/tmltranslator/modelcompiler/AdaifBuffer.java b/src/tmltranslator/modelcompiler/AdaifBuffer.java index 5a27071662d6ac36f88016069ef557994b09ad64..b442ec520b7a192df409e6cb2ee93f7db272d3c7 100644 --- a/src/tmltranslator/modelcompiler/AdaifBuffer.java +++ b/src/tmltranslator/modelcompiler/AdaifBuffer.java @@ -44,17 +44,22 @@ * @see */ -package tmltranslator.modelcompiler;; +package tmltranslator.modelcompiler; + +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.util.ArrayList; + +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; -import java.util.*; -import java.nio.*; import org.w3c.dom.Element; -import javax.swing.*; -import java.awt.*; -import java.awt.event.*; -import myutil.*; -import tmltranslator.*; +import tmltranslator.TMLTask; public class AdaifBuffer extends Buffer { diff --git a/src/tmltranslator/modelcompiler/AdaifMEC.java b/src/tmltranslator/modelcompiler/AdaifMEC.java index 65e1b7a73b36f121f92872d27a2e2ca2c95afd67..c6042ee1cc25607aa97bfde3ee9a9e81c13bf217 100644 --- a/src/tmltranslator/modelcompiler/AdaifMEC.java +++ b/src/tmltranslator/modelcompiler/AdaifMEC.java @@ -44,10 +44,7 @@ * @see */ -package tmltranslator.modelcompiler;; - -import java.util.*; -//import Ctranslator.*; +package tmltranslator.modelcompiler; public class AdaifMEC extends ArchUnitMEC { diff --git a/src/tmltranslator/modelcompiler/AdaifOperationMEC.java b/src/tmltranslator/modelcompiler/AdaifOperationMEC.java index 11f3310017adeb5facca66b72ce1df4ee420a136..31cb2f6616aaae10d20659f0102a9cba391fda82 100644 --- a/src/tmltranslator/modelcompiler/AdaifOperationMEC.java +++ b/src/tmltranslator/modelcompiler/AdaifOperationMEC.java @@ -44,10 +44,7 @@ * @see */ -package tmltranslator.modelcompiler;; - -import java.util.*; -//import Ctranslator.*; +package tmltranslator.modelcompiler; public class AdaifOperationMEC extends OperationMEC { diff --git a/src/tmltranslator/modelcompiler/ArchUnitMEC.java b/src/tmltranslator/modelcompiler/ArchUnitMEC.java index e2c125f3de8afe2f39b862fdd0cfc67a743931a7..4466db81ed8fdcf02de33edf90eaee2716279fdc 100755 --- a/src/tmltranslator/modelcompiler/ArchUnitMEC.java +++ b/src/tmltranslator/modelcompiler/ArchUnitMEC.java @@ -46,9 +46,8 @@ package tmltranslator.modelcompiler; -import java.util.*; -import java.nio.*; -import myutil.*; +import java.util.Arrays; +import java.util.Vector; public abstract class ArchUnitMEC { diff --git a/src/tmltranslator/modelcompiler/BaseBuffer.java b/src/tmltranslator/modelcompiler/BaseBuffer.java index be6afe54714a98f2880cbdcbfc0bbe51b0edcded..cb0a5b338c6f1b6d765e8b72ec584fa22105f0c7 100755 --- a/src/tmltranslator/modelcompiler/BaseBuffer.java +++ b/src/tmltranslator/modelcompiler/BaseBuffer.java @@ -44,12 +44,9 @@ * @see */ -package tmltranslator.modelcompiler;; +package tmltranslator.modelcompiler; -import java.util.*; -import java.nio.*; -import myutil.*; -import tmltranslator.*; +import tmltranslator.TMLTask; public class BaseBuffer extends Buffer { diff --git a/src/tmltranslator/modelcompiler/Buffer.java b/src/tmltranslator/modelcompiler/Buffer.java index 511e563ea39d1fa591f92693008592686d004434..72e522ca8837089645c90593db1337b960f5f078 100755 --- a/src/tmltranslator/modelcompiler/Buffer.java +++ b/src/tmltranslator/modelcompiler/Buffer.java @@ -44,17 +44,13 @@ * @see */ -package tmltranslator.modelcompiler;; +package tmltranslator.modelcompiler; -import java.util.*; -import java.nio.*; -import org.w3c.dom.Element; -import javax.swing.*; -import java.awt.*; -import java.awt.event.*; +import java.util.ArrayList; -import myutil.*; -import tmltranslator.*; +import tmltranslator.TMLCPLibArtifact; +import tmltranslator.TMLPort; +import tmltranslator.TMLTask; public class Buffer { diff --git a/src/tmltranslator/modelcompiler/BufferMEC.java b/src/tmltranslator/modelcompiler/BufferMEC.java index 179b1cd5e0c78b3de886ec9eb9136d64ee21c8c6..72ecff9fdc57bd49c70c3b93ebdab3de6786a15f 100644 --- a/src/tmltranslator/modelcompiler/BufferMEC.java +++ b/src/tmltranslator/modelcompiler/BufferMEC.java @@ -43,17 +43,15 @@ * @see */ -package tmltranslator.modelcompiler;; +package tmltranslator.modelcompiler; -import java.util.*; -import java.nio.*; -import org.w3c.dom.Element; -import javax.swing.*; -import java.awt.*; -import java.awt.event.*; +import java.awt.Frame; +import java.awt.GridBagConstraints; +import java.util.ArrayList; + +import javax.swing.JPanel; -import myutil.*; -import tmltranslator.*; +import org.w3c.dom.Element; public interface BufferMEC { diff --git a/src/tmltranslator/modelcompiler/CFunctionPrototype.java b/src/tmltranslator/modelcompiler/CFunctionPrototype.java new file mode 100644 index 0000000000000000000000000000000000000000..b232204faf7419947bc5677aef216a5e83bea76e --- /dev/null +++ b/src/tmltranslator/modelcompiler/CFunctionPrototype.java @@ -0,0 +1,98 @@ +/**Copyright or (C) + + 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, + that may mean that it is complicated to manipulate, and that also + therefore means that it is reserved for developers and experienced + professionals having in-depth computer knowledge. Users are therefore + encouraged to load and test the software's suitability as regards their + 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. + + /** + * Class CFunctionPrototype: an Abstract Data Type for the prototype of a C function + * Creation: 05/10/2016 + * @version 1.0 05/10/2016 + * @author Andrea ENRICI + * @see + */ + +package tmltranslator.modelcompiler; + +import java.util.ArrayList; + +public class CFunctionPrototype { + + private final static String SPACE = " "; + private final static String COMMA = ","; + private final static String SEMICOLON = ";"; + // private String declarationLine; + private String returnType; + private String functionName; + private ArrayList<CVariable> parameters; + + public CFunctionPrototype( String _line ) { + // declarationLine = _line; + init(); + } + + private void init() { + returnType = new String(""); + functionName = new String(""); + parameters = new ArrayList<CVariable>(); + } + + public void setReturnType( String s ) { + returnType = s; + } + + public String getReturnType() { + return returnType; + } + + public void setFunctionName( String s ) { + functionName = s; + } + + public String getFunctionName() { + return functionName; + } + + public void setParameter( String type, String name ) { + parameters.add( new CVariable( type, name ) ); + } + + @Override public String toString() { + StringBuffer strBuf = new StringBuffer( returnType + SPACE + functionName + "(" ); + for( int i = 0; i < parameters.size()-1; i++ ) { + strBuf.append( SPACE + parameters.get(i).toString() + COMMA ); + } + strBuf.append( SPACE + parameters.get(parameters.size()-1).toString() ); + strBuf.append( SPACE + ")" + SEMICOLON ); + return strBuf.toString(); + } +} diff --git a/src/tmltranslator/modelcompiler/CPMEC.java b/src/tmltranslator/modelcompiler/CPMEC.java index 867f2626bfdea79c9b480d932ef2f2f57f5e2aa8..6acff1d57f6d21adf6cd523604c5b890f47f440d 100755 --- a/src/tmltranslator/modelcompiler/CPMEC.java +++ b/src/tmltranslator/modelcompiler/CPMEC.java @@ -44,12 +44,7 @@ * @see */ -package tmltranslator.modelcompiler;; - -import java.util.*; -import java.nio.*; -import myutil.*; -//import Ctranslator.*; +package tmltranslator.modelcompiler; public abstract class CPMEC { diff --git a/src/tmltranslator/modelcompiler/CVariable.java b/src/tmltranslator/modelcompiler/CVariable.java new file mode 100755 index 0000000000000000000000000000000000000000..7e7305d3c340ce2c79f98cd3cc0d78cd7827adc8 --- /dev/null +++ b/src/tmltranslator/modelcompiler/CVariable.java @@ -0,0 +1,180 @@ +/**Copyright or (C) + * + * 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, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * 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. + * + * /** + * Class CVariable + * Abstract Data Type that implements a C variable composed of type and identifier + * Creation: 11/10/2016 + * @version 1.0 11/10/2016 + * @author Andrea ENRICI + * @see + */ + + +package tmltranslator.modelcompiler; + +import java.util.HashSet; + +public class CVariable { + + // type + private final static String SPACE = " "; + + public final static int NATURAL = 1; + public final static int BOOLEAN = 2; + public final static int ADDRESS = 3; + public final static int OTHER = 4; + + public final static String NATURAL_STRING = "int"; + public final static String BOOLEAN_STRING = "bool"; + public final static String ADDRESS_STRING = "addr"; + + public final static HashSet<String> typesDataBase = new HashSet<String>(); + /*typesDataBase.add( "void" ); + typesDataBase.add( "float" ); + typesDataBase.add( "double" ); + typesDataBase.add( "char" ); + typesDataBase.add( "unsigned char" ); + typesDataBase.add( "int" ); + typesDataBase.add( "unsigned int" ); + typesDataBase.add( "short" ); + typesDataBase.add( "unsigned short" ); + typesDataBase.add( "long" ); + typesDataBase.add( "unsigned long" ); + typesDataBase.add( "uint32_t" ); + typesDataBase.add( "int32_t" ); + typesDataBase.add( "uint64_t" ); + typesDataBase.add( "int64_t" ); + typesDataBase.add( "uintptr_t" ); + typesDataBase.add( "intprt_t" );*/ + + private String type; + private String name; + + public CVariable( String _type, String _name ) { + type = _type; + name = _name; + } + + public String getType() { + return type; + } + + public String getName() { + return name; + } + + public void setType( String _type ) { + type = _type; + } + + public void setName( String _name ) { + name = _name; + } + + public static int getIntegerType( String s ) { + s = s.toUpperCase(); + if (s.equals("NATURAL")) { + return NATURAL; + } else if (s.equals("BOOLEAN")) { + return BOOLEAN; + } else if (s.equals("ADDRESS")) { + return ADDRESS; + } else if (s.equals("NAT")) { + return NATURAL; + } else if (s.equals("INT")) { + return NATURAL; + } else if (s.equals("BOOL")) { + return BOOLEAN; + } else if (!s.equals("")) { + return OTHER; + } + + return -1; + } + + public static String getStringType( String type ) { + switch(type) { + case NATURAL_STRING: + return "nat"; + case BOOLEAN_STRING: + return "bool"; + case ADDRESS_STRING: + return "addr"; + default: + return "" + type; + } + } + + public static boolean isAValidType( String type ) { + type = type.toUpperCase(); + + if (type.compareTo("NAT") == 0) { + return true; + } + + if (type.compareTo("INT") == 0) { + return true; + } + + if (type.compareTo("BOOL") == 0) { + return true; + } + + return false; + + } + + @Override public String toString() { + return type + SPACE + name; + } + + @Override public boolean equals( Object o ) { + if( !( o instanceof CVariable ) ) { + return false; + } + else { + CVariable var = (CVariable)o; + return ( (getType().equals(var.getType())) && (getName().equals(var.getName())) ); + } + } + + @Override public int hashCode() { + int result = 17; + result = 31 * result + type.hashCode(); + return result; + } + +} //End of class diff --git a/src/tmltranslator/modelcompiler/Context.java b/src/tmltranslator/modelcompiler/Context.java index 1bec262efc2ea879e114909148625d659e70702f..96a1efd08681be18e108d795c566e968e2fdac4b 100644 --- a/src/tmltranslator/modelcompiler/Context.java +++ b/src/tmltranslator/modelcompiler/Context.java @@ -44,28 +44,20 @@ * @see */ -package tmltranslator.modelcompiler;; - -import java.util.*; -import java.nio.*; -import javax.swing.*; -import javax.swing.event.*; -import myutil.*; - -import tmltranslator.*; +package tmltranslator.modelcompiler; public abstract class Context { private String code = ""; - private String declaration = ""; - private String CR = "\n"; - private String CR2 = "\n\n"; - private String TAB = "\t"; - private String TAB2 = "\t\t"; - private String TAB3 = "\t\t\t"; - private String TAB4 = "\t\t\t\t"; - private String SP = " "; - private String SC = ";"; +// private String declaration = ""; +// private String CR = "\n"; +// private String CR2 = "\n\n"; +// private String TAB = "\t"; +// private String TAB2 = "\t\t"; +// private String TAB3 = "\t\t\t"; +// private String TAB4 = "\t\t\t\t"; +// private String SP = " "; +// private String SC = ";"; public Context() { diff --git a/src/tmltranslator/modelcompiler/CpuMEC.java b/src/tmltranslator/modelcompiler/CpuMEC.java index c97983cd5a1ca5d012214f99d4d87588cdfb3597..49cb9cdb8d6633752ad958e4c3af9cd94fa5101b 100644 --- a/src/tmltranslator/modelcompiler/CpuMEC.java +++ b/src/tmltranslator/modelcompiler/CpuMEC.java @@ -44,9 +44,7 @@ * @see */ -package tmltranslator.modelcompiler;; - -import java.util.*; +package tmltranslator.modelcompiler; public class CpuMEC extends ArchUnitMEC { diff --git a/src/tmltranslator/modelcompiler/CpuMemoryCopyMEC.java b/src/tmltranslator/modelcompiler/CpuMemoryCopyMEC.java index 207cb21292e308ed42da3c2977d16aee9cd16337..6ec8234c6b4cdc5f726b4500d5bcc5e0dba51f3a 100644 --- a/src/tmltranslator/modelcompiler/CpuMemoryCopyMEC.java +++ b/src/tmltranslator/modelcompiler/CpuMemoryCopyMEC.java @@ -45,10 +45,9 @@ * @see */ -package tmltranslator.modelcompiler;; +package tmltranslator.modelcompiler; -import java.util.*; -import myutil.*; +import java.util.Vector; public class CpuMemoryCopyMEC extends CPMEC { diff --git a/src/tmltranslator/modelcompiler/CpuOperationMEC.java b/src/tmltranslator/modelcompiler/CpuOperationMEC.java index bad4176eb79b94095a5d5da85c24c314805bd926..91f1806128569b507f4d11c1c1319dc7f3e148d9 100644 --- a/src/tmltranslator/modelcompiler/CpuOperationMEC.java +++ b/src/tmltranslator/modelcompiler/CpuOperationMEC.java @@ -44,10 +44,7 @@ * @see */ -package tmltranslator.modelcompiler;; - -import java.util.*; -//import Ctranslator.*; +package tmltranslator.modelcompiler; public class CpuOperationMEC extends OperationMEC { diff --git a/src/tmltranslator/modelcompiler/CwaMEC.java b/src/tmltranslator/modelcompiler/CwaMEC.java index c48314fcf52f7b51f5a61db1cf7546235924cec5..3747d37e88d82f48cff855fe087b94a448345506 100644 --- a/src/tmltranslator/modelcompiler/CwaMEC.java +++ b/src/tmltranslator/modelcompiler/CwaMEC.java @@ -44,10 +44,7 @@ * @see */ -package tmltranslator.modelcompiler;; - -import java.util.*; -//import Ctranslator.*; +package tmltranslator.modelcompiler; public class CwaMEC extends FepOperationMEC { diff --git a/src/tmltranslator/modelcompiler/CwlMEC.java b/src/tmltranslator/modelcompiler/CwlMEC.java index 2e69d274defbc29ad7d7f8c45779c78f73cc1c84..6c0da327b39829eb362aba74d1daa5e1b29a2237 100755 --- a/src/tmltranslator/modelcompiler/CwlMEC.java +++ b/src/tmltranslator/modelcompiler/CwlMEC.java @@ -44,10 +44,7 @@ * @see */ -package tmltranslator.modelcompiler;; - -import java.util.*; -//import Ctranslator.*; +package tmltranslator.modelcompiler; public class CwlMEC extends FepOperationMEC { diff --git a/src/tmltranslator/modelcompiler/CwmMEC.java b/src/tmltranslator/modelcompiler/CwmMEC.java index 8bbed09772c780cd22331708d3d577b713d96309..f09f828c51088494eb5dc88958e41bba8d6a123e 100755 --- a/src/tmltranslator/modelcompiler/CwmMEC.java +++ b/src/tmltranslator/modelcompiler/CwmMEC.java @@ -44,10 +44,7 @@ * @see */ -package tmltranslator.modelcompiler;; - -import java.util.*; -//import Ctranslator.*; +package tmltranslator.modelcompiler; public class CwmMEC extends FepOperationMEC { diff --git a/src/tmltranslator/modelcompiler/CwpMEC.java b/src/tmltranslator/modelcompiler/CwpMEC.java index 05268a653ada5e1247927e8cffa249cb38180a5a..0d99acadd75686b16a2204e36d00a505cb66735e 100755 --- a/src/tmltranslator/modelcompiler/CwpMEC.java +++ b/src/tmltranslator/modelcompiler/CwpMEC.java @@ -44,10 +44,7 @@ * @see */ -package tmltranslator.modelcompiler;; - -import java.util.*; -//import Ctranslator.*; +package tmltranslator.modelcompiler; public class CwpMEC extends FepOperationMEC { diff --git a/src/tmltranslator/modelcompiler/DataTransfer.java b/src/tmltranslator/modelcompiler/DataTransfer.java index 29053667847b9ef6a114df031be38206a8c42160..f40e75a6f05f3113cfbc5e2b11dabe21f72043a3 100755 --- a/src/tmltranslator/modelcompiler/DataTransfer.java +++ b/src/tmltranslator/modelcompiler/DataTransfer.java @@ -44,13 +44,12 @@ * @see */ -package tmltranslator.modelcompiler;; +package tmltranslator.modelcompiler; -import java.util.*; -import java.nio.*; -import myutil.*; +import java.util.ArrayList; -import tmltranslator.*; +import tmltranslator.TMLCP; +import tmltranslator.TMLCPLib; public class DataTransfer { diff --git a/src/tmltranslator/modelcompiler/DoubleDmaMEC.java b/src/tmltranslator/modelcompiler/DoubleDmaMEC.java index 3eeadeb9ca9724bef1d4d6c0b9978522d82888dc..de8a840c4cb3e3a882f90198c30ca8f0fc204628 100755 --- a/src/tmltranslator/modelcompiler/DoubleDmaMEC.java +++ b/src/tmltranslator/modelcompiler/DoubleDmaMEC.java @@ -44,10 +44,10 @@ * @see */ -package tmltranslator.modelcompiler;; +package tmltranslator.modelcompiler; -import java.util.*; -import myutil.*; +import java.util.ArrayList; +import java.util.Vector; public class DoubleDmaMEC extends CPMEC { @@ -73,8 +73,8 @@ public class DoubleDmaMEC extends CPMEC { private String srcAddress1 = USER_TO_DO; private String dstAddress2 = USER_TO_DO; private String srcAddress2 = USER_TO_DO; - private String memoryBaseAddress1 = USER_TO_DO; - private String memoryBaseAddress2 = USER_TO_DO; +// private String memoryBaseAddress1 = USER_TO_DO; +// private String memoryBaseAddress2 = USER_TO_DO; private String ctxName1 = USER_TO_DO; private String ctxName2 = USER_TO_DO; @@ -105,7 +105,7 @@ public class DoubleDmaMEC extends CPMEC { } } - int dstMemoryType = dstMemoryTypes.get(0).intValue(); + //int dstMemoryType = dstMemoryTypes.get(0).intValue(); ArchUnitMEC archMEC = archMECs.get(0); if( attributes.size() > 0 ) { diff --git a/src/tmltranslator/modelcompiler/FepBuffer.java b/src/tmltranslator/modelcompiler/FepBuffer.java index a67bb6a6691fbdc5546b335511a5ef5eb74c6a64..b397407f5926bb4a8efd250e1c9a35d1ca92e88e 100755 --- a/src/tmltranslator/modelcompiler/FepBuffer.java +++ b/src/tmltranslator/modelcompiler/FepBuffer.java @@ -44,17 +44,25 @@ * @see */ -package tmltranslator.modelcompiler;; +package tmltranslator.modelcompiler; + +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Vector; + +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; -import java.util.*; -import java.nio.*; import org.w3c.dom.Element; -import javax.swing.*; -import java.awt.*; -import java.awt.event.*; -import myutil.*; -import tmltranslator.*; +import tmltranslator.TMLTask; public class FepBuffer extends Buffer { diff --git a/src/tmltranslator/modelcompiler/FepMEC.java b/src/tmltranslator/modelcompiler/FepMEC.java index b9fbc270501e50add67a6fd558e5570204d0f7b2..2ccb360de80e139480a3fae13c0abbfc9aad315b 100644 --- a/src/tmltranslator/modelcompiler/FepMEC.java +++ b/src/tmltranslator/modelcompiler/FepMEC.java @@ -44,10 +44,9 @@ * @see */ -package tmltranslator.modelcompiler;; +package tmltranslator.modelcompiler; import java.util.*; -//import Ctranslator.*; public class FepMEC extends ArchUnitMEC { diff --git a/src/tmltranslator/modelcompiler/FftMEC.java b/src/tmltranslator/modelcompiler/FftMEC.java index 614459d75d4fa0e925b7c1cb5912600bf6fc101e..2fc4a8769a0d1a11471162c9c71b82b0c322bf66 100644 --- a/src/tmltranslator/modelcompiler/FftMEC.java +++ b/src/tmltranslator/modelcompiler/FftMEC.java @@ -44,10 +44,7 @@ * @see */ -package tmltranslator.modelcompiler;; - -import java.util.*; -//import Ctranslator.*; +package tmltranslator.modelcompiler; public class FftMEC extends FepOperationMEC { diff --git a/src/tmltranslator/modelcompiler/InterleaverBuffer.java b/src/tmltranslator/modelcompiler/InterleaverBuffer.java index 7318750e5b91a555e8fad83b557e964e15ab8b08..2301749884e613ea57e22af1073f12f63244cc20 100644 --- a/src/tmltranslator/modelcompiler/InterleaverBuffer.java +++ b/src/tmltranslator/modelcompiler/InterleaverBuffer.java @@ -44,17 +44,25 @@ * @see */ -package tmltranslator.modelcompiler;; +package tmltranslator.modelcompiler; + +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Vector; + +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; -import java.util.*; -import java.nio.*; import org.w3c.dom.Element; -import javax.swing.*; -import java.awt.*; -import java.awt.event.*; -import myutil.*; -import tmltranslator.*; +import tmltranslator.TMLTask; public class InterleaverBuffer extends Buffer { diff --git a/src/tmltranslator/modelcompiler/InterleaverMEC.java b/src/tmltranslator/modelcompiler/InterleaverMEC.java index 134482a943de443e58b365b9ff45db95e38429a4..e98305d7f6196ee36eee6914ec2b4d267dfeaff0 100644 --- a/src/tmltranslator/modelcompiler/InterleaverMEC.java +++ b/src/tmltranslator/modelcompiler/InterleaverMEC.java @@ -44,10 +44,7 @@ * @see */ -package tmltranslator.modelcompiler;; - -import java.util.*; -//import Ctranslator.*; +package tmltranslator.modelcompiler; public class InterleaverMEC extends ArchUnitMEC { diff --git a/src/tmltranslator/modelcompiler/IntlOperationMEC.java b/src/tmltranslator/modelcompiler/IntlOperationMEC.java index 0a63201fb8748ec93373ab21fb89825f5a6b688f..fac8d8c7dad1839706f77091577dac164fddf37d 100644 --- a/src/tmltranslator/modelcompiler/IntlOperationMEC.java +++ b/src/tmltranslator/modelcompiler/IntlOperationMEC.java @@ -44,9 +44,7 @@ * @see */ -package tmltranslator.modelcompiler;; - -import java.util.*; +package tmltranslator.modelcompiler; public class IntlOperationMEC extends OperationMEC { diff --git a/src/tmltranslator/modelcompiler/MMBuffer.java b/src/tmltranslator/modelcompiler/MMBuffer.java index d48317e9bfb23272bf9c6f5ae071a832dede7820..9a28b60535e0665b25980194d357a517cb668782 100644 --- a/src/tmltranslator/modelcompiler/MMBuffer.java +++ b/src/tmltranslator/modelcompiler/MMBuffer.java @@ -44,17 +44,22 @@ * @see */ -package tmltranslator.modelcompiler;; +package tmltranslator.modelcompiler; + +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.util.ArrayList; + +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; -import java.util.*; -import java.nio.*; import org.w3c.dom.Element; -import javax.swing.*; -import java.awt.*; -import java.awt.event.*; -import myutil.*; -import tmltranslator.*; +import tmltranslator.TMLTask; public class MMBuffer extends Buffer { diff --git a/src/tmltranslator/modelcompiler/MappOperationMEC.java b/src/tmltranslator/modelcompiler/MappOperationMEC.java index 8825c4c638fbeba55f79e463f4b59059d919be02..3cb23df2a04a476aaa64b21c980ded00689f3868 100644 --- a/src/tmltranslator/modelcompiler/MappOperationMEC.java +++ b/src/tmltranslator/modelcompiler/MappOperationMEC.java @@ -44,9 +44,7 @@ * @see */ -package tmltranslator.modelcompiler;; - -import java.util.*; +package tmltranslator.modelcompiler; public class MappOperationMEC extends OperationMEC { diff --git a/src/tmltranslator/modelcompiler/MapperBuffer.java b/src/tmltranslator/modelcompiler/MapperBuffer.java index 5dbc759b66fcdf7dd0ab31e22431578209614493..af6fb8843a389e044b02fda375ef3efdf14a8610 100644 --- a/src/tmltranslator/modelcompiler/MapperBuffer.java +++ b/src/tmltranslator/modelcompiler/MapperBuffer.java @@ -44,17 +44,25 @@ * @see */ -package tmltranslator.modelcompiler;; +package tmltranslator.modelcompiler; + +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Vector; + +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; -import java.util.*; -import java.nio.*; import org.w3c.dom.Element; -import javax.swing.*; -import java.awt.*; -import java.awt.event.*; -import myutil.*; -import tmltranslator.*; +import tmltranslator.TMLTask; public class MapperBuffer extends Buffer { diff --git a/src/tmltranslator/modelcompiler/MapperMEC.java b/src/tmltranslator/modelcompiler/MapperMEC.java index 70e508833b956a522a3714b3115665f9c4dc19ec..bb2d42fe181352efd04b3a357f0cb6a41fd8dee9 100644 --- a/src/tmltranslator/modelcompiler/MapperMEC.java +++ b/src/tmltranslator/modelcompiler/MapperMEC.java @@ -44,10 +44,7 @@ * @see */ -package tmltranslator.modelcompiler;; - -import java.util.*; -//import Ctranslator.*; +package tmltranslator.modelcompiler; public class MapperMEC extends ArchUnitMEC { diff --git a/src/tmltranslator/modelcompiler/Operation.java b/src/tmltranslator/modelcompiler/Operation.java index 40226d5fa1888862362ae149f68dbdc293a1591f..c908aab26cc0bed059d739240169ced1b96ea79a 100755 --- a/src/tmltranslator/modelcompiler/Operation.java +++ b/src/tmltranslator/modelcompiler/Operation.java @@ -44,13 +44,12 @@ * @see */ -package tmltranslator.modelcompiler;; +package tmltranslator.modelcompiler; -import java.util.*; -import java.nio.*; -import myutil.*; +import java.util.ArrayList; -import tmltranslator.*; +import tmltranslator.HwNode; +import tmltranslator.TMLTask; public class Operation { @@ -62,8 +61,8 @@ public class Operation { private String name = ""; private TMLTask fTask; private TMLTask xTask; - private boolean prex; - private boolean postex; +// private boolean prex; +// private boolean postex; private ArrayList<Signal> inSignals = new ArrayList<Signal>(); private Signal outSignal; private Buffer inBuffer; diff --git a/src/tmltranslator/modelcompiler/Scheduler.java b/src/tmltranslator/modelcompiler/Scheduler.java index 67b80c1319bd7e22b44d2c72a286cfaf07db6553..af192a83f4137d73601f901469917614d6acf7f0 100644 --- a/src/tmltranslator/modelcompiler/Scheduler.java +++ b/src/tmltranslator/modelcompiler/Scheduler.java @@ -44,15 +44,7 @@ * @see */ -package tmltranslator.modelcompiler;; - -import java.util.*; -import java.nio.*; -import javax.swing.*; -import javax.swing.event.*; -import myutil.*; - -import tmltranslator.*; +package tmltranslator.modelcompiler; public class Scheduler { @@ -60,13 +52,13 @@ public class Scheduler { private String code = ""; private String CR = "\n"; - private String CR2 = "\n\n"; +// private String CR2 = "\n\n"; private String TAB = "\t"; private String TAB2 = "\t\t"; private String TAB3 = "\t\t\t"; private String TAB4 = "\t\t\t\t"; - private String SP = " "; - private String SC = ";"; +// private String SP = " "; +// private String SC = ";"; public Scheduler( int type ) { diff --git a/src/tmltranslator/modelcompiler/Signal.java b/src/tmltranslator/modelcompiler/Signal.java index 8af66a61a56528db6ea20e1391ff8f2f38db1278..9557e403199828f8f97af6eaaa189bdb7ea9bc16 100755 --- a/src/tmltranslator/modelcompiler/Signal.java +++ b/src/tmltranslator/modelcompiler/Signal.java @@ -44,12 +44,10 @@ * @see */ -package tmltranslator.modelcompiler;; +package tmltranslator.modelcompiler; -import java.util.*; -import java.nio.*; -import myutil.*; -import tmltranslator.*; +import tmltranslator.TMLChannel; +import tmltranslator.TMLEvent; public class Signal { @@ -59,8 +57,8 @@ public class Signal { public String CR = "\n"; public String SC = ";"; - private boolean status = false; - private Buffer buffPointer = null; + //private boolean status = false; + //private Buffer buffPointer = null; private String name; private TMLChannel channel; private TMLEvent event; diff --git a/src/tmltranslator/modelcompiler/SingleDmaMEC.java b/src/tmltranslator/modelcompiler/SingleDmaMEC.java index 1f48a173a1894f5bf078760e8c61948460d875d4..29bd978ceff29a575a83be1c01275db41c5725bc 100755 --- a/src/tmltranslator/modelcompiler/SingleDmaMEC.java +++ b/src/tmltranslator/modelcompiler/SingleDmaMEC.java @@ -44,10 +44,9 @@ * @see */ -package tmltranslator.modelcompiler;; +package tmltranslator.modelcompiler; -import java.util.*; -import myutil.*; +import java.util.Vector; public class SingleDmaMEC extends CPMEC { diff --git a/src/tmltranslator/modelcompiler/SumMEC.java b/src/tmltranslator/modelcompiler/SumMEC.java index 0f97ed3efc86926e9e2def8d752a61a1db09e3f7..dd447e4e2d47e8ac4d6069f8704b43a18ecd8d29 100644 --- a/src/tmltranslator/modelcompiler/SumMEC.java +++ b/src/tmltranslator/modelcompiler/SumMEC.java @@ -44,9 +44,7 @@ * @see */ -package tmltranslator.modelcompiler;; - -import java.util.*; +package tmltranslator.modelcompiler; public class SumMEC extends FepOperationMEC { diff --git a/src/tmltranslator/modelcompiler/TMLModelCompiler.java b/src/tmltranslator/modelcompiler/TMLModelCompiler.java index 1343099c48c7020e234923b742f06e4ec549c655..e4def3dca62cac746cc108cdf9e16f1d529953aa 100755 --- a/src/tmltranslator/modelcompiler/TMLModelCompiler.java +++ b/src/tmltranslator/modelcompiler/TMLModelCompiler.java @@ -46,19 +46,35 @@ * @see */ -package tmltranslator.modelcompiler;; - -import java.util.*; -import java.io.*; -import java.nio.*; -import javax.swing.*; -import javax.swing.event.*; -import myutil.*; - -import tmltranslator.*; -import ui.tmlcompd.*; +package tmltranslator.modelcompiler; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Vector; + +import javax.swing.JFrame; + +import myutil.FileException; +import myutil.FileUtils; +import myutil.TraceManager; +import tmltranslator.HwNode; +import tmltranslator.TMLArchitecture; +import tmltranslator.TMLCP; +import tmltranslator.TMLCPLib; +import tmltranslator.TMLChannel; +import tmltranslator.TMLElement; +import tmltranslator.TMLMapping; +import tmltranslator.TMLModeling; +import tmltranslator.TMLPort; +import tmltranslator.TMLReadChannel; +import tmltranslator.TMLTask; +import tmltranslator.TMLWriteChannel; import ui.ConfigurationTTool; -import ui.*; +import ui.GTMLModeling; +import ui.TMLCommunicationPatternPanel; public class TMLModelCompiler { @@ -67,15 +83,15 @@ public class TMLModelCompiler { private String CR = "\n"; private String CR2 = "\n\n"; private String TAB = "\t"; - private String TAB2 = "\t\t"; - private String TAB3 = "\t\t\t"; - private String TAB4 = "\t\t\t\t"; +// private String TAB2 = "\t\t"; +// private String TAB3 = "\t\t\t"; +// private String TAB4 = "\t\t\t\t"; private String SP = " "; private String SC = ";"; - private String COLON = ","; +// private String COLON = ","; private TMLMapping tmap; - private TMLCP tmlcp; +// private TMLCP tmlcp; private TMLModeling tmlm; private TMLArchitecture tmla; private String applicationName; @@ -83,11 +99,11 @@ public class TMLModelCompiler { private StringBuffer headerString; private StringBuffer programString; private StringBuffer initFileString; - private ArrayList<TMLTask> mappedTasks; - private ArrayList<TMLElement> commElts; +// private ArrayList<TMLTask> mappedTasks; +// private ArrayList<TMLElement> commElts; private ArrayList<Operation> operationsList; - private int SDRoperationsCounter; - private int signalsCounter; +// private int SDRoperationsCounter; +// private int signalsCounter; private ArrayList<Signal> signalsList; private ArrayList<TMLCPLib> mappedCPLibs; private ArrayList<TMLPort> postexList; @@ -97,8 +113,8 @@ public class TMLModelCompiler { private ArrayList<TMLCommunicationPatternPanel> tmlcpps; private ArrayList<TMLCP> tmlcpsList; - private ArrayList<TMLModelCompilerError> errors; - private ArrayList<TMLModelCompilerError> warnings; +// private ArrayList<TMLModelCompilerError> errors; +// private ArrayList<TMLModelCompilerError> warnings; private String debugFileName; PrintWriter outputStream; @@ -120,16 +136,16 @@ public class TMLModelCompiler { } private void init() { - mappedTasks = new ArrayList<TMLTask>(); - commElts = new ArrayList<TMLElement>(); - errors = new ArrayList<TMLModelCompilerError>(); + // mappedTasks = new ArrayList<TMLTask>(); + // commElts = new ArrayList<TMLElement>(); + //errors = new ArrayList<TMLModelCompilerError>(); mainFileString = new StringBuffer(); headerString = new StringBuffer(); programString = new StringBuffer(); initFileString = new StringBuffer(); operationsList = new ArrayList<Operation>(); - SDRoperationsCounter = 0; - signalsCounter = 0; + // SDRoperationsCounter = 0; +// signalsCounter = 0; signalsList = new ArrayList<Signal>(); postexList = new ArrayList<TMLPort>(); prexList = new ArrayList<TMLPort>(); @@ -219,7 +235,7 @@ public class TMLModelCompiler { inBuffer = createInBuffer( xTask, tmap.getHwNodeOf( xTask ) ); //null for Source outBuffer = createOutBuffer( xTask, tmap.getHwNodeOf( xTask ) ); //null for Sink operationsList.add( new Operation( fTask, xTask, tmap.getHwNodeOf( xTask ), tmap.getHwNodeOf( fTask ), inSignals, outSignal, inBuffer, outBuffer, prexPostexList[0], prexPostexList[1] ) ); - SDRoperationsCounter++; + //SDRoperationsCounter++; } } } @@ -376,7 +392,7 @@ public class TMLModelCompiler { private ArrayList<Signal> getInSignals( TMLTask task ) { //Find the signal associated to the write channel of task - TMLPort originPort, destinationPortCh, originPortSigChannel, destinationPortSigChannel; + TMLPort originPort, destinationPortCh,/* originPortSigChannel,*/ destinationPortSigChannel; TMLChannel sigChannel; ArrayList<Signal> sigsList = new ArrayList<Signal>(); @@ -424,7 +440,7 @@ public class TMLModelCompiler { private Signal getOutSignal( TMLTask task ) { //Find the signal associated to the write channel of task - TMLPort originPort, destinationPort, originPortSigChannel; + TMLPort originPort,/* destinationPort,*/ originPortSigChannel; TMLChannel sigChannel; for( TMLChannel ch: task.getWriteTMLChannels() ) { @@ -493,7 +509,7 @@ public class TMLModelCompiler { private void makeDataTransfersList() { ArrayList<Signal> inSignals; - Signal outSignal; + //Signal outSignal; for( TMLCPLib cplib: mappedCPLibs ) { if( cplib.getArtifacts().size() == 1 ) { @@ -948,7 +964,7 @@ public class TMLModelCompiler { private void generateCodeForOperations() { //generate the code for the execution operations //for each operations add the exec code + the info for all the signals and stuff - String exec_code = ""; + //String exec_code = ""; for( Operation op: operationsList ) { if( op.getType() == Operation.SDR ) { @@ -1495,7 +1511,7 @@ public class TMLModelCompiler { transferType = tmlcplib.getTransferTypes().get(0); for( String s: tmlcplib.getMappedUnits() ) { if( s.contains( CPMEC.dmaController ) ) { - String dmaUnit = s.split(":")[1].replaceAll("\\s+",""); + //String dmaUnit = s.split(":")[1].replaceAll("\\s+",""); //dmaArchMEC = tmla.getHwCPUByName( dmaUnit ).MEC; break; } diff --git a/src/tmltranslator/modelcompiler/TMLModelCompilerError.java b/src/tmltranslator/modelcompiler/TMLModelCompilerError.java index 08734bfb7db09d0974c9a3d23be789a823732e54..1d1670d93f47ed2f86f8f6ec767e00e2d0bcdd1b 100755 --- a/src/tmltranslator/modelcompiler/TMLModelCompilerError.java +++ b/src/tmltranslator/modelcompiler/TMLModelCompilerError.java @@ -47,7 +47,7 @@ */ -package tmltranslator.modelcompiler;; +package tmltranslator.modelcompiler; import tmltranslator.*; diff --git a/src/tmltranslator/modelcompiler/TMLModelCompilerMakefile.java b/src/tmltranslator/modelcompiler/TMLModelCompilerMakefile.java index 42e2de6e78d55ebba8d2e6a61597095cc6acdffe..fc29e801fa130e5b9f7b58bbf18f519801317f21 100644 --- a/src/tmltranslator/modelcompiler/TMLModelCompilerMakefile.java +++ b/src/tmltranslator/modelcompiler/TMLModelCompilerMakefile.java @@ -46,18 +46,7 @@ * @see */ -package tmltranslator.modelcompiler;; - -import java.util.*; -import java.io.*; -import java.nio.*; -import javax.swing.*; -import javax.swing.event.*; -import myutil.*; - -import tmltranslator.*; -import ui.tmlcompd.*; -import ui.ConfigurationTTool; +package tmltranslator.modelcompiler; public class TMLModelCompilerMakefile { diff --git a/src/tmltranslator/modelcompiler/TMLModelCompilerParser.java b/src/tmltranslator/modelcompiler/TMLModelCompilerParser.java index 07a6ea00ec4e7c397b852c2fbcc8647bff64625e..ba5865e5cb18616dcaf74804d1981633ec618747 100755 --- a/src/tmltranslator/modelcompiler/TMLModelCompilerParser.java +++ b/src/tmltranslator/modelcompiler/TMLModelCompilerParser.java @@ -47,7 +47,7 @@ */ -package tmltranslator.modelcompiler;; +package tmltranslator.modelcompiler; import tmltranslator.*; import java.util.*; @@ -57,10 +57,10 @@ public class TMLModelCompilerParser { public TMLActivityElement element; private ArrayList<TMLModelCompilerError> errors; - private ArrayList<TMLTask> mappedTasks; + // private ArrayList<TMLTask> mappedTasks; private TMLMapping tmap; private TMLModeling tmlm; - private TMLArchitecture tmla; + //private TMLArchitecture tmla; private ArrayList<TMLCPLib> mappedCPLibs; public final static int ERROR_STRUCTURE = 0; @@ -76,7 +76,7 @@ public class TMLModelCompilerParser { errors = new ArrayList<TMLModelCompilerError>(); tmap = _tmap; tmlm = _tmlm; - tmla = _tmla; + // tmla = _tmla; mappedCPLibs = _tmap.getMappedTMLCPLibs(); } diff --git a/src/tmltranslator/modelcompiler/TMLPECParser.java b/src/tmltranslator/modelcompiler/TMLPECParser.java index bf66c7c3ccad26f39bab9d0f97ecabf39389aba7..2fbfeba9d40ba1c83ed885a147f972be69abc80b 100755 --- a/src/tmltranslator/modelcompiler/TMLPECParser.java +++ b/src/tmltranslator/modelcompiler/TMLPECParser.java @@ -1921,3 +1921,739 @@ public class TMLPECParser { // } } //End of class +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille, Andrea Enrici + + ludovic.apvrille AT enst.fr + andrea.enrici AT enstr.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, + that may mean that it is complicated to manipulate, and that also + therefore means that it is reserved for developers and experienced + professionals having in-depth computer knowledge. Users are therefore + encouraged to load and test the software's suitability as regards their + 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. + + /** + * Class TMLPECParser: this class parses the Platform Extension Contruct (PEC) file and the files containing the code + * snippets that are referenced by the PEC file + * Creation: 01/09/2016 + * @version 1.0 01/09/2016 + * @author Andrea ENRICI + * @see + */ + +package tmltranslator.modelcompiler; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashSet; + +import javax.swing.JFrame; + +import myutil.TraceManager; + +public class TMLPECParser { + + public String title; + +// private String CR = "\n"; +// private String CR2 = "\n\n"; +// private String TAB = "\t"; +// private String TAB2 = "\t\t"; +// private String TAB3 = "\t\t\t"; +// private String TAB4 = "\t\t\t\t"; + private String SPACE = " "; +// private String COLON = ":"; + private String SEMICOLON = ";"; +// private String COMMA = ","; + private String FORBIDDEN_CHARACTERS = ";|é|è|ê|ë|ù|ü|à |â|ö|ï|ç|\"|\\/|\\%|\\(|\\)|\\.|\\'|\\?|\\!|\\,|\\@|\\$|\\#|\\-"; // Characters forbidden in ID names + + // List of reserved keywords + private final static String DMA_KW = "DMA"; + private final static String CPU_KW = "CPU"; + private final static String MEMORY_KW = "MEMORY"; + private final static String HWA_KW = "HWA"; + private final static String TYPE_KW = "TYPE"; + private final static String OPERATION_KW = "Operation"; + private final static String EXECUTE_KW = "executes"; + private final static String INCLUDE_KW = "#include"; + private final static String TYPE_INCLUDE_KW = "#typeinclude"; + private final static String INIT_CATEGORY = "init"; + private final static String CLEANUP_CATEGORY = "cleanup"; + private final static String EXECUTION_CATEGORY = "execution"; + + // List of error codes + public final static int ERROR_SEPARATOR = 0; + public final static int ERROR_SEMICOLON = 1; + public final static int ERROR_MULTIPLE_DECLARATION = 2; + public final static int ERROR_UNVALID_CHARACTERS = 3; + public final static int ERROR_FILE_NOT_FOUND = 4; + public final static int ERROR_UNDECLARED_UNIT = 5; + public final static int ERROR_SYMBOL_NOT_FOUND = 6; + public final static int ERROR_INVALID_LINE_TERMINATOR = 7; + public final static int ERROR_INVALID_CATEGORY_TYPE = 8; + public final static int ERROR_INVALID_STATEMENT = 9; + public final static int ERROR_INVALID_TYPE = 10; + public final static int ERROR_INVALID_IDENTIFIER = 11; + public final static int ERROR_INVALID_PARAMETER_DECLARATION = 12; + public final static int ERROR_UNHANDLED = 13; + + public final static String ERROR = "ERROR"; + + // Parser data structures + private ArrayList<String> cpus; + private ArrayList<String> dmas; + private ArrayList<String> memories; + private ArrayList<String> hwas; + + private ArrayList<String> operations; + private ArrayList<ArrayList<String>> unitsOps; + + private HashSet<String> typesDataBase; + private ArrayList<String> includeTypeLines; + + private ArrayList<TMLPECParserError> errors; + //private ArrayList<TMLPECParserError> warnings; + + private File file; + + private ArrayList<CFunctionPrototype> initializationFunctions; + private ArrayList<CFunctionPrototype> executionFunctions; + private ArrayList<CFunctionPrototype> cleanupFunctions; + + //private String debugFileName; + PrintWriter outputStream; + + JFrame frame; + + public TMLPECParser( File _file ) { + file = _file; + init(); + } + + private void init() { + cpus = new ArrayList<String>(); + dmas = new ArrayList<String>(); + memories = new ArrayList<String>(); + hwas = new ArrayList<String>(); + operations = new ArrayList<String>(); + unitsOps = new ArrayList<ArrayList<String>>(); + errors = new ArrayList<TMLPECParserError>(); + //warnings = new ArrayList<TMLPECParserError>(); + initializationFunctions = new ArrayList<CFunctionPrototype>(); + executionFunctions = new ArrayList<CFunctionPrototype>(); + cleanupFunctions = new ArrayList<CFunctionPrototype>(); + includeTypeLines = new ArrayList<String>(); + typesDataBase = new HashSet<String>(); + } + + public void parsePEC() { + + // Temporary data structures to store the three sections of a .pec file + ArrayList<String> unitDeclarationLines = new ArrayList<String>(); + ArrayList<String> opLines = new ArrayList<String>(); + ArrayList<String> unitToOpsLines = new ArrayList<String>(); + ArrayList<String> includeLines = new ArrayList<String>(); + String id; + + Charset charset = Charset.forName("US-ASCII"); + try( BufferedReader reader = Files.newBufferedReader( Paths.get( file.getAbsolutePath() ), charset ) ) { + int lineCounter = 0; + String line = null; + while( (line = reader.readLine()) != null ) { + lineCounter++; + if( line.length() > 0 ) { // Filter empty lines + if( line.charAt(0) != '%' ) { // Ignore lines starting with % as they are comments + // So far there are three cases: diplodocus-to-unit mapping, operation declatation, operation-to-unit mapping + // Therefore trim the file in 3 separate data structures, then parse each of these + // data-structures + String arr[] = line.split( SPACE ); + String word = arr[0]; + switch( word ) { + case OPERATION_KW: + opLines.add( String.valueOf(lineCounter) + " * " + line ); + break; + case DMA_KW: + unitDeclarationLines.add( String.valueOf(lineCounter) + " * " + line ); + break; + case CPU_KW: + unitDeclarationLines.add( String.valueOf(lineCounter) + " * " + line ); + break; + case HWA_KW: + unitDeclarationLines.add( String.valueOf(lineCounter) + " * " + line ); + break; + case MEMORY_KW: + unitDeclarationLines.add( String.valueOf(lineCounter) + " * " + line ); + break; + case INCLUDE_KW: + includeLines.add( String.valueOf(lineCounter) + " * " + line ); + break; + case TYPE_INCLUDE_KW: + includeTypeLines.add( String.valueOf(lineCounter) + " * " + line ); + break; + default: + if( arr[1].equals( EXECUTE_KW ) ) { + unitToOpsLines.add( String.valueOf(lineCounter) + " * " + line ); + } + else { + addError( "Unrecognized error in " + file.getAbsolutePath() + ", at line " + String.valueOf(lineCounter) + ":" + SPACE + arr[1], ERROR_UNHANDLED ); + } + break; + } + // Associate each unit to an index that will be used in the data structure unitsOps to access + // the list of operations that are associated to that unit, e.g., FEP_PSS has index 0 and + // operations FFT, CWL, CWP, CWA, CWM, CWS, MOV. + // Then unitsOps[0] contains the list FFT, CWL, CWP, CWA, CWM, CWS, MOV* + } + } + } // End of while loop + // Parse the lines the include the declaration of data types + for( String s: includeTypeLines ) { + int lineCnt = Integer.parseInt( s.split( " \\* " )[0] ); + String s1 = s.split( "\\* " )[1].trim(); + String[] tokensArray = s1.split( SPACE ); + // String keyword = tokensArray[0]; + for( int i = 1; i < tokensArray.length; i++ ) { + String token = tokensArray[i]; + if( (token.charAt(token.length()-1) == ',') || (token.charAt(token.length()-1) == ';') ) { + token = token.substring(0,token.length()-1); + if( parseIdentifier( token ).equals(ERROR) ) { + addError( "Error in " + file.getAbsolutePath() + " at line " + String.valueOf(lineCnt) + ": + " + token + " invalid data type" , ERROR_INVALID_TYPE ); + } + else { + typesDataBase.add( token ); + } + } + else { + addError( "Error in " + file.getAbsolutePath() + ", at line " + String.valueOf(lineCounter) + ":" + SPACE + token, ERROR_SEPARATOR ); // ERROR: missing comma separator + } + } + } + // Parse the declaration of operations: at this point the only certain thing is that the line begins with + // the keyword Operation + for( String s: opLines ) { + int lineCnt = Integer.parseInt( s.split( " \\* " )[0] ); + String s1 = s.split( "\\* " )[1]; + String[] opArray = s1.split( SPACE ); + for( int i = 1; i < opArray.length; i++ ) { // i = 1 to skip the keyword Operation + char c = opArray[i].charAt( opArray[i].length()-1 ); + if( c == ',' ) { + id = parseIdentifier( opArray[i] ); + if( id.equals(ERROR) ) { + addError( "Error in " + file.getAbsolutePath() + " at line " + String.valueOf(lineCnt) + ", invalid statement" , ERROR_INVALID_STATEMENT ); + } + else { + operations.add(id); + } + } + else { // Test if the last character of the identier is a semicolon + if( (c == ';') && (i != (opArray.length-1)) ) { + addError( "Error in " + file.getAbsolutePath() + ", at line " + String.valueOf(lineCounter) + ":" + SPACE + opArray[i], ERROR_SEMICOLON ); // ERROR: semicolon has been used as a wrong separator + } + else { + if( (c == ';') && (i == (opArray.length-1)) ) { + id = parseIdentifier( opArray[i] ); + if( id.equals(ERROR) ) { + addError( "Error in " + file.getAbsolutePath() + " at line " + String.valueOf(lineCnt) + ", invalid statement" , ERROR_INVALID_STATEMENT ); + } + else { + operations.add(id); + } + } + else { // ERROR: the identifier is not followed by a valid separator + addError( "Error in " + file.getAbsolutePath() + ", at line " + String.valueOf(lineCounter) + ":" + SPACE + opArray[i], ERROR_SEPARATOR ); + } + } + } + } + } + // Parse the declaration of units: at this point the only certain thing is that the line begins with a valid keyword + for( String s: unitDeclarationLines ) { + int lineCnt = Integer.parseInt( s.split( " \\* " )[0] ); + String s1 = s.split( "\\* " )[1]; + String[] unitArray = s1.split( SPACE ); + for( int i = 1; i < unitArray.length; i++ ) { // i = 1 to skip the keyword Operation + char c = unitArray[i].charAt( unitArray[i].length()-1 ); + if( c == ',' ) { + switch( unitArray[0] ) { + case DMA_KW: + id = parseIdentifier( unitArray[i] ); + if( id.equals(ERROR) ) { + addError( "Error in " + file.getAbsolutePath() + " at line " + String.valueOf(lineCnt) + ", invalid statement" , ERROR_INVALID_STATEMENT ); + } + else { + dmas.add(id); + } + break; + case MEMORY_KW: + id = parseIdentifier( unitArray[i] ); + if( id.equals(ERROR) ) { + addError( "Error in " + file.getAbsolutePath() + " at line " + String.valueOf(lineCnt) + ", invalid statement" , ERROR_INVALID_STATEMENT ); + } + else { + memories.add(id); + } + break; + case CPU_KW: + id = parseIdentifier( unitArray[i] ); + if( id.equals(ERROR) ) { + addError( "Error in " + file.getAbsolutePath() + " at line " + String.valueOf(lineCnt) + ", invalid statement" , ERROR_INVALID_STATEMENT ); + } + else { + cpus.add(id); + } + break; + case HWA_KW: + id = parseIdentifier( unitArray[i] ); + if( id.equals(ERROR) ) { + addError( "Error in " + file.getAbsolutePath() + " at line " + String.valueOf(lineCnt) + ", invalid statement" , ERROR_INVALID_STATEMENT ); + } + else { + hwas.add(id); + } + break; + } + } + else { // Test if the last character of the identier is a semicolon + if( (c == ';') && (i != (unitArray.length-1)) ) { + addError( "Error in " + file.getAbsolutePath() + ", at line " + String.valueOf(lineCounter) + ":" + SPACE + unitArray[i], ERROR_SEMICOLON ); // ERROR: semicolon has been used as a wrong separator + } + else { + if( (c == ';') && (i == (unitArray.length-1)) ) { + id = parseIdentifier( unitArray[i] ); + if( id.equals(ERROR) ) { + addError( "Error in " + file.getAbsolutePath() + " at line " + String.valueOf(lineCnt) + ", invalid statement" , ERROR_INVALID_STATEMENT ); + } + else { + operations.add(id); + } + switch( unitArray[0] ) { + case DMA_KW: + id = parseIdentifier( unitArray[i] ); + if( id.equals(ERROR) ) { + addError( "Error in " + file.getAbsolutePath() + " at line " + String.valueOf(lineCnt) + ", invalid statement" , ERROR_INVALID_STATEMENT ); + } + else { + dmas.add(id); + } + break; + case MEMORY_KW: + id = parseIdentifier( unitArray[i] ); + if( id.equals(ERROR) ) { + addError( "Error in " + file.getAbsolutePath() + " at line " + String.valueOf(lineCnt) + ", invalid statement" , ERROR_INVALID_STATEMENT ); + } + else { + memories.add(id); + } + break; + case CPU_KW: + id = parseIdentifier( unitArray[i] ); + if( id.equals(ERROR) ) { + addError( "Error in " + file.getAbsolutePath() + " at line " + String.valueOf(lineCnt) + ", invalid statement" , ERROR_INVALID_STATEMENT ); + } + else { + cpus.add(id); + } + break; + case HWA_KW: + id = parseIdentifier( unitArray[i] ); + if( id.equals(ERROR) ) { + addError( "Error in " + file.getAbsolutePath() + " at line " + String.valueOf(lineCnt) + ", invalid statement" , ERROR_INVALID_STATEMENT ); + } + else { + hwas.add(id); + } + break; + } + } + else { // ERROR: the identifier is not followed by a valid separator + addError( "Error in " + file.getAbsolutePath() + ", at line " + String.valueOf(lineCounter) + ":" + SPACE + unitArray[i], ERROR_SEPARATOR ); + } + } + } + } + } + // Parse the mapping of operations to units + for( String s: unitToOpsLines ) { + int lineCnt = Integer.parseInt( s.split( " \\* " )[0] ); + String s1 = s.split( "\\* " )[1]; + //String[] unitArray = s1.split( SPACE ); + String[] mapArray = s1.split( SPACE ); + ArrayList<String> mappingLine = new ArrayList<String>(); + mappingLine.add( mapArray[0] ); + id = parseIdentifier( mapArray[0] ); + if( id.equals(ERROR) ) { + addError( "Error in " + file.getAbsolutePath() + " at line " + String.valueOf(lineCnt) + ": " + id + " invalid parameter type" , ERROR_INVALID_TYPE ); + } + /*else { + mappingLine.add(id); + }*/ + for( int i = 2; i < mapArray.length; i++ ) { // i = 1 to skip the keyword Operation + char c = mapArray[i].charAt( mapArray[i].length()-1 ); + if( c == ',' ) { + id = parseIdentifier( mapArray[i] ); + if( id.equals(ERROR) ) { + addError( "Error in " + file.getAbsolutePath() + " at line " + String.valueOf(lineCnt) + ": " + id + " invalid parameter type" , ERROR_INVALID_TYPE ); + } + else { + mappingLine.add(id); + } + } + else { // Test if the last character of the identier is a semicolon + if( (c == ';') && (i != (mapArray.length-1)) ) { + addError( "Error in " + file.getAbsolutePath() + " at line " + String.valueOf(lineCnt) + ", wrong semicolon: " + mapArray[i], ERROR_SEMICOLON ); // ERROR: semicolon has been used as a wrong separator + } + else { + if( (c == ';') && (i == (mapArray.length-1)) ) { + id = parseIdentifier( mapArray[i] ); + if( id.equals(ERROR) ) { + addError( "Error in " + file.getAbsolutePath() + " at line " + String.valueOf(lineCnt) + ": " + id + " invalid parameter type" , ERROR_INVALID_TYPE ); + } + else { + mappingLine.add(id); + } + } + else { // ERROR: the identifier is not followed by a valid separator + addError( "Error in " + file.getAbsolutePath() + " at line " + String.valueOf(lineCnt) + ", no valid separator : " + mapArray[i], ERROR_SEPARATOR ); + } + } + } + } + unitsOps.add( mappingLine ); + } + // Parse the include lines for single files of code snippets associated to units + for( String s: includeLines ) { + int lineCnt = Integer.parseInt( s.split( " \\* " )[0] ); + String s1 = s.split( "\\* " )[1]; + String[] tokensArray = s1.split( SPACE ); + File f1 = new File( tokensArray[1] ); + String keyword = tokensArray[2]; + String unit = tokensArray[3]; + if( !f1.exists() ) { + addError( "Error in " + file.getAbsolutePath() + " at line " + String.valueOf(lineCnt) + ", file " + f1.getAbsolutePath() + " not found", ERROR_FILE_NOT_FOUND ); + } + else { // Parse the content of each file containing file snippets (C function prototypes) + parseCodeSnippet( f1 ); + } + if( !cpus.contains( unit ) && !dmas.contains( unit ) && !memories.contains( unit ) && !hwas.contains( unit ) ) { + addError( "Error in " + file.getAbsolutePath() + " at line " + String.valueOf(lineCnt) + ", unit " + unit + " has not been declared", ERROR_UNDECLARED_UNIT ); + } + if( !keyword.equals( "for" ) ) { + addError( "Error in " + file.getAbsolutePath() + " at line " + String.valueOf(lineCnt) + ", symbol not found: " + keyword, ERROR_SYMBOL_NOT_FOUND ); + } + } + } catch( IOException x ) { + System.err.format( "IOException: %s%n", x ); + } + TraceManager.addDev( "Printing the data base of types:" ); + for( String dt: typesDataBase ) { + TraceManager.addDev( dt ); + } + TraceManager.addDev( "Printing parsed code snippets INITIALIZATION:" ); + for( CFunctionPrototype function: initializationFunctions ) { + TraceManager.addDev( function.toString() ); + } + TraceManager.addDev( "Printing parsed code snippets EXECUTION:" ); + for( CFunctionPrototype function: executionFunctions ) { + TraceManager.addDev( function.toString() ); + } + TraceManager.addDev( "Printing parsed code snippets CLEANUP:" ); + for( CFunctionPrototype function: cleanupFunctions ) { + TraceManager.addDev( function.toString() ); + } + } + + private void parseCodeSnippet( File f ) { + // boolean flags used to select the storage of code snippets into the appropriate data structure + boolean init_category = false; + boolean execution_category = false; + boolean cleanup_category = false; + + Charset charset = Charset.forName("US-ASCII"); + try( BufferedReader reader = Files.newBufferedReader( Paths.get( f.getAbsolutePath() ), charset ) ) { + int lineCounter = 0; + String line = null; + while( (line = reader.readLine()) != null ) { + lineCounter++; + if( line.length() > 0 ) { // Filter empty lines + if( line.charAt(0) != '%' ) { // Ignore lines starting with % as they are comments + // Parse the line that defines the category of code snippets + if( line.substring(0,4).equals(TYPE_KW) ) { // ubstring() cuts from startIndex to endIndex-1 + String[] arr = line.split(" "); + if( arr.length != 2 ) { + addError( "Error in " + f.getAbsolutePath() + " at line " + String.valueOf(lineCounter) + ", invalid statement" , ERROR_INVALID_STATEMENT ); + } + else { + switch( arr[1] ) { + case INIT_CATEGORY: + init_category = true; + execution_category = false; + cleanup_category = false; + break; + case CLEANUP_CATEGORY: + init_category = false; + execution_category = false; + cleanup_category = true; + break; + case EXECUTION_CATEGORY: + init_category = false; + execution_category = true; + cleanup_category = false; + break; + default: + addError( "Error in " + f.getAbsolutePath() + " at line " + String.valueOf(lineCounter) + ", invalid category type" , ERROR_INVALID_CATEGORY_TYPE ); + break; + } + } + + } + // Parse the line for a code snippet + else { + // Check that only one flag is active per each line being parsed + if( init_category && execution_category && cleanup_category ) { + addError( "Error in " + f.getAbsolutePath() + " at line " + String.valueOf(lineCounter) + ", invalid category type" , ERROR_INVALID_CATEGORY_TYPE ); + } + if( init_category ) { + if( execution_category || cleanup_category ) { + addError( "Error in " + f.getAbsolutePath() + " at line " + String.valueOf(lineCounter) + ", invalid category type" , ERROR_INVALID_CATEGORY_TYPE ); + } + else { + CFunctionPrototype func = parseFunctionPrototype( f, line, lineCounter ); // return an ADT for a C function protype + initializationFunctions.add( func ); + } + } + if( execution_category ) { + if( init_category || cleanup_category ) { + addError( "Error in " + f.getAbsolutePath() + " at line " + String.valueOf(lineCounter) + ", invalid category type" , ERROR_INVALID_CATEGORY_TYPE ); + } + else { + CFunctionPrototype func = parseFunctionPrototype( f, line, lineCounter ); + executionFunctions.add( func ); + } + } + if( cleanup_category ) { + if( init_category || execution_category ) { + addError( "Error in " + f.getAbsolutePath() + " at line " + String.valueOf(lineCounter) + ", invalid category type" , ERROR_INVALID_CATEGORY_TYPE ); + } + else { + CFunctionPrototype func = parseFunctionPrototype( f, line, lineCounter ); + cleanupFunctions.add( func ); + } + } + } + } + } + } + } catch( IOException x ) { + System.err.format( "IOException: %s%n", x ); + } + return; + } + + // This routine must be completed with more checks and it must return a complete object CFunctionPrototype! + private CFunctionPrototype parseFunctionPrototype( File f, String line, int lineCounter ) { + String trailingString = "#"; + String returnType = ""; + String functionName = ""; + // String token = ""; + String[] tokens; + String name = ""; + String type = ""; + String parameterList = ""; + CFunctionPrototype functionPrototype = new CFunctionPrototype( line ); // Temporary object creation + + int index = line.indexOf( SPACE ); + + if( index == -1 ) { + addError( "Error in " + f.getAbsolutePath() + " at line " + String.valueOf(lineCounter) + ", invalid statement" , ERROR_INVALID_STATEMENT ); + return new CFunctionPrototype( "ERROR_INVALID_STATEMENT" ); // Stop parsing when error occurs + } + else { + returnType = line.substring(0,index); // If there is no match the input string is returned + // TO DO: must distinguish the case of a function returning a pointer. Check returnType and functionName! + /*if( returnType.charAt(returnType.length()-1) == '*' ) { + }*/ + if( parseIdentifier( returnType ).equals(ERROR) ) { + addError( "Error in " + f.getAbsolutePath() + " at line " + String.valueOf(lineCounter) + ", invalid statement" , ERROR_INVALID_STATEMENT ); + return new CFunctionPrototype( "ERROR_INVALID_STATEMENT" ); + } + else { + if( !verifyType(returnType) ) { + addError( "Error in " + f.getAbsolutePath() + " at line " + String.valueOf(lineCounter) + ": " + returnType + " invalid return type" , ERROR_INVALID_TYPE ); + } + else { + functionPrototype.setReturnType( returnType ); + } + } + } + line = line.substring(index+1,line.length()); + index = line.indexOf("("); + if( index == -1 ) { + addError( "Error in " + f.getAbsolutePath() + " at line " + String.valueOf(lineCounter) + ", invalid statement" , ERROR_INVALID_STATEMENT ); + return new CFunctionPrototype( "ERROR_INVALID_STATEMENT" ); + } + else { + functionName = line.substring(0,index); + if( parseIdentifier( functionName).equals(ERROR) ) { + addError( "Error in " + f.getAbsolutePath() + " at line " + String.valueOf(lineCounter) + ", invalid statement" , ERROR_INVALID_STATEMENT ); + return new CFunctionPrototype( "ERROR_INVALID_STATEMENT" ); + } + else { + functionPrototype.setFunctionName( functionName ); + } + parameterList = line.substring(index+1,line.indexOf(")")); + tokens = parameterList.split(","); // Each token is a pair type - parameter + for( int i = 0; i < tokens.length; i++ ) { + tokens[i] = tokens[i].trim(); // Eliminate leading and trailing whitespaces + if( tokens[i].split( SPACE ).length == 2 ) { + type = tokens[i].split( SPACE )[0]; + name = tokens[i].split( SPACE )[1]; + if( (type.charAt(type.length()-1) == '*') ) { // Test if the parameter type is an address or an array + type = parseIdentifier( type.substring(0,type.length()-1) ) + '*'; + if( type.equals(ERROR) ) { + addError( "Error in " + f.getAbsolutePath() + " at line " + String.valueOf(lineCounter) + ": " + type + " invalid parameter type" , ERROR_INVALID_TYPE ); + return new CFunctionPrototype( "ERROR_INVALID_STATEMENT" ); + } + } + else { + if( type.substring(type.length()-2,type.length()-1).equals("[]") ) { // Test if the parameter type is an array + type = parseIdentifier( type.substring(type.length()-2,type.length()-1) ) + "[]"; + if( type.equals(ERROR) ) { + addError( "Error in " + f.getAbsolutePath() + " at line " + String.valueOf(lineCounter) + ": " + type + " invalid parameter type" , ERROR_INVALID_TYPE ); + return new CFunctionPrototype( "ERROR_INVALID_STATEMENT" ); + } + } + else { + type = parseIdentifier( type ); + if( !verifyType( type ) ) { + addError( "Error in " + f.getAbsolutePath() + " at line " + String.valueOf(lineCounter) + ": " + type + " invalid parameter identifier" , ERROR_INVALID_TYPE ); + } + } + } + if( name.charAt(0) == '*') { // Test if the parameter name is an address + name = '*' + parseIdentifier( name.substring(1,name.length()) ); + if( name.equals(ERROR) ) { + addError( "Error in " + f.getAbsolutePath() + " at line " + String.valueOf(lineCounter) + ": " + name + " invalid identifier" , ERROR_INVALID_TYPE ); + return new CFunctionPrototype( "ERROR_INVALID_STATEMENT" ); + } + } + else { + if( name.substring(0,1).equals("[]") ) { // Test if the parameter name is an array + name = parseIdentifier( name.substring(2,name.length()-1) ) + "[]"; + if( name.equals(ERROR) ) { + addError( "Error in " + f.getAbsolutePath() + " at line " + String.valueOf(lineCounter) + ": " + name + " invalid parameter type" , ERROR_INVALID_TYPE ); + return new CFunctionPrototype( "ERROR_INVALID_STATEMENT" ); + } + } + name = parseIdentifier( name ); + } + functionPrototype.setParameter( type, name ); + } + else { + addError( "Error in " + f.getAbsolutePath() + " at line " + String.valueOf(lineCounter) + ", invalid parameter declaration" , ERROR_INVALID_PARAMETER_DECLARATION ); + return new CFunctionPrototype( "ERROR_INVALID_STATEMENT" ); + } + } + } + index = line.indexOf(")"); + line = line.substring(index+1,line.length()); + if( index == -1 ) { + addError( "Error in " + f.getAbsolutePath() + " at line " + String.valueOf(lineCounter) + ", invalid line terminator" , ERROR_INVALID_LINE_TERMINATOR ); + return new CFunctionPrototype( "ERROR_INVALID_STATEMENT" ); + } + else { + trailingString = line.substring(0,line.length()); + if( !trailingString.equals(SEMICOLON) ) { + addError( "Error in " + f.getAbsolutePath() + " at line " + String.valueOf(lineCounter) + ", invalid line terminator" , ERROR_INVALID_LINE_TERMINATOR ); + return new CFunctionPrototype( "ERROR_INVALID_STATEMENT" ); + } + } + return functionPrototype; + } + + // Parse the identifier passed as 1rst parameter and return the identifier if correct or ERROR string + private String parseIdentifier( String id ) { + + // Remove trailing character: comma or semicolon + if( (id.charAt( id.length()-1) == ',') || (id.charAt( id.length()-1) == ';') ) { + id = id.substring( 0, id.length()-1 ); + } + // Test that it does not contain special characters at the beginning and at the end + if( id.split( FORBIDDEN_CHARACTERS ).length == 1 ) { // There are no special characters + return id; + } + else { // ERROR: the identifier contains special characters + return ERROR; + } + } + + private boolean verifyType( String type ) { + if( typesDataBase.contains( type ) ) { + return true; + } + return false; + } + + public void addError( String message, int type ) { + TMLPECParserError error = new TMLPECParserError( type ); + error.message = message; + errors.add( error ); + } + + public ArrayList<TMLPECParserError> getErrors() { + return errors; + } + + public boolean hasErrors() { + if( errors.size() > 0 ) { + return true; + } + return false; + } + + // Accessor methods to return data structures of code snippets + public ArrayList<CFunctionPrototype> getInitializationFunctions() { + return initializationFunctions; + } + + public ArrayList<CFunctionPrototype> getExecutionFunctions() { + return executionFunctions; + } + + public ArrayList<CFunctionPrototype> getCleanupFunctions() { + return cleanupFunctions; + } + +} //End of class diff --git a/src/tmltranslator/modelcompiler/TMLPECParserError.java b/src/tmltranslator/modelcompiler/TMLPECParserError.java index 9e4757288e41276c01df11f52a4a03a0ce6a15ed..a54e1c268d6e89fe8c19128883e03a8f8ff4e7d4 100755 --- a/src/tmltranslator/modelcompiler/TMLPECParserError.java +++ b/src/tmltranslator/modelcompiler/TMLPECParserError.java @@ -46,9 +46,7 @@ */ -package tmltranslator.modelcompiler;; - -import tmltranslator.*; +package tmltranslator.modelcompiler; public class TMLPECParserError {