From 9d54c1080cfd3b16f78011688aebc53cdc50131d Mon Sep 17 00:00:00 2001 From: keremi Date: Thu, 4 Aug 2016 11:39:28 +0200 Subject: [PATCH] Codegenerator new version Signed-off-by: keremi --- org.eclipse.titan.codegenerator/.classpath | 2 - .../META-INF/MANIFEST.MF | 21 +- .../Additional_Class_Writer.java | 135 +- .../titan/codegenerator/AstWalkerJava.java | 182 +- .../Def_AltStatement_Writer.java | 490 ++++++ .../Def_Const_Visit_Handler.java | 538 ++++++ .../titan/codegenerator/Def_Const_Writer.java | 115 +- .../codegenerator/Def_Function_Writer.java | 986 +++++------ .../codegenerator/Def_ModulePar_Writer.java | 95 + .../Def_Template_Visit_Handler.java | 296 ++++ .../codegenerator/Def_Template_Writer.java | 163 +- .../codegenerator/Def_Testcase_Writer.java | 1236 ++++++++++--- ...ng.java => Def_Type_Bitstring_Writer.java} | 30 +- .../Def_Type_Charstring_Writer.java | 109 ++ ...nt.java => Def_Type_Component_Writer.java} | 79 +- .../titan/codegenerator/Def_Type_Enum.java | 80 - .../codegenerator/Def_Type_Enum_Writer.java | 95 + .../titan/codegenerator/Def_Type_Integer.java | 107 -- .../Def_Type_Integer_Writer.java | 101 ++ ...pe_Port.java => Def_Type_Port_Writer.java} | 104 +- .../Def_Type_Record_Of_Writer.java | 97 ++ ...ecord.java => Def_Type_Record_Writer.java} | 69 +- .../titan/codegenerator/Def_Type_Set_Of.java | 128 -- .../codegenerator/Def_Type_Set_Of_Writer.java | 105 ++ ...Type_Set.java => Def_Type_Set_Writer.java} | 157 +- ..._Union.java => Def_Type_Union_Writer.java} | 97 +- .../codegenerator/Def_Type_Visit_Handler.java | 745 ++++++++ .../codegenerator/JavaSourceProvider.java | 18 + .../titan/codegenerator/SourceCode.java | 52 + .../TTCN3JavaAPI/AllTestComponents.java | 52 + .../TTCN3JavaAPI/Arithmetical.java | 28 + .../TTCN3JavaAPI/BINARY_STRING.java | 88 + .../codegenerator/TTCN3JavaAPI/BITSTRING.java | 55 + .../codegenerator/TTCN3JavaAPI/BOOLEAN.java | 79 + .../TTCN3JavaAPI/CHARSTRING.java | 48 + .../TTCN3JavaAPI/Comparable.java | 22 + .../TTCN3JavaAPI/ComponentDef.java | 76 + .../TTCN3JavaAPI/ENUMERATED.java | 82 + .../codegenerator/TTCN3JavaAPI/FLOAT.java | 91 + .../codegenerator/TTCN3JavaAPI/HEXSTRING.java | 55 + .../codegenerator/TTCN3JavaAPI/INTEGER.java | 140 ++ .../codegenerator/TTCN3JavaAPI/Indexable.java | 34 + .../titan/codegenerator/TTCN3JavaAPI/MC.java | 36 + .../codegenerator/TTCN3JavaAPI/MCType.java | 251 +++ .../TTCN3JavaAPI/MessagePortDef.java | 48 + .../codegenerator/TTCN3JavaAPI/ModuleDef.java | 21 + .../TTCN3JavaAPI/OCTETSTRING.java | 78 + .../codegenerator/TTCN3JavaAPI/PortDef.java | 25 + .../TTCN3JavaAPI/PrimitiveTypeDef.java | 20 + .../codegenerator/TTCN3JavaAPI/RecordDef.java | 29 + .../TTCN3JavaAPI/RecordOfDef.java | 47 + .../TTCN3JavaAPI/Relational.java | 28 + .../codegenerator/TTCN3JavaAPI/STRING.java | 83 + .../codegenerator/TTCN3JavaAPI/SetDef.java | 22 + .../codegenerator/TTCN3JavaAPI/SetOfDef.java | 41 + .../TTCN3JavaAPI/StructuredTypeDef.java | 20 + .../TTCN3JavaAPI/SubTypeDef.java | 54 + .../TTCN3JavaAPI/SubTypeInterval.java | 32 + .../TTCN3JavaAPI/TTCN3Logger.java | 83 + .../TTCN3JavaAPI/TTCNJavaAPIException.java | 22 + .../codegenerator/TTCN3JavaAPI/Timer.java | 87 + .../codegenerator/TTCN3JavaAPI/TypeDef.java | 26 + .../TTCN3JavaAPI/UNIVERSAL_CHARSTRING.java | 29 + .../codegenerator/TTCN3JavaAPI/UnionDef.java | 20 + .../TestCase_Function_Visit_Handler.java | 1533 +++++++++++++++++ .../titan/codegenerator/javagen/HCType.java | 40 + .../titan/codegenerator/myASTVisitor.java | 1305 +------------- .../titan/codegenerator/walker.properties | 6 +- 68 files changed, 8437 insertions(+), 2831 deletions(-) create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_AltStatement_Writer.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Const_Visit_Handler.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_ModulePar_Writer.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Template_Visit_Handler.java rename org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/{Def_Type_Charstring.java => Def_Type_Bitstring_Writer.java} (79%) create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Charstring_Writer.java rename org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/{Def_Type_Component.java => Def_Type_Component_Writer.java} (71%) delete mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Enum.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Enum_Writer.java delete mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Integer.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Integer_Writer.java rename org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/{Def_Type_Port.java => Def_Type_Port_Writer.java} (88%) create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Record_Of_Writer.java rename org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/{Def_Type_Record.java => Def_Type_Record_Writer.java} (75%) delete mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Set_Of.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Set_Of_Writer.java rename org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/{Def_Type_Set.java => Def_Type_Set_Writer.java} (50%) rename org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/{Def_Type_Union.java => Def_Type_Union_Writer.java} (80%) create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Visit_Handler.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/JavaSourceProvider.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/SourceCode.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/AllTestComponents.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/Arithmetical.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/BINARY_STRING.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/BITSTRING.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/BOOLEAN.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/CHARSTRING.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/Comparable.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/ComponentDef.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/ENUMERATED.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/FLOAT.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/HEXSTRING.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/INTEGER.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/Indexable.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/MC.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/MCType.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/MessagePortDef.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/ModuleDef.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/OCTETSTRING.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/PortDef.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/PrimitiveTypeDef.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/RecordDef.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/RecordOfDef.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/Relational.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/STRING.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/SetDef.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/SetOfDef.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/StructuredTypeDef.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/SubTypeDef.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/SubTypeInterval.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/TTCN3Logger.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/TTCNJavaAPIException.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/Timer.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/TypeDef.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/UNIVERSAL_CHARSTRING.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/UnionDef.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TestCase_Function_Visit_Handler.java create mode 100644 org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/javagen/HCType.java diff --git a/org.eclipse.titan.codegenerator/.classpath b/org.eclipse.titan.codegenerator/.classpath index e4b88f61a..64ed6b379 100644 --- a/org.eclipse.titan.codegenerator/.classpath +++ b/org.eclipse.titan.codegenerator/.classpath @@ -3,7 +3,5 @@ - - diff --git a/org.eclipse.titan.codegenerator/META-INF/MANIFEST.MF b/org.eclipse.titan.codegenerator/META-INF/MANIFEST.MF index ff12eaf27..285808be3 100644 --- a/org.eclipse.titan.codegenerator/META-INF/MANIFEST.MF +++ b/org.eclipse.titan.codegenerator/META-INF/MANIFEST.MF @@ -10,23 +10,6 @@ Require-Bundle: org.eclipse.titan.designer;bundle-version="5.4.0", org.eclipse.jface;bundle-version="3.10.1", org.eclipse.ui;bundle-version="3.106.0", org.eclipse.ui.ide;bundle-version="3.10.0", - org.eclipse.titan.common;bundle-version="5.4.0" -Bundle-ClassPath: . + org.eclipse.ui.console;bundle-version="3.5.300", + org.junit Bundle-RequiredExecutionEnvironment: JavaSE-1.8 -Import-Package: org.eclipse.titan.designer, - org.eclipse.titan.designer.AST, - org.eclipse.titan.designer.AST.ASN1, - org.eclipse.titan.designer.AST.ASN1.Object, - org.eclipse.titan.designer.AST.ASN1.definitions, - org.eclipse.titan.designer.AST.ASN1.types, - org.eclipse.titan.designer.AST.ASN1.values, - org.eclipse.titan.designer.AST.TTCN3, - org.eclipse.titan.designer.AST.TTCN3.attributes, - org.eclipse.titan.designer.AST.TTCN3.definitions, - org.eclipse.titan.designer.AST.TTCN3.statements, - org.eclipse.titan.designer.AST.TTCN3.templates, - org.eclipse.titan.designer.AST.TTCN3.types, - org.eclipse.titan.designer.AST.TTCN3.types.subtypes, - org.eclipse.titan.designer.AST.TTCN3.values, - org.eclipse.titan.designer.AST.TTCN3.values.expressions - diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Additional_Class_Writer.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Additional_Class_Writer.java index 9c7a753c4..4781c28d5 100644 --- a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Additional_Class_Writer.java +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Additional_Class_Writer.java @@ -47,6 +47,7 @@ public class Additional_Class_Writer { hcTypeString.append("public class HCType {" + "\r\n"); hcTypeString.append(" " + "\r\n"); hcTypeString.append(" boolean waitingforconnect;" + "\r\n"); + hcTypeString.append(" boolean waitingformap;" + "\r\n"); hcTypeString.append(" Socket sock;" + "\r\n"); hcTypeString.append(" BufferedWriter writer;" + "\r\n"); hcTypeString.append(" BufferedReader reader;" + "\r\n"); @@ -61,6 +62,7 @@ public class Additional_Class_Writer { // sockets hcTypeString.append(" public boolean debugmode; " + "\r\n"); hcTypeString.append(" " + "\r\n"); + hcTypeString.append(" public HCType(){" + "\r\n"); hcTypeString.append(" componentpool = new Vector();" + "\r\n"); @@ -69,6 +71,7 @@ public class Additional_Class_Writer { hcTypeString.append(" this.debugmode=debugmode;"+ "\r\n"); hcTypeString.append(" }" + "\r\n"); hcTypeString.append(" " + "\r\n"); + hcTypeString .append(" public void connect(String comp1, String port1, String comp2, String port2){" + "\r\n"); @@ -84,6 +87,17 @@ public class Additional_Class_Writer { hcTypeString.append(" }" + "\r\n"); hcTypeString.append(" }" + "\r\n"); hcTypeString.append(" " + "\r\n"); + + hcTypeString.append("public void map(String comp1, String port1, String comp2, String port2){" + "\r\n"); + hcTypeString.append(" this.waitingformap=true;" + "\r\n"); + hcTypeString.append(" sendtomc(\"map \"+comp1+\" \"+ port1+\" \"+comp2+\" \"+port2);" + "\r\n"); + hcTypeString.append(" for(;this.waitingformap;){" + "\r\n"); + hcTypeString.append(" try{" + "\r\n"); + hcTypeString.append(" Thread.sleep(100);" + "\r\n"); + hcTypeString.append(" }catch(Exception e){}" + "\r\n"); + hcTypeString.append(" }" + "\r\n"); + hcTypeString.append("}" + "\r\n"); + hcTypeString .append(" public void start(String component, String function){" + "\r\n"); @@ -101,20 +115,7 @@ public class Additional_Class_Writer { + "\r\n"); hcTypeString.append(" }" + "\r\n"); hcTypeString.append(" " + "\r\n"); - hcTypeString.append(" public void sendtomc(String message){" + "\r\n"); // hc.sendtomc-kent - // hivodik, - // igy - // nem - // hc.writer-kent - // hivatkozik - // a - // writerre. - // itt - // mar - // hc-ban - // (az - // instance-ban) - // vagyunk + hcTypeString.append(" public void sendtomc(String message){" + "\r\n"); hcTypeString.append(" try{" + "\r\n"); hcTypeString.append(" writer.write(message + \"\\r\\n\");" + "\r\n"); hcTypeString.append(" writer.flush();" + "\r\n"); @@ -129,9 +130,9 @@ public class Additional_Class_Writer { hcTypeString .append(" TTCN3Logger.writeLog(\"hc\", \"EXECUTOR\", \"Creating PTC \" + name + \" with ID \" + ID, false);"+ "\r\n"); - for (int i = 0; i < myASTVisitor.componentList.size(); i++) { - hcTypeString.append(" if(type.equals(\"" + myASTVisitor.componentList.get(i) - + "\")) componentpool.add(new " + myASTVisitor.componentList.get(i) + for (int i = 0; i < AstWalkerJava.componentList.size(); i++) { + hcTypeString.append(" if(type.equals(\"" + AstWalkerJava.componentList.get(i) + + "\")) componentpool.add(new " + AstWalkerJava.componentList.get(i) + "(this,name,ID));" + "\r\n"); } hcTypeString.append(" }" + "\r\n"); @@ -183,7 +184,7 @@ public class Additional_Class_Writer { + "\r\n"); hcTypeString .append(" writer = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream()));" - + "\r\n"); // ezt bekommentezed, elszall + + "\r\n"); hcTypeString .append(" reader = new BufferedReader(new InputStreamReader(sock.getInputStream()));" + "\r\n"); @@ -199,6 +200,9 @@ public class Additional_Class_Writer { hcTypeString.append(" if(msg.equals(\"connected\")){" + "\r\n"); hcTypeString.append(" this.waitingforconnect=false;" + "\r\n"); hcTypeString.append(" }" + "\r\n"); + hcTypeString.append(" if(msg.equals(\"mapped\")){" + "\r\n"); + hcTypeString.append(" this.waitingformap=false;" + "\r\n"); + hcTypeString.append(" }" + "\r\n"); hcTypeString.append(" String command = msg.split(\" \")[0];" + "\r\n"); hcTypeString.append(" //logged on receiver side instead of default sender side (because a test case might be the entry point of execution)"+ "\r\n"); @@ -208,21 +212,15 @@ public class Additional_Class_Writer { - for (int i = 0; i < myASTVisitor.testCaseList.size(); i++) { + for (int i = 0; i < AstWalkerJava.testCaseList.size(); i++) { hcTypeString.append(" if(tcasename.equals(\"" - + myASTVisitor.testCaseList.get(i) + "\")){" + "\r\n"); // minden egyes - // testcase-re - // kell ez az if + + AstWalkerJava.testCaseList.get(i) + "\")){" + "\r\n"); hcTypeString.append(" if(debugmode)TTCN3Logger.writeLog(\"hc\", \"EXECUTOR\", \"Creating MTC\", false);" + "\r\n"); hcTypeString.append(" registercomponent(\"mtc\", \"" - + myASTVisitor.testCaseRunsOnList.get(i) + "\", \"2\");" + "\r\n"); // masodik//TODO ezmi - // parameter - // az adott - // tc - // runsonja + + AstWalkerJava.testCaseRunsOnList.get(i) + "\", \"2\");" + "\r\n"); hcTypeString.append(" if(debugmode)TTCN3Logger.writeLog(\"hc\", \"EXECUTOR\", \"Starting new Thread for MTC\", false);" + "\r\n"); hcTypeString.append(" Thread testcasethread = new Thread(new " - + myASTVisitor.testCaseList.get(i) + "((" + myASTVisitor.testCaseRunsOnList.get(i) + + AstWalkerJava.testCaseList.get(i) + "((" + AstWalkerJava.testCaseRunsOnList.get(i) + ")getcomponent(\"mtc\")));" + "\r\n"); hcTypeString .append(" getcomponent(\"mtc\").thread=testcasethread;" @@ -271,10 +269,20 @@ public class Additional_Class_Writer { hcTypeString.append(" if(debugmode)TTCN3Logger.writeLog(\"hc\", \"EXECUTOR\", \"Connecting to component \" + component + \" port \" + port + \" on \" + ip + \":\" + portnum, false);"+ "\r\n"); hcTypeString .append(" getcomponent(component).connect(port,ip,portnum);" - + "\r\n"); // cast az adott nevu komponens tipusara megy - // mindig + + "\r\n"); hcTypeString.append(" sendtomc(\"connected\");" + "\r\n"); hcTypeString.append(" }" + "\r\n"); + + hcTypeString.append("if(command.equals(\"map\")){" + "\r\n"); + hcTypeString.append(" String thiscomp = msg.split(\" \")[1];" + "\r\n"); + hcTypeString.append(" String thisport = msg.split(\" \")[2];" + "\r\n"); + hcTypeString.append(" String remotecomp = msg.split(\" \")[3];" + "\r\n"); + hcTypeString.append(" String remoteport = msg.split(\" \")[4];" + "\r\n"); + hcTypeString.append(" getcomponent(thiscomp).domap(thisport, remotecomp, remoteport);" + "\r\n"); + hcTypeString.append(" sendtomc(\"mapped\");" + "\r\n"); + hcTypeString.append("}" + "\r\n"); + + hcTypeString.append(" if(command.equals(\"start\")){" + "\r\n"); hcTypeString .append(" ComponentDef component = getcomponent(msg.split(\" \")[1]);" @@ -283,17 +291,14 @@ public class Additional_Class_Writer { + "\r\n"); - for (int i = 0; i < myASTVisitor.functionList.size(); i++) { + for (int i = 0; i < AstWalkerJava.functionList.size(); i++) { hcTypeString.append(" if(function.equals(\"" - + myASTVisitor.functionList.get(i) + "\")){ " + "\r\n");// minden letezo - // fuggvenynevre - // kell ilyen if + + AstWalkerJava.functionList.get(i) + "\")){ " + "\r\n"); hcTypeString .append(" if(component.thread!=null) component.thread.join();" - + "\r\n"); // ha fut rajta valami, előbb joinolni - // kell + + "\r\n"); hcTypeString.append(" Thread functionthread = new Thread(new " - + myASTVisitor.functionList.get(i) + "((" + myASTVisitor.functionRunsOnList.get(i) + + AstWalkerJava.functionList.get(i) + "((" + AstWalkerJava.functionRunsOnList.get(i) + ")component));" + "\r\n"); hcTypeString.append(" component.thread=functionthread;" + "\r\n"); @@ -313,7 +318,7 @@ public class Additional_Class_Writer { hcTypeString .append(" TTCN3Logger.writeLog(\"hc\", \"EXECUTOR\", \"Waiting for component \" + c.name + \" to be done\", false);" + "\r\n"); - hcTypeString.append(" c.thread.join();" + "\r\n"); + hcTypeString.append(" if(c.thread!=null) c.thread.join();" + "\r\n"); hcTypeString.append(" //logged by mc too" + "\r\n"); hcTypeString .append(" if(debugmode)TTCN3Logger.writeLog(\"hc\", \"EXECUTOR\", \"Component \" + c.name + \" is done\", false);" @@ -364,4 +369,58 @@ public class Additional_Class_Writer { return hcTypeString.toString(); } + public static void writeExternalPortClass(String nodeName) { + StringBuilder externalPort=new StringBuilder(); + + externalPort.append("package org.eclipse.titan.codegenerator.javagen;"+"\r\n"); + externalPort.append("import java.io.ObjectInputStream;"+"\r\n"); + externalPort.append("import java.io.ObjectOutputStream;"+"\r\n"); + externalPort.append("import java.net.ServerSocket;"+"\r\n"); + externalPort.append("import java.net.Socket;"+"\r\n"); + externalPort.append("import java.util.Scanner; "+"\r\n"); + + externalPort.append("import org.eclipse.titan.codegenerator.TTCN3JavaAPI.*;"+"\r\n"); + + externalPort.append("public class TP_"+nodeName+" {"+"\r\n"); + externalPort.append(" private "+nodeName+" port;"+"\r\n"); + externalPort.append(" public TP_"+nodeName+"("+nodeName+" p){"+"\r\n"); + externalPort.append(" port=p;"+"\r\n"); + externalPort.append(" }"+"\r\n"); + + externalPort.append(" //must block until map is done"+"\r\n"); + externalPort.append(" public void user_map(String remotecomp, String remoteport){"+"\r\n"); + externalPort.append(" new TestPortDaemon(this).start();"+"\r\n"); + externalPort.append(" }"+"\r\n"); + + externalPort.append(" //must block until unmap is done"+"\r\n"); + externalPort.append(" public void user_unmap(String remotecomp, String remoteport){ "+"\r\n"); + externalPort.append(" }"+"\r\n"); + + externalPort.append(" public void user_send(Object o){"+"\r\n"); + externalPort.append(" System.out.println(\"TESTPORT OUTPUT \" + ((CHARSTRING)o).toString());"+"\r\n"); //TODO fix logging + externalPort.append(" }"+"\r\n"); + + externalPort.append(" class TestPortDaemon extends Thread{"+"\r\n"); + externalPort.append(" private TP_"+nodeName+" testport;"+"\r\n"); + externalPort.append(" public TestPortDaemon(TP_"+nodeName+" p){"+"\r\n"); + externalPort.append(" testport = p;"+"\r\n"); + externalPort.append(" }"+"\r\n"); + externalPort.append(" public void run(){"+"\r\n"); + externalPort.append(" testport.port.mapped=true;"+"\r\n"); + externalPort.append(" Scanner scanner = new Scanner(System.in);"+"\r\n"); + externalPort.append(" for(;;){"+"\r\n"); + externalPort.append(" String inmsg = scanner.nextLine();"+"\r\n"); + externalPort.append(" testport.port.enqueue(new CHARSTRING(inmsg));"+"\r\n"); + externalPort.append(" }"+"\r\n"); + externalPort.append(" }"+"\r\n"); + externalPort.append(" }"+"\r\n"); + externalPort.append("}"+"\r\n"); + + String backupFilename=myASTVisitor.currentFileName; + myASTVisitor.currentFileName="TP_"+nodeName; + myASTVisitor.visualizeNodeToJava(externalPort.toString()); + myASTVisitor.currentFileName=backupFilename; + + } + } diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/AstWalkerJava.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/AstWalkerJava.java index 2dba5283f..9b6594cf2 100644 --- a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/AstWalkerJava.java +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/AstWalkerJava.java @@ -18,9 +18,11 @@ package org.eclipse.titan.codegenerator; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Properties; @@ -32,7 +34,6 @@ import java.util.logging.SimpleFormatter; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IPath; - import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ISelection; @@ -48,6 +49,13 @@ import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.IConsoleConstants; +import org.eclipse.ui.console.IConsoleManager; +import org.eclipse.ui.console.IConsoleView; +import org.eclipse.ui.console.MessageConsole; +import org.eclipse.ui.console.MessageConsoleStream; import org.eclipse.ui.part.FileEditorInput; import org.eclipse.titan.designer.AST.Module; import org.eclipse.titan.designer.AST.TTCN3.definitions.Definitions; @@ -55,46 +63,39 @@ import org.eclipse.titan.designer.AST.TTCN3.definitions.ImportModule; import org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module; import org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3Analyzer; -public class AstWalkerJava implements IWorkbenchWindowActionDelegate { +public final class AstWalkerJava implements IWorkbenchWindowActionDelegate { - IWorkbenchWindow window; + private static IWorkbenchWindow window; private static Logger logger; - private ISelection selection; - private IProject selectedProject; - public static Properties props; - private List fileNames; - private List files; - private TTCN3Module currentTTCN3module; + private static IProject selectedProject; + public static Properties props; + private static List fileNames; + private static List files; + private static TTCN3Module currentTTCN3module; public static String moduleElementName = ""; - public static boolean areCommentsAllowed=true; - - //public static String currentFileName = ""; - - - + public static boolean areCommentsAllowed = true; + public static List componentList = new ArrayList(); + public static List testCaseList = new ArrayList(); + public static List testCaseRunsOnList = new ArrayList(); + public static List functionList = new ArrayList(); + public static List functionRunsOnList = new ArrayList(); - // copied from ttcn-3 - static { try { boolean append = true; props = new Properties(); props.load(AstWalkerJava.class .getResourceAsStream("walker.properties")); - // props.list(System.err); - // FileHandler fh = new - // FileHandler("D:\\temp\\GenerateModelActionDelegate.log", append); FileHandler fh = new FileHandler(props.getProperty("log.path"), append); - // fh.setFormatter(new XMLFormatter()); fh.setFormatter(new SimpleFormatter()); logger = Logger.getLogger(AstWalkerJava.class.getName()); logger.addHandler(fh); @@ -107,15 +108,42 @@ public class AstWalkerJava implements IWorkbenchWindowActionDelegate { new AstWalkerJava().run(null); } + @SuppressWarnings("unchecked") public void run(IAction action) { - // logger.severe(hu.bme.tmit.catg.data.model.System.getSystem().getModelNames()); - // hu.bme.tmit.catg.data.model.System.getSystem().reset(); - // logger.severe(hu.bme.tmit.catg.data.model.System.getSystem().getModelNames()); - - this.files.clear(); - this.fileNames.clear(); + AstWalkerJava.files.clear(); + AstWalkerJava.fileNames.clear(); + AstWalkerJava.componentList.clear(); + AstWalkerJava.testCaseList.clear(); + AstWalkerJava.testCaseRunsOnList.clear(); + AstWalkerJava.functionList.clear(); + AstWalkerJava.functionRunsOnList.clear(); + //initialize folder + //clear if exists + Path outputPath=Paths.get(props.getProperty("javafile.path")); + if(Files.exists(outputPath)){ + System.out.println(""); + File folder = new File(outputPath.toUri()); + File[] listOfFiles = folder.listFiles(); + for(int i=0;i 0) { for (int i = 0, num = files.size(); i < num; i++) { - - //process files + + // process files currentTTCN3module = (TTCN3Module) doAnalysis(files.get(i), null); modules.put(fileNames.get(i), currentTTCN3module); @@ -222,7 +262,7 @@ public class AstWalkerJava implements IWorkbenchWindowActionDelegate { + currentTTCN3module.getIdentifier() .getDisplayName()); if (currentTTCN3module.getOutlineChildren().length > 1) { - for (ImportModule mm : (List) currentTTCN3module + for (@SuppressWarnings("unused") ImportModule mm : (List) currentTTCN3module .getOutlineChildren()[0]) { logger.severe(currentTTCN3module.getName() + " imported " @@ -236,10 +276,11 @@ public class AstWalkerJava implements IWorkbenchWindowActionDelegate { Object[] modulestart = modules.get(fileNames.get(i)) .getOutlineChildren(); - - //start AST processing + logToConsole("Version built on 2016.08.04."); + logToConsole("Starting to generate files into: " + props.getProperty("javafile.path")); + // start AST processing walkChildren(modulestart); - + logToConsole("Files generated into: "+props.getProperty("javafile.path")); } } else { @@ -253,27 +294,22 @@ public class AstWalkerJava implements IWorkbenchWindowActionDelegate { return; } - - - //write additional classes - Additional_Class_Writer additional_class=new Additional_Class_Writer(); + // write additional classes + Additional_Class_Writer additional_class = new Additional_Class_Writer(); myASTVisitor.currentFileName = "HC"; - - myASTVisitor.visualizeNodeToJava(myASTVisitor.importListStrings); + + myASTVisitor.visualizeNodeToJava(myASTVisitor.importListStrings); myASTVisitor.visualizeNodeToJava(additional_class.writeHCClass()); - + myASTVisitor.currentFileName = "HCType"; - myASTVisitor.visualizeNodeToJava(myASTVisitor.importListStrings); - myASTVisitor.visualizeNodeToJava(additional_class.writeHCTypeClass()); - - //clear lists - myASTVisitor.componentList.clear(); - myASTVisitor.testCaseList.clear(); - myASTVisitor.testCaseRunsOnList.clear(); - myASTVisitor.functionList.clear(); - myASTVisitor.functionRunsOnList.clear(); + myASTVisitor.visualizeNodeToJava(myASTVisitor.importListStrings); + myASTVisitor.visualizeNodeToJava(additional_class + .writeHCTypeClass()); + + // clear lists + + - logger.severe("analysis complete"); } finally { @@ -295,7 +331,7 @@ public class AstWalkerJava implements IWorkbenchWindowActionDelegate { public void init(IWorkbenchWindow window) { fileNames = new ArrayList(); files = new ArrayList(); - this.window = window; + AstWalkerJava.window = window; try { FileOutputStream fos = new FileOutputStream( props.getProperty("log.path")); @@ -332,7 +368,7 @@ public class AstWalkerJava implements IWorkbenchWindowActionDelegate { private final Module doAnalysis(IFile file, String code) { TTCN3Analyzer ttcn3Analyzer = new TTCN3Analyzer(); - // try { + if (file != null) { logger.severe("Calling TTCN3 parser with " + file.getName() + " and " + null + "\n"); @@ -347,10 +383,6 @@ public class AstWalkerJava implements IWorkbenchWindowActionDelegate { return module; - /* - * } catch (FileNotFoundException e) { // TODO Auto-generated catch - * block e.printStackTrace(); } return null; - */ } public void walkChildren(Object[] uncastedChildren) { @@ -363,12 +395,34 @@ public class AstWalkerJava implements IWorkbenchWindowActionDelegate { moduleElementName = castedChildren.getFullName().toString(); - + logToConsole("Starting processing: " + moduleElementName ); myASTVisitor v = new myASTVisitor(); + myASTVisitor.myFunctionTestCaseVisitHandler.clearEverything(); + //myASTVisitor.templateIdValuePairs.clear(); + castedChildren.accept(v); + logToConsole("Finished processing: " + moduleElementName ); } } } + private static MessageConsole findConsole(String name) { + ConsolePlugin plugin = ConsolePlugin.getDefault(); + IConsoleManager conMan = plugin.getConsoleManager(); + IConsole[] existing = conMan.getConsoles(); + for (int i = 0; i < existing.length; i++) + if (name.equals(existing[i].getName())) + return (MessageConsole) existing[i]; + // no console found, so create a new one + MessageConsole myConsole = new MessageConsole(name, null); + conMan.addConsoles(new IConsole[] { myConsole }); + return myConsole; + } + + public static void logToConsole(String msg) { + MessageConsole myConsole = findConsole("myLogger"); + MessageConsoleStream consoleLogger = myConsole.newMessageStream(); + consoleLogger.println(msg); + } } diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_AltStatement_Writer.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_AltStatement_Writer.java new file mode 100644 index 000000000..bf06073bf --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_AltStatement_Writer.java @@ -0,0 +1,490 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.titan.designer.AST.TTCN3.statements.AltGuard; +import org.eclipse.titan.designer.AST.TTCN3.statements.AltGuards; +import org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.Operation_Altguard; +import org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.Repeat_Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.Send_Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.Setverdict_Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock; +import org.eclipse.titan.designer.AST.TTCN3.statements.Timeout_Statement; +import org.eclipse.titan.designer.AST.TTCN3.values.Verdict_Value; + +public class Def_AltStatement_Writer { + private Alt_Statement altStatement; + private StringBuilder altString = new StringBuilder(""); + + private String currentTimerName = null; + private String nodeName = null; + + private int altReceiveCounter = -1; + private int timeOutCounter = -1; + + private boolean isFunction = false; + private boolean isTestCase = false; + + public List altGuardConditions = new ArrayList(); + public List altGuardPortReference = new ArrayList(); + public List altGuardReceiveValue = new ArrayList(); + public List altGuardReceiveType = new ArrayList(); + public List altGuardTimeout = new ArrayList(); + + private boolean isThereAStartedTimer = false; + public List altGuardReceiveAnyValValue = new ArrayList(); + + Def_Testcase_Writer testcaseParent; + Def_Function_Writer functionParent; + + public Def_AltStatement_Writer(Alt_Statement altStatement, + String parentNodeName) { + this.altStatement = altStatement; + this.nodeName = parentNodeName; + } + + public void writeTestCaseAltStatement(Alt_Statement altStatement) { + + AltGuards currentAltGuards = altStatement.getAltGuards(); + + String[] negativeConditions = new String[currentAltGuards + .getNofAltguards()]; + String[] positiveConditions = new String[currentAltGuards + .getNofAltguards()]; + + // initialize values + for (int i = 0; i < currentAltGuards.getNofAltguards(); i++) { + + AltGuard currentAltGuard = currentAltGuards.getAltguardByIndex(i); + if (currentAltGuard instanceof Operation_Altguard) { + + Statement currentStatement = ((Operation_Altguard) currentAltGuard) + .getGuardStatement(); + + if (currentStatement instanceof Receive_Port_Statement) { + + altReceiveCounter++; + if (altGuardConditions.get(i) != null) {// alt guard present + + // alt guard present && any port receive + if (altGuardPortReference.get(altReceiveCounter) + .equals("any port")) { + positiveConditions[i] = altGuardConditions.get(altReceiveCounter) + + ".getValue()" + "&&(" + + "anyPortReceive(true))"; + + negativeConditions[i] = altGuardConditions.get(altReceiveCounter) + + ".getValue()" + "&&(" + + "anyPortReceive(false))"; + + } else {// alt guard present && normal port receive + positiveConditions[i] = altGuardConditions.get(altReceiveCounter) + + ".getValue()" + + "&&(" + + altGuardPortReference + .get(altReceiveCounter) + + ".receive(" + + altGuardReceiveValue + .get(altReceiveCounter) + + ",true)!=null)"; + + negativeConditions[i] = altGuardConditions.get(altReceiveCounter) + + ".getValue()" + + "&&(" + + altGuardPortReference + .get(altReceiveCounter) + + ".receive(" + + altGuardReceiveValue + .get(altReceiveCounter) + + ",false)!=null)"; + + if (altGuardReceiveValue.get(altReceiveCounter) + .startsWith("Templates")) { + altGuardReceiveType.set(altReceiveCounter, "Templates"); + } + } + + } else {// no alt guard + + // no alt guard && any port recieve + if (altGuardPortReference.get(altReceiveCounter) + .equals("any port")) { + positiveConditions[i] = "anyPortReceive(true)"; + negativeConditions[i] = "anyPortReceive(false)"; + } else { + // no alt guard && typed port recieve + if (altGuardReceiveType.get(altReceiveCounter).equals( + "_TYPED_PARAM_")) { + negativeConditions[i] = altGuardPortReference + .get(altReceiveCounter) + + ".receive_" + + altGuardReceiveValue + .get(altReceiveCounter) + + "(false)!=null"; + + if (altGuardReceiveAnyValValue.get(altReceiveCounter) != null) { + positiveConditions[i] = "(" + + altGuardReceiveAnyValValue.get(altReceiveCounter) + + "=" + + altGuardPortReference + .get(altReceiveCounter) + + ".receive_" + + altGuardReceiveValue + .get(altReceiveCounter) + + "(true))!=null"; + + } else { + + } + + } else { // no alt guard && normal port recieve + positiveConditions[i] = altGuardPortReference + .get(altReceiveCounter) + + ".receive(" + + altGuardReceiveValue + .get(altReceiveCounter) + + ",true)!=null"; + + negativeConditions[i] = altGuardPortReference + .get(altReceiveCounter) + + ".receive(" + + altGuardReceiveValue + .get(altReceiveCounter) + + ",false)!=null"; + } + if (altGuardReceiveValue.get(altReceiveCounter) + .startsWith("Templates")) { + altGuardReceiveType.set(altReceiveCounter, "Templates"); + } + } + } + } + + if (currentStatement instanceof Timeout_Statement) { + timeOutCounter++; + if (altGuardConditions.get(i) != null) { + positiveConditions[i] = altGuardConditions.get(i) + + "&&(" + altGuardTimeout.get(timeOutCounter) + + ".timeout()"; + negativeConditions[i] = altGuardConditions.get(i) + + "&&(!" + altGuardTimeout.get(i) + + ".timeout()"; + + } else { + positiveConditions[i] = altGuardTimeout + .get(timeOutCounter) + ".timeout()"; + negativeConditions[i] = "!" + + altGuardTimeout.get(timeOutCounter) + + ".timeout()"; + } + + } + + } + } + + // write + altString.append("rownum=" + altStatement.getLocation().getLine() + + ";\r\n"); + altString.append("for(;;){" + "\r\n"); + + altString.append("if(!("); + for (int j = 0; j < negativeConditions.length; j++) { + altString.append(negativeConditions[j]); + if (j + 1 < negativeConditions.length) { + altString.append("||"); + } + } + + altString.append(")){" + "\r\n"); + + // timer + if (isThereAStartedTimer) { + altString.append("long timeout = -1;" + "\r\n"); + altString.append("long newtimeout;" + "\r\n"); + + altString + .append("if(" + + currentTimerName + + ".running)if((newtimeout=(long)(" + + currentTimerName + + ".read().value*1000.0))0) try{queue.poll(timeout,TimeUnit.MILLISECONDS);}catch(InterruptedException e){} " + + "\r\n"); + + } else { + + altString + .append("try{queue.take();}catch(InterruptedException e){}" + + "\r\n"); + + } + // endoftimer + + altString.append("}" + "\r\n"); + altString.append("this.lock();" + "\r\n"); + // ifwriter + + altReceiveCounter = -1; + boolean isFirstIf = true; + for (int i = 0; i < currentAltGuards.getNofAltguards(); i++) { + + AltGuard currentAltGuard = currentAltGuards.getAltguardByIndex(i); + if (currentAltGuard instanceof Operation_Altguard) { + + Statement currentStatement = ((Operation_Altguard) currentAltGuard) + .getGuardStatement(); + StatementBlock currentStatementBlock = ((Operation_Altguard) currentAltGuard) + .getStatementBlock(); + + if (isFirstIf) { + altString.append("if(" + positiveConditions[i] + "){\r\n"); + isFirstIf = false; + } else { + altString.append("else if(" + positiveConditions[i] + + "){\r\n"); + } + + if (currentStatement instanceof Receive_Port_Statement) { + altReceiveCounter++; + + altString.append("rownum=" + + currentStatement.getLocation().getLine() + + ";\r\n"); + + if (altGuardReceiveType.get(altReceiveCounter).equals( + "Templates")) { + String methodName = altGuardReceiveValue + .get(altReceiveCounter); + if (methodName.endsWith("()") + && methodName.startsWith("Templates.")) { + + methodName = (String) methodName.subSequence(10, + methodName.length() - 2); + } + + altString + .append(" TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + + nodeName + + "\", \"RECEIVE event on port " + + altGuardPortReference + .get(altReceiveCounter) + + ":\\n " + + methodName + + ":=\" + " + + altGuardReceiveValue + .get(altReceiveCounter) + + ".toString(), true);" + "\r\n"); + } else if (altGuardReceiveType.get(altReceiveCounter) + .equals("any port")) { + altString + .append(" TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + + nodeName + + "\", \"RECEIVE event on port any port\", true);" + + "\r\n"); + } else if (altGuardReceiveType.get(altReceiveCounter) + .equals("_TYPED_PARAM_")) { + altString + .append(" TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + + nodeName + + "\", \"RECEIVE event on port " + + altGuardPortReference + .get(altReceiveCounter) + + ": type " + + altGuardReceiveValue + .get(altReceiveCounter) + + "\", true);" + "\r\n"); + + } else { + altString + .append(" TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + + nodeName + + "\", \"RECEIVE event on port " + + altGuardPortReference + .get(altReceiveCounter) + + ":\" + " + + altGuardReceiveValue + .get(altReceiveCounter) + + ".toString(), true);" + "\r\n"); + } + } else if (currentStatement instanceof Timeout_Statement) { + altString + .append("rownum=" + + currentStatement.getLocation().getLine() + + ";\r\n" + + "TTCN3Logger.writeLog(compid, \"TIMEROP\", sourcefilename, rownum, \"function\", \"" + + nodeName + "\", \"Timeout on timer " + + currentTimerName + ".\", false);" + + "\r\n"); + + } + + boolean isThereARepeatStatement = false; + for (int j = 0; j < currentStatementBlock.getSize(); j++) { + Statement currentStatementBlockStatement = currentStatementBlock + .getStatementByIndex(j); + + if (currentStatementBlockStatement instanceof Setverdict_Statement) { + Setverdict_Statement setVerdictStatement = (Setverdict_Statement) currentStatementBlockStatement; + String verdict = ""; + + if (setVerdictStatement.getVerdictValue() instanceof Verdict_Value) { + Verdict_Value verdictValue = (Verdict_Value) setVerdictStatement + .getVerdictValue(); + if (verdictValue.getValue().toString() + .equals("PASS")) { + verdict = "pass"; + } else if (verdictValue.getValue().toString() + .equals("INCONC")) { + verdict = "inconc"; + } else { + verdict = "fail"; + } + } + altString.append("rownum=" + + setVerdictStatement.getLocation().getLine() + + ";\r\n"); + altString + .append("TTCN3Logger.writeLog(compid, \"VERDICTOP\", sourcefilename, rownum, \"function\", \"" + + nodeName + + "\", \"setverdict(" + + verdict + + "): \" + getVerdict() + \" -> " + + verdict + "\", true);" + "\r\n"); + altString.append("setVerdict(\"" + verdict + "\");" + + "\r\n"); + + } + + if (currentStatementBlockStatement instanceof Assignment_Statement) { + + if (isFunction) { + functionParent.assignCounter++; + + altString + .append(functionParent + .writeAssignmentStatement((Assignment_Statement) currentStatementBlockStatement)); + + String test = ""; + test.toString(); + + } else if (isTestCase) { + testcaseParent.assignCounter++; + altString + .append(testcaseParent + .writeAssignmentStatement((Assignment_Statement) currentStatementBlockStatement)); + + } + + } + + if (currentStatementBlockStatement instanceof Send_Statement) { + + if (isFunction) { + functionParent.sendCounter++; + + altString + .append(functionParent + .writeSendStatement((Send_Statement) currentStatementBlockStatement)); + + } else if (isTestCase) { + testcaseParent.sendCounter++; + altString + .append(testcaseParent + .writeSendStatement((Send_Statement) currentStatementBlockStatement)); + + } + } + + if (currentStatementBlockStatement instanceof Repeat_Statement) { + isThereARepeatStatement = true; + } + + } + if (isThereARepeatStatement) { + isThereARepeatStatement = false; + } else { + altString.append("break;\r\n"); + } + + altString.append("}\r\n"); + + } + } + + altString.append("this.unlock();" + "\r\n"); + altString.append("}" + "\r\n"); + + } + + public void clearLists() { + altGuardConditions.clear(); + altGuardPortReference.clear(); + altGuardReceiveValue.clear(); + altGuardReceiveType.clear(); + altGuardTimeout.clear(); + + altReceiveCounter = -1; + timeOutCounter = -1; + + } + + public String getJavaSource() { + + this.writeTestCaseAltStatement(altStatement); + + String returnString = altString.toString(); + altString.setLength(0); + clearLists(); + + return returnString; + } + + + public void setTimerInfo(boolean isThereAStartedTimer2, + String currentTimerName2) { + isThereAStartedTimer = isThereAStartedTimer2; + currentTimerName = currentTimerName2; + + } + + + public void setType(String string) { + if (string.equals("Function")) { + isFunction = true; + } else if (string.equals("TestCase")) { + isTestCase = true; + } + } + + public void setParent(Object parent) { + if (parent instanceof Def_Function_Writer) { + functionParent = (Def_Function_Writer) parent; + } else if (parent instanceof Def_Testcase_Writer) { + testcaseParent = (Def_Testcase_Writer) parent; + } + } + +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Const_Visit_Handler.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Const_Visit_Handler.java new file mode 100644 index 000000000..fdc4ab25d --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Const_Visit_Handler.java @@ -0,0 +1,538 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.titan.designer.AST.IVisitableNode; +import org.eclipse.titan.designer.AST.Identifier; +import org.eclipse.titan.designer.AST.Reference; +import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const; +import org.eclipse.titan.designer.AST.TTCN3.types.BitString_Type; +import org.eclipse.titan.designer.AST.TTCN3.types.Boolean_Type; +import org.eclipse.titan.designer.AST.TTCN3.types.CharString_Type; +import org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type; +import org.eclipse.titan.designer.AST.TTCN3.types.OctetString_Type; +import org.eclipse.titan.designer.AST.TTCN3.types.subtypes.Range_ParsedSubType; +import org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value; +import org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value; +import org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value; +import org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value; +import org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value; +import org.eclipse.titan.designer.AST.TTCN3.values.Omit_Value; +import org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.AddExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.DivideExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.EqualsExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.GreaterThanExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.GreaterThanOrEqualExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.LessThanExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.LessThanOrEqualExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.Log2StrExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.ModuloExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.MultiplyExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.NotExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.NotequalesExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.RemainderExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.Str2IntExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.SubstractExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.ValueofExpression; + +public class Def_Const_Visit_Handler { + + public static String constNodeType = null; + private static String lastConstName = null; + + private static boolean waitForConstValues = false; + private static boolean constValueIsAReference = false; + + // counts the members for each setof + // has to be -3 because the node's name and type increases it by 2 + // should be increased to 0 only at the first constant value + private static int constParamCounter = -3; + + + private static List constValues = new ArrayList(); + private static List constParamCount = new ArrayList(); + private static List expressionValue = new ArrayList(); + + public void visit(IVisitableNode node) { + + if (!myASTVisitor.myFunctionTestCaseVisitHandler.waitForDefStatement + && (node instanceof Def_Const)) { + myASTVisitor.currentFileName = "Constants"; + + Def_Const_Writer.getInstance(((Def_Const) node)); + myASTVisitor.nodeNameNodeTypeHashMap.put(((Def_Const) node) + .getIdentifier().toString(), "constant"); + waitForConstValues = true; + constParamCount.add(0); + } + + // constants + visitConstantNodes(node); + } + + public void visitConstantNodes(IVisitableNode node) { + + if (waitForConstValues && (node instanceof Identifier)) { + constParamCounter++; + if (constParamCounter > 0) { + constParamCount.add(0); + } + lastConstName = ((Identifier) node).toString(); + } + + if (waitForConstValues && (node instanceof Charstring_Value)) { + String value=((Charstring_Value) node).getValue(); + + expressionValue.add(value); + + constValueIsAReference = false; + + if (constParamCounter == -1) { + constParamCounter = 0; + } + if (constParamCounter == -2) { + constParamCounter = 0; + } + + constParamCount.set(constParamCounter, + constParamCount.get(constParamCounter) + 1); + } + + if (waitForConstValues && (node instanceof Integer_Value)) { + + String value=((Integer_Value) node).toString(); + + if (myASTVisitor.isNextIntegerNegative) { + value="-" + value; + } + + expressionValue.add(value); + + constValueIsAReference = false; + + if (constParamCounter == -1) { + constParamCounter = 0; + } + if (constParamCounter == -2) { + constParamCounter = 0; + } + + constParamCount.set(constParamCounter, + constParamCount.get(constParamCounter) + 1); + myASTVisitor.isNextIntegerNegative = false; + + } + + if (waitForConstValues && (node instanceof Bitstring_Value)) { + + String value=((Bitstring_Value) node).getValue(); + + expressionValue.add(value); + + constValueIsAReference = false; + + if (constParamCounter == -1) { + constParamCounter = 0; + } + if (constParamCounter == -2) { + constParamCounter = 0; + } + + constParamCount.set(constParamCounter, + constParamCount.get(constParamCounter) + 1); + + } + + if (waitForConstValues && (node instanceof Octetstring_Value)) { + + + String value=((Octetstring_Value) node).getValue(); + + expressionValue.add(value); + + constValueIsAReference = false; + + if (constParamCounter == -1) { + constParamCounter = 0; + } + if (constParamCounter == -2) { + constParamCounter = 0; + } + + constParamCount.set(constParamCounter, + constParamCount.get(constParamCounter) + 1); + + } + + if (waitForConstValues && (node instanceof Boolean_Value)) { + + String value=Boolean.toString(((Boolean_Value) node).getValue()); + + expressionValue.add(value); + + constValueIsAReference = false; + + if (constParamCounter == -1) { + constParamCounter = 0; + } + if (constParamCounter == -2) { + constParamCounter = 0; + } + + constParamCount.set(constParamCounter, + constParamCount.get(constParamCounter) + 1); + + } + + if (waitForConstValues && (node instanceof Omit_Value)) { + + expressionValue.add("omit"); + + constValueIsAReference = false; + + if (constParamCounter == -1) { + constParamCounter = 0; + } + + constParamCount.set(constParamCounter, + constParamCount.get(constParamCounter) + 1); + + myASTVisitor.constOmitHashes.add(lastConstName); + + } + + if (waitForConstValues && (node instanceof Undefined_LowerIdentifier_Value)) { + + String value=((Undefined_LowerIdentifier_Value) node).getIdentifier().toString(); + + expressionValue.add(value); + + constValueIsAReference = true; + + if (constParamCounter == -1) { + constParamCounter = 0; + } + if (constParamCounter == -2) { + constParamCounter = 0; + } + + constParamCount.set(constParamCounter, + constParamCount.get(constParamCounter) + 1); + + } + + if(waitForConstValues){ + setType(node); + visitExpressionTypeSelectors(node); + } + /* + // AddExpression + if (waitForConstValues && (node instanceof AddExpression)) { + waitForConstAddFirstValue = true; + } + + if (waitForConstAddSecondValue + && (node instanceof Undefined_LowerIdentifier_Value)) { + + String valueIdentifier = ((Undefined_LowerIdentifier_Value) node) + .getIdentifier().toString(); + if (myASTVisitor.nodeNameNodeTypeHashMap + .containsKey(valueIdentifier)) { + if (myASTVisitor.nodeNameNodeTypeHashMap.get(valueIdentifier) + .equals("constant")) { + valueIdentifier = valueIdentifier + "()"; + } + } + + constValueIsAReference = true; + + constValues.set(constAddValueIndex, + constValues.get(constAddValueIndex) + ".plus(" + + valueIdentifier + ")"); + + waitForConstAddSecondValue = false; + waitForConstValues = false; + } + + if (waitForConstAddFirstValue + && (node instanceof Undefined_LowerIdentifier_Value)) { + waitForConstAddFirstValue = false; + waitForConstAddSecondValue = true; + + String valueIdentifier = ((Undefined_LowerIdentifier_Value) node) + .getIdentifier().toString(); + if (myASTVisitor.nodeNameNodeTypeHashMap + .containsKey(valueIdentifier)) { + if (myASTVisitor.nodeNameNodeTypeHashMap.get(valueIdentifier) + .equals("constant")) { + valueIdentifier = valueIdentifier + "()"; + } + + } + + constAddValueIndex = constValues.size(); + constValues.add(valueIdentifier); + + if (constParamCounter == -1) { + constParamCounter = 0; + } + if (constParamCounter == -2) { + constParamCounter = 0; + } + + constParamCount.set(constParamCounter, + constParamCount.get(constParamCounter) + 1); + + }*/ + + } + + public void setType(IVisitableNode node){ + + if (node instanceof Reference) { + constNodeType = ((Reference) node).getId().toString(); + } + + if (node instanceof Integer_Type) { + constNodeType = "INTEGER"; + } + + if (node instanceof CharString_Type) { + constNodeType = "CHARSTRING"; + } + + if (node instanceof BitString_Type) { + constNodeType = "BITSTRING"; + } + + if (node instanceof OctetString_Type) { + constNodeType = "OCTETSTRING"; + } + + if (node instanceof Boolean_Type) { + constNodeType = "BOOLEAN"; + } + } + + public void evaluateExpression() { + int size = expressionValue.size() - 1; + boolean operatorFound = false; + boolean unaryOperatorFound = false; + String rightHand = ""; + String leftHand = ""; + + for (int i = size; i >= 0; i--) { + + if (myASTVisitor.nodeNameNodeTypeHashMap.containsKey(expressionValue.get(i))) { + + if (myASTVisitor.nodeNameNodeTypeHashMap.get(expressionValue.get(i)).equals("constant")) { + expressionValue.set(i, "Constants." + expressionValue.get(i) + "().value"); + + } else if (myASTVisitor.nodeNameNodeTypeHashMap.get(expressionValue.get(i)).equals("template")) { + expressionValue.set(i, "Templates." + expressionValue.get(i) + "()"); + + } + } + + if (i <= size - 2) { + leftHand = expressionValue.get(i + 1); + rightHand = expressionValue.get(i + 2); + } + + // + if (expressionValue.get(i).equals("Str2IntExpression")) { + expressionValue.set(i, "(" + expressionValue.get(i + 1) + "str2int())"); + unaryOperatorFound = true; + } else if (expressionValue.get(i).equals("Log2StrExpression")) { + expressionValue.set(i, "(" + expressionValue.get(i + 1) + "log2str())"); + unaryOperatorFound = true; + } else if (expressionValue.get(i).equals("ValueofExpression")) { + expressionValue.set(i, "(" + expressionValue.get(i + 1) + ").value"); + unaryOperatorFound = true; + } else if (expressionValue.get(i).equals("NotExpression")) { + expressionValue.set(i, "(" + expressionValue.get(i + 1) + ").not()"); + unaryOperatorFound = true; + } else if (expressionValue.get(i).equals("AddExpression")) { + expressionValue.set(i, "(" + leftHand + ").plus(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("SubstractExpression")) { + expressionValue.set(i, "(" + leftHand + ").minus(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("MultiplyExpression")) { + expressionValue.set(i, "(" + leftHand + ").multipleBy(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("DivideExpression")) { + expressionValue.set(i, "(" + leftHand + ").divideBy(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("ModuloExpression")) { + expressionValue.set(i, "(" + leftHand + ").mod(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("RemainderExpression")) { + expressionValue.set(i, "(" + leftHand + ").rem(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("NotequalesExpression")) { + expressionValue.set(i, "(" + leftHand + ").equalsWith(" + rightHand + ").not()"); + operatorFound = true; + } else if (expressionValue.get(i).equals("LessThanExpression")) { + expressionValue.set(i, "(" + leftHand + ").isLessThan(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("LessThanOrEqualExpression")) { + expressionValue.set(i, "(" + leftHand + ").isLessOrEqualThan(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("GreaterThanExpression")) { + expressionValue.set(i, "(" + leftHand + ").isGreaterThan(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("GreaterThanOrEqualExpression")) { + expressionValue.set(i, "(" + leftHand + ").isGreaterOrEqualThan(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("EqualsExpression")) { + expressionValue.set(i, "(" + leftHand + ").equals(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("Range_ParsedSubType")) { + expressionValue.set(i, "new SubTypeInterval(" + expressionValue.get(i + 1) + "," + + expressionValue.get(i + 2) + ")"); + operatorFound = true; + } + + if (unaryOperatorFound) { + unaryOperatorFound = false; + expressionValue.remove(i + 1); + size = expressionValue.size() - 1; + i = size; + } else if (operatorFound) { + operatorFound = false; + expressionValue.remove(i + 2); + expressionValue.remove(i + 1); + size = expressionValue.size() - 1; + i = size; + } + + } + + constValues.addAll(expressionValue); + + expressionValue.clear(); + } + + + public void visitExpressionTypeSelectors(IVisitableNode node) { + + if (node instanceof AddExpression) { + expressionValue.add("AddExpression"); + } + + if (node instanceof SubstractExpression) { + expressionValue.add("SubstractExpression"); + } + + if (node instanceof MultiplyExpression) { + expressionValue.add("MultiplyExpression"); + } + + if (node instanceof DivideExpression) { + expressionValue.add("DivideExpression"); + } + + if (node instanceof ModuloExpression) { + expressionValue.add("ModuloExpression"); + } + + if (node instanceof RemainderExpression) { + expressionValue.add("RemainderExpression"); + } + + if (node instanceof NotequalesExpression) { + expressionValue.add("NotequalesExpression"); + } + + if (node instanceof LessThanExpression) { + expressionValue.add("LessThanExpression"); + } + + if (node instanceof LessThanOrEqualExpression) { + expressionValue.add("LessThanOrEqualExpression"); + } + + if (node instanceof GreaterThanExpression) { + expressionValue.add("GreaterThanExpression"); + } + + if (node instanceof GreaterThanOrEqualExpression) { + expressionValue.add("GreaterThanOrEqualExpression"); + } + + if (node instanceof EqualsExpression) { + expressionValue.add("EqualsExpression"); + } + + if (node instanceof NotExpression) { + expressionValue.add("NotExpression"); + } + + if (node instanceof Range_ParsedSubType) { + expressionValue.add("Range_ParsedSubType"); + } + + if (node instanceof Str2IntExpression) { + expressionValue.add("Str2IntExpression"); + } + + if (node instanceof Log2StrExpression) { + expressionValue.add("Log2StrExpression"); + } + + if (node instanceof ValueofExpression) { + expressionValue.add("ValueofExpression"); + } + + } + + public void leave(IVisitableNode node) { + if (!myASTVisitor.myFunctionTestCaseVisitHandler.waitForDefStatement + && (node instanceof Def_Const)) { + evaluateExpression(); + handleConst(node); + + } + } + + public void handleConst(IVisitableNode node) { + Def_Const_Writer constNode = Def_Const_Writer + .getInstance(((Def_Const) node)); + constNode.clearLists(); + + constNode.setConstNodeType(constNodeType); + constNode.constValues.addAll(constValues); + constNode.constParamCount.addAll(constParamCount); + constNode.constValueIsAReference = constValueIsAReference; + + constValues.clear(); + constValueIsAReference = false; + waitForConstValues = false; + constParamCounter = -3; + constParamCount.clear(); + + + myASTVisitor.deleteLastBracket(myASTVisitor.currentFileName); + myASTVisitor.visualizeNodeToJava(constNode.getJavaSource() + "\r\n}"); + myASTVisitor.constOmitHashes.clear(); + } + +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Const_Writer.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Const_Writer.java index bf3eeaa45..d8ab467b7 100644 --- a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Const_Writer.java +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Const_Writer.java @@ -20,38 +20,29 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import org.eclipse.titan.designer.AST.ASTNode; -import org.eclipse.titan.designer.AST.IVisitableNode; -import org.eclipse.titan.designer.AST.Value; import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const; -import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type; -import org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value; -import org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value; -import org.eclipse.titan.designer.AST.TTCN3.values.Omit_Value; -import org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value; -import org.eclipse.titan.designer.AST.TTCN3.values.Sequence_Value; -import org.eclipse.titan.designer.parsers.CompilationTimeStamp; public class Def_Const_Writer { private Def_Const constNode; private StringBuilder constString = new StringBuilder(""); - private CompilationTimeStamp compilationCounter = CompilationTimeStamp - .getNewCompilationCounter(); + private String nodeName = null; - private List constValues = new ArrayList(); + public List constValues = new ArrayList(); private String constNodeType = null; private int valueCounter = 0; - private List constSetOfAmount = new ArrayList(); - private boolean isSetOf = false; + public List constParamCount = new ArrayList(); + public boolean constValueIsAReference = false; + private boolean isSetOf = false; private static Map constHashes = new LinkedHashMap(); + private Def_Const_Writer(Def_Const node) { super(); this.constNode = node; - nodeName = node.getIdentifier().toString(); + nodeName = constNode.getIdentifier().toString(); } public static Def_Const_Writer getInstance(Def_Const node) { @@ -63,20 +54,15 @@ public class Def_Const_Writer { .toString()); } - public void addConstValues(String value) { - constValues.add(value); - } + public void setConstNodeType(String value) { constNodeType = value; } - public void setConstSetOfAmount(int num) { - this.constSetOfAmount.add(num); - } - public void writeConstConstructor(String rootNodeType, String prefix) { + //type with children, child values need to be assigned if (myASTVisitor.nodeNameChildrenNamesHashMap.containsKey(rootNodeType)) { if (!isSetOf) { @@ -107,6 +93,7 @@ public class Def_Const_Writer { valueCounter++; } else if (childrenNodeTypes[i].equals("INTEGER")) { + // printvalue if (constValues.get(valueCounter).equals("omit")) { constString.append(prefix + "." + childrenNodeNames[i] @@ -115,9 +102,11 @@ public class Def_Const_Writer { .append(prefix + "." + "omitField=true;\r\n"); } else { + constString.append(prefix + "." + childrenNodeNames[i] - + "= new " + childrenNodeTypes[i] + "(" - + constValues.get(valueCounter) + ");\r\n"); + + "= new " + childrenNodeTypes[i] + "(new BigInteger(\"" + + constValues.get(valueCounter) + "\"));\r\n"); + } valueCounter++; @@ -181,24 +170,87 @@ public class Def_Const_Writer { } } - } else { + } else { //simple type, no child value assignments if (myASTVisitor.nodeNameNodeTypeHashMap.containsKey(rootNodeType)) { String type = myASTVisitor.nodeNameNodeTypeHashMap .get(rootNodeType); + + if (type.equals("CHARSTRING") || type.equals("INTEGER")) { - constString.append("value=new " + constNodeType + "(new " - + type + "(" + constValues.get(valueCounter) - + "));\r\n"); + if(constValueIsAReference){ + if(myASTVisitor.nodeNameNodeTypeHashMap.containsKey(constValues.get(valueCounter))){ + if(myASTVisitor.nodeNameNodeTypeHashMap.get(constValues.get(valueCounter)).equals("constant")){ + constString.append("value = new "+constNodeType+"("+constValues.get(valueCounter)+".value)" + + ";\r\n"); + } + } + + + constString.append("value="+constValues.get(valueCounter) + + ";\r\n"); + }else{ + + constString.append("value=new " + constNodeType + "(new " + + type + "(new BigInteger(\"" + constValues.get(valueCounter) + + "\")));\r\n"); + } valueCounter++; } + } else if(constNodeType.equals("INTEGER")){ + + if(constValueIsAReference){ + constString.append("value="+constValues.get(valueCounter) + + ";\r\n"); + }else{ + constString.append("value=new " + constNodeType + "(new BigInteger(\"" + constValues.get(valueCounter) + + "\"));\r\n"); + } + + valueCounter++; + } else if(constNodeType.equals("BITSTRING")){ + constString.append("value=new " + + "BITSTRING" + "(\"" + constValues.get(valueCounter) + + "\");\r\n"); + + valueCounter++; + } else if(constNodeType.equals("CHARSTRING")){ + constString.append("value=new " + + "CHARSTRING" + "(\"" + constValues.get(valueCounter) + + "\");\r\n"); + + valueCounter++; + } else if(constNodeType.equals("OCTETSTRING")){ + constString.append("value=new " + + "OCTETSTRING" + "(\"" + constValues.get(valueCounter) + + "\");\r\n"); + + valueCounter++; + } else if(constNodeType.equals("BOOLEAN")){ + constString.append("value=new " + + "BOOLEAN" + "(" + constValues.get(valueCounter) + + ");\r\n"); + + valueCounter++; } } } + + public void clearLists(){ + valueCounter = 0; + + constValueIsAReference = false; + isSetOf = false; + + constParamCount.clear(); + constValues.clear(); + } public String getJavaSource() { + AstWalkerJava.logToConsole(" Starting processing: Constant " + nodeName ); + constString.append("public static " + constNodeType + " " + nodeName + "(){\r\n"); constString.append(constNodeType + " value;\r\n"); @@ -209,9 +261,8 @@ public class Def_Const_Writer { String returnString = constString.toString(); valueCounter = 0; constString.setLength(0); - constSetOfAmount.clear(); - constValues.clear(); - + + AstWalkerJava.logToConsole(" Finished processing: Constant " + nodeName ); return returnString; } } diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Function_Writer.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Function_Writer.java index cdf5b8830..340ad48a5 100644 --- a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Function_Writer.java +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Function_Writer.java @@ -15,7 +15,6 @@ package org.eclipse.titan.codegenerator; -import java.math.BigInteger; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; @@ -23,40 +22,35 @@ import java.util.Map; import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function; import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Timer; -import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type; -import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var; import org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement; import org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement; import org.eclipse.titan.designer.AST.TTCN3.statements.Definition_Statement; -import org.eclipse.titan.designer.AST.TTCN3.statements.Operation_Altguard; import org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement; -import org.eclipse.titan.designer.AST.TTCN3.statements.Repeat_Statement; -import org.eclipse.titan.designer.AST.TTCN3.statements.Return_Statement; import org.eclipse.titan.designer.AST.TTCN3.statements.Send_Statement; import org.eclipse.titan.designer.AST.TTCN3.statements.Setverdict_Statement; import org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock; -import org.eclipse.titan.designer.AST.TTCN3.statements.Timeout_Statement; import org.eclipse.titan.designer.AST.TTCN3.statements.Unknown_Start_Statement; import org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template; -import org.eclipse.titan.designer.AST.TTCN3.types.CompField; -import org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type; -import org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type; +import org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value; +import org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value; import org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value; import org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value; +import org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value; import org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value; import org.eclipse.titan.designer.AST.TTCN3.values.Verdict_Value; import org.eclipse.titan.designer.AST.TTCN3.values.expressions.AddExpression; -import org.eclipse.titan.designer.AST.TTCN3.values.expressions.Int2StrExpression; -import org.eclipse.titan.designer.declarationsearch.Declaration; -import org.eclipse.titan.designer.parsers.CompilationTimeStamp; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.DivideExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.ModuloExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.MultiplyExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.RemainderExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.SubstractExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.UnaryMinusExpression; public class Def_Function_Writer { private Def_Function functionNode; private StringBuilder functionString = new StringBuilder(""); - private CompilationTimeStamp compilationCounter = CompilationTimeStamp - .getNewCompilationCounter(); - private String nodeName = null; + public String nodeName = null; private static Map functionHashes = new LinkedHashMap(); @@ -65,33 +59,49 @@ public class Def_Function_Writer { private String currentTimerName = null; public String returnStatementValue = null; - private String runsOnValue = null; - private String returnType = null; - private String timerValue = null; - private String unknownStartReference = null; - private List sendPortReference = new ArrayList(); - private List sendParameter = new ArrayList(); - private List sendParameterType = new ArrayList(); - private int sendCounter = -1; - private List recievePortReference = new ArrayList(); - private List recieveParameter = new ArrayList(); - private List recieveParameterType = new ArrayList(); - private int recieveCounter = -1; - private List addValues = new ArrayList(); + public String runsOnValue = null; + public String returnType = null; + + public String unknownStartReference = null; + public String unknownStopReference = null; + public static List sendPortReference = new ArrayList(); + public static List sendParameter = new ArrayList(); + public static List sendParameterType = new ArrayList(); + public int sendCounter = -1; + + public List altStatements = new ArrayList(); + private int altStatementCounter = -1; + + public List functionVars = new ArrayList(); + public List functionVarTypes = new ArrayList(); + public List functionVarValues = new ArrayList(); + public List functionAssignIdentifiers = new ArrayList(); + public List functionAssignValues = new ArrayList(); + + public int receiveCounter = -1; + + public List receivePortReference = new ArrayList(); + public List receiveValue = new ArrayList(); + public List receiveAnyValValue = new ArrayList(); + public List receiveType = new ArrayList(); + public List receiveStatements = new ArrayList(); + + public List functionValueIsAValueReference = new ArrayList(); + public List functionVarIsConstant = new ArrayList(); + private int defCounter = -1; + public int assignCounter = -1; private Def_Function_Writer(Def_Function typeNode) { super(); this.functionNode = typeNode; - nodeName = typeNode.getIdentifier().toString(); + nodeName = functionNode.getIdentifier().toString(); } public static Def_Function_Writer getInstance(Def_Function typeNode) { if (!functionHashes.containsKey(typeNode.getIdentifier().toString())) { - functionHashes.put(typeNode.getIdentifier().toString(), - new Def_Function_Writer(typeNode)); + functionHashes.put(typeNode.getIdentifier().toString(), new Def_Function_Writer(typeNode)); } - return (Def_Function_Writer) functionHashes.get(typeNode - .getIdentifier().toString()); + return (Def_Function_Writer) functionHashes.get(typeNode.getIdentifier().toString()); } public void setStatementBlock(StatementBlock statementBlock) { @@ -100,575 +110,435 @@ public class Def_Function_Writer { public void writeFunction() { - functionString.append("public void " + nodeName + "(){\r\n"); + if (returnType != null) { + if (returnType.equals("Integer_Type")) { + functionString.append("public static INTEGER " + nodeName + "(){\r\n"); + } else if (returnType.equals("Boolean_Type")) { + functionString.append("public static BOOLEAN " + nodeName + "(){\r\n"); + } + } else { + functionString.append("public void " + nodeName + "(){\r\n"); - /* - * if (AstWalkerJava.areCommentsAllowed) { - * functionString.append("System.out.println(\"" + nodeName + - * " started\");" + "\r\n"); } - */ + functionString.append("String sourcefilename = \"" + + statementBlock.getLocation().getFile().getFullPath().lastSegment() + "\";" + "\r\n"); + functionString.append("int rownum=" + statementBlock.getLocation().getLine() + ";\r\n"); + functionString.append("if(!created) return;" + "\r\n"); - functionString.append("String sourcefilename = \"" - + statementBlock.getLocation().getFile().getFullPath() - .lastSegment() + "\";" + "\r\n"); - functionString.append("int rownum=" + functionNode.getLocation().getLine() - + ";\r\n"); - functionString.append("if(!created) return;" + "\r\n"); + functionString.append("TTCN3Logger.writeLog(compid, \"PARALLEL\", sourcefilename, rownum, \"function\", \"" + + nodeName + "\", \"Function started on \" + compid + \".\", false);" + "\r\n"); - functionString - .append("TTCN3Logger.writeLog(compid, \"PARALLEL\", sourcefilename, rownum, \"function\", \"" - + nodeName - + "\", \"Function started on \" + compid + \".\", false);" - + "\r\n"); + } for (int i = 0; i < statementBlock.getSize(); i++) { if (statementBlock.getStatementByIndex(i) instanceof Definition_Statement) { - writeDefinitionStatement((Definition_Statement) statementBlock - .getStatementByIndex(i)); + writeDefinitionStatement((Definition_Statement) statementBlock.getStatementByIndex(i)); + } else if (statementBlock.getStatementByIndex(i) instanceof Assignment_Statement) { + assignCounter++; + + functionString + .append(writeAssignmentStatement((Assignment_Statement) statementBlock.getStatementByIndex(i))); + } else if (statementBlock.getStatementByIndex(i) instanceof Send_Statement) { sendCounter++; - writeSendStatement((Send_Statement) statementBlock - .getStatementByIndex(i)); + functionString.append(writeSendStatement((Send_Statement) statementBlock.getStatementByIndex(i))); } else if (statementBlock.getStatementByIndex(i) instanceof Unknown_Start_Statement) { - writeUnknownStartStatement((Unknown_Start_Statement) statementBlock - .getStatementByIndex(i)); + writeUnknownStartStatement((Unknown_Start_Statement) statementBlock.getStatementByIndex(i)); } else if (statementBlock.getStatementByIndex(i) instanceof Alt_Statement) { - writeAltStatement((Alt_Statement) statementBlock - .getStatementByIndex(i)); + + altStatementCounter++; + + altStatements.get(altStatementCounter).setTimerInfo(isThereAStartedTimer, currentTimerName); + functionString.append(altStatements.get(altStatementCounter).getJavaSource()); + } else if (statementBlock.getStatementByIndex(i) instanceof Setverdict_Statement) { - writeSetVerdictStatement((Setverdict_Statement) statementBlock - .getStatementByIndex(i)); + writeSetVerdictStatement((Setverdict_Statement) statementBlock.getStatementByIndex(i)); } } + if (returnStatementValue != null) { + functionString.append("return " + returnStatementValue + ";\r\n"); + } + } - public String[] writeAltCommands(Operation_Altguard altGuard) { - int rownum = 0; - StringBuilder altString = new StringBuilder(); - - int guardBlockSize = altGuard.getStatementBlock().getSize(); - for (int j = 0; j < guardBlockSize; j++) { - - if (altGuard.getStatementBlock().getStatementByIndex(j) instanceof Setverdict_Statement) { - - if (altGuard.getStatementBlock().getStatementByIndex(j) instanceof Setverdict_Statement) { - Setverdict_Statement verdictAltGuard = (Setverdict_Statement) altGuard - .getStatementBlock().getStatementByIndex(j); - - String verdict = ""; - if (verdictAltGuard.getVerdictValue() instanceof Verdict_Value) { - Verdict_Value verdictValue = (Verdict_Value) verdictAltGuard - .getVerdictValue(); - if (verdictValue.getValue().toString().equals("PASS")) { - verdict = "pass"; - } else if (verdictValue.getValue().toString() - .equals("INCONC")) { - verdict = "inconc"; - } else { - verdict = "fail"; - - } - altString.append("rownum=" - + verdictValue.getLocation().getLine() - + ";\r\n"); - altString - .append("TTCN3Logger.writeLog(compid, \"VERDICTOP\", sourcefilename, rownum, \"function\", \"" - + nodeName - + "\", \"setverdict(" - + verdict - + "): \" + getVerdict() + \" -> " - + verdict + "\", true);" + "\r\n"); - - altString.append("setVerdict(\"" + verdict - + "\");break;" + "\r\n"); - rownum = verdictValue.getLocation().getLine(); - } - } + // updated + public void writeDefinitionStatement(Definition_Statement tc_defStatement) { + + defCounter++; + if (tc_defStatement.getDefinition() instanceof Def_Timer) { + Def_Timer def_Timer = (Def_Timer) tc_defStatement.getDefinition(); + + functionString.append("rownum=" + def_Timer.getLocation().getLine() + ";\r\n"); + functionString.append("Timer " + def_Timer.getIdentifier().toString() + " = new Timer (new FLOAT(" + + functionVarValues.get(defCounter) + "));\r\n"); + + functionString.append("TTCN3Logger.writeLog(compid, \"TIMEROP\", sourcefilename, rownum, \"function\", \"" + + nodeName + "\", \"Timer " + def_Timer.getIdentifier().toString() + " set to " + + functionVarValues.get(defCounter) + ".\", false);" + "\r\n"); + + } else if (functionVarTypes.get(defCounter).equals("BITSTRING")) { + functionString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n"); + + if (functionVarIsConstant.get(defCounter)) { + functionString.append("final "); } - if (altGuard.getStatementBlock().getStatementByIndex(j) instanceof Assignment_Statement) { - Assignment_Statement assignmentGuard = (Assignment_Statement) altGuard - .getStatementBlock().getStatementByIndex(j); + if (functionVarValues.get(defCounter).equals("null")) { + functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + + "=new BITSTRING();\r\n"); - String assignmentName = assignmentGuard.getReference() - .getSubreferences().get(0).getId().toString(); + } else if (functionValueIsAValueReference.get(defCounter)) { + functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=" + + functionVarValues.get(defCounter) + ";\r\n"); - if (assignmentGuard.getTemplate().getValue() instanceof AddExpression) { - altString.append("rownum="+assignmentGuard.getLocation().getLine()+";\r\n"); - altString.append(assignmentName + "=" + addValues.get(0) - + ".plus(new INTEGER(" + addValues.get(1) + ")); \r\n"); - } + } else { + functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + + "=new BITSTRING(\"" + functionVarValues.get(defCounter) + "\");\r\n"); } + // TODO: add logging here - if (altGuard.getStatementBlock().getStatementByIndex(j) instanceof Repeat_Statement) { - // TODO + } else if (functionVarTypes.get(defCounter).equals("INTEGER")) { + + functionString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n"); + if (functionVarIsConstant.get(defCounter)) { + functionString.append("final "); } - if (altGuard.getStatementBlock().getStatementByIndex(j) instanceof Send_Statement) { - sendCounter++; - Send_Statement sendAltGuard = (Send_Statement) altGuard - .getStatementBlock().getStatementByIndex(j); + if (functionVarValues.get(defCounter).equals("null")) { + functionString.append( + functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=new INTEGER();\r\n"); - String portReferenceName = sendPortReference.get(sendCounter); - String parameterName = null; - String parameterType = null; - String valueType = sendParameterType.get(sendCounter); - String valueName = sendParameter.get(sendCounter); + } else if (functionValueIsAValueReference.get(defCounter)) { + functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=" + + functionVarValues.get(defCounter) + ";\r\n"); - if (valueType.equals("Undefined_LowerIdentifier_Value")) { + } else { + functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + + "=new INTEGER(new BigInteger(\"" + functionVarValues.get(defCounter) + "\"));\r\n"); - parameterName = valueName; - } + } + // TODO: add logging here - if (valueType.equals("Charstring_Value")) { - parameterName = "new CHARSTRING(\"" + valueName + "\")"; - } + } else if (functionVarTypes.get(defCounter).equals("CHARSTRING")) { - if (valueType.equals("Int2StrExpression")) { - parameterName = valueName+".int2str()"; - } + functionString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n"); - altString.append("rownum="+sendAltGuard.getLocation().getLine()+";\r\n"); - altString.append(portReferenceName + ".send(" + parameterName - + ");" + "\r\n"); + if (functionVarIsConstant.get(defCounter)) { + functionString.append("final "); + } - altString.append("TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \""+nodeName+"\", \"SEND event on port "+portReferenceName+":\" + "+parameterName+".toString(), true);"+"\r\n"); + if (functionVarValues.get(defCounter).equals("null")) { + functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + + "=new CHARSTRING();\r\n"); + + } else if (functionValueIsAValueReference.get(defCounter)) { + functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=" + + functionVarValues.get(defCounter) + ";\r\n"); + + } else { + functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + + "=new CHARSTRING(\"" + functionVarValues.get(defCounter) + "\");\r\n"); + + } + // TODO: add logging here + + } else if (functionVarTypes.get(defCounter).equals("BOOLEAN")) { + + functionString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n"); + + if (functionVarIsConstant.get(defCounter)) { + functionString.append("final "); + } + + if (functionVarValues.get(defCounter).equals("null")) { + functionString.append( + functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=new BOOLEAN();\r\n"); + + } else if (functionValueIsAValueReference.get(defCounter)) { + functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=" + + functionVarValues.get(defCounter) + ";\r\n"); + + } else { + functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + + "=new BOOLEAN(" + functionVarValues.get(defCounter) + ");\r\n"); + + } + // TODO: add logging here + } else if (myASTVisitor.nodeNameNodeTypeHashMap.containsKey(functionVarTypes.get(defCounter))) { + functionString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n"); + if (functionVarValues.get(defCounter) != null) { + functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "= new " + + functionVarTypes.get(defCounter) + "(" + functionVarValues.get(defCounter) + ")" + ";\r\n"); + } else { + functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + ";\r\n"); } } - String[] returnvalue = new String[2]; - returnvalue[0] = altString.toString(); - returnvalue[1] = Integer.toString(rownum); - return returnvalue; } - public void writeDefinitionStatement( - Definition_Statement definitionStatement) { + // updated + public String writeAssignmentStatement(Assignment_Statement tc_assignStatement) { - if (definitionStatement.getDefinition() instanceof Def_Timer) { - String statementName = definitionStatement.getDefinition() - .getIdentifier().toString(); - Def_Timer currentTimer = (Def_Timer) definitionStatement - .getDefinition(); + StringBuilder functionString = new StringBuilder(""); - functionString.append("rownum=" - + definitionStatement.getDefinition().getLocation() - .getLine() + ";\r\n"); - functionString.append("Timer " + statementName - + " = new Timer (new FLOAT(" + timerValue + "));\r\n"); + if (tc_assignStatement.getTemplate() instanceof SpecificValue_Template) { + SpecificValue_Template specValTemplate = (SpecificValue_Template) tc_assignStatement.getTemplate(); - functionString - .append("TTCN3Logger.writeLog(compid, \"TIMEROP\", sourcefilename, rownum, \"function\", \"" - + nodeName - + "\", \"Timer " - + statementName - + " set to " + timerValue + ".\", false);" + "\r\n"); + if (specValTemplate.getSpecificValue() instanceof Bitstring_Value) { - } + functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n"); - if (definitionStatement.getDefinition() instanceof Def_Var) { - String variableType = ""; - String variableName = ""; - String variableValue = ""; - - Def_Var currentVar = (Def_Var) definitionStatement.getDefinition(); - variableName = definitionStatement.getDefinition().getIdentifier() - .toString(); - - if (currentVar.getType(compilationCounter) instanceof Referenced_Type) { - Referenced_Type ref = (Referenced_Type) currentVar - .getType(compilationCounter); - variableType = ref.getReference().getSubreferences().get(0) - .getId().toString(); - - - } + functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new BITSTRING(\"" + + functionAssignValues.get(assignCounter) + "\");\r\n"); - if (currentVar.getType(compilationCounter) instanceof Integer_Type) { - Integer_Type ref = (Integer_Type) currentVar - .getType(compilationCounter); - variableType = "INTEGER"; - if (currentVar.getInitialValue() instanceof Integer_Value) { - Integer_Value varValue = (Integer_Value) currentVar - .getInitialValue(); - variableValue = " = new INTEGER(" + varValue.getValueValue().toString()+")"; - } + // TODO: add logging here } - functionString.append("rownum=" - + currentVar.getLocation().getLine() + ";\r\n"); - functionString.append(variableType + " " + variableName - + variableValue + ";\r\n"); - } + if (specValTemplate.getSpecificValue() instanceof Integer_Value) { - } + functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n"); - public void writeSendStatement(Send_Statement sendStatement) { + functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new INTEGER(new BigInteger(\"" + + functionAssignValues.get(assignCounter) + "\"));\r\n"); - String portReferenceName = sendPortReference.get(sendCounter); - String parameterName = null; - String parameterType = null; - String valueType = sendParameterType.get(sendCounter); - String valueName = sendParameter.get(sendCounter); + // TODO: add logging here - if (valueType.equals("Undefined_LowerIdentifier_Value")) { + } + + if (specValTemplate.getSpecificValue() instanceof Charstring_Value) { + + functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n"); + + functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new CHARSTRING(\"" + + functionAssignValues.get(assignCounter) + "\");\r\n"); + + // TODO: add logging here - if (myASTVisitor.nodeNameNodeTypeHashMap.containsKey(valueName)) { - parameterType = myASTVisitor.nodeNameNodeTypeHashMap - .get(valueName); } - if (parameterType.equals("template")) { - parameterType = "Templates"; + if (specValTemplate.getSpecificValue() instanceof Boolean_Value) { + + functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n"); + + functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new BOOLEAN(" + + functionAssignValues.get(assignCounter) + ");\r\n"); + + // TODO: add logging here + } - parameterName = parameterType + "." + valueName + "()"; - - functionString.append("rownum=" + sendStatement.getLocation().getLine() - + ";\r\n"); - functionString.append(portReferenceName + ".send(" + parameterName - + ");" + "\r\n"); - functionString - .append("TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" - + nodeName - + "\", \"SEND event on port " - + portReferenceName - + ": " - + valueName - + ":=\" + " - + parameterName + ".toString(), true);" + "\r\n"); - - } + if (specValTemplate.getSpecificValue() instanceof Undefined_LowerIdentifier_Value) { - if (valueType.equals("Charstring_Value")) { - parameterName = "new CHARSTRING(\"" + valueName + "\")"; - functionString.append("rownum=" + sendStatement.getLocation().getLine() - + ";\r\n"); - functionString.append(portReferenceName + ".send(" + parameterName - + ");" + "\r\n"); - functionString - .append("TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" - + nodeName - + "\", \"SEND event on port " - + portReferenceName - + ":\"+" - + parameterName + ".toString(), false);" + "\r\n"); - - - - - - } - + functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n"); - } + functionString.append(functionAssignIdentifiers.get(assignCounter) + "=" + + functionAssignValues.get(assignCounter) + ";\r\n"); - public void writeUnknownStartStatement( - Unknown_Start_Statement unknownStartStatement) { - functionString.append("rownum=" - + unknownStartStatement.getLocation().getLine() + ";\r\n"); - functionString.append(unknownStartReference + ".start();" + "\r\n"); - isThereAStartedTimer = true; - currentTimerName = unknownStartReference; - functionString - .append("TTCN3Logger.writeLog(compid, \"TIMEROP\", sourcefilename, rownum, \"function\", \"" - + nodeName - + "\", \"Timer " - + unknownStartReference - + " started.\", false);" + "\r\n"); + // TODO: add logging here + } - } + if (specValTemplate.getSpecificValue() instanceof Referenced_Value) { - public void writeAltStatement(Alt_Statement altStatement) { - functionString.append("rownum=" + altStatement.getLocation().getLine() - + ";\r\n"); - functionString.append("for(;;){" + "\r\n"); - - int altSize = altStatement.getAltGuards().getNofAltguards(); - - String[] allPortname = new String[altSize]; - String[] allPortRecieveType = new String[altSize]; - String[] negativeConditions = new String[altSize]; - String[] positiveConditions = new String[altSize]; - String[] altCommands = new String[altSize]; - String[] altRowNum = new String[altSize]; - String[] logReceiveType = new String[altSize]; - String[] logReceiveValue = new String[altSize]; - boolean[] isTheRecieveTyped = new boolean[altSize]; - int[] receiveRowNum = new int[altSize]; - String[] logTimeout = new String[altSize]; - - // portsetter - for (int i = 0; i < altSize; i++) { - - String[] portType = new String[altSize]; - - if (altStatement.getAltGuards().getAltguardByIndex(i) instanceof Operation_Altguard) { - - Operation_Altguard altGuard = (Operation_Altguard) altStatement - .getAltGuards().getAltguardByIndex(i); - - // if recieves from a specific prot - if (altGuard.getGuardStatement() instanceof Receive_Port_Statement) { - recieveCounter++; - Receive_Port_Statement recievePortAltGuard = (Receive_Port_Statement) altGuard - .getGuardStatement(); - if (recieveParameterType.get(recieveCounter).equals( - "Any_Value_Template")) { - recieveCounter++; - } - if ((!recievePortReference.get(recieveCounter).equals( - "_ANY_"))) { + functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n"); - String valueType = recieveParameterType - .get(recieveCounter); - String valueName = recieveParameter.get(recieveCounter); + functionString.append(functionAssignIdentifiers.get(assignCounter) + "=" + + functionAssignValues.get(assignCounter) + ";\r\n"); - if (valueType.equals("Undefined_LowerIdentifier_Value")) { + // TODO: add logging here + } - String parameterType = null; + if ((specValTemplate.getSpecificValue() instanceof AddExpression) + || (specValTemplate.getSpecificValue() instanceof SubstractExpression) + || (specValTemplate.getSpecificValue() instanceof MultiplyExpression) + || (specValTemplate.getSpecificValue() instanceof DivideExpression) + || (specValTemplate.getSpecificValue() instanceof ModuloExpression) + || (specValTemplate.getSpecificValue() instanceof RemainderExpression)) { - if (myASTVisitor.nodeNameNodeTypeHashMap - .containsKey(valueName)) { - parameterType = myASTVisitor.nodeNameNodeTypeHashMap - .get(valueName); - } + functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n"); - if (parameterType.equals("template")) { - parameterType = "Templates"; - } + functionString.append(functionAssignIdentifiers.get(assignCounter) + + functionAssignValues.get(assignCounter) + ";\r\n"); - allPortRecieveType[i] = parameterType + "." - + valueName + "()"; - logReceiveValue[i] = valueName; - } - if (valueType.equals("Charstring_Value")) { + // TODO: add logging here - allPortRecieveType[i] = "new CHARSTRING(" + "\"" - + valueName + "\")"; - } - receiveRowNum[i]=recievePortAltGuard.getLocation().getLine(); - allPortname[i] = recievePortAltGuard.getPort() - .getSubreferences().get(0).getId().toString(); + } - } else { - receiveRowNum[i]=recievePortAltGuard.getLocation().getLine(); - allPortname[i] = "any port"; + if (specValTemplate.getSpecificValue() instanceof UnaryMinusExpression) { - } + functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n"); - } + functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new INTEGER(new BigInteger(\"" + + functionAssignValues.get(assignCounter) + "\"));\r\n"); + + // TODO: add logging here } + } - int recieveParamCounter = -1; - for (int i = 0; i < altSize; i++) { - String portname = allPortname[i]; - String portRecieveType = allPortRecieveType[i]; - String verdict = ""; - String timerName = ""; - String portType = ""; - - if (altStatement.getAltGuards().getAltguardByIndex(i) instanceof Operation_Altguard) { - Operation_Altguard altGuard = (Operation_Altguard) altStatement - .getAltGuards().getAltguardByIndex(i); - - // if recieves from a specific prot - if (altGuard.getGuardStatement() instanceof Receive_Port_Statement) { - Receive_Port_Statement recievePortAltGuard = (Receive_Port_Statement) altGuard - .getGuardStatement(); - recieveParamCounter++; - - if (!recievePortReference.get(recieveParamCounter).equals( - "_ANY_")) { - - if (recieveParameterType.get(recieveParamCounter) - .equals("_TYPED_PARAM_")) { - portType = recieveParameter - .get(recieveParamCounter); - recieveCounter++; - } - } + return functionString.toString(); + } - if (recievePortAltGuard.getPort() != null) { - portname = recievePortAltGuard.getPort() - .getSubreferences().get(0).getId().toString(); - // if the port is set - - if (portType.equals("")) { - negativeConditions[i] = portname + ".receive(" - + portRecieveType + ",false)!=null"; - positiveConditions[i] = portname + ".receive(" - + portRecieveType + ",true)!=null"; - - isTheRecieveTyped[i] = false; - } else { - negativeConditions[i] = portname + ".receive" + "_" - + portType + "(false)!=null"; - - String redirectString = recievePortAltGuard - .getRedirectValue().getSubreferences() - .get(0).getId().toString(); - positiveConditions[i] = "(" + redirectString + "=" - + portname + ".receive" + "_" + portType - + "(true))!=null"; - isTheRecieveTyped[i] = true; - logReceiveType[i] = portType; - } + public String writeSendStatement(Send_Statement sendStatement) { - } else { - // if no port is set - negativeConditions[i] = "anyPortReceive(false)"; - positiveConditions[i] = "anyPortReceive(true)"; + StringBuilder functionString = new StringBuilder(""); - } + String portReferenceName = sendPortReference.get(sendCounter); + String parameterName = null; + String parameterType = null; + String valueType = sendParameterType.get(sendCounter); + String valueName = sendParameter.get(sendCounter); - } + if (valueType.equals("IDENTIFIER")) { - if (altGuard.getGuardStatement() instanceof Timeout_Statement) { - Timeout_Statement timeOutAltGuard = (Timeout_Statement) altGuard - .getGuardStatement(); - - isThereAStartedTimer = true; - negativeConditions[i] = ("!" + currentTimerName + ".timeout()"); - positiveConditions[i] = ("" + currentTimerName + ".timeout()"); - - logTimeout[i]="rownum="+timeOutAltGuard.getLocation().getLine()+";\r\n"+"TTCN3Logger.writeLog(compid, \"TIMEROP\", sourcefilename, rownum, \"function\", \""+nodeName+"\", \"Timeout on timer "+currentTimerName+".\", false);"+"\r\n"; - - - } - String[] commandBlock=writeAltCommands(altGuard); - altCommands[i] = commandBlock[0]; - altRowNum[i] = commandBlock[1]; + if (myASTVisitor.nodeNameNodeTypeHashMap.containsKey(valueName)) { + parameterType = myASTVisitor.nodeNameNodeTypeHashMap.get(valueName); + if (parameterType.equals("template")) { + parameterType = "Templates"; + } + parameterName = parameterType + "." + valueName + "()"; + } else { + parameterName = valueName; } + functionString.append("rownum=" + sendStatement.getLocation().getLine() + ";\r\n"); + functionString.append(portReferenceName + ".send(" + parameterName + ");" + "\r\n"); + functionString.append("TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + + nodeName + "\", \"SEND event on port " + portReferenceName + ": " + valueName + ":=\" + " + + parameterName + ".toString(), true);" + "\r\n"); + } - functionString.append("if(!("); - for (int condStepper = 0; condStepper < altSize; condStepper++) { - functionString.append(negativeConditions[condStepper]); - if (condStepper + 1 < altSize) { - functionString.append("||"); - } + if (valueType.equals("CHARSTRING")) { + parameterName = valueName; + functionString.append("rownum=" + sendStatement.getLocation().getLine() + ";\r\n"); + functionString.append(portReferenceName + ".send(" + parameterName + ");" + "\r\n"); + functionString.append("TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + + nodeName + "\", \"SEND event on port " + portReferenceName + ":\"+" + parameterName + + ".toString(), false);" + "\r\n"); + } - functionString.append(")){" + "\r\n"); - - // timer - if (isThereAStartedTimer) { - functionString.append("long timeout = -1;" + "\r\n"); - functionString.append("long newtimeout;" + "\r\n"); - - functionString - .append("if(" - + currentTimerName - + ".running)if((newtimeout=(long)(" - + currentTimerName - + ".read().value*1000.0))0) try{queue.poll(timeout,TimeUnit.MILLISECONDS);}catch(InterruptedException e){} " - + "\r\n"); - functionString.append("this.lock();" + "\r\n"); + + return functionString.toString(); + + } + + public String writeReceiveStatement(Receive_Port_Statement currentStatement) { + StringBuilder testCaseString = new StringBuilder(""); + String receiveStatement = ""; + + // no alt guard && any port recieve + if (receivePortReference.get(receiveCounter).equals("any port")) { + receiveStatement = "anyPortReceive(true)"; + } else { + // no alt guard && typed port recieve + if (receiveType.get(receiveCounter).equals("_TYPED_PARAM_")) { + + if (receiveAnyValValue.get(receiveCounter) != null) { + receiveStatement = "(" + receiveAnyValValue.get(receiveCounter) + "=" + + receivePortReference.get(receiveCounter) + ".receive_" + receiveValue.get(receiveCounter) + + "(true))!=null"; + + } else { - functionString - .append("try{queue.take();}catch(InterruptedException e){}" - + "\r\n"); - functionString.append("this.lock();" + "\r\n"); + } + } else { // no alt guard && normal port recieve + receiveStatement = receivePortReference.get(receiveCounter) + ".receive(" + + receiveValue.get(receiveCounter) + ",true)!=null"; + } + if (receiveValue.get(receiveCounter).startsWith("Templates")) { + receiveType.set(receiveCounter, "Templates"); + } } - // endoftimer - functionString.append("}" + "\r\n"); + testCaseString.append("if(" + receiveStatement + "){\r\n"); + testCaseString.append("rownum=" + currentStatement.getLocation().getLine() + ";\r\n"); - // ifwriter - for (int condCounter = 0; condCounter < altSize; condCounter++) { + if (receiveType.get(receiveCounter).equals("Templates")) { + String methodName = receiveValue.get(receiveCounter); + if (methodName.endsWith("()") && methodName.startsWith("Templates.")) { - if (condCounter > 0) { - functionString.append("else "); + methodName = (String) methodName.subSequence(10, methodName.length() - 2); } - functionString.append("if("); - functionString.append(positiveConditions[condCounter]); - functionString.append("){" + "\r\n"); - - if (allPortname[condCounter] != null) { - if (!isTheRecieveTyped[condCounter]) { - if (logReceiveValue[condCounter] != null) { - functionString.append("rownum="+receiveRowNum[condCounter]+";\r\n"); - functionString - .append("TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" - + nodeName - + "\", \"RECEIVE event on port " - + allPortname[condCounter] - + ":\\n " - + logReceiveValue[condCounter] - + ":=\" + " - + allPortRecieveType[condCounter] - + ".toString(), true);" + "\r\n"); + + testCaseString + .append(" TTCN3Logger.writeLog(\"mtc\", \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + + nodeName + "\", \"RECEIVE event on port " + receivePortReference.get(receiveCounter) + + ":\\n " + methodName + ":=\" + " + receiveValue.get(receiveCounter) + + ".toString(), true);" + "\r\n"); + } else if (receiveType.get(receiveCounter).equals("any port")) { + testCaseString + .append(" TTCN3Logger.writeLog(\"mtc\", \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + + nodeName + "\", \"RECEIVE event on port any port\", true);" + "\r\n"); + } else if (receiveType.get(receiveCounter).equals("_TYPED_PARAM_")) { + testCaseString + .append(" TTCN3Logger.writeLog(\"mtc\", \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + + nodeName + "\", \"RECEIVE event on port " + receivePortReference.get(receiveCounter) + + ": type " + receiveValue.get(receiveCounter) + "\", true);" + "\r\n"); + + } else { + testCaseString + .append(" TTCN3Logger.writeLog(\"mtc\", \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + + nodeName + "\", \"RECEIVE event on port " + receivePortReference.get(receiveCounter) + + ":\" + " + receiveValue.get(receiveCounter) + ".toString(), true);" + "\r\n"); + } + + for (int i = 0; i < receiveStatements.get(receiveCounter).getSize(); i++) { + if (receiveStatements.get(receiveCounter).getStatementByIndex(i) instanceof Setverdict_Statement) { + + Setverdict_Statement setVerdictStatement = (Setverdict_Statement) receiveStatements.get(receiveCounter) + .getStatementByIndex(i); + String verdict = ""; + + if (setVerdictStatement.getVerdictValue() instanceof Verdict_Value) { + Verdict_Value verdictValue = (Verdict_Value) setVerdictStatement.getVerdictValue(); + if (verdictValue.getValue().toString().equals("PASS")) { + verdict = "pass"; + } else if (verdictValue.getValue().toString().equals("INCONC")) { + verdict = "inconc"; } else { - if (allPortRecieveType[condCounter] != null) { - functionString.append("rownum="+receiveRowNum[condCounter]+";\r\n"); - functionString - .append(" TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" - + nodeName - + "\", \"RECEIVE event on port " - + allPortname[condCounter] - + ":\" + " - + allPortRecieveType[condCounter] - + ".toString(), true);" + "\r\n"); - } else { - functionString.append("rownum="+receiveRowNum[condCounter]+";\r\n"); - functionString - .append("TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" - + nodeName - + "\", \"RECEIVE event on port " - + allPortname[condCounter] - + "\", true);" + "\r\n"); - } + verdict = "fail"; } - } else { - functionString.append("rownum="+receiveRowNum[condCounter]+";\r\n"); - functionString - .append("TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" - + nodeName - + "\", \"RECEIVE event on port " - + allPortname[condCounter] - + ": type " - + logReceiveType[condCounter] - + "\", true);" + "\r\n"); } + testCaseString.append("rownum=" + setVerdictStatement.getLocation().getLine() + ";\r\n"); + testCaseString + .append("TTCN3Logger.writeLog(\"mtc\", \"VERDICTOP\", sourcefilename, rownum, \"function\", \"" + + nodeName + "\", \"setverdict(" + verdict + "): \" + getVerdict() + \" -> " + verdict + + "\", true);" + "\r\n"); + testCaseString.append("setVerdict(\"" + verdict + "\");" + "\r\n"); + } - - if(logTimeout[condCounter]!=null){ - functionString.append(logTimeout[condCounter]); - } + } - // TODO: ide jön az if log - functionString.append(altCommands[condCounter]); + testCaseString.append("}\r\n"); - functionString.append("}" + "\r\n"); + return testCaseString.toString(); + } - } - functionString.append("this.unlock();" + "\r\n"); - functionString.append("}" + "\r\n"); + // updated + public void writeUnknownStartStatement(Unknown_Start_Statement unknownStartStatement) { + functionString.append("rownum=" + unknownStartStatement.getLocation().getLine() + ";\r\n"); + functionString.append(unknownStartReference + ".start();" + "\r\n"); + isThereAStartedTimer = true; + currentTimerName = unknownStartReference; + functionString.append("TTCN3Logger.writeLog(compid, \"TIMEROP\", sourcefilename, rownum, \"function\", \"" + + nodeName + "\", \"Timer " + unknownStartReference + " started.\", false);" + "\r\n"); } - public void writeSetVerdictStatement( - Setverdict_Statement setVerdictStatement) { + public void writeSetVerdictStatement(Setverdict_Statement setVerdictStatement) { String verdict = ""; if (setVerdictStatement.getVerdictValue() instanceof Verdict_Value) { - Verdict_Value verdictValue = (Verdict_Value) setVerdictStatement - .getVerdictValue(); + Verdict_Value verdictValue = (Verdict_Value) setVerdictStatement.getVerdictValue(); if (verdictValue.getValue().toString().equals("PASS")) { verdict = "pass"; } else if (verdictValue.getValue().toString().equals("INCONC")) { @@ -677,16 +547,10 @@ public class Def_Function_Writer { verdict = "fail"; } } - functionString.append("rownum=" - + setVerdictStatement.getLocation().getLine() + ";\r\n"); - functionString - .append("TTCN3Logger.writeLog(compid, \"VERDICTOP\", sourcefilename, rownum, \"function\", \"" - + nodeName - + "\", \"setverdict(" - + verdict - + "): \" + getVerdict() + \" -> " - + verdict - + "\", true);" + "\r\n"); + functionString.append("rownum=" + setVerdictStatement.getLocation().getLine() + ";\r\n"); + functionString.append("TTCN3Logger.writeLog(compid, \"VERDICTOP\", sourcefilename, rownum, \"function\", \"" + + nodeName + "\", \"setverdict(" + verdict + "): \" + getVerdict() + \" -> " + verdict + "\", true);" + + "\r\n"); functionString.append("setVerdict(\"" + verdict + "\");" + "\r\n"); } @@ -694,12 +558,9 @@ public class Def_Function_Writer { StringBuilder functionFileString = new StringBuilder(); - functionFileString.append("class " + nodeName + " implements Runnable{" - + "\r\n"); - functionFileString.append("private " + runsOnValue + " component;" - + "\r\n"); - functionFileString.append("public " + nodeName + "(" + runsOnValue - + " c){" + "\r\n"); + functionFileString.append("class " + nodeName + " implements Runnable{" + "\r\n"); + functionFileString.append("private " + runsOnValue + " component;" + "\r\n"); + functionFileString.append("public " + nodeName + "(" + runsOnValue + " c){" + "\r\n"); functionFileString.append("component = c;" + "\r\n"); functionFileString.append("}" + "\r\n"); functionFileString.append("public void run(){" + "\r\n"); @@ -711,97 +572,60 @@ public class Def_Function_Writer { } public String getJavaSource() { - recieveCounter = -1; + AstWalkerJava.logToConsole(" Starting processing: Function " + nodeName); + sendCounter = -1; + this.writeFunction(); functionString.append("\r\n}"); String returnString = functionString.toString(); functionString.setLength(0); - return returnString; - } - - private void writeFunctionWithoutRunsOn() { - BigInteger currentValue = BigInteger.ZERO; - - if (returnType.equals("Integer_Type")) { - functionString.append("public static INTEGER " + nodeName - + "(){\r\n"); - - functionString.append("return new INTEGER (" + returnStatementValue - + ");\r\n"); - functionString.append("}\r\n"); - } - - } + sendPortReference.clear(); + sendParameter.clear(); + sendParameterType.clear(); - public String getJavaSourceWithoutRunOn() { - - this.writeFunctionWithoutRunsOn(); - functionString.append("\r\n}"); - String returnString = functionString.toString(); - functionString.setLength(0); + AstWalkerJava.logToConsole(" Finished processing: Function " + nodeName); + clearLists(); return returnString; } - public void setRunsOnValue(String runsOnValue) { - this.runsOnValue = runsOnValue; - - } - - public void setReturnType(String returnType) { - this.returnType = returnType; - - } - - public void setReturnStatementValue(String returnStatementValue) { - this.returnStatementValue = returnStatementValue; + public void clearAltLists() { + altStatements.clear(); + altStatementCounter = -1; } - public void setTimerValue(String timerValue) { - this.timerValue = timerValue; - - } - - public void addPortReference(String portRef) { - sendPortReference.add(portRef); - - } - - public void addParameter(String param) { - sendParameter.add(param); - - } - - public void addParameterType(String string) { - sendParameterType.add(string); - - } - - public void setUnknownStartReference(String unknownStartReference) { - this.unknownStartReference = unknownStartReference; - - } - - public void addRecievePortReference(String portRef) { - recievePortReference.add(portRef); + public void clearLists() { + functionString.setLength(0); + returnType = null; + returnStatementValue = null; - } + isThereAStartedTimer = false; - public void addRecieveParameter(String param) { - recieveParameter.add(param); + sendCounter = -1; - } + sendPortReference.clear(); + sendParameter.clear(); + sendParameterType.clear(); - public void addRecieveParameterType(String string) { - recieveParameterType.add(string); + receivePortReference.clear(); + receiveValue.clear(); + receiveAnyValValue.clear(); + receiveType.clear(); - } + functionVars.clear(); + functionVarTypes.clear(); + functionVarValues.clear(); + functionAssignIdentifiers.clear(); + functionAssignValues.clear(); - public void addAddValues(String string) { - addValues.add(string); + functionValueIsAValueReference.clear(); + functionVarIsConstant.clear(); + defCounter = -1; + assignCounter = -1; + receiveStatements.clear(); } } diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_ModulePar_Writer.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_ModulePar_Writer.java new file mode 100644 index 000000000..e8b78b698 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_ModulePar_Writer.java @@ -0,0 +1,95 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar; + +public class Def_ModulePar_Writer { + private Def_ModulePar moduleParNode; + + private StringBuilder moduleParString = new StringBuilder(""); + + private String nodeName = null; + + public List moduleParValues = new ArrayList(); + private String moduleParNodeType = null; + + private static Map moduleParHashes = new LinkedHashMap(); + + private Def_ModulePar_Writer(Def_ModulePar node) { + super(); + this.moduleParNode = node; + nodeName = moduleParNode.getIdentifier().toString(); + } + + + + public static Def_ModulePar_Writer getInstance(Def_ModulePar node) { + if (!moduleParHashes.containsKey(node.getIdentifier().toString())) { + moduleParHashes.put(node.getIdentifier().toString(), + new Def_ModulePar_Writer(node)); + } + return (Def_ModulePar_Writer) moduleParHashes.get(node.getIdentifier() + .toString()); + } + + public void setModuleParNodeType(String value) { + moduleParNodeType = value; + } + + public void writeModuleParConstructor(String rootNodeType, + String prefix) { + + if(moduleParValues.size()>0){ + for(int i=0;i templateListValues = new ArrayList(); + private static List templateAllIdentifiers = new ArrayList(); + private static List templateRefdVals = new ArrayList(); + private boolean waitForTemplateList = false; + private boolean blockTemplateListing = false; + + + public void visit(IVisitableNode node) { + + if (node instanceof Def_Template) { + myASTVisitor.currentFileName = "Templates"; + + Def_Template_Writer.getInstance(((Def_Template) node)); + + myASTVisitor.nodeNameNodeTypeHashMap.put(((Def_Template) node) + .getIdentifier().toString(), "template"); + + waitForModifierValue = true; + waitForTemplateValues = true; + + } + + visitTemplateNodes(node); + } + + public void visitTemplateNodes(IVisitableNode node) { + if (waitForTemplateValues && (node instanceof Reference)) { + Def_Const_Visit_Handler.constNodeType = ((Reference) node).getId() + .toString(); + } + + //ListOfTemplates is returned twice, should be recorded only once + if (waitForTemplateValues && !blockTemplateListing&&(node instanceof ListOfTemplates)) { + waitForTemplateList = true; + } + + if (waitForTemplateValues && (node instanceof SpecificValue_Template)) { + waitForSepcValTemplate = true; + + } + if (waitForTemplateValues + && (node instanceof Undefined_LowerIdentifier_Value)) { + String value = ((Undefined_LowerIdentifier_Value) node) + .getIdentifier().toString(); + + if (waitForTemplateList) { + templateListValues.add(value); + } else { + myASTVisitor.templateIdValuePairs.put(lastTemplateName, value); + } + myASTVisitor.blockIdListing = true; + } + + if (waitForTemplateValues && (node instanceof Charstring_Value)) { + + String value = ((Charstring_Value) node).getValue(); + + if (waitForTemplateList) { + templateListValues.add(value); + } else { + myASTVisitor.templateIdValuePairs.put(lastTemplateName, value); + } + + myASTVisitor.blockIdListing = true; + } + + if (waitForTemplateValues && (node instanceof Integer_Value)) { + + String value = ((Integer_Value) node).toString(); + + if (waitForTemplateList) { + templateListValues.add(value); + } else { + myASTVisitor.templateIdValuePairs.put(lastTemplateName, value); + } + + myASTVisitor.blockIdListing = true; + } + + + if (waitForTemplateValues && (node instanceof Omit_Value)) { + + if (waitForTemplateList) { + templateListValues.add("omit"); + } else { + myASTVisitor.templateIdValuePairs.put(lastTemplateName, "omit"); + } + myASTVisitor.blockIdListing = true; + } + + if (waitForTemplateValues && (node instanceof Any_Value_Template)) { + + if (waitForTemplateList) { + templateListValues.add("?"); + } else { + myASTVisitor.templateIdValuePairs.put(lastTemplateName, "?"); + } + myASTVisitor.blockIdListing = true; + } + + if (waitForTemplateValues && (node instanceof AnyOrOmit_Template)) { + + if (waitForTemplateList) { + templateListValues.add("*"); + } else { + myASTVisitor.templateIdValuePairs.put(lastTemplateName, "*"); + } + myASTVisitor.blockIdListing = true; + } + + if (waitForTemplateValues && (node instanceof Reference)) { + + String value = ((Reference) node).toString().toString(); + + if (waitForTemplateList) { + templateListValues.add(value); + } else if (!waitForSepcValTemplate) { + myASTVisitor.templateIdValuePairs.put(lastTemplateName, value); + } + + myASTVisitor.blockIdListing = true; + } + + if (waitForTemplateValues && (node instanceof Identifier) + && !myASTVisitor.blockIdListing) { + templateAllIdentifiers.add(((Identifier) node).toString()); + lastTemplateName = ((Identifier) node).toString(); + myASTVisitor.templateIDs.add(lastTemplateName); + + if (!isTemplateNameSet) { + currentTemplateNodeName = ((Identifier) node).toString(); + isTemplateNameSet = true; + } + + } + + if (waitForSepcValTemplate && (node instanceof Referenced_Value)) { + templateRefdValCounter++; + waitForTemplateRefdVals = true; + + }// Referenced_Value Reference + + if (waitForTemplateRefdVals && (node instanceof FieldSubReference)) { + if (templateRefdVals.size() == templateRefdValCounter) { + templateRefdVals.add(((FieldSubReference) node).getId() + .toString()); + } else { + templateRefdVals + .set(templateRefdValCounter, + templateRefdVals.get(templateRefdValCounter) + + "." + + ((FieldSubReference) node).getId() + .toString()); + } + } + + if (waitForTemplateValues && (node instanceof Integer_Value)) { + + String value = ((Integer_Value) node).toString(); + + if (myASTVisitor.isNextIntegerNegative) { + value = "-" + value; + } + + if (waitForTemplateList) { + templateListValues.add(value); + } else { + myASTVisitor.templateIdValuePairs.put(lastTemplateName, value); + } + + myASTVisitor.isNextIntegerNegative = false; + } + + if (waitForModifierValue && (node instanceof Named_Template_List)) { + waitForModifierValue = false; + } + + if (waitForModifierValue && (node instanceof Reference)) { + modifierValue = ((Reference) node).getId().toString(); + } + } + + public void leave(IVisitableNode node) { + if (node instanceof Def_Template) { + handleTemplate(node); + } + + if (waitForTemplateValues + && ((node instanceof Undefined_LowerIdentifier_Value) + || (node instanceof Charstring_Value) + || (node instanceof Omit_Value) + || (node instanceof Any_Value_Template) + || (node instanceof AnyOrOmit_Template) || (node instanceof Reference))) { + myASTVisitor.blockIdListing = false; + } + + if (waitForTemplateValues && (node instanceof ListOfTemplates)) { + waitForTemplateList = false; + //ListOfTemplates is returned twice, should be recorded only once + blockTemplateListing= true; + + } + + if (waitForSepcValTemplate && (node instanceof Referenced_Value)) { + myASTVisitor.templateIdValuePairs.put(currentTemplateNodeName, + templateRefdVals.get(templateRefdValCounter)); + + waitForSepcValTemplate = false; + // waitForTemplateRefdVals = false; + + } + } + + public void handleTemplate(IVisitableNode node) { + Def_Template_Writer tempNode = Def_Template_Writer + .getInstance(((Def_Template) node)); + + tempNode.clearLists(); + tempNode.init(); + myASTVisitor.blockIdListing = false; + + tempNode.templateIdentifiers.addAll(templateAllIdentifiers); + tempNode.templateRefdVals.addAll(templateRefdVals); + tempNode.templateListValues.addAll(templateListValues); + + if (modifierValue != null) { + tempNode.setModifierValue(modifierValue); + } + + templateAllIdentifiers.clear(); + templateListValues.clear(); + templateRefdVals.clear(); + isTemplateNameSet = false; + waitForTemplateValues = false; + waitForModifierValue = false; + templateRefdValCounter = -1; + waitForTemplateRefdVals = false; + blockTemplateListing= false; + + myASTVisitor.deleteLastBracket(myASTVisitor.currentFileName); + myASTVisitor.visualizeNodeToJava(tempNode.getJavaSource() + "\r\n}"); + myASTVisitor.templateIDs.clear(); + myASTVisitor.templateIdValuePairs.clear(); + } + +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Template_Writer.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Template_Writer.java index 1352c87ec..95a5c867f 100644 --- a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Template_Writer.java +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Template_Writer.java @@ -20,20 +20,10 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import org.eclipse.titan.designer.AST.ASTNode; -import org.eclipse.titan.designer.AST.IVisitableNode; -import org.eclipse.titan.designer.AST.Value; -import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const; import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template; -import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type; +import org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type; import org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type; -import org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value; -import org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value; -import org.eclipse.titan.designer.AST.TTCN3.values.Omit_Value; -import org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value; -import org.eclipse.titan.designer.AST.TTCN3.values.Sequence_Value; import org.eclipse.titan.designer.parsers.CompilationTimeStamp; -import org.eclipse.titan.designer.AST.Reference; public class Def_Template_Writer { private Def_Template templateNode; @@ -43,50 +33,33 @@ public class Def_Template_Writer { .getNewCompilationCounter(); private String nodeName = null; - private List templateIdentifiers = new ArrayList(); + public List templateListValues = new ArrayList(); + public List templateIdentifiers = new ArrayList(); + public List templateRefdVals = new ArrayList(); private String templateNodeType = null; private String modifierValue = null; - private int idCounter = 0; private int firstIdentifier = 0; private int paramCount = 0; private List paramNames = new ArrayList(); private List paramTypes = new ArrayList(); - private Map idValuePairs = new LinkedHashMap(); - private static Map templateHashes = new LinkedHashMap(); private Def_Template_Writer(Def_Template node) { super(); this.templateNode = node; - if (node.getType(compilationCounter) instanceof Referenced_Type) { - templateNodeType = ((Referenced_Type) node + if (this.templateNode.getType(compilationCounter) instanceof Referenced_Type) { + templateNodeType = ((Referenced_Type) this.templateNode .getType(compilationCounter)).getReference().getId() .toString(); - } - firstIdentifier = 1; - if (node.getFormalParameterList() != null) { - paramCount = node.getFormalParameterList().getNofParameters(); - for (int i = 0; i < paramCount; i++) { - paramNames.add(node.getFormalParameterList() - .getParameterByIndex(i).getIdentifier().toString()); - if (node.getFormalParameterList().getParameterByIndex(i) - .getType(compilationCounter) instanceof Referenced_Type) { + } else if (this.templateNode.getType(compilationCounter) instanceof Integer_Type) { + templateNodeType = "INTEGER"; - paramTypes.add(((Referenced_Type) node - .getFormalParameterList().getParameterByIndex(i) - .getType(compilationCounter)).getReference() - .getId().toString()); - } - firstIdentifier++; - } } - idCounter = firstIdentifier; - nodeName = node.getIdentifier().toString(); } @@ -99,11 +72,7 @@ public class Def_Template_Writer { .toString()); } - public void addTemplateIdentifiers(String value) { - templateIdentifiers.add(value); - } - - public void writeTempltaeConstructor(String rootNodeType, String prefix) { + public void writeTemplateConstructor(String rootNodeType, String prefix) { if (myASTVisitor.nodeNameChildrenNamesHashMap.containsKey(rootNodeType)) { if (myASTVisitor.nodeNameNodeTypeHashMap.get(rootNodeType).equals( @@ -125,6 +94,10 @@ public class Def_Template_Writer { prefix = "((SC_" + unionElementId + "_" + rootNodeType + ")value)"; + } else if (myASTVisitor.nodeNameNodeTypeHashMap.get(rootNodeType).equals( + "record")){ + templateString.append(prefix + "= new " + rootNodeType + "();\r\n"); + } String[] childrenNodeNames = myASTVisitor.nodeNameChildrenNamesHashMap @@ -148,7 +121,7 @@ public class Def_Template_Writer { String prefixBackup = prefix; prefix = prefix.concat("." + childrenNodeNames[i]); - writeTempltaeConstructor(childrenNodeTypes[i], prefix); + writeTemplateConstructor(childrenNodeTypes[i], prefix); prefix = prefixBackup; @@ -159,6 +132,8 @@ public class Def_Template_Writer { .containsKey(childrenNodeNames[i])) { String currentvalue = myASTVisitor.templateIdValuePairs .get(childrenNodeNames[i]); + + if (myASTVisitor.nodeNameNodeTypeHashMap .containsKey(currentvalue)) { if (myASTVisitor.nodeNameNodeTypeHashMap.get( @@ -183,7 +158,14 @@ public class Def_Template_Writer { } } } + } else if (childrenNodeTypes[i].equals("INTEGER")){ + templateString.append(prefix + "." + + childrenNodeNames[i] + + "= new INTEGER(new BigInteger(\"" + currentvalue + + "\"));\r\n"); } + + } // everything else @@ -301,13 +283,27 @@ public class Def_Template_Writer { } } } + } if(templateListValues.size() > 0 ){ + if (childrenNodeTypes[i].equals("INTEGER")){ + templateString.append(prefix + "." + + childrenNodeNames[i] + + "= new INTEGER(new BigInteger(\"" + templateListValues.get(i) + + "\"));\r\n"); + } } + + } + } else if (rootNodeType.equals("INTEGER")) { + String integerValue = myASTVisitor.templateIdValuePairs + .get(nodeName); + templateString.append("value=new INTEGER(new BigInteger(\"" + + integerValue + "\"));\r\n"); } } - public void writeModifierTempltaeConstructor(String rootNodeType, + public void writeModifierTemplateConstructor(String rootNodeType, String prefix) { if (myASTVisitor.nodeNameChildrenNamesHashMap.containsKey(rootNodeType)) { @@ -325,9 +321,8 @@ public class Def_Template_Writer { } } - templateString.append(prefix + "= " - + modifierValue - + "();\r\n"); + templateString + .append(prefix + "= " + modifierValue + "();\r\n"); prefix = "((SC_" + unionElementId + "_" + rootNodeType + ")value)"; @@ -368,7 +363,7 @@ public class Def_Template_Writer { String prefixBackup = prefix; prefix = prefix.concat("." + childrenNodeNames[i]); - writeModifierTempltaeConstructor(childrenNodeTypes[i], + writeModifierTemplateConstructor(childrenNodeTypes[i], prefix); prefix = prefixBackup; @@ -425,15 +420,7 @@ public class Def_Template_Writer { } else if (myASTVisitor.nodeNameNodeTypeHashMap.get( childrenNodeTypes[i]).equals("CHARSTRING")) { - /* - * templateString.append(prefix + "." + - * childrenNodeNames[i] + "=new " + - * childrenNodeTypes[i] + "(new " + - * myASTVisitor.nodeNameNodeTypeHashMap - * .get(childrenNodeTypes[i]) + "(\"" + - * myASTVisitor.templateIdValuePairs - * .get(childrenNodeNames[i]) + "\"));" + "\r\n"); - */ + // TODO CHARSTRING } @@ -456,14 +443,7 @@ public class Def_Template_Writer { childrenNodeNames[i], true, false, false, true); } else { - - /* - * templateString.append(prefix + "." + - * childrenNodeNames[i] + "=new " + - * childrenNodeTypes[i] + "(\"" + - * myASTVisitor.templateIdValuePairs - * .get(childrenNodeNames[i]) + "\");" + "\r\n"); - */ + // TODO rest } } if (myASTVisitor.nodeNameChildrenNamesHashMap @@ -487,6 +467,15 @@ public class Def_Template_Writer { } } } + } else if (rootNodeType.equals("INTEGER")) { + String integerValue = myASTVisitor.templateIdValuePairs + .get(nodeName); + + // if (paramCount > 0) { + templateString.append("value=new INTEGER(new BigInteger(\"" + + integerValue + "\"));\r\n"); + // } + } } @@ -533,8 +522,42 @@ public class Def_Template_Writer { } } + public void clearLists() { + templateListValues.clear(); + templateIdentifiers.clear(); + templateRefdVals.clear(); + paramNames.clear(); + paramTypes.clear(); + + } + + public void init() { + + firstIdentifier = 1; + if (templateNode.getFormalParameterList() != null) { + paramCount = templateNode.getFormalParameterList() + .getNofParameters(); + for (int i = 0; i < paramCount; i++) { + paramNames.add(templateNode.getFormalParameterList() + .getParameterByIndex(i).getIdentifier().toString()); + if (templateNode.getFormalParameterList() + .getParameterByIndex(i).getType(compilationCounter) instanceof Referenced_Type) { + + paramTypes.add(((Referenced_Type) templateNode + .getFormalParameterList().getParameterByIndex(i) + .getType(compilationCounter)).getReference() + .getId().toString()); + } + firstIdentifier++; + } + } + } + public String getJavaSource() { + AstWalkerJava.logToConsole(" Starting processing: Template " + + nodeName); + templateString.append("public static " + templateNodeType + " " + nodeName + "("); @@ -547,20 +570,24 @@ public class Def_Template_Writer { templateString.append(templateNodeType + " value;\r\n"); if ((modifierValue == null)) { - writeTempltaeConstructor(templateNodeType, "value"); + writeTemplateConstructor(templateNodeType, "value"); } else { - writeModifierTempltaeConstructor(templateNodeType, "value"); - + writeModifierTemplateConstructor(templateNodeType, "value"); + } templateString.append("return value;\r\n"); templateString.append("}\r\n"); String returnString = templateString.toString(); - modifierValue=null; - idCounter = firstIdentifier; + modifierValue = null; + templateString.setLength(0); + AstWalkerJava.logToConsole(" Finished processing: Template " + + nodeName); + return returnString; + } public void setModifierValue(String modifierValue) { diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Testcase_Writer.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Testcase_Writer.java index 4e7e8fe0c..9f4b8d0f8 100644 --- a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Testcase_Writer.java +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Testcase_Writer.java @@ -20,62 +20,134 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import org.eclipse.titan.designer.AST.Reference; import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase; -import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type; +import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Timer; +import org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement; import org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement; import org.eclipse.titan.designer.AST.TTCN3.statements.Connect_Statement; import org.eclipse.titan.designer.AST.TTCN3.statements.Definition_Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.Disconnect_Statement; import org.eclipse.titan.designer.AST.TTCN3.statements.Done_Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.If_Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.Map_Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.Send_Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.Setverdict_Statement; import org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock; +import org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock_Statement; import org.eclipse.titan.designer.AST.TTCN3.statements.Unknown_Start_Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.Unknown_Stop_Statement; import org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template; -import org.eclipse.titan.designer.AST.TTCN3.types.CompField; -import org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type; +import org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value; +import org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value; import org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value; +import org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value; +import org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value; import org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value; +import org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value; +import org.eclipse.titan.designer.AST.TTCN3.values.Verdict_Value; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.AddExpression; import org.eclipse.titan.designer.AST.TTCN3.values.expressions.ComponentCreateExpression; -import org.eclipse.titan.designer.parsers.CompilationTimeStamp; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.DivideExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.ModuloExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.MultiplyExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.RemainderExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.SubstractExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.UnaryMinusExpression; public class Def_Testcase_Writer { private Def_Testcase testCaseNode; private StringBuilder testCaseString = new StringBuilder(""); - private CompilationTimeStamp compilationCounter = CompilationTimeStamp - .getNewCompilationCounter(); + /* + * private CompilationTimeStamp compilationCounter = CompilationTimeStamp + * .getNewCompilationCounter(); + */ + + public String nodeName = null; - private String nodeName=null; - private static Map testcaseHashes = new LinkedHashMap(); - private String testCaseRunsOn=null; - private StatementBlock tcStatementBlock; - - private List tcVars = new ArrayList(); - private List tcVarTypes = new ArrayList(); - private List tcAssignValues = new ArrayList(); - private List tcCreateValues = new ArrayList(); - private List tcCreateCounter = new ArrayList(); - - private int createCounter=-1; - - private List tcConnectValues = new ArrayList(); - private List tcConnectCounter = new ArrayList(); - private int connectCounter=-1; - - private List tcStartValues = new ArrayList(); - private List tcStartCounter = new ArrayList(); - private int startCounter=-1; + public String testCaseRunsOn = null; + private String currentTimerName = null; + + public StatementBlock tcMainStatementBlock; + + public int sendCounter = -1; + public int assignCounter = -1; + private int createCounter = -1; + private int startStatementCounter = -1; + private int stopStatementCounter = -1; + private int connectCounter = -1; + private int currentCounterValue = 0; + private int logCreateCounter = 0; + private int currentMapValueIndex = 0; + private int defCounter = -1; + private int defValueCounter = -1; + private int mapCounter = 0; + private int tcIfConditionCounter = -1; + + private int disconnectCounter = -1; + private int altStatementCounter = -1; + + private boolean blockWriter = false; + private boolean isThereAStartedTimer = false; + + public static List sendPortReference = new ArrayList(); + public static List sendParameter = new ArrayList(); + public static List sendParameterType = new ArrayList(); + public List tcVars = new ArrayList(); + public List tcVarTypes = new ArrayList(); + public List tcVarValues = new ArrayList(); + public List tcAssignIdentifiers = new ArrayList(); + public List tcAssignValues = new ArrayList(); + public List tcCreateValues = new ArrayList(); + public List tcCreateCounter = new ArrayList(); + public List tcConnectValues = new ArrayList(); + public List tcStartIdentifiers = new ArrayList(); + public List tcStartCounter = new ArrayList(); + public List tcMapValues = new ArrayList(); + public List tcMapCounter = new ArrayList(); + public List tcIfConditions = new ArrayList(); + public List testCaseStartValueParameters = new ArrayList(); + public List tcDisconnectValues = new ArrayList(); + public List tcVarIsConstant = new ArrayList(); + public List tcVarIsTemplate = new ArrayList(); + public List tcValueIsAValueReference = new ArrayList(); + public List tcValueTypeIsAReference = new ArrayList(); + + public List tcStopIdentifiers = new ArrayList(); + public List tcStopCounter = new ArrayList(); + public List testCaseStopValueParameters = new ArrayList(); + + public List altStatements = new ArrayList(); + + public int receiveCounter = -1; + + public List receivePortReference = new ArrayList(); + public List receiveValue = new ArrayList(); + public List receiveAnyValValue = new ArrayList(); + public List receiveType = new ArrayList(); + public List receiveStatements = new ArrayList(); + + public List nodeVarIsRecord = new ArrayList(); + + public int structSize = 0; + public int currentRecordCounter = 0; + private boolean blockStatementBlockStatementWriter = false; private Def_Testcase_Writer(Def_Testcase typeNode) { super(); this.testCaseNode = typeNode; nodeName = typeNode.getIdentifier().toString(); + } public static Def_Testcase_Writer getInstance(Def_Testcase typeNode) { if (!testcaseHashes.containsKey(typeNode.getIdentifier().toString())) { - testcaseHashes.put(typeNode.getIdentifier().toString(), new Def_Testcase_Writer(typeNode)); + testcaseHashes.put(typeNode.getIdentifier().toString(), + new Def_Testcase_Writer(typeNode)); } - return (Def_Testcase_Writer) testcaseHashes.get(typeNode.getIdentifier().toString()); + return (Def_Testcase_Writer) testcaseHashes.get(typeNode + .getIdentifier().toString()); } public String writeTestcaseFile(Def_Testcase testNode) { @@ -84,16 +156,14 @@ public class Def_Testcase_Writer { testCaseString.append("public class " + nodeName + " implements Runnable{ " + "\r\n"); testCaseString.append(" " + "\r\n"); - testCaseString.append(" private " + testCaseRunsOn - + " component;" + "\r\n"); - testCaseString.append(" public " - + nodeName + "(" - + testCaseRunsOn + " c){" + "\r\n"); + testCaseString.append(" private " + testCaseRunsOn + " component;" + + "\r\n"); + testCaseString.append(" public " + nodeName + "(" + testCaseRunsOn + + " c){" + "\r\n"); testCaseString.append(" component = c;" + "\r\n"); testCaseString.append(" }" + "\r\n"); testCaseString.append(" public void run(){" + "\r\n"); - testCaseString.append(" component." - + nodeName + "();" + "\r\n"); + testCaseString.append(" component." + nodeName + "();" + "\r\n"); testCaseString.append(" component.hc.finished(component, \"" + nodeName + "\");" + "\r\n"); testCaseString.append(" }" + "\r\n"); @@ -101,258 +171,956 @@ public class Def_Testcase_Writer { return testCaseString.toString(); } - - public String writeTestCaseFunction() { - - String createLocation = ""; - String createName = ""; - String createType = ""; - testCaseString.append("public void " + nodeName - + "(){" + "\r\n"); + public void writeTestCaseFunctionHeader(StatementBlock tcStatementBlock) { + testCaseString.append("\r\n"); + testCaseString.append("public void " + nodeName + "(){" + "\r\n"); testCaseString.append("String sourcefilename = \"" + testCaseNode.getLocation().getFile().getFullPath() .lastSegment() + "\";" + "\r\n"); - testCaseString.append("int rownum=" +tcStatementBlock.getLocation().getLine()+ ";\r\n"); + testCaseString.append("int rownum=" + + tcStatementBlock.getLocation().getLine() + ";\r\n"); testCaseString.append("while(!created);" + "\r\n"); - - testCaseString.append("TTCN3Logger.writeLog(\"mtc\", \"PARALLEL\", sourcefilename, rownum, \"testcase\", \""+nodeName+"\", \"Testcase started on mtc\", false);"+ "\r\n"); - int currentCounterValue=0; - int logCreateCounter=0; - - int currentConnectValue=0; - int logConnectCounter=0; - - int currentStartValue=0; - int logStartCounter=0; - int testcaseSize = tcStatementBlock.getSize(); - for (int j = 0; j < testcaseSize; j++) { - - if (tcStatementBlock.getStatementByIndex(j) instanceof Definition_Statement) { - //TODO: tcVars and tcVarTypes hold the def statement values - } - if (tcStatementBlock.getStatementByIndex(j) instanceof Assignment_Statement) { - Assignment_Statement tc_assignStatement = (Assignment_Statement) tcStatementBlock - .getStatementByIndex(j); - - if (tc_assignStatement.getTemplate() instanceof SpecificValue_Template) { - SpecificValue_Template specValTemplate = (SpecificValue_Template) tc_assignStatement - .getTemplate(); - if (specValTemplate.getSpecificValue() instanceof ComponentCreateExpression) { - ComponentCreateExpression componenetCreateExp = (ComponentCreateExpression) specValTemplate - .getSpecificValue(); - - createCounter++; - logCreateCounter++; - int logSizeValue=1; - while(tcCreateCounter.get(logCreateCounter).equals(String.valueOf(createCounter))){ - logCreateCounter++; - logSizeValue++; - if(tcCreateCounter.size()==(logCreateCounter)){ - break;} - - } - String[] logValues=new String[logSizeValue]; - int logWriteCounter=0; - testCaseString.append("rownum="+componenetCreateExp.getLocation().getLine()+";\r\n"); - testCaseString.append("hc.create("+"\"" +tcCreateValues.get(currentCounterValue)+"\""); - logValues[logWriteCounter]=tcCreateValues.get(currentCounterValue); - currentCounterValue++; - - logWriteCounter++; - while(tcCreateCounter.get(currentCounterValue).equals(String.valueOf(createCounter))){ - testCaseString.append(",\"" +tcCreateValues.get(currentCounterValue)+"\""); - - logValues[logWriteCounter]=tcCreateValues.get(currentCounterValue); - logWriteCounter++; - currentCounterValue++; - - if(tcCreateCounter.size()==(currentCounterValue)){ - break;} - - } - testCaseString.append( "); "+ "\r\n"); - - testCaseString.append("TTCN3Logger.writeLog(\"mtc\", \"PARALLEL\", sourcefilename, rownum, \"testcase\", \""+nodeName+"\", \"Starting PTC "+logValues[0]+" type "+logValues[1]+" on "+logValues[2]+"\", false);"+"\r\n"); - - - } + testCaseString + .append("TTCN3Logger.writeLog(\"mtc\", \"PARALLEL\", sourcefilename, rownum, \"testcase\", \"" + + nodeName + + "\", \"Testcase started on mtc\", false);" + + "\r\n"); + } - } + public String getJavaSource() { + testCaseString.setLength(0); + AstWalkerJava.logToConsole(" Starting processing: Testcase " + + nodeName); + + this.writeTestCaseFunctionHeader(tcMainStatementBlock); + + this.writeTestCaseFunction(tcMainStatementBlock); + + String returnString = testCaseString.toString(); + testCaseString.setLength(0); + + AstWalkerJava.logToConsole(" Finished processing: Testcase " + + nodeName); + + return returnString; + } + + public String writeTestCaseFunction(StatementBlock tcStatementBlock) { + + int testcaseSize = tcStatementBlock.getSize(); + + for (int j = 0; j < testcaseSize; j++) { + + if (tcStatementBlock.getStatementByIndex(j) instanceof Definition_Statement) { + + Definition_Statement tc_defStatement = (Definition_Statement) tcStatementBlock + .getStatementByIndex(j); + defCounter++; + defValueCounter++; + writeDefinitionStatement(tc_defStatement); + + } else if (tcStatementBlock.getStatementByIndex(j) instanceof Assignment_Statement) { + Assignment_Statement tc_assignStatement = (Assignment_Statement) tcStatementBlock + .getStatementByIndex(j); + + assignCounter++; + + testCaseString + .append(writeAssignmentStatement(tc_assignStatement)); + + } else if (tcStatementBlock.getStatementByIndex(j) instanceof Connect_Statement) { + Connect_Statement tc_connectStatement = (Connect_Statement) tcStatementBlock + .getStatementByIndex(j); + connectCounter++; + + writeConnectStatement(tc_connectStatement); + + } else if (tcStatementBlock.getStatementByIndex(j) instanceof Unknown_Start_Statement) { + Unknown_Start_Statement tc_startStatement = (Unknown_Start_Statement) tcStatementBlock + .getStatementByIndex(j); + + writeUnknownStartStatement(tc_startStatement); + + } else if (tcStatementBlock.getStatementByIndex(j) instanceof Done_Statement) { + + testCaseString.append("hc.done(\"all component\");" + "\r\n"); + // TODO: where is all coming from? + + } else if (tcStatementBlock.getStatementByIndex(j) instanceof Map_Statement) { + Map_Statement tc_mapStatement = (Map_Statement) tcStatementBlock + .getStatementByIndex(j); + mapCounter++; + + writeMapStatement(tc_mapStatement); + + } else if (tcStatementBlock.getStatementByIndex(j) instanceof If_Statement) { + If_Statement tc_ifStatement = (If_Statement) tcStatementBlock + .getStatementByIndex(j); + + tcIfConditionCounter++; + + writeIfStatement(tc_ifStatement); + + } else if (tcStatementBlock.getStatementByIndex(j) instanceof Setverdict_Statement) { + + Setverdict_Statement tc_setVerdictStatement = (Setverdict_Statement) tcStatementBlock + .getStatementByIndex(j); + + writeSetVerdictStatement(tc_setVerdictStatement); + + } else if (tcStatementBlock.getStatementByIndex(j) instanceof Send_Statement) { + Send_Statement tc_SendStatement = (Send_Statement) tcStatementBlock + .getStatementByIndex(j); + + sendCounter++; + + testCaseString.append(writeSendStatement(tc_SendStatement)); + + } else if (tcStatementBlock.getStatementByIndex(j) instanceof Receive_Port_Statement) { + Receive_Port_Statement tc_ReceiveStatement = (Receive_Port_Statement) tcStatementBlock + .getStatementByIndex(j); + + receiveCounter++; + + blockStatementBlockStatementWriter = true; + + testCaseString + .append(writeReceiveStatement(tc_ReceiveStatement)); + + } else if (tcStatementBlock.getStatementByIndex(j) instanceof Unknown_Stop_Statement) { + Unknown_Stop_Statement tc_StopStatement = (Unknown_Stop_Statement) tcStatementBlock + .getStatementByIndex(j); + + writeUnknownStopStatement(tc_StopStatement); + + } else if (tcStatementBlock.getStatementByIndex(j) instanceof Alt_Statement) { + + altStatementCounter++; + altStatements.get(altStatementCounter).setTimerInfo( + isThereAStartedTimer, currentTimerName); + + testCaseString.append(altStatements.get(altStatementCounter) + .getJavaSource()); + + } else if (tcStatementBlock.getStatementByIndex(j) instanceof Disconnect_Statement) { + Disconnect_Statement tc_disconnectStatement = (Disconnect_Statement) tcStatementBlock + .getStatementByIndex(j); + disconnectCounter++; + + writeDisconnectStatement(tc_disconnectStatement); + + } else if ((tcStatementBlock.getStatementByIndex(j) instanceof StatementBlock_Statement) + && !blockStatementBlockStatementWriter) { + StatementBlock_Statement tc_statementBlockStatement = (StatementBlock_Statement) tcStatementBlock + .getStatementByIndex(j); + blockStatementBlockStatementWriter = false; + testCaseString.append("{\r\n"); + blockWriter = true; + writeTestCaseFunction(tc_statementBlockStatement + .getStatementBlock()); + blockWriter = false; + testCaseString.append("}\r\n"); + + } + } + + if (!blockWriter) { + testCaseString.append("}" + "\r\n"); + } + + return testCaseString.toString(); + } + + public void writeDefinitionStatement(Definition_Statement tc_defStatement) { + if (tc_defStatement.getDefinition() instanceof Def_Timer) { + Def_Timer def_Timer = (Def_Timer) tc_defStatement.getDefinition(); + + testCaseString.append("rownum=" + def_Timer.getLocation().getLine() + + ";\r\n"); + testCaseString.append("Timer " + + def_Timer.getIdentifier().toString() + + " = new Timer (new FLOAT(" + tcVarValues.get(defCounter) + + "));\r\n"); + + testCaseString + .append("TTCN3Logger.writeLog(\"mtc\", \"TIMEROP\", sourcefilename, rownum, \"function\", \"" + + nodeName + + "\", \"Timer " + + def_Timer.getIdentifier().toString() + + " set to " + + tcVarValues.get(defCounter) + ".\", false);" + "\r\n"); + + } else if (tcVarTypes.get(defCounter).equals("BITSTRING")) { + + testCaseString.append("rownum=" + + tc_defStatement.getLocation().getLine() + ";\r\n"); + + if (tcVarIsConstant.get(defCounter)) { + testCaseString.append("final "); + } + + if (tcVarIsTemplate.get(defCounter)) { + testCaseString.append("template "); + } + + if (tcVarValues.get(defValueCounter) == null) { + testCaseString.append(tcVarTypes.get(defCounter) + " " + + tcVars.get(defCounter) + "=new BITSTRING();\r\n"); + // TODO: add logging here + } else if (tcValueIsAValueReference.get(defCounter)) { + testCaseString.append(tcVarTypes.get(defCounter) + " " + + tcVars.get(defCounter) + "=" + + tcVarValues.get(defValueCounter) + ";\r\n"); + // TODO: add logging here + } else { + testCaseString.append(tcVarTypes.get(defCounter) + " " + + tcVars.get(defCounter) + "=new BITSTRING(\"" + + tcVarValues.get(defValueCounter) + "\");\r\n"); + // TODO: add logging here + } + + } else if (tcVarTypes.get(defCounter).equals("INTEGER")) { + + testCaseString.append("rownum=" + + tc_defStatement.getLocation().getLine() + ";\r\n"); + if (tcVarIsConstant.get(defCounter)) { + testCaseString.append("final "); + } + + if (tcVarIsTemplate.get(defCounter)) { + testCaseString.append("template "); + } + + if (tcVarValues.get(defValueCounter) == null) { + testCaseString.append(tcVarTypes.get(defCounter) + " " + + tcVars.get(defCounter) + "=new INTEGER();\r\n"); + // TODO: add logging here + } else if (tcValueIsAValueReference.get(defCounter)) { + testCaseString.append(tcVarTypes.get(defCounter) + " " + + tcVars.get(defCounter) + "=" + + tcVarValues.get(defValueCounter) + ";\r\n"); + // TODO: add logging here + } else { + testCaseString.append(tcVarTypes.get(defCounter) + " " + + tcVars.get(defCounter) + + "=new INTEGER(new BigInteger(\"" + + tcVarValues.get(defValueCounter) + "\"));\r\n"); + // TODO: add logging here + } + + } else if (tcVarTypes.get(defCounter).equals("CHARSTRING")) { + + testCaseString.append("rownum=" + + tc_defStatement.getLocation().getLine() + ";\r\n"); + + if (tcVarIsConstant.get(defCounter)) { + testCaseString.append("final "); + } + + if (tcVarIsTemplate.get(defCounter)) { + testCaseString.append("template "); + } + + if (tcVarValues.get(defValueCounter) == null) { + testCaseString.append(tcVarTypes.get(defCounter) + " " + + tcVars.get(defCounter) + "=new CHARSTRING();\r\n"); + // TODO: add logging here + } else if (tcValueIsAValueReference.get(defCounter)) { + testCaseString.append(tcVarTypes.get(defCounter) + " " + + tcVars.get(defCounter) + "=" + + tcVarValues.get(defValueCounter) + ";\r\n"); + // TODO: add logging here + } else { + testCaseString.append(tcVarTypes.get(defCounter) + " " + + tcVars.get(defCounter) + "=new CHARSTRING(\"" + + tcVarValues.get(defValueCounter) + "\");\r\n"); + // TODO: add logging here + } + + } else if (tcVarTypes.get(defCounter).equals("OCTETSTRING")) { + testCaseString + .append("rownum = ") + .append(tc_defStatement.getLocation().getLine()) + .append(";") + .append("\r\n"); + // TODO : replace each "\r\n" with System.lineSeparator() to make it cross-platform + + if (tcVarIsConstant.get(defCounter)) { + testCaseString.append("final "); + } + + if (tcVarIsTemplate.get(defCounter)) { + testCaseString.append("template "); + } + + if (tcVarValues.get(defValueCounter) == null) { + testCaseString.append(tcVarTypes.get(defCounter) + " " + + tcVars.get(defCounter) + "=new OCTETSTRING();\r\n"); + // TODO: add logging here + } else if (tcValueIsAValueReference.get(defCounter)) { + testCaseString.append(tcVarTypes.get(defCounter) + " " + + tcVars.get(defCounter) + "=" + + tcVarValues.get(defValueCounter) + ";\r\n"); + // TODO: add logging here + } else { + testCaseString.append(tcVarTypes.get(defCounter) + " " + + tcVars.get(defCounter) + "=new OCTETSTRING(\"" + + tcVarValues.get(defValueCounter) + "\");\r\n"); + // TODO: add logging here + } + + } else if (tcVarTypes.get(defCounter).equals("BOOLEAN")) { + + testCaseString.append("rownum=" + + tc_defStatement.getLocation().getLine() + ";\r\n"); + + if (tcVarIsConstant.get(defCounter)) { + testCaseString.append("final "); + } + + if (tcVarIsTemplate.get(defCounter)) { + testCaseString.append("template "); + } + + if (tcVarValues.get(defValueCounter) == null) { + testCaseString.append(tcVarTypes.get(defCounter) + " " + + tcVars.get(defCounter) + "=new BOOLEAN();\r\n"); + // TODO: add logging here + } else if (tcValueIsAValueReference.get(defCounter)) { + testCaseString.append(tcVarTypes.get(defCounter) + " " + + tcVars.get(defCounter) + "=" + + tcVarValues.get(defValueCounter) + ";\r\n"); + // TODO: add logging here + } else { + testCaseString.append(tcVarTypes.get(defCounter) + " " + + tcVars.get(defCounter) + "=new BOOLEAN(" + + tcVarValues.get(defValueCounter) + ");\r\n"); + // TODO: add logging here + } + + } else if (nodeVarIsRecord.get(defCounter)) { + + testCaseString.append("rownum=" + + tc_defStatement.getLocation().getLine() + ";\r\n"); + + testCaseString.append(tcVarTypes.get(defCounter) + " " + + tcVars.get(defCounter) + "= new " + + tcVarTypes.get(defCounter) + "();\r\n"); - + int childSize = myASTVisitor.nodeNameChildrenNamesHashMap + .get(tcVarTypes.get(defCounter)).length; + for (int i = 0; i < childSize; i++) { + + String childType = myASTVisitor.nodeNameChildrenTypesHashMap + .get(tcVarTypes.get(defCounter))[i]; + String childName = myASTVisitor.nodeNameChildrenNamesHashMap + .get(tcVarTypes.get(defCounter))[i]; + + testCaseString.append("rownum=" + + tc_defStatement.getLocation().getLine() + ";\r\n"); + + writeRecordChildren(childType, childName); + + if (i + 1 < childSize) { + defValueCounter++; } + } - if (tcStatementBlock.getStatementByIndex(j) instanceof Connect_Statement) { - Connect_Statement tc_connectStatement = (Connect_Statement) tcStatementBlock - .getStatementByIndex(j); - connectCounter++; - logConnectCounter++; - int logSizeValue=1; - while(tcConnectCounter.get(logConnectCounter).equals(String.valueOf(connectCounter))){ - logConnectCounter++; - logSizeValue++; - if(tcConnectCounter.size()==(logConnectCounter)){ - break;} - - } - - String[] logValues=new String[logSizeValue]; - int logWriteCounter=0; - testCaseString.append("rownum="+tc_connectStatement.getLocation().getLine()+";\r\n"); - testCaseString.append("hc.connect("+"\"" +tcConnectValues.get(currentConnectValue)+"\""); - - logValues[logWriteCounter]=tcConnectValues.get(currentConnectValue); - currentConnectValue++; + } else if (tcValueTypeIsAReference.get(defCounter)) { + testCaseString.append("rownum=" + + tc_defStatement.getLocation().getLine() + ";\r\n"); - logWriteCounter++; + if (tcVarIsConstant.get(defCounter)) { + testCaseString.append("final "); + } - while(tcConnectCounter.get(currentConnectValue).equals(String.valueOf(connectCounter))){ - testCaseString.append(",\"" +tcConnectValues.get(currentConnectValue)+"\""); - - logValues[logWriteCounter]=tcConnectValues.get(currentConnectValue); - logWriteCounter++; - currentConnectValue++; - if(tcConnectCounter.size()==(currentConnectValue)){break;} - + if (tcVarIsTemplate.get(defCounter)) { + testCaseString.append("template "); + } + + if (tcVarValues.get(defValueCounter) == null) { + testCaseString.append(tcVarTypes.get(defCounter) + " " + + tcVars.get(defCounter) + ";\r\n"); + // TODO: add logging here + } else if (tcValueIsAValueReference.get(defCounter)) { + + if (myASTVisitor.nodeNameNodeTypeHashMap.containsKey(tcVarTypes + .get(defCounter))) { + if (myASTVisitor.nodeNameNodeTypeHashMap.get( + tcVarTypes.get(defCounter)).equals("enum")) { + testCaseString + .append(tcVarTypes.get(defCounter) + " " + + tcVars.get(defCounter) + "= new " + + tcVarTypes.get(defCounter) + "(\"" + + tcVarValues.get(defValueCounter) + + "\");\r\n"); } - - testCaseString.append( "); "+ "\r\n"); - - - testCaseString.append("TTCN3Logger.writeLog(\"mtc\", \"PARALLEL\", sourcefilename, rownum, \"testcase\", \""+nodeName+"\", \"Connecting port "+logValues[1]+" of "+logValues[0]+" to port "+logValues[3]+" of "+logValues[2]+"\", false);"+"\r\n"); - - - - + } else { + testCaseString.append(tcVarTypes.get(defCounter) + " " + + tcVars.get(defCounter) + "=" + + tcVarValues.get(defValueCounter) + ";\r\n"); } + // TODO: add logging here + } else { + testCaseString.append(tcVarTypes.get(defCounter) + " " + + tcVars.get(defCounter) + "=" + + tcVarValues.get(defValueCounter) + ";\r\n"); + // TODO: add logging here + } + } + + } - if (tcStatementBlock.getStatementByIndex(j) instanceof Unknown_Start_Statement) { - Unknown_Start_Statement tc_startStatement = (Unknown_Start_Statement) tcStatementBlock.getStatementByIndex(j); - startCounter++; - logStartCounter++; - int logSizeValue=1; - while(tcStartCounter.get(logStartCounter).equals(String.valueOf(startCounter))){ - logStartCounter++; - logSizeValue++; - if(tcStartCounter.size()==(logStartCounter)){ - break;} - + public void writeRecordChildren(String childType, String childName) { + + if (childType.equals("INTEGER")) { + testCaseString.append(tcVars.get(defCounter) + "." + childName + + "=" + + tcVarValues.get(defValueCounter) + ";\r\n"); + } else if (childType.equals("CHARSTRING")) { + + } else if (childType.equals("BITSTRING")) { + + } else if (childType.equals("BOOLEAN")) { + + } + } + + public String writeAssignmentStatement( + Assignment_Statement tc_assignStatement) { + + StringBuilder testCaseString = new StringBuilder(""); + + if (tc_assignStatement.getTemplate() instanceof SpecificValue_Template) { + SpecificValue_Template specValTemplate = (SpecificValue_Template) tc_assignStatement + .getTemplate(); + if (specValTemplate.getSpecificValue() instanceof ComponentCreateExpression) { + ComponentCreateExpression componenetCreateExp = (ComponentCreateExpression) specValTemplate + .getSpecificValue(); + + createCounter++; + logCreateCounter++; + int logSizeValue = 1; + while (tcCreateCounter.get(logCreateCounter).equals( + String.valueOf(createCounter))) { + logCreateCounter++; + logSizeValue++; + if (tcCreateCounter.size() == (logCreateCounter)) { + break; } - - String[] logValues=new String[logSizeValue]; - int logWriteCounter=0; - testCaseString.append("rownum="+tc_startStatement.getLocation().getLine()+";\r\n"); - testCaseString.append("hc.start("+"\"" +tcStartValues.get(currentStartValue)+"\""); - - logValues[logWriteCounter]=tcStartValues.get(currentStartValue); - currentStartValue++; + } + String[] logValues = new String[logSizeValue]; + int logWriteCounter = 0; + testCaseString + .append("rownum=" + + componenetCreateExp.getLocation().getLine() + + ";\r\n"); + testCaseString.append("hc.create(" + "\"" + + tcCreateValues.get(currentCounterValue) + "\""); + logValues[logWriteCounter] = tcCreateValues + .get(currentCounterValue); + currentCounterValue++; + + logWriteCounter++; + while (tcCreateCounter.get(currentCounterValue).equals( + String.valueOf(createCounter))) { + testCaseString.append(",\"" + + tcCreateValues.get(currentCounterValue) + "\""); + + logValues[logWriteCounter] = tcCreateValues + .get(currentCounterValue); logWriteCounter++; - - while(tcStartCounter.get(currentStartValue).equals(String.valueOf(startCounter))){ - testCaseString.append(",\"" +tcStartValues.get(currentStartValue)+"\""); - - logValues[logWriteCounter]=tcStartValues.get(currentStartValue); - logWriteCounter++; - currentStartValue++; - if(tcStartCounter.size()==(currentStartValue)){break;} - + currentCounterValue++; + + if (tcCreateCounter.size() == (currentCounterValue)) { + break; } - - testCaseString.append( "); "+ "\r\n"); - testCaseString.append("TTCN3Logger.writeLog(\"mtc\", \"PARALLEL\", sourcefilename, rownum, \"testcase\", \""+nodeName+"\", \"Starting function "+logValues[1]+" on component "+logValues[0]+"\", false);"+"\r\n"); } + testCaseString.append("); " + "\r\n"); - if (tcStatementBlock.getStatementByIndex(j) instanceof Done_Statement) { - Done_Statement tc_doneStatement = (Done_Statement) tcStatementBlock - .getStatementByIndex(j); + testCaseString + .append("TTCN3Logger.writeLog(\"mtc\", \"PARALLEL\", sourcefilename, rownum, \"testcase\", \"" + + nodeName + + "\", \"Starting PTC " + + logValues[0] + + " type " + + logValues[1] + + " on " + + logValues[2] + + "\", false);" + + "\r\n"); - testCaseString.append("hc.done(\"all component\");" - + "\r\n");// TODO: all honnan jön? + } else if ((specValTemplate.getSpecificValue() instanceof Bitstring_Value) + || (specValTemplate.getSpecificValue() instanceof Integer_Value) + || (specValTemplate.getSpecificValue() instanceof Charstring_Value) + || (specValTemplate.getSpecificValue() instanceof Boolean_Value) + ||(specValTemplate.getSpecificValue() instanceof Octetstring_Value) + || (specValTemplate.getSpecificValue() instanceof Undefined_LowerIdentifier_Value) + || (specValTemplate.getSpecificValue() instanceof Referenced_Value) + || (specValTemplate.getSpecificValue() instanceof AddExpression) + || (specValTemplate.getSpecificValue() instanceof SubstractExpression) + || (specValTemplate.getSpecificValue() instanceof MultiplyExpression) + || (specValTemplate.getSpecificValue() instanceof DivideExpression) + || (specValTemplate.getSpecificValue() instanceof ModuloExpression) + || (specValTemplate.getSpecificValue() instanceof RemainderExpression) + ||(specValTemplate.getSpecificValue() instanceof UnaryMinusExpression)) { + // TODO assignments for indexed bitstrings + testCaseString.append("rownum=" + + specValTemplate.getLocation().getLine() + ";\r\n"); - } - } + testCaseString.append(tcAssignIdentifiers.get(assignCounter) + + tcAssignValues.get(assignCounter) + ";\r\n"); - + + + // TODO: add logging here + } - testCaseString.append("}" + "\r\n"); + } return testCaseString.toString(); } - - public String getJavaSource(){ - createCounter=-1; - connectCounter=-1; - startCounter=-1; - this.writeTestCaseFunction(); - - String returnString=testCaseString.toString(); - testCaseString.setLength(0); - return returnString; - } + public void writeConnectStatement(Connect_Statement tc_connectStatement) { + testCaseString.append("rownum=" + + tc_connectStatement.getLocation().getLine() + ";\r\n"); - public void setTcRunsOn(String testCaseRunsOn) { - this.testCaseRunsOn=testCaseRunsOn; - - } + testCaseString.append("hc.connect(" + "\"" + + tcConnectValues.get(connectCounter * 4) + "\"," + "\"" + + tcConnectValues.get(connectCounter * 4 + 1) + "\"," + "\"" + + tcConnectValues.get(connectCounter * 4 + 2) + "\"," + "\"" + + tcConnectValues.get(connectCounter * 4 + 3) + "\"); " + + "\r\n"); + + testCaseString + .append("TTCN3Logger.writeLog(\"mtc\", \"PARALLEL\", sourcefilename, rownum, \"testcase\", \"" + + nodeName + + "\", \"Connecting port " + + tcConnectValues.get(connectCounter * 4 + 1) + + " of " + + tcConnectValues.get(connectCounter * 4) + + " to port " + + tcConnectValues.get(connectCounter * 4 + 3) + + " of " + + tcConnectValues.get(connectCounter * 4 + 2) + + "\", false);" + "\r\n"); - public void setStatementBlock(StatementBlock tcStatementBlock) { - this.tcStatementBlock=tcStatementBlock; - } - public void addVars(String string) { - tcVars.add(string); - + public void writeUnknownStartStatement( + Unknown_Start_Statement tc_startStatement) { + startStatementCounter++; + testCaseString.append("rownum=" + + tc_startStatement.getLocation().getLine() + ";\r\n"); + + if (testCaseStartValueParameters.get(startStatementCounter) != null) { + testCaseString.append("hc.start(" + "\"" + + tcStartIdentifiers.get(startStatementCounter) + "\",\"" + + testCaseStartValueParameters.get(startStatementCounter) + + "\"); " + "\r\n"); + } else { + testCaseString.append(tcStartIdentifiers.get(startStatementCounter) + + ".start()" + ";\r\n"); + } + if (testCaseStartValueParameters.get(startStatementCounter) != null) { + testCaseString + .append("TTCN3Logger.writeLog(\"mtc\", \"PARALLEL\", sourcefilename, rownum, \"testcase\", \"" + + nodeName + + "\", \"Starting function " + + testCaseStartValueParameters + .get(startStatementCounter) + + " on component " + + tcStartIdentifiers.get(startStatementCounter) + + "\", false);" + "\r\n"); + } else {// timer + testCaseString + .append("TTCN3Logger.writeLog(\"mtc\", \"TIMEROP\", sourcefilename, rownum, \"function\", \"" + + nodeName + + "\", \"Timer " + + tcStartIdentifiers.get(startStatementCounter) + + " started.\", false);" + "\r\n"); + isThereAStartedTimer = true; + currentTimerName = tcStartIdentifiers.get(startStatementCounter); + + } + } - public void addVarTypes(String string) { - tcVarTypes.add(string); - + public void writeUnknownStopStatement( + Unknown_Stop_Statement tc_stopStatement) { + stopStatementCounter++; + testCaseString.append("rownum=" + + tc_stopStatement.getLocation().getLine() + ";\r\n"); + + if (testCaseStopValueParameters.get(stopStatementCounter) != null) { + testCaseString.append("hc.stop(" + "\"" + + tcStopIdentifiers.get(stopStatementCounter) + "\",\"" + + testCaseStopValueParameters.get(stopStatementCounter) + + "\"); " + "\r\n"); + } else { + testCaseString.append(tcStopIdentifiers.get(stopStatementCounter) + + ".stop()" + ";\r\n"); + } + if (testCaseStopValueParameters.get(stopStatementCounter) != null) { + testCaseString + .append("TTCN3Logger.writeLog(\"mtc\", \"PARALLEL\", sourcefilename, rownum, \"testcase\", \"" + + nodeName + + "\", \"Stopping function " + + testCaseStopValueParameters + .get(stopStatementCounter) + + " on component " + + tcStopIdentifiers.get(stopStatementCounter) + + "\", false);" + "\r\n"); + } else {// timer + testCaseString + .append("TTCN3Logger.writeLog(\"mtc\", \"TIMEROP\", sourcefilename, rownum, \"function\", \"" + + nodeName + + "\", \"Timer " + + tcStopIdentifiers.get(stopStatementCounter) + + " stopped.\", false);" + "\r\n"); + isThereAStartedTimer = true; + currentTimerName = tcStopIdentifiers.get(stopStatementCounter); + + } + } - public void addAssignValues(String string) { - tcAssignValues.add(string); - + public void writeMapStatement(Map_Statement tc_mapStatement) { + StringBuilder mapValueString = new StringBuilder(); + + while (Integer.toString(mapCounter).equals( + tcMapCounter.get(currentMapValueIndex))) { + + mapValueString.append(tcMapValues.get(currentMapValueIndex) + " "); + + currentMapValueIndex++; + if (currentMapValueIndex == tcMapCounter.size()) { + break; + } + + } + + String[] mapValues = mapValueString.toString().split(" "); + + testCaseString.append("rownum=" + + tc_mapStatement.getLocation().getLine() + ";\r\n"); + testCaseString.append("hc.map(" + "\"" + mapValues[0] + "\",\"" + + mapValues[1] + "\",\"" + mapValues[2] + "\",\"" + + mapValues[3] + "\"" + ");\r\n"); + + testCaseString + .append("TTCN3Logger.writeLog(\"mtc\", \"PARALLEL\", sourcefilename, rownum, \"testcase\", \"" + + nodeName + + "\", \"Mapping port " + + mapValues[1] + + " of " + + mapValues[0] + + " to port " + + mapValues[3] + + " of " + mapValues[2] + "\", false);" + "\r\n"); } - public void addCreateValues(String string) { - tcCreateValues.add(string); - + public void writeIfStatement(If_Statement tc_ifStatement) { + testCaseString.append("rownum=" + + tc_ifStatement.getLocation().getLine() + ";\r\n"); + + testCaseString.append("if(" + tcIfConditions.get(tcIfConditionCounter) + + ".getValue()){\r\n"); + + // TODO check if several IfClauses are possible + writeTestCaseFunction(tc_ifStatement.getIfClauses().getClauses().get(0) + .getStatementBlock()); + if (blockWriter) { + testCaseString.append("}" + "\r\n"); + } + + if (tc_ifStatement.getStatementBlock() != null) { + testCaseString.append("else{\r\n"); + writeTestCaseFunction(tc_ifStatement.getStatementBlock()); + if (blockWriter) { + testCaseString.append("}" + "\r\n"); + } + + } } - - public void addCreateCounter(String string) { - tcCreateCounter.add(string); - + + public void writeSetVerdictStatement( + Setverdict_Statement tc_setVerdictStatement) { + Verdict_Value tc_VerdictValue = (Verdict_Value) tc_setVerdictStatement + .getVerdictValue(); + + testCaseString.append("rownum=" + + tc_setVerdictStatement.getLocation().getLine() + ";\r\n"); + + if (tc_VerdictValue.getValue().toString().equals("PASS")) { + testCaseString.append("setVerdict(\"pass\")" + ";\r\n"); + } else if (tc_VerdictValue.getValue().toString().equals("FAIL")) { + testCaseString.append("setVerdict(\"fail\")" + ";\r\n"); + } + } - public void addConnectValues(String string) { - tcConnectValues.add(string); - + public String writeSendStatement(Send_Statement tc_SendStatement) { + + StringBuilder testCaseString = new StringBuilder(""); + + if (sendParameterType.get(sendCounter).equals("INTEGER")) { + String parameterValue =sendParameter.get(sendCounter); + testCaseString.append("rownum=" + + tc_SendStatement.getLocation().getLine() + ";\r\n"); + testCaseString.append(sendPortReference.get(sendCounter) + ".send(" + + parameterValue + ");" + "\r\n"); + testCaseString + .append("TTCN3Logger.writeLog(\"mtc\", \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + + nodeName + + "\", \"SEND event on port " + + sendPortReference.get(sendCounter) + + ":INTEGER \"" + + " + " + + parameterValue + + ".toString(), false);" + "\r\n"); + + } + if (sendParameterType.get(sendCounter).equals("IDENTIFIER")) { + String parameterValue = sendParameter.get(sendCounter); + testCaseString.append("rownum=" + + tc_SendStatement.getLocation().getLine() + ";\r\n"); + testCaseString.append(sendPortReference.get(sendCounter) + ".send(" + + parameterValue + ");" + "\r\n"); + testCaseString + .append("TTCN3Logger.writeLog(\"mtc\", \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + + nodeName + + "\", \"SEND event on port " + + sendPortReference.get(sendCounter) + + ": \"" + + " + " + + parameterValue + + ".toString(), false);" + + "\r\n"); + + } + + return testCaseString.toString(); } - public void addConnectCounter(String string) { - tcConnectCounter.add(string); - + public String writeReceiveStatement(Receive_Port_Statement currentStatement) { + StringBuilder testCaseString = new StringBuilder(""); + String receiveStatement = ""; + + // no alt guard && any port recieve + if (receivePortReference.get(receiveCounter).equals("any port")) { + receiveStatement = "anyPortReceive(true)"; + + } else { + // no alt guard && typed port recieve + if (receiveType.get(receiveCounter).equals("_TYPED_PARAM_")) { + + if (receiveAnyValValue.get(receiveCounter) != null) { + receiveStatement = "(" + + receiveAnyValValue.get(receiveCounter) + "=" + + receivePortReference.get(receiveCounter) + + ".receive_" + receiveValue.get(receiveCounter) + + "(true))!=null"; + + } else { + + } + + } else { // no alt guard && normal port recieve + receiveStatement = receivePortReference.get(receiveCounter) + + ".receive(" + receiveValue.get(receiveCounter) + + ",true)!=null"; + } + if (receiveValue.get(receiveCounter).startsWith("Templates")) { + receiveType.set(receiveCounter, "Templates"); + } + } + + testCaseString.append("if(" + receiveStatement + "){\r\n"); + testCaseString.append("rownum=" + + currentStatement.getLocation().getLine() + ";\r\n"); + + if (receiveType.get(receiveCounter).equals("Templates")) { + String methodName = receiveValue.get(receiveCounter); + if (methodName.endsWith("()") + && methodName.startsWith("Templates.")) { + + methodName = (String) methodName.subSequence(10, + methodName.length() - 2); + } + + testCaseString + .append(" TTCN3Logger.writeLog(\"mtc\", \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + + nodeName + + "\", \"RECEIVE event on port " + + receivePortReference.get(receiveCounter) + + ":\\n " + + methodName + + ":=\" + " + + receiveValue.get(receiveCounter) + + ".toString(), true);" + "\r\n"); + } else if (receiveType.get(receiveCounter).equals("any port")) { + testCaseString + .append(" TTCN3Logger.writeLog(\"mtc\", \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + + nodeName + + "\", \"RECEIVE event on port any port\", true);" + + "\r\n"); + } else if (receiveType.get(receiveCounter).equals("_TYPED_PARAM_")) { + testCaseString + .append(" TTCN3Logger.writeLog(\"mtc\", \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + + nodeName + + "\", \"RECEIVE event on port " + + receivePortReference.get(receiveCounter) + + ": type " + + receiveValue.get(receiveCounter) + + "\", true);" + "\r\n"); + + } else { + testCaseString + .append(" TTCN3Logger.writeLog(\"mtc\", \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + + nodeName + + "\", \"RECEIVE event on port " + + receivePortReference.get(receiveCounter) + + ":\" + " + + receiveValue.get(receiveCounter) + + ".toString(), true);" + "\r\n"); + } + + for (int i = 0; i < receiveStatements.get(receiveCounter).getSize(); i++) { + if (receiveStatements.get(receiveCounter).getStatementByIndex(i) instanceof Setverdict_Statement) { + + Setverdict_Statement setVerdictStatement = (Setverdict_Statement) receiveStatements + .get(receiveCounter).getStatementByIndex(i); + String verdict = ""; + + if (setVerdictStatement.getVerdictValue() instanceof Verdict_Value) { + Verdict_Value verdictValue = (Verdict_Value) setVerdictStatement + .getVerdictValue(); + if (verdictValue.getValue().toString().equals("PASS")) { + verdict = "pass"; + } else if (verdictValue.getValue().toString() + .equals("INCONC")) { + verdict = "inconc"; + } else { + verdict = "fail"; + } + } + testCaseString + .append("rownum=" + + setVerdictStatement.getLocation().getLine() + + ";\r\n"); + testCaseString + .append("TTCN3Logger.writeLog(\"mtc\", \"VERDICTOP\", sourcefilename, rownum, \"function\", \"" + + nodeName + + "\", \"setverdict(" + + verdict + + "): \" + getVerdict() + \" -> " + + verdict + + "\", true);" + "\r\n"); + testCaseString.append("setVerdict(\"" + verdict + "\");" + + "\r\n"); + + } + } + + testCaseString.append("}\r\n"); + + return testCaseString.toString(); } - public void addStartValues(String string) { - tcStartValues.add(string); - + public void writeDisconnectStatement( + Disconnect_Statement tc_disconnectStatement) { + + testCaseString.append("rownum=" + + tc_disconnectStatement.getLocation().getLine() + ";\r\n"); + + testCaseString.append("hc.disconnect(" + "\"" + + tcDisconnectValues.get(disconnectCounter * 4) + "\"," + "\"" + + tcDisconnectValues.get(disconnectCounter * 4 + 1) + "\"," + + "\"" + tcDisconnectValues.get(disconnectCounter * 4 + 2) + + "\"," + "\"" + + tcDisconnectValues.get(disconnectCounter * 4 + 3) + "\"); " + + "\r\n"); + + testCaseString + .append("TTCN3Logger.writeLog(\"mtc\", \"PARALLEL\", sourcefilename, rownum, \"testcase\", \"" + + nodeName + + "\", \"Disconnecting port " + + tcDisconnectValues.get(disconnectCounter * 4 + 1) + + " of " + + tcDisconnectValues.get(disconnectCounter * 4) + + " to port " + + tcDisconnectValues.get(disconnectCounter * 4 + 3) + + " of " + + tcDisconnectValues.get(disconnectCounter * 4 + 2) + + "\", false);" + "\r\n"); } - public void addStartCounter(String string) { - tcStartCounter.add(string); - + public void clearLists() { + + logCreateCounter = 0; + createCounter = -1; + connectCounter = -1; + disconnectCounter = -1; + currentCounterValue = 0; + defCounter = -1; + defValueCounter = -1; + assignCounter = -1; + mapCounter = 0; + tcIfConditionCounter = -1; + sendCounter = -1; + startStatementCounter = -1; + stopStatementCounter = -1; + currentMapValueIndex = 0; + receiveCounter = -1; + + tcConnectValues.clear(); + tcStartIdentifiers.clear(); + tcStartCounter.clear(); + tcMapValues.clear(); + tcMapCounter.clear(); + tcIfConditions.clear(); + tcVars.clear(); + tcVarTypes.clear(); + tcVarValues.clear(); + tcAssignIdentifiers.clear(); + tcAssignValues.clear(); + tcValueIsAValueReference.clear(); + tcCreateValues.clear(); + tcCreateCounter.clear(); + sendPortReference.clear(); + sendParameter.clear(); + sendParameterType.clear(); + + tcVarIsConstant.clear(); + tcVarIsTemplate.clear(); + tcDisconnectValues.clear(); + testCaseStartValueParameters.clear(); + tcValueTypeIsAReference.clear(); + tcStopIdentifiers.clear(); + tcStopCounter.clear(); + testCaseStopValueParameters.clear(); + + receivePortReference.clear(); + receiveValue.clear(); + receiveAnyValValue.clear(); + receiveType.clear(); + nodeVarIsRecord.clear(); + receiveStatements.clear(); } + public void clearAltLists() { + altStatementCounter = -1; + + altStatements.clear(); + } } diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Charstring.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Bitstring_Writer.java similarity index 79% rename from org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Charstring.java rename to org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Bitstring_Writer.java index 861482b30..16949eba0 100644 --- a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Charstring.java +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Bitstring_Writer.java @@ -15,38 +15,34 @@ package org.eclipse.titan.codegenerator; -import java.util.ArrayList; import java.util.LinkedHashMap; -import java.util.List; import java.util.Map; import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type; -import org.eclipse.titan.designer.parsers.CompilationTimeStamp; - -public class Def_Type_Charstring { +//TODO: duplicate of charstring, ONLY A PLACEHOLDER YET +public class Def_Type_Bitstring_Writer { private Def_Type typeNode; private StringBuilder charStringString = new StringBuilder(""); - private CompilationTimeStamp compilationCounter = CompilationTimeStamp - .getNewCompilationCounter(); + private String charStringValue = null; private String nodeName = null; private static Map charStringHashes = new LinkedHashMap(); - private Def_Type_Charstring(Def_Type typeNode) { + private Def_Type_Bitstring_Writer(Def_Type typeNode) { super(); this.typeNode = typeNode; - nodeName = typeNode.getIdentifier().toString(); + nodeName = this.typeNode.getIdentifier().toString(); } - public static Def_Type_Charstring getInstance(Def_Type typeNode) { + public static Def_Type_Bitstring_Writer getInstance(Def_Type typeNode) { if (!charStringHashes.containsKey(typeNode.getIdentifier().toString())) { charStringHashes.put(typeNode.getIdentifier().toString(), - new Def_Type_Charstring(typeNode)); + new Def_Type_Bitstring_Writer(typeNode)); } - return (Def_Type_Charstring) charStringHashes.get(typeNode + return (Def_Type_Bitstring_Writer) charStringHashes.get(typeNode .getIdentifier().toString()); } @@ -86,7 +82,14 @@ public class Def_Type_Charstring { } + public void clearLists(){ + //TODO put lists and fields here which should be initialized + } + public String getJavaSource() { + + AstWalkerJava.logToConsole(" Starting processing: Bitstring " + nodeName ); + charStringString.append("class " + nodeName + " extends SubTypeDef{" + "\r\n"); this.writeConstructor(); @@ -96,6 +99,9 @@ public class Def_Type_Charstring { String returnString = charStringString.toString(); charStringString.setLength(0); charStringValue = null; + + AstWalkerJava.logToConsole(" Finished processing: Bitstring " + nodeName ); + return returnString; } diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Charstring_Writer.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Charstring_Writer.java new file mode 100644 index 000000000..ad65eed5f --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Charstring_Writer.java @@ -0,0 +1,109 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator; + +import java.util.LinkedHashMap; +import java.util.Map; + +import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type; + +public class Def_Type_Charstring_Writer { + private Def_Type typeNode; + private StringBuilder charStringString = new StringBuilder(""); + + private String charStringValue = null; + private String nodeName = null; + + private static Map charStringHashes = new LinkedHashMap(); + + private Def_Type_Charstring_Writer(Def_Type typeNode) { + super(); + this.typeNode = typeNode; + nodeName = this.typeNode.getIdentifier().toString(); + + } + + public static Def_Type_Charstring_Writer getInstance(Def_Type typeNode) { + if (!charStringHashes.containsKey(typeNode.getIdentifier().toString())) { + charStringHashes.put(typeNode.getIdentifier().toString(), + new Def_Type_Charstring_Writer(typeNode)); + + } + return (Def_Type_Charstring_Writer) charStringHashes.get(typeNode + .getIdentifier().toString()); + } + + public void addCharStringValue(String value) { + charStringValue = value; + } + + private void writeConstructor() { + charStringString.append(nodeName + "(" + "CHARSTRING" + " val){"); + charStringString.append("\r\n" + "super(val);"); + + if (charStringValue != null) { + + charStringString.append("\r\n" + "allowedValues.add" + + "(new CHARSTRING(\"" + charStringValue + "\"));"); + + } + + charStringString.append("\r\n }\r\n"); + + } + + private void writeMatcher() { + charStringString.append("public static boolean match(" + nodeName + + " pattern, " + "Object " + " message){" + "\r\n"); + charStringString.append("if(!(message instanceof " + nodeName + + ")) return false;" + "\r\n"); + charStringString.append(" return CHARSTRING.match(pattern.value, ((" + + nodeName + ")message).value);" + "\r\n"); + charStringString.append("}" + "\r\n"); + } + + private void writeEquals() { + charStringString.append("public BOOLEAN equals(" + nodeName + + " v){\r\n"); + charStringString.append(" return value.equals(v.value);\r\n"); + charStringString.append("}\r\n"); + + } + + public void clearLists(){ + //TODO put lists and fields here which should be initialized + } + + public String getJavaSource() { + + AstWalkerJava.logToConsole(" Starting processing: Charstring " + nodeName ); + + charStringString.append("class " + nodeName + + " extends SubTypeDef{" + "\r\n"); + this.writeConstructor(); + this.writeMatcher(); + this.writeEquals(); + charStringString.append("\r\n}"); + String returnString = charStringString.toString(); + charStringString.setLength(0); + charStringValue = null; + + AstWalkerJava.logToConsole(" Finished processing: Charstring " + nodeName ); + + return returnString; + } + +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Component.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Component_Writer.java similarity index 71% rename from org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Component.java rename to org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Component_Writer.java index 15c64ebbe..04f2a2124 100644 --- a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Component.java +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Component_Writer.java @@ -20,39 +20,31 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Port; import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type; -import org.eclipse.titan.designer.parsers.CompilationTimeStamp; -public class Def_Type_Component { +public class Def_Type_Component_Writer { private Def_Type typeNode; private StringBuilder compString = new StringBuilder(""); - private CompilationTimeStamp compilationCounter = CompilationTimeStamp - .getNewCompilationCounter(); - private List compFieldTypes = new ArrayList(); - private List compFieldNames = new ArrayList(); - private String nodeName=null; - + + public List compFieldTypes = new ArrayList(); + public List compFieldNames = new ArrayList(); + private String nodeName = null; + private static Map compHashes = new LinkedHashMap(); - private Def_Type_Component(Def_Type typeNode) { + private Def_Type_Component_Writer(Def_Type typeNode) { super(); this.typeNode = typeNode; - nodeName = typeNode.getIdentifier().toString(); + nodeName = this.typeNode.getIdentifier().toString(); } - public static Def_Type_Component getInstance(Def_Type typeNode) { + public static Def_Type_Component_Writer getInstance(Def_Type typeNode) { if (!compHashes.containsKey(typeNode.getIdentifier().toString())) { compHashes.put(typeNode.getIdentifier().toString(), - new Def_Type_Component(typeNode)); + new Def_Type_Component_Writer(typeNode)); } - return (Def_Type_Component) compHashes.get(typeNode.getIdentifier() - .toString()); - } - - public void addCompFields(String type, String name) { - compFieldTypes.add(type); - compFieldNames.add(name); + return (Def_Type_Component_Writer) compHashes.get(typeNode + .getIdentifier().toString()); } public void writeCompFields() { @@ -69,12 +61,15 @@ public class Def_Type_Component { compString.append("super(name);" + "\r\n"); compString.append("hc=hcont;" + "\r\n"); - compString.append("if(hc.debugmode)TTCN3Logger.writeLog(name, \"PARALLEL\", \"Test component \" + name + \" created.\", false);" + "\r\n"); - + compString + .append("if(hc.debugmode)TTCN3Logger.writeLog(name, \"PARALLEL\", \"Test component \" + name + \" created.\", false);" + + "\r\n"); + for (int i = 0; i < compFieldNames.size(); i++) { compString.append(compFieldNames.get(i) + " =new " - + compFieldTypes.get(i) + "(this,\"+compFieldNames.get(i)+\");" + "\r\n"); + + compFieldTypes.get(i) + "(this,\"" + + compFieldNames.get(i) + "\");" + "\r\n"); } compString.append("created = true;" + "\r\n"); @@ -130,7 +125,7 @@ public class Def_Type_Component { compString.append(" " + "\r\n"); compString.append("}" + "\r\n"); } - + public void writeDomap() { compString.append("" + "\r\n"); compString.append("@Override" + "\r\n"); @@ -138,15 +133,36 @@ public class Def_Type_Component { .append("public void domap(String thisport, String remotecomp, String remoteport) {" + "\r\n"); - //TODO + // TODO + for (int i = 0; i < compFieldTypes.size(); i++) { + if (myASTVisitor.nodeNameNodeTypeHashMap.get(compFieldTypes.get(i)) + .equals("port")) { + if (!(myASTVisitor.portNamePortTypeHashMap.get(compFieldTypes + .get(i)).equals("TP_INTERNAL"))) { + compString.append("if(thisport.equals(\"" + + compFieldNames.get(i) + "\")) " + + compFieldNames.get(i) + + ".map(remotecomp, remoteport);" + "\r\n"); + } + } + } compString.append(" " + "\r\n"); compString.append("}" + "\r\n"); } + public void clearLists() { + compFieldTypes.clear(); + compFieldNames.clear(); + } + public String getJavaSource() { - compString.append("class " + nodeName - + " extends ComponentDef{" + "\r\n"); + + AstWalkerJava.logToConsole(" Starting processing: Component " + + nodeName); + + compString.append("class " + nodeName + " extends ComponentDef{" + + "\r\n"); this.writeCompFields(); this.writeConstructor(); this.writeAnyPortReceive(); @@ -154,12 +170,13 @@ public class Def_Type_Component { this.writeConnect(); this.writeDomap(); compString.append("\r\n}"); - + String returnString = compString.toString(); compString.setLength(0); - compFieldTypes.clear(); - compFieldNames.clear(); - + + AstWalkerJava.logToConsole(" Finished processing: Component " + + nodeName); + return returnString; } } diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Enum.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Enum.java deleted file mode 100644 index 17057efda..000000000 --- a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Enum.java +++ /dev/null @@ -1,80 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2000-2016 Ericsson Telecom AB - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * - * Keremi, Andras - * Eros, Levente - * Kovacs, Gabor - * - ******************************************************************************/ - -package org.eclipse.titan.codegenerator; - -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.titan.designer.AST.IVisitableNode; -import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type; -import org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type; -import org.eclipse.titan.designer.parsers.CompilationTimeStamp; - -public class Def_Type_Enum { - private Def_Type enumNode; - private StringBuilder enumString = new StringBuilder(""); - private CompilationTimeStamp compilationCounter = CompilationTimeStamp - .getNewCompilationCounter(); - private List enumItems = new ArrayList(); - private String nodeName=null; - - private static Map enumStringHashes = new LinkedHashMap(); - - private Def_Type_Enum(Def_Type typeNode) { - super(); - this.enumNode = typeNode; - nodeName = typeNode.getIdentifier().toString(); - } - - public static Def_Type_Enum getInstance(Def_Type typeNode) { - if (!enumStringHashes.containsKey(typeNode.getIdentifier().toString())) { - enumStringHashes.put(typeNode.getIdentifier().toString(), - new Def_Type_Enum(typeNode)); - } - return (Def_Type_Enum) enumStringHashes.get(typeNode - .getIdentifier().toString()); - } - - public void addEnumItem(String value) { - enumItems.add(value); - } - - private void writeConstructors() { - enumString.append("public Method(){"+ "\r\n"); - for(int i=0;i enumItems = new ArrayList(); + public List enumItemValues = new ArrayList(); + private String nodeName = null; + + private static Map enumStringHashes = new LinkedHashMap(); + + private Def_Type_Enum_Writer(Def_Type typeNode) { + super(); + this.typeNode = typeNode; + nodeName = this.typeNode.getIdentifier().toString(); + } + + public static Def_Type_Enum_Writer getInstance(Def_Type typeNode) { + if (!enumStringHashes.containsKey(typeNode.getIdentifier().toString())) { + enumStringHashes.put(typeNode.getIdentifier().toString(), + new Def_Type_Enum_Writer(typeNode)); + } + return (Def_Type_Enum_Writer) enumStringHashes.get(typeNode + .getIdentifier().toString()); + } + + private void writeConstructors() { + enumString.append("public " + nodeName + "(){" + "\r\n"); + int enumValueCounter = 0; + for (int i = 0; i < enumItems.size(); i++) { + enumString.append("values.put(\"" + enumItems.get(i) + "\","); + if (enumItemValues.get(i) != null) { + enumString.append(enumItemValues.get(i) + ");" + "\r\n"); + } else { + while (enumItemValues.contains(Integer + .toString(enumValueCounter))) { + enumValueCounter++; + } + enumString.append(+enumValueCounter + ");" + "\r\n"); + enumValueCounter++; + } + + } + enumString.append("}" + "\r\n"); + + enumString.append("public " + nodeName + "(String v){" + "\r\n"); + enumString.append("this();" + "\r\n"); + enumString.append("setValue(v);}"); + } + + public void clearLists() { + enumItems.clear(); + enumItemValues.clear(); + } + + public String getJavaSource() { + + AstWalkerJava.logToConsole(" Starting processing: Enum " + nodeName); + + enumString + .append("class " + nodeName + " extends ENUMERATED{" + "\r\n"); + this.writeConstructors(); + enumString.append("\r\n}"); + String returnString = enumString.toString(); + enumString.setLength(0); + + AstWalkerJava.logToConsole(" Finished processing: Enum " + nodeName); + + return returnString; + } + +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Integer.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Integer.java deleted file mode 100644 index f58a2ee68..000000000 --- a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Integer.java +++ /dev/null @@ -1,107 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2000-2016 Ericsson Telecom AB - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * - * Keremi, Andras - * Eros, Levente - * Kovacs, Gabor - * - ******************************************************************************/ - -package org.eclipse.titan.codegenerator; - -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type; -import org.eclipse.titan.designer.parsers.CompilationTimeStamp; - -public class Def_Type_Integer { - private Def_Type typeNode; - private StringBuilder integerString = new StringBuilder(""); - private CompilationTimeStamp compilationCounter = CompilationTimeStamp - .getNewCompilationCounter(); - private boolean isValueRangeSet=false; - private int minValue; - private int maxValue; - private String nodeName=null; - - private static Map integerHashes = new LinkedHashMap(); - - - private Def_Type_Integer(Def_Type typeNode) { - super(); - this.typeNode = typeNode; - nodeName = typeNode.getIdentifier().toString(); - } - - public static Def_Type_Integer getInstance(Def_Type typeNode) { - if (!integerHashes.containsKey(typeNode.getIdentifier().toString())) { - integerHashes.put(typeNode.getIdentifier().toString(), new Def_Type_Integer(typeNode)); - } - return (Def_Type_Integer) integerHashes.get(typeNode.getIdentifier().toString()); - } - - public void addMinMaxFields(int min, int max){ - isValueRangeSet=true; - minValue=min; - maxValue=max; - } - - private void writeConstructor() { - integerString.append(nodeName + "(" - + "INTEGER" + " val){"); - integerString.append("\r\n" +"super(val);"); - - integerString.append("\r\n" + "allowedIntervals.add(new SubTypeInterval(new INTEGER("+minValue+"),new INTEGER("+maxValue+")));\r\n"); - integerString.append("\r\n" + " " + " " + "checkValue();"); - integerString.append("\r\n }\r\n"); - } - private void writeMatcher() { - integerString.append("public static boolean match(" - + nodeName + " pattern, " + "Object " - + " message){" + "\r\n"); - integerString.append("if(!(message instanceof " - + nodeName + ")) return false;" - + "\r\n"); - integerString.append(" return INTEGER.match(pattern.value, ((" - + nodeName + ")message).value);" - + "\r\n"); - integerString.append("}" + "\r\n"); - - } - - private void writeEquals() { - integerString.append("public boolean equals(" - + nodeName + " v){\r\n"); - integerString.append(" return value.equals(v.value);\r\n"); - integerString.append("}\r\n"); - - } - - public String getJavaSource(){ - integerString.append("class " + nodeName - + " extends SubTypeDef{" - + "\r\n"); - this.writeConstructor(); - this.writeMatcher(); - this.writeEquals(); - integerString.append("\r\n}"); - String returnString=integerString.toString(); - integerString.setLength(0); - minValue=0; - maxValue=0; - isValueRangeSet=false; - return returnString; - } - - - -} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Integer_Writer.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Integer_Writer.java new file mode 100644 index 000000000..d54a39143 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Integer_Writer.java @@ -0,0 +1,101 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type; + +public class Def_Type_Integer_Writer { + private Def_Type typeNode; + private StringBuilder integerString = new StringBuilder(""); + + private String nodeName = null; + public static List allowedValues = new ArrayList(); + + private static Map integerHashes = new LinkedHashMap(); + + private Def_Type_Integer_Writer(Def_Type typeNode) { + super(); + this.typeNode = typeNode; + nodeName = this.typeNode.getIdentifier().toString(); + } + + public static Def_Type_Integer_Writer getInstance(Def_Type typeNode) { + if (!integerHashes.containsKey(typeNode.getIdentifier().toString())) { + integerHashes.put(typeNode.getIdentifier().toString(), new Def_Type_Integer_Writer(typeNode)); + } + return (Def_Type_Integer_Writer) integerHashes.get(typeNode.getIdentifier().toString()); + } + + private void writeConstructor() { + integerString.append(nodeName + "(" + "INTEGER" + " val){" + "\r\n"); + integerString.append("super(val);\r\n"); + + for (int i = 0; i < allowedValues.size(); i++) { + + if (allowedValues.get(i).startsWith("new SubTypeInterval")) { + integerString.append("allowedIntervals.add(" + allowedValues.get(i) + ");\r\n"); + } else { + integerString.append("allowedValues.add(" + allowedValues.get(i) + ");\r\n"); + } + } + + integerString.append("\r\n" + " " + " " + "checkValue();"); + integerString.append("\r\n }\r\n"); + } + + private void writeMatcher() { + integerString + .append("public static boolean match(" + nodeName + " pattern, " + "Object " + " message){" + "\r\n"); + integerString.append("if(!(message instanceof " + nodeName + ")) return false;" + "\r\n"); + integerString.append(" return INTEGER.match(pattern.value, ((" + nodeName + ")message).value);" + "\r\n"); + integerString.append("}" + "\r\n"); + + } + + private void writeEquals() { + integerString.append("public BOOLEAN equals(" + nodeName + " v){\r\n"); + integerString.append(" return value.equals(v.value);\r\n"); + integerString.append("}\r\n"); + + } + + public void clearLists() { + // TODO put lists and fields here which should be initialized + } + + public String getJavaSource() { + + AstWalkerJava.logToConsole(" Starting processing: Integer " + nodeName); + + integerString.append("class " + nodeName + " extends SubTypeDef{" + "\r\n"); + this.writeConstructor(); + this.writeMatcher(); + this.writeEquals(); + integerString.append("\r\n}"); + String returnString = integerString.toString(); + integerString.setLength(0); + allowedValues.clear(); + AstWalkerJava.logToConsole(" Finished processing: Integer " + nodeName); + + return returnString; + } + +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Port.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Port_Writer.java similarity index 88% rename from org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Port.java rename to org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Port_Writer.java index a3c811e62..206b773a3 100644 --- a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Port.java +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Port_Writer.java @@ -21,58 +21,50 @@ import java.util.List; import java.util.Map; import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type; -import org.eclipse.titan.designer.parsers.CompilationTimeStamp; //only supports inout messages -public class Def_Type_Port { +public class Def_Type_Port_Writer { private Def_Type typeNode; private StringBuilder portString = new StringBuilder(""); - private CompilationTimeStamp compilationCounter = CompilationTimeStamp - .getNewCompilationCounter(); - private List inMessageName = new ArrayList(); - private List outMessageName = new ArrayList(); - private List inOutMessageName = new ArrayList(); + public List inMessageName = new ArrayList(); + public List outMessageName = new ArrayList(); + public List inOutMessageName = new ArrayList(); private boolean isPortTypeAReferencedType = false; + private boolean isPortInternal = false; private String nodeName = null; private static Map portHashes = new LinkedHashMap(); - private Def_Type_Port(Def_Type typeNode) { + private Def_Type_Port_Writer(Def_Type typeNode) { super(); this.typeNode = typeNode; - nodeName = typeNode.getIdentifier().toString(); + nodeName = this.typeNode.getIdentifier().toString(); } - public static Def_Type_Port getInstance(Def_Type typeNode) { + public static Def_Type_Port_Writer getInstance(Def_Type typeNode) { if (!portHashes.containsKey(typeNode.getIdentifier().toString())) { portHashes.put(typeNode.getIdentifier().toString(), - new Def_Type_Port(typeNode)); + new Def_Type_Port_Writer(typeNode)); } - return (Def_Type_Port) portHashes.get(typeNode.getIdentifier() + return (Def_Type_Port_Writer) portHashes.get(typeNode.getIdentifier() .toString()); } - public void addInMessage(String message) { - inMessageName.add(message); + public void setPortTypeAReferencedType(boolean isPortTypeAReferencedType) { + this.isPortTypeAReferencedType = isPortTypeAReferencedType; } - public void addOutMessage(String message) { - outMessageName.add(message); - } + private void writeExternalPorts() { + portString.append("private TP_" + nodeName + " testport = new TP_" + + nodeName + "(this); " + "\r\n"); - public void addInOutMessage(String message) { - inOutMessageName.add(message); } - public void setPortTypeAReferencedType(boolean isPortTypeAReferencedType) { - this.isPortTypeAReferencedType = isPortTypeAReferencedType; - } - - private void writeRecieve() { + private void writeReceive() { for (int i = 0; i < inMessageName.size(); i++) { portString.append("public " + inMessageName.get(i) + " receive(" + inMessageName.get(i) + " s, boolean take){ " + "\r\n"); @@ -166,7 +158,7 @@ public class Def_Type_Port { } } - private void writeTypedRecieve() { + private void writeTypedReceive() { for (int i = 0; i < inMessageName.size(); i++) { portString.append("public " + inMessageName.get(i) + " receive_" + inMessageName.get(i) + "(boolean take){" + "\r\n"); @@ -232,7 +224,7 @@ public class Def_Type_Port { } } - private void writeObjectRecieve() { + private void writeObjectReceive() { portString.append("public Object receive(boolean take){" + "\r\n"); portString.append("while(!mapped){" + "\r\n"); portString @@ -261,15 +253,19 @@ public class Def_Type_Port { + "\r\n"); portString.append("}\r\n"); portString.append("try{ " + "\r\n"); - - portString.append("owriter.writeObject(o);" + "\r\n"); + if (!isPortInternal) { + portString.append("testport.user_send(o);" + "\r\n"); + } else { + portString.append("owriter.writeObject(o);" + "\r\n"); + } portString.append("}catch(Exception e){e.printStackTrace();}" + "\r\n"); portString.append("}" + "\r\n"); } private void writeConstructor() { - portString.append("public "+nodeName + "(ComponentDef c, String name){\r\n"); + portString.append("public " + nodeName + + "(ComponentDef c, String name){\r\n"); portString.append(" super(c,name);" + "\r\n"); portString.append(" inBuffer = new ArrayList();" + "\r\n"); for (int counter = 0; counter < inMessageName.size(); counter++) { @@ -342,6 +338,17 @@ public class Def_Type_Port { } + private void writeMap() { + portString + .append("public void map(String remotecomp, String remoteport){" + + "\r\n"); + if (!isPortInternal) { // TODO check if needed! + portString.append(" testport.user_map(remotecomp, remoteport);" + + "\r\n"); + } + portString.append("}" + "\r\n"); + } + private void writeBufferDaemon() { portString.append("class BufferDaemon extends Thread{ " + "\r\n"); @@ -354,9 +361,10 @@ public class Def_Type_Port { portString.append(" port = p;" + "\r\n"); portString.append(" portnum = pnum;" + "\r\n"); portString.append(" isinitiator = init;" + "\r\n"); - portString.append(" if(component.hc.debugmode)TTCN3Logger.writeLog(component.compid + \":\" + port.name + \"--buffer-daemon\", \"PORTEVENT\", \"Buffer daemon started. Listening on port \" + portnum + \", in \" + (isinitiator?\"INITIATOR\":\"RESPONDER\") + \" mode\", false);" - + "\r\n"); - + portString + .append(" if(component.hc.debugmode)TTCN3Logger.writeLog(component.compid + \":\" + port.name + \"--buffer-daemon\", \"PORTEVENT\", \"Buffer daemon started. Listening on port \" + portnum + \", in \" + (isinitiator?\"INITIATOR\":\"RESPONDER\") + \" mode\", false);" + + "\r\n"); + portString.append(" }" + "\r\n"); portString.append(" public BufferDaemon(" + nodeName + " p, String ipaddr, int pnum, boolean init){" + "\r\n"); @@ -424,24 +432,44 @@ public class Def_Type_Port { } + public void clearLists() { + isPortTypeAReferencedType = false; + isPortInternal = false; + + inMessageName.clear(); + outMessageName.clear(); + inOutMessageName.clear(); + } + public String getJavaSource() { + + AstWalkerJava.logToConsole(" Starting processing: Port " + nodeName); + portString.append("class " + typeNode.getIdentifier().toString() + " extends MessagePortDef{" + "\r\n"); - this.writeRecieve(); - this.writeTypedRecieve(); - this.writeObjectRecieve(); + isPortInternal = myASTVisitor.portNamePortTypeHashMap.get(nodeName) + .equals("TP_INTERNAL"); + if (!isPortInternal) { + this.writeExternalPorts(); + Additional_Class_Writer.writeExternalPortClass(nodeName); + } + + this.writeReceive(); + this.writeTypedReceive(); + this.writeObjectReceive(); this.send(); this.writeConstructor(); this.writePrepareforconnection(); this.writeConnect(); + this.writeMap(); this.writeBufferDaemon(); portString.append("\r\n}"); String returnString = portString.toString(); portString.setLength(0); - inMessageName.clear(); - outMessageName.clear(); - inOutMessageName.clear(); + + AstWalkerJava.logToConsole(" Finished processing: Port " + nodeName); + return returnString; } diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Record_Of_Writer.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Record_Of_Writer.java new file mode 100644 index 000000000..f20186743 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Record_Of_Writer.java @@ -0,0 +1,97 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Meszaros, Mate Robert + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator; + +import java.util.LinkedHashMap; +import java.util.Map; + +import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type; + +public class Def_Type_Record_Of_Writer implements JavaSourceProvider { + + private static Map writers = new LinkedHashMap<>(); + + public static Def_Type_Record_Of_Writer getInstance(Def_Type typeNode) { + String id = typeNode.getIdentifier().toString(); + if (writers.containsKey(id)) { + return writers.get(id); + } + Def_Type_Record_Of_Writer writer = new Def_Type_Record_Of_Writer(typeNode); + writers.put(id, writer); + return writer; + } + + private SourceCode code = new SourceCode(); + + private final String typeName; + private String fieldType; + + public Def_Type_Record_Of_Writer(Def_Type typeNode) { + typeName = typeNode.getIdentifier().toString(); + } + + public void setFieldType(String fieldType) { + this.fieldType = fieldType; + } + + @Override + public String getJavaSource() { + code.clear(); + AstWalkerJava.logToConsole(" Starting processing: RecordOf " + typeName); + code.line("class ", typeName, " extends RecordOfDef<", fieldType, "> {"); + writeConstructors(); + code.line(); + writeMatcher(); + code.line(); + writeEquals(); + code.line("}"); + AstWalkerJava.logToConsole(" Finishing processing: RecordOf " + typeName); + return code.toString(); + } + + private void writeConstructors() { + code.indent(1).line("public ", typeName, "() {"); + code.indent(2).line("value = new ArrayList<", fieldType, ">();"); + code.indent(1).line("}"); + code.line(); + code.indent(1).line("public ", typeName, "(List<", fieldType, "> list) {"); + code.indent(2).line("value = list;"); + code.indent(1).line("}"); + } + + private void writeMatcher() { + code.indent(1).line("public static boolean match(", typeName, " pattern, Object message) {"); + code.indent(2).line("if (!(message instanceof ", typeName, ")) return false;"); + // TODO : introduce a type-safe variable instead of casting it each time + // TODO : simplify the if statements into one boolean expression (eg.: a && b || c) + code.indent(2).line("if (pattern.omitField && ((", typeName, ")message).omitField) return true;"); + code.indent(2).line("if (pattern.anyOrOmitField) return true;"); + code.indent(2).line("if (pattern.anyField && !((", typeName, ")message).omitField) return true;"); + code.indent(2).line("if (pattern.anyField && !((", typeName, ")message).omitField) return true;"); + code.indent(2).line("if (pattern.omitField && !((", typeName, ")message).omitField) return false;"); + code.indent(2).line("if (pattern.anyField && ((", typeName, ")message).omitField) return false;"); + code.indent(2).line("return new BOOLEAN(pattern.equals((", typeName, ")message)).getValue();"); + code.indent(1).line("}"); + } + + private void writeEquals() { + code.indent(1).line("public BOOLEAN equals(RecordOfDef<", fieldType, "> v) {"); + code.indent(2).line("if (value.size() != v.value.size()) return new BOOLEAN(false);"); + code.indent(2).line("for (int i = 0; i < value.size(); ++i) {"); + code.indent(3).line("if (value.get(i) != v.value.get(i)) return new BOOLEAN(false);"); + code.indent(2).line("}"); + code.indent(2).line("return new BOOLEAN(true);"); + code.indent(1).line("}"); + } +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Record.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Record_Writer.java similarity index 75% rename from org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Record.java rename to org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Record_Writer.java index 59fa6515c..06a0f2e60 100644 --- a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Record.java +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Record_Writer.java @@ -21,39 +21,30 @@ import java.util.List; import java.util.Map; import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type; -import org.eclipse.titan.designer.AST.TTCN3.types.CompField; -import org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type; -import org.eclipse.titan.designer.parsers.CompilationTimeStamp; -public class Def_Type_Record { +public class Def_Type_Record_Writer { private Def_Type typeNode; private StringBuilder recordString = new StringBuilder(""); - private CompilationTimeStamp compilationCounter = CompilationTimeStamp - .getNewCompilationCounter(); - private List compFieldTypes = new ArrayList(); - private List compFieldNames = new ArrayList(); + + public List compFieldTypes = new ArrayList(); + public List compFieldNames = new ArrayList(); private String nodeName = null; private static Map recordHashes = new LinkedHashMap(); - private Def_Type_Record(Def_Type typeNode) { + private Def_Type_Record_Writer(Def_Type typeNode) { super(); this.typeNode = typeNode; - nodeName = typeNode.getIdentifier().toString(); + nodeName = this.typeNode.getIdentifier().toString(); } - public static Def_Type_Record getInstance(Def_Type typeNode) { + public static Def_Type_Record_Writer getInstance(Def_Type typeNode) { if (!recordHashes.containsKey(typeNode.getIdentifier().toString())) { recordHashes.put(typeNode.getIdentifier().toString(), - new Def_Type_Record(typeNode)); + new Def_Type_Record_Writer(typeNode)); } - return (Def_Type_Record) recordHashes.get(typeNode.getIdentifier() - .toString()); - } - - public void addCompFields(String type, String name) { - compFieldTypes.add(type); - compFieldNames.add(name); + return (Def_Type_Record_Writer) recordHashes.get(typeNode + .getIdentifier().toString()); } public void writeCompFields() { @@ -82,8 +73,7 @@ public class Def_Type_Record { recordString.append("if(pattern.anyField&&((" + nodeName + ")message).omitField) return false;" + "\r\n"); - - recordString.append(" return "); // + recordString.append(" return "); for (int i = 0; i < compFieldTypes.size(); i++) { @@ -104,17 +94,17 @@ public class Def_Type_Record { } public void writeEquals() { - recordString.append("public boolean equals(" + nodeName + " v){ " - + "\r\n");// 0901 + recordString.append("public BOOLEAN equals(" + nodeName + " v){ " + + "\r\n"); for (int i = 0; i < compFieldTypes.size(); i++) { recordString.append(" if(!" + compFieldNames.get(i) + ".equals(v." - + compFieldNames.get(i) + "))return false;" + "\r\n"); + + compFieldNames.get(i) + ").getValue())return new BOOLEAN(false);" + "\r\n"); } - recordString.append(" return true;" + "\r\n"); + recordString.append(" return new BOOLEAN(true);" + "\r\n"); recordString.append("}" + "\r\n"); } @@ -149,13 +139,15 @@ public class Def_Type_Record { recordString.append("return \"{\\n\" + " + "\r\n"); for (int i = 0; i < compFieldTypes.size(); i++) { - if((i+1) setOfHashes = new LinkedHashMap(); - - private Def_Type_Set_Of(Def_Type typeNode) { - super(); - this.typeNode = typeNode; - nodeName = typeNode.getIdentifier().toString(); - } - - public static Def_Type_Set_Of getInstance(Def_Type typeNode) { - if (!setOfHashes.containsKey(typeNode.getIdentifier().toString())) { - setOfHashes.put(typeNode.getIdentifier().toString(), - new Def_Type_Set_Of(typeNode)); - } - return (Def_Type_Set_Of) setOfHashes.get(typeNode.getIdentifier() - .toString()); - } - - public void addField(String field) { - fieldName = field; - } - - private void writeConstructor() { - setOfString.append("public " + nodeName - + "(){" + "\r\n"); - setOfString.append("value=new HashSet<" + fieldName + ">();" + "\r\n"); - setOfString.append("}" + "\r\n"); - setOfString.append("public " + nodeName - + "(HashSet<" + fieldName + "> v){" + "\r\n"); - setOfString.append(" value=v;" + "\r\n"); - setOfString.append("}" + "\r\n"); - } - - private void writeMatcher() { - setOfString.append("public static boolean match(" - + nodeName + " pattern, " + "Object" - + " message){" + "\r\n"); - - setOfString.append("if(!(message instanceof " - + nodeName + ")) return false;" - + "\r\n"); - setOfString.append("if(pattern.omitField&&((" - + nodeName - + ")message).omitField) return true;" + "\r\n"); - setOfString.append("if(pattern.anyOrOmitField) return true;" + "\r\n"); - setOfString.append("if(pattern.anyField&&!((" - + nodeName - + ")message).omitField) return true;" + "\r\n"); - setOfString.append("if(pattern.omitField&&!((" - + nodeName - + ")message).omitField) return false;" + "\r\n"); - setOfString.append("if(pattern.anyField&&((" - + nodeName - + ")message).omitField) return false;" + "\r\n"); - - - setOfString.append("return pattern.equals((" - + nodeName + ")message);" + "\r\n"); - setOfString.append("}\r\n"); - - } - - private void writeEquals() { - setOfString.append("public boolean equals(SetOfDef<" + fieldName - + "> v) {" + "\r\n"); - setOfString.append(" if(value.size()!=v.value.size()) return false;" - + "\r\n"); - setOfString.append(" for (" + fieldName + " i : value) {" + "\r\n"); - setOfString.append(" boolean found = false;" + "\r\n"); - setOfString.append(" for (" + fieldName + " j : v.value){" - + "\r\n"); - setOfString.append(" if (i.equals(j)) {" + "\r\n"); - setOfString.append(" found = true;" + "\r\n"); - setOfString.append(" break;" + "\r\n"); - setOfString.append(" }" + "\r\n"); - setOfString.append(" }" + "\r\n"); - setOfString.append(" if (!found) return false;" + "\r\n"); - setOfString.append(" }" + "\r\n"); - setOfString.append(" return true;" + "\r\n"); - setOfString.append("}" + "\r\n"); - - } - - public String getJavaSource() { - setOfString.append("class " + nodeName - + " extends SetOfDef<" + fieldName + ">{" + "\r\n"); - this.writeConstructor(); - this.writeMatcher(); - this.writeEquals(); - setOfString.append("\r\n}"); - String returnString = setOfString.toString(); - setOfString.setLength(0); - - return returnString; - } - -} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Set_Of_Writer.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Set_Of_Writer.java new file mode 100644 index 000000000..8a9a97cd1 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Set_Of_Writer.java @@ -0,0 +1,105 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * Meszaros, Mate Robert + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator; + +import java.util.LinkedHashMap; +import java.util.Map; + +import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type; + +public class Def_Type_Set_Of_Writer implements JavaSourceProvider { + + private static Map setOfHashes = new LinkedHashMap<>(); + + public static Def_Type_Set_Of_Writer getInstance(Def_Type typeNode) { + String id = typeNode.getIdentifier().toString(); + if (!setOfHashes.containsKey(id)) { + setOfHashes.put(id, new Def_Type_Set_Of_Writer(typeNode)); + } + return setOfHashes.get(id); + } + + private SourceCode code = new SourceCode(); + + private final String typeName; + private String fieldType; + + public Def_Type_Set_Of_Writer(Def_Type typeNode) { + typeName = typeNode.getIdentifier().toString(); + } + + public void setFieldType(String fieldType) { + this.fieldType = fieldType; + } + + @Override + public String getJavaSource() { + code.clear(); + AstWalkerJava.logToConsole(" Starting processing: Set of " + typeName); + code.line("class ", typeName, " extends SetOfDef<", fieldType, "> {"); + writeConstructor(); + code.line(); + writeMatcher(); + code.line(); + writeEquals(); + code.line("}"); + AstWalkerJava.logToConsole(" Finished processing: Set of " + typeName); + return code.toString(); + } + + private void writeConstructor() { + code.indent(1).line("public ", typeName, "() {"); + code.indent(2).line("value = new HashSet<", fieldType, ">();"); + code.indent(1).line("}"); + code.line(); + code.indent(1).line("public ", typeName, "(HashSet<", fieldType, "> set) {"); + code.indent(2).line("value = set;"); + code.indent(1).line("}"); + } + + private void writeMatcher() { + code.indent(1).line("public static boolean match(", typeName, " pattern, Object message) {"); + code.indent(2).line("if (!(message instanceof ", typeName, ")) return false;"); + // TODO : introduce a type-safe variable instead of casting it each time + // TODO : simplify the if statements into one boolean expression (eg.: a && b || c) + code.indent(2).line("if (pattern.omitField && ((", typeName, ")message).omitField) return true;"); + code.indent(2).line("if (pattern.anyOrOmitField) return true;"); + code.indent(2).line("if (pattern.anyField && !((", typeName, ")message).omitField) return true;"); + code.indent(2).line("if (pattern.anyField && !((", typeName, ")message).omitField) return true;"); + code.indent(2).line("if (pattern.omitField && !((", typeName, ")message).omitField) return false;"); + code.indent(2).line("if (pattern.anyField && ((", typeName, ")message).omitField) return false;"); + code.indent(2).line("return new BOOLEAN(pattern.equals((", typeName, ")message)).getValue();"); + code.indent(1).line("}"); + } + + private void writeEquals() { + code.indent(1).line("public BOOLEAN equals(SetOfDef<", fieldType, "> v) {"); + code.indent(2).line("if (value.size() != v.value.size()) return new BOOLEAN(false);"); + code.indent(2).line("for (", fieldType, " i : value) {"); + code.indent(3).line("boolean found = false;"); + code.indent(3).line("for (", fieldType, " j : v.value) {"); + code.indent(4).line("if (i.equals(j).getValue()) {"); + code.indent(5).line("found = true;"); + code.indent(5).line("break;"); + code.indent(4).line("}"); + code.indent(3).line("}"); + code.indent(3).line("if (!found) return new BOOLEAN(false);"); + code.indent(2).line("}"); + code.indent(2).line("return new BOOLEAN(true);"); + code.indent(1).line("}"); + } +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Set.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Set_Writer.java similarity index 50% rename from org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Set.java rename to org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Set_Writer.java index 536be0f93..beacb3315 100644 --- a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Set.java +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Set_Writer.java @@ -21,114 +21,94 @@ import java.util.List; import java.util.Map; import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type; -import org.eclipse.titan.designer.AST.TTCN3.types.CompField; -import org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type; -import org.eclipse.titan.designer.parsers.CompilationTimeStamp; -public class Def_Type_Set { +public class Def_Type_Set_Writer { private Def_Type typeNode; private StringBuilder setString = new StringBuilder(""); - private CompilationTimeStamp compilationCounter = CompilationTimeStamp - .getNewCompilationCounter(); - private List compFieldTypes = new ArrayList(); - private List compFieldNames = new ArrayList(); - private String nodeName=null; - - - private static Map setHashes = new LinkedHashMap(); + public List compFieldTypes = new ArrayList(); + public List compFieldNames = new ArrayList(); + private String nodeName = null; + + private static Map setHashes = new LinkedHashMap(); - private Def_Type_Set(Def_Type typeNode) { + private Def_Type_Set_Writer(Def_Type typeNode) { super(); this.typeNode = typeNode; - nodeName = typeNode.getIdentifier().toString(); + nodeName = this.typeNode.getIdentifier().toString(); } - public static Def_Type_Set getInstance(Def_Type typeNode) { + public static Def_Type_Set_Writer getInstance(Def_Type typeNode) { if (!setHashes.containsKey(typeNode.getIdentifier().toString())) { - setHashes.put(typeNode.getIdentifier().toString(), new Def_Type_Set(typeNode)); + setHashes.put(typeNode.getIdentifier().toString(), + new Def_Type_Set_Writer(typeNode)); } - return (Def_Type_Set) setHashes.get(typeNode.getIdentifier().toString()); + return (Def_Type_Set_Writer) setHashes.get(typeNode.getIdentifier() + .toString()); } - public void addCompFields(String type, String name){ - compFieldTypes.add(type); - compFieldNames.add(name); - } - - public void writeCompFields(){ - - for(int i=0;i compFieldTypes = new ArrayList(); - private List compFieldNames = new ArrayList(); + + public List compFieldTypes = new ArrayList(); + public List compFieldNames = new ArrayList(); private String nodeName = null; private static Map unionHashes = new LinkedHashMap(); - private Def_Type_Union(Def_Type typeNode) { + private Def_Type_Union_Writer(Def_Type typeNode) { super(); this.typeNode = typeNode; - nodeName = typeNode.getIdentifier().toString(); + nodeName = this.typeNode.getIdentifier().toString(); } - public static Def_Type_Union getInstance(Def_Type typeNode) { + public static Def_Type_Union_Writer getInstance(Def_Type typeNode) { if (!unionHashes.containsKey(typeNode.getIdentifier().toString())) { unionHashes.put(typeNode.getIdentifier().toString(), - new Def_Type_Union(typeNode)); + new Def_Type_Union_Writer(typeNode)); } - return (Def_Type_Union) unionHashes.get(typeNode.getIdentifier() + return (Def_Type_Union_Writer) unionHashes.get(typeNode.getIdentifier() .toString()); } - public void addCompFields(String type, String name) { - compFieldTypes.add(type); - compFieldNames.add(name); - } - private void writeCompFields() { // TODO Auto-generated method stub @@ -68,8 +60,6 @@ public class Def_Type_Union { unionString.append("if(!(message instanceof " + nodeName + "))return false;" + "\r\n"); - - unionString.append("if(pattern.omitField&&((" + nodeName + ")message).omitField) return true;" + "\r\n"); unionString.append("if(pattern.anyOrOmitField) return true;" + "\r\n"); @@ -95,8 +85,8 @@ public class Def_Type_Union { } private void writeEquals() { - unionString.append("public boolean equals(" + nodeName + " v){ " - + "\r\n");// 0901 + unionString.append("public BOOLEAN equals(" + nodeName + " v){ " + + "\r\n"); for (int l = 0; l < compFieldTypes.size(); l++) { @@ -108,7 +98,7 @@ public class Def_Type_Union { } - unionString.append(" return false;" + "\r\n"); + unionString.append(" return new BOOLEAN(false);" + "\r\n"); unionString.append("}" + "\r\n"); } @@ -135,10 +125,11 @@ public class Def_Type_Union { + (i + 1) + "_" + nodeName + " pattern, " + "Object" + " message){" + "\r\n"); - /*if (AstWalkerJava.areCommentsAllowed) { - unionChildString.append("System.out.println(\"SC_" + (i + 1) - + "\");" + "\r\n"); - }*/ + /* + * if (AstWalkerJava.areCommentsAllowed) { + * unionChildString.append("System.out.println(\"SC_" + (i + 1) + + * "\");" + "\r\n"); } + */ unionChildString.append("if(!(message instanceof " + "SC_" + (i + 1) + "_" + nodeName + ")) return false;" + "\r\n"); @@ -147,9 +138,9 @@ public class Def_Type_Union { + ")message).omitField) return true;" + "\r\n"); unionChildString.append("if(pattern.anyOrOmitField) return true;" + "\r\n"); - unionChildString.append("if(pattern.anyField&&!((" + "SC_" + (i + 1) - + "_" + nodeName + ")message).omitField) return true;" - + "\r\n"); + unionChildString.append("if(pattern.anyField&&!((" + "SC_" + + (i + 1) + "_" + nodeName + + ")message).omitField) return true;" + "\r\n"); unionChildString.append("if(pattern.omitField&&!((" + "SC_" + (i + 1) + "_" + nodeName + ")message).omitField) return false;" + "\r\n"); @@ -164,27 +155,27 @@ public class Def_Type_Union { unionChildString.append("}\r\n"); - unionChildString.append("public boolean equals(" + "SC_" + (i + 1) - + "_" + nodeName + " v){" + "\r\n"); // 0901 + unionChildString.append("public BOOLEAN equals(" + "SC_" + (i + 1) + + "_" + nodeName + " v){" + "\r\n"); unionChildString.append(" return this." + compFieldNames.get(i) + ".equals(v." + compFieldNames.get(i) + ");" + "\r\n"); unionChildString.append("}" + "\r\n"); - + unionChildString.append("public String toString(){" + "\r\n"); unionChildString.append(" return toString(\"\");" + "\r\n"); unionChildString.append("}" + "\r\n"); - unionChildString.append("public String toString(String tabs){" + "\r\n"); + unionChildString.append("public String toString(String tabs){" + + "\r\n"); unionChildString.append(" if(anyField) return \"?\";" + "\r\n"); unionChildString.append(" if(omitField) return \"omit\";" + "\r\n"); - unionChildString.append(" if(anyOrOmitField) return \"*\";" + "\r\n"); - unionChildString.append(" return "+compFieldNames.get(i)+".toString(tabs);" + "\r\n"); + unionChildString.append(" if(anyOrOmitField) return \"*\";" + + "\r\n"); + unionChildString.append(" return " + compFieldNames.get(i) + + ".toString(tabs);" + "\r\n"); unionChildString.append("}" + "\r\n"); - - - - + unionChildString.append("}" + "\r\n"); myASTVisitor.visualizeNodeToJava(unionChildString.toString()); unionChildString.delete(0, unionChildString.length()); @@ -193,17 +184,19 @@ public class Def_Type_Union { myASTVisitor.currentFileName = fileNameBackup; } - public void writeToString(){ + + public void writeToString() { unionString.append("public String toString(){" + "\r\n"); unionString.append("return toString(\"\");" + "\r\n"); unionString.append("}\r\n"); } - public void writeToStringWithParam(){ + + public void writeToStringWithParam() { unionString.append("public String toString(String tabs){" + "\r\n"); unionString.append("if(anyField) return \"?\";" + "\r\n"); unionString.append("if(omitField) return \"omit\";" + "\r\n"); unionString.append("if(anyOrOmitField) return \"*\";" + "\r\n"); - + for (int l = 0; l < compFieldTypes.size(); l++) { unionString.append("if(this instanceof " + "SC_" + (l + 1) + "_" @@ -211,13 +204,20 @@ public class Def_Type_Union { + nodeName + ")this).toString(tabs);" + "\r\n"); } - - unionString.append(" return \"\";"+ "\r\n"); + + unionString.append(" return \"\";" + "\r\n"); unionString.append("}\r\n"); } - - + + public void clearLists() { + compFieldTypes.clear(); + compFieldNames.clear(); + } + public String getJavaSource() { + + AstWalkerJava.logToConsole(" Starting processing: Union " + nodeName); + unionString.append("class " + nodeName + " extends UnionDef{" + "\r\n"); this.writeCompFields(); this.writeMatcher(); @@ -229,8 +229,9 @@ public class Def_Type_Union { unionString.append("\r\n}"); String returnString = unionString.toString(); unionString.setLength(0); - compFieldTypes.clear(); - compFieldNames.clear(); + + AstWalkerJava.logToConsole(" Finished processing: Union " + nodeName); + return returnString; } diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Visit_Handler.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Visit_Handler.java new file mode 100644 index 000000000..322717348 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/Def_Type_Visit_Handler.java @@ -0,0 +1,745 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * Meszaros, Mate Robert + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.titan.codegenerator.TTCN3JavaAPI.BITSTRING; +import org.eclipse.titan.codegenerator.TTCN3JavaAPI.BOOLEAN; +import org.eclipse.titan.codegenerator.TTCN3JavaAPI.CHARSTRING; +import org.eclipse.titan.codegenerator.TTCN3JavaAPI.INTEGER; +import org.eclipse.titan.codegenerator.TTCN3JavaAPI.OCTETSTRING; +import org.eclipse.titan.designer.AST.IVisitableNode; +import org.eclipse.titan.designer.AST.Reference; +import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Port; +import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type; +import org.eclipse.titan.designer.AST.TTCN3.types.CharString_Type; +import org.eclipse.titan.designer.AST.TTCN3.types.CompField; +import org.eclipse.titan.designer.AST.TTCN3.types.EnumerationItems; +import org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type; +import org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody; +import org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type; +import org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type; +import org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type; +import org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type; +import org.eclipse.titan.designer.AST.TTCN3.types.subtypes.Range_ParsedSubType; +import org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value; +import org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value; +import org.eclipse.titan.designer.AST.TTCN3.values.Real_Value; +import org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.AddExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.DivideExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.EqualsExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.GreaterThanExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.GreaterThanOrEqualExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.LessThanExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.LessThanOrEqualExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.Log2StrExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.ModuloExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.MultiplyExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.NotExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.NotequalesExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.RemainderExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.Str2IntExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.SubstractExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.ValueofExpression; +import org.eclipse.titan.designer.AST.Type; +import org.eclipse.titan.designer.parsers.CompilationTimeStamp; + +import static org.eclipse.titan.designer.AST.IType.Type_type.TYPE_COMPONENT; +import static org.eclipse.titan.designer.AST.IType.Type_type.TYPE_PORT; +import static org.eclipse.titan.designer.AST.IType.Type_type.TYPE_SEQUENCE_OF; +import static org.eclipse.titan.designer.AST.IType.Type_type.TYPE_SET_OF; +import static org.eclipse.titan.designer.AST.IType.Type_type.TYPE_TTCN3_CHOICE; +import static org.eclipse.titan.designer.AST.IType.Type_type.TYPE_TTCN3_SEQUENCE; +import static org.eclipse.titan.designer.AST.IType.Type_type.TYPE_TTCN3_SET; + +public class Def_Type_Visit_Handler { + + private static String setOfFieldType = null; + private static String recordOfFieldType = null; + private static String currentPortName; + private static String charstringValue = null; + private static String parentName = null; + + private static boolean waitForSetOfFieldType = false; + private static boolean waitForRecordOfFieldType = false; + private static boolean isPortTypeAReferencedType = false; + private static boolean waitingForPortAttriburtes = false; + private static boolean waitForCompReference = false; + private static boolean waitForDefType = false; + private static boolean waitForValue = false; + + public static List portTypeList = new ArrayList(); + private static List compPortTypes = new ArrayList(); + private static List compPortNames = new ArrayList(); + private static List compFieldTypes = new ArrayList(); + private static List compFieldNames = new ArrayList(); + private static List enumItems = new ArrayList(); + private static List enumItemValues = new ArrayList(); + private static List inMessageName = new ArrayList(); + private static List outMessageName = new ArrayList(); + private static List inOutMessageName = new ArrayList(); + + private static List expressionValue = new ArrayList(); + private boolean isInteger = false; + + public void visit(IVisitableNode node) { + if (node instanceof Def_Type) { + Def_Type_Integer_Writer.allowedValues.clear(); + expressionValue.clear();// Str2IntExpression Log2StrExpression + // ValueofExpression + visitDefTypeNodes(node); + charstringValue = null; + waitForDefType = true; + waitForValue = true; + + } + + if (waitForDefType) { + visitDefTypeChildrenNodes(node); + visitExpressionTypeSelectors(node); + } + } + + public void evaluateExpression() { + int size = expressionValue.size() - 1; + boolean operatorFound = false; + boolean unaryOperatorFound = false; + String rightHand = ""; + String leftHand = ""; + + for (int i = size; i >= 0; i--) { + + if (myASTVisitor.nodeNameNodeTypeHashMap.containsKey(expressionValue.get(i))) { + + if (myASTVisitor.nodeNameNodeTypeHashMap.get(expressionValue.get(i)).equals("constant")) { + expressionValue.set(i, "Constants." + expressionValue.get(i) + "().value"); + + } else if (myASTVisitor.nodeNameNodeTypeHashMap.get(expressionValue.get(i)).equals("template")) { + expressionValue.set(i, "Templates." + expressionValue.get(i) + "()"); + + } + } + + if (i <= size - 2) { + leftHand = expressionValue.get(i + 1); + rightHand = expressionValue.get(i + 2); + } + + // + if (expressionValue.get(i).equals("Str2IntExpression")) { + expressionValue.set(i, "(" + expressionValue.get(i + 1) + "str2int())"); + unaryOperatorFound = true; + } else if (expressionValue.get(i).equals("Log2StrExpression")) { + expressionValue.set(i, "(" + expressionValue.get(i + 1) + "log2str())"); + unaryOperatorFound = true; + } else if (expressionValue.get(i).equals("ValueofExpression")) { + expressionValue.set(i, "(" + expressionValue.get(i + 1) + ").value"); + unaryOperatorFound = true; + } else if (expressionValue.get(i).equals("NotExpression")) { + expressionValue.set(i, "(" + expressionValue.get(i + 1) + ").not()"); + unaryOperatorFound = true; + } else if (expressionValue.get(i).equals("AddExpression")) { + expressionValue.set(i, "(" + leftHand + ").plus(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("SubstractExpression")) { + expressionValue.set(i, "(" + leftHand + ").minus(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("MultiplyExpression")) { + expressionValue.set(i, "(" + leftHand + ").multipleBy(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("DivideExpression")) { + expressionValue.set(i, "(" + leftHand + ").divideBy(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("ModuloExpression")) { + expressionValue.set(i, "(" + leftHand + ").mod(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("RemainderExpression")) { + expressionValue.set(i, "(" + leftHand + ").rem(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("NotequalesExpression")) { + expressionValue.set(i, "(" + leftHand + ").equalsWith(" + rightHand + ").not()"); + operatorFound = true; + } else if (expressionValue.get(i).equals("LessThanExpression")) { + expressionValue.set(i, "(" + leftHand + ").isLessThan(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("LessThanOrEqualExpression")) { + expressionValue.set(i, "(" + leftHand + ").isLessOrEqualThan(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("GreaterThanExpression")) { + expressionValue.set(i, "(" + leftHand + ").isGreaterThan(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("GreaterThanOrEqualExpression")) { + expressionValue.set(i, "(" + leftHand + ").isGreaterOrEqualThan(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("EqualsExpression")) { + expressionValue.set(i, "(" + leftHand + ").equals(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("Range_ParsedSubType")) { + expressionValue.set(i, "new SubTypeInterval(" + expressionValue.get(i + 1) + "," + + expressionValue.get(i + 2) + ")"); + operatorFound = true; + + } + + if (unaryOperatorFound) { + unaryOperatorFound = false; + expressionValue.remove(i + 1); + size = expressionValue.size() - 1; + i = size; + } else if (operatorFound) { + operatorFound = false; + expressionValue.remove(i + 2); + expressionValue.remove(i + 1); + size = expressionValue.size() - 1; + i = size; + } + + } + + if (isInteger) { + Def_Type_Integer_Writer.allowedValues.addAll(expressionValue); + } + + expressionValue.clear(); + } + + public void visitExpressionTypeSelectors(IVisitableNode node) { + + if (waitForValue && (node instanceof AddExpression)) { + expressionValue.add("AddExpression"); + } + + if (waitForValue && (node instanceof SubstractExpression)) { + expressionValue.add("SubstractExpression"); + } + + if (waitForValue && (node instanceof MultiplyExpression)) { + expressionValue.add("MultiplyExpression"); + } + + if (waitForValue && (node instanceof DivideExpression)) { + expressionValue.add("DivideExpression"); + } + + if (waitForValue && (node instanceof ModuloExpression)) { + expressionValue.add("ModuloExpression"); + } + + if (waitForValue && (node instanceof RemainderExpression)) { + expressionValue.add("RemainderExpression"); + } + + if (waitForValue && (node instanceof NotequalesExpression)) { + expressionValue.add("NotequalesExpression"); + } + + if (waitForValue && (node instanceof LessThanExpression)) { + expressionValue.add("LessThanExpression"); + } + + if (waitForValue && (node instanceof LessThanOrEqualExpression)) { + expressionValue.add("LessThanOrEqualExpression"); + } + + if (waitForValue && (node instanceof GreaterThanExpression)) { + expressionValue.add("GreaterThanExpression"); + } + + if (waitForValue && (node instanceof GreaterThanOrEqualExpression)) { + expressionValue.add("GreaterThanOrEqualExpression"); + } + + if (waitForValue && (node instanceof EqualsExpression)) { + expressionValue.add("EqualsExpression"); + } + + if (waitForValue && (node instanceof NotExpression)) { + expressionValue.add("NotExpression"); + } + + if (node instanceof Range_ParsedSubType) { + expressionValue.add("Range_ParsedSubType"); + } + + if (node instanceof Str2IntExpression) { + expressionValue.add("Str2IntExpression"); + } + + if (node instanceof Log2StrExpression) { + expressionValue.add("Log2StrExpression"); + } + + if (node instanceof ValueofExpression) { + expressionValue.add("ValueofExpression"); + } + + /* + * if (waitForValue && ((node instanceof RemainderExpression) || (node + * instanceof ModuloExpression) || (node instanceof DivideExpression) || + * (node instanceof MultiplyExpression) || (node instanceof + * SubstractExpression) || (node instanceof AddExpression || (node + * instanceof NotequalesExpression) || (node instanceof + * LessThanExpression) || (node instanceof LessThanOrEqualExpression) || + * (node instanceof GreaterThanExpression) || (node instanceof + * GreaterThanOrEqualExpression) || (node instanceof + * EqualsExpression)))) { + * + * } + */ + + } + + public void visitDefTypeNodes(IVisitableNode node) { + + Def_Type typeNode = (Def_Type) node; + + CompilationTimeStamp compilationCounter = CompilationTimeStamp.getNewCompilationCounter(); + + String nodeName = typeNode.getIdentifier().toString(); + myASTVisitor.currentFileName = nodeName; + + myASTVisitor.visualizeNodeToJava(myASTVisitor.importListStrings); + + Type type = typeNode.getType(compilationCounter); + if (type.getTypetype().equals(TYPE_TTCN3_SEQUENCE)) {// record + + Def_Type_Record_Writer.getInstance(typeNode); + + myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "record"); + parentName = nodeName; + + } else if (type.getTypetype().equals(TYPE_TTCN3_SET)) { + + Def_Type_Set_Writer.getInstance(typeNode); + + myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "set"); + parentName = nodeName; + + } else if (type.getTypetype().equals(TYPE_TTCN3_CHOICE)) { + + Def_Type_Union_Writer.getInstance(typeNode); + + myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "union"); + parentName = nodeName; + + } else if (type instanceof Integer_Type) { + + Def_Type_Integer_Writer.getInstance(typeNode); + + myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "INTEGER"); + parentName = nodeName; + isInteger = true; + + } else if (type instanceof CharString_Type) { + + Def_Type_Charstring_Writer.getInstance(typeNode); + + myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "CHARSTRING"); + parentName = nodeName; + + } else if (type instanceof TTCN3_Enumerated_Type) { + + Def_Type_Enum_Writer.getInstance(typeNode); + + myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "enum"); + parentName = nodeName; + + } else if (type.getTypetype().equals(TYPE_SET_OF)) { + + waitForSetOfFieldType = true; + myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "setof"); + parentName = nodeName; + + } else if (type.getTypetype().equals(TYPE_SEQUENCE_OF)) { + + waitForRecordOfFieldType = true; + myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "recordof"); + parentName = nodeName; + + } else if (type.getTypetype().equals(TYPE_PORT)) { + + Def_Type_Port_Writer.getInstance(typeNode); + + waitingForPortAttriburtes = true; + currentPortName = nodeName; + myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "port"); + parentName = nodeName; + + } else if (type.getTypetype().equals(TYPE_COMPONENT)) { + + Def_Type_Component_Writer.getInstance(typeNode); + waitForCompReference = true; + + AstWalkerJava.componentList.add(nodeName); + myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "component"); + parentName = nodeName; + } + } + + /** + * Primitive mapper function to map the typename to its respective class. + * Returns null, if the given typename is not supported + * @param typename the typename to map + * @return the simple name of the respective class, or null if not supported. + */ + private String mapBaseType(String typename) { + switch (typename) { + case "boolean": + return BOOLEAN.class.getSimpleName(); + case "integer": + return INTEGER.class.getSimpleName(); + case "charstring": + return CHARSTRING.class.getSimpleName(); + case "bitstring": + return BITSTRING.class.getSimpleName(); + case "octetstring": + return OCTETSTRING.class.getSimpleName(); + default: + System.out.println("Unknown type " + typename); + return null; + } + } + + public void visitDefTypeChildrenNodes(IVisitableNode node) { + + if (node instanceof Def_Port) { + Def_Port port = (Def_Port) node; + compPortNames.add(port.getIdentifier().toString()); + } + + if (waitForCompReference && (node instanceof Reference)) { + compPortTypes.add(((Reference) node).getId().toString()); + } + + if (waitForSetOfFieldType) { + if (node instanceof Reference) { + setOfFieldType = node.toString(); + myASTVisitor.nodeNameSetOfTypesHashMap.put(parentName, setOfFieldType); + waitForSetOfFieldType = false; + } else if (node instanceof Type + && !(node instanceof Referenced_Type) + && !(node instanceof SetOf_Type)) { + Type type = (Type) node; + setOfFieldType = mapBaseType(type.getTypename()); + myASTVisitor.nodeNameSetOfTypesHashMap.put(parentName, setOfFieldType); + waitForSetOfFieldType = false; + } + } + + if (waitForRecordOfFieldType) { + if (node instanceof Reference) { + recordOfFieldType = node.toString(); + myASTVisitor.nodeNameRecordOfTypesHashMap.put(parentName, recordOfFieldType); + waitForRecordOfFieldType = false; + } else if (node instanceof Type + && !(node instanceof Referenced_Type) + && !(node instanceof SequenceOf_Type)) { + Type type = (Type) node; + recordOfFieldType = mapBaseType(type.getTypename()); + myASTVisitor.nodeNameRecordOfTypesHashMap.put(parentName, recordOfFieldType); + waitForRecordOfFieldType = false; + } + } + + if (node instanceof CompField) { // component + + CompField compFieldNode = (CompField) node; + + if (compFieldNode.getType() instanceof Referenced_Type) { + + compFieldTypes.add(((Referenced_Type) compFieldNode.getType()).getReference().getId().toString()); + } else { + compFieldTypes.add(myASTVisitor.cutModuleNameFromBeginning(compFieldNode.getType().getTypename())); + } + compFieldNames.add(compFieldNode.getIdentifier().toString()); + + } + + if (node instanceof Charstring_Value) {// charstring + + Charstring_Value singleValuedNode = (Charstring_Value) node; + + charstringValue = singleValuedNode.getValue(); + + } + + if (node instanceof Integer_Value) { + String value = ((Integer_Value) node).toString(); + if (myASTVisitor.isNextIntegerNegative) { + value = "-" + value; + } + + expressionValue.add("new INTEGER(new BigInteger(\"" + value + "\"))"); + } + + if (node instanceof Real_Value) { + String value = ((Real_Value) node).toString(); + if (myASTVisitor.isNextIntegerNegative) { + value = "-" + value; + } + + expressionValue.add(value); + } + + if (node instanceof Undefined_LowerIdentifier_Value) { + String value = ((Undefined_LowerIdentifier_Value) node).getIdentifier().toString(); + if (myASTVisitor.isNextIntegerNegative) { + value = "-" + value; + } + + expressionValue.add(value); + } + + if (node instanceof EnumerationItems) {// enum + + for (int i = 0; i < ((EnumerationItems) node).getItems().size(); i++) { + enumItems.add(((EnumerationItems) node).getItems().get(i).getId().toString()); + if (((EnumerationItems) node).getItems().get(i).getValue() != null) { + enumItemValues.add(((EnumerationItems) node).getItems().get(i).getValue().toString()); + } else { + enumItemValues.add(null); + } + } + } + + if (waitingForPortAttriburtes && (node instanceof Referenced_Type)) { + isPortTypeAReferencedType = true; + + } + + if (waitingForPortAttriburtes && (node instanceof PortTypeBody)) { + PortTypeBody body = (PortTypeBody) node; + int inCount = body.getInMessages().getNofTypes(); + int outCount = body.getOutMessage().getNofTypes(); + + for (int i = 0; i < inCount; i++) { + inMessageName.add( + myASTVisitor.cutModuleNameFromBeginning(body.getInMessages().getTypeByIndex(i).getTypename())); + } + for (int i = 0; i < outCount; i++) { + outMessageName.add( + myASTVisitor.cutModuleNameFromBeginning(body.getOutMessage().getTypeByIndex(i).getTypename())); + } + + int shorterListSize = inMessageName.size() <= outMessageName.size() ? inMessageName.size() + : outMessageName.size(); + + // check if one of the messages is inout + // if inout delete from both lists and add to inout + for (int i = 0; i < shorterListSize; i++) { + if (inMessageName.size() == shorterListSize) { + for (int j = 0; j < outMessageName.size(); j++) { + if (inMessageName.get(i).equals(outMessageName.get(j))) { + inOutMessageName.add(inMessageName.get(i)); + + } + } + } else { + for (int j = 0; j < outMessageName.size(); j++) { + if (outMessageName.get(i).equals(inMessageName.get(j))) { + inOutMessageName.add(outMessageName.get(i)); + + } + } + } + } + int counter = 0; + while (counter < inMessageName.size()) { + for (int i = 0; i < inOutMessageName.size(); i++) { + if (inMessageName.get(counter).equals(inOutMessageName.get(i))) { + inMessageName.remove(counter); + } else { + counter++; + } + } + } + counter = 0; + while (counter < outMessageName.size()) { + for (int i = 0; i < inOutMessageName.size(); i++) { + if (outMessageName.get(counter).equals(inOutMessageName.get(i))) { + outMessageName.remove(counter); + } else { + counter++; + } + } + } + + myASTVisitor.portNamePortTypeHashMap.put(currentPortName, body.getTestportType().toString()); + portTypeList.add(body.getTestportType().toString()); + } + } + + public void leave(IVisitableNode node) { + if (node instanceof Def_Type) { + evaluateExpression(); + handleDefTypeNodes(node); + waitForDefType = false; + waitForValue = false; + + isInteger = false; + } + } + + public void handleDefTypeNodes(IVisitableNode node) { + Def_Type typeNode = (Def_Type) node; + + CompilationTimeStamp compilationCounter = CompilationTimeStamp.getNewCompilationCounter(); + + myASTVisitor.currentFileName = typeNode.getIdentifier().toString(); + + Type type = typeNode.getType(compilationCounter); + if (type.getTypetype().equals(TYPE_TTCN3_SEQUENCE)) {// record + + Def_Type_Record_Writer recordNode = Def_Type_Record_Writer.getInstance(typeNode); + recordNode.clearLists(); + // add component fields + recordNode.compFieldTypes.addAll(compFieldTypes); + recordNode.compFieldNames.addAll(compFieldNames); + + String[] typeArray = (String[]) compFieldTypes.toArray(new String[compFieldTypes.size()]); + String[] nameArray = (String[]) compFieldNames.toArray(new String[compFieldNames.size()]); + + myASTVisitor.nodeNameChildrenTypesHashMap.put(parentName, typeArray); + myASTVisitor.nodeNameChildrenNamesHashMap.put(parentName, nameArray); + + compFieldTypes.clear(); + compFieldNames.clear(); + + myASTVisitor.visualizeNodeToJava(recordNode.getJavaSource()); + + } else if (type.getTypetype().equals(TYPE_TTCN3_SET)) {// set + + Def_Type_Set_Writer setdNode = Def_Type_Set_Writer.getInstance(typeNode); + setdNode.clearLists(); + // add component fields + setdNode.compFieldTypes.addAll(compFieldTypes); + setdNode.compFieldNames.addAll(compFieldNames); + + String[] typeArray = (String[]) compFieldTypes.toArray(new String[compFieldTypes.size()]); + String[] nameArray = (String[]) compFieldNames.toArray(new String[compFieldNames.size()]); + + myASTVisitor.nodeNameChildrenTypesHashMap.put(parentName, typeArray); + myASTVisitor.nodeNameChildrenNamesHashMap.put(parentName, nameArray); + + compFieldTypes.clear(); + compFieldNames.clear(); + + myASTVisitor.visualizeNodeToJava(setdNode.getJavaSource()); + + } else if (type.getTypetype().equals(TYPE_TTCN3_CHOICE)) {// union + + Def_Type_Union_Writer uniondNode = Def_Type_Union_Writer.getInstance(typeNode); + uniondNode.clearLists(); + // add component fields + uniondNode.compFieldTypes.addAll(compFieldTypes); + uniondNode.compFieldNames.addAll(compFieldNames); + + String[] typeArray = (String[]) compFieldTypes.toArray(new String[compFieldTypes.size()]); + String[] nameArray = (String[]) compFieldNames.toArray(new String[compFieldNames.size()]); + + myASTVisitor.nodeNameChildrenTypesHashMap.put(parentName, typeArray); + myASTVisitor.nodeNameChildrenNamesHashMap.put(parentName, nameArray); + + compFieldTypes.clear(); + compFieldNames.clear(); + + myASTVisitor.visualizeNodeToJava(uniondNode.getJavaSource()); + + } else if (type instanceof Integer_Type) { + + Def_Type_Integer_Writer integerNode = Def_Type_Integer_Writer.getInstance(typeNode); + integerNode.clearLists(); + + myASTVisitor.visualizeNodeToJava(integerNode.getJavaSource()); + + } else if (type instanceof CharString_Type) { + + Def_Type_Charstring_Writer charstringNode = Def_Type_Charstring_Writer.getInstance(typeNode); + charstringNode.clearLists(); + + charstringNode.addCharStringValue(charstringValue); + charstringValue = null; + + myASTVisitor.visualizeNodeToJava(charstringNode.getJavaSource()); + + } else if (type instanceof TTCN3_Enumerated_Type) { + + Def_Type_Enum_Writer enumTypeNode = Def_Type_Enum_Writer.getInstance(typeNode); + enumTypeNode.clearLists(); + + enumTypeNode.enumItems.addAll(enumItems); + enumTypeNode.enumItemValues.addAll(enumItemValues); + + enumItemValues.clear(); + enumItems.clear(); + + myASTVisitor.visualizeNodeToJava(enumTypeNode.getJavaSource()); + + } else if (type.getTypetype().equals(TYPE_SET_OF)) { + + Def_Type_Set_Of_Writer setOfNode = new Def_Type_Set_Of_Writer(typeNode); + setOfNode.setFieldType(setOfFieldType); + setOfFieldType = null; + + myASTVisitor.visualizeNodeToJava(setOfNode.getJavaSource()); + + } else if (type.getTypetype().equals(TYPE_SEQUENCE_OF)) { + + Def_Type_Record_Of_Writer writer = new Def_Type_Record_Of_Writer(typeNode); + writer.setFieldType(recordOfFieldType); + myASTVisitor.visualizeNodeToJava(writer.getJavaSource()); + + } else if (type.getTypetype().equals(TYPE_PORT)) { + + Def_Type_Port_Writer portNode = Def_Type_Port_Writer.getInstance(typeNode); + portNode.clearLists(); + + portNode.inMessageName.addAll(inMessageName); + portNode.outMessageName.addAll(outMessageName); + portNode.inOutMessageName.addAll(inOutMessageName); + + portNode.setPortTypeAReferencedType(isPortTypeAReferencedType); + + waitingForPortAttriburtes = false; + isPortTypeAReferencedType = false; + inMessageName.clear(); + outMessageName.clear(); + inOutMessageName.clear(); + myASTVisitor.visualizeNodeToJava(portNode.getJavaSource()); + + } else if (type.getTypetype().equals(TYPE_COMPONENT)) { + + Def_Type_Component_Writer compNode = Def_Type_Component_Writer.getInstance(typeNode); + compNode.clearLists(); + + // add component fields + + compNode.compFieldTypes.addAll(compPortTypes); + compNode.compFieldNames.addAll(compPortNames); + + compPortTypes.clear(); + compPortNames.clear(); + waitForCompReference = false; + myASTVisitor.visualizeNodeToJava(compNode.getJavaSource()); + + } + parentName = null; + } +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/JavaSourceProvider.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/JavaSourceProvider.java new file mode 100644 index 000000000..e829d2f47 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/JavaSourceProvider.java @@ -0,0 +1,18 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Meszaros, Mate Robert + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator; + +public interface JavaSourceProvider { + String getJavaSource(); +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/SourceCode.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/SourceCode.java new file mode 100644 index 000000000..145810757 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/SourceCode.java @@ -0,0 +1,52 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Meszaros, Mate Robert + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator; + +import static org.eclipse.titan.codegenerator.SourceCode.Indentation.MAX_LEVEL; +import static org.eclipse.titan.codegenerator.SourceCode.Indentation.TOKEN; + +public class SourceCode { + + interface Indentation { + int MAX_LEVEL = 50; + String TOKEN = "\t"; + } + + private static final String BASE = new String(new char[MAX_LEVEL]).replace("\0", TOKEN); + + private StringBuilder builder = new StringBuilder(); + + public SourceCode indent(int level) { + builder.append(BASE.substring(0, level)); + return this; + } + + public SourceCode line(Object... objects) { + for (Object o : objects) { + builder.append(o); + } + builder.append(System.lineSeparator()); + return this; + } + + public SourceCode clear() { + builder.setLength(0); + return this; + } + + @Override + public String toString() { + return builder.toString(); + } +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/AllTestComponents.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/AllTestComponents.java new file mode 100644 index 000000000..a1eb6a2ed --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/AllTestComponents.java @@ -0,0 +1,52 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +import java.util.ArrayList; +import java.util.List; + +//class for registering all test components taking part in text execution +public class AllTestComponents { + + private static List components; + + public static List getComponents() { + return components; + } + + public static void addComponent(ComponentDef c) { + if (components == null) components = new ArrayList(); + components.add(c); + } + + public static String getGlobalVerdict(){ + int verdict=-1; + for(int i=0;iverdict) verdict=v; + } + switch (verdict){ + case 0: return "none"; + case 1: return "pass"; + case 2: return "inconc"; + case 3: return "fail"; + case 4: return "error"; + } + return null; + } + +} \ No newline at end of file diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/Arithmetical.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/Arithmetical.java new file mode 100644 index 000000000..ceee3dbc9 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/Arithmetical.java @@ -0,0 +1,28 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +public abstract class Arithmetical extends Relational { + + public abstract T plus(T t); + + public abstract T minus(T t); + + public abstract T multipleBy(T t); + + public abstract T divideBy(T t); + +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/BINARY_STRING.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/BINARY_STRING.java new file mode 100644 index 000000000..3b705c402 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/BINARY_STRING.java @@ -0,0 +1,88 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +//maybe this should be abstract and the fromXXX methods should be removed. + +public class BINARY_STRING extends STRING{ + + public BINARY_STRING(){ + } + + public BINARY_STRING(String s){ + super(s); + } + + protected int fromBitString(byte[] b){ + String str = new String(b); + return Integer.parseInt(str, 2); + } + + protected int fromOctetString(byte[] b){ + String str = new String(b); + return Integer.parseInt(str, 8); + } + + protected int fromHexString(byte[] b){ + String str = new String(b); + return Integer.parseInt(str, 16); + } + + public int generalBitwiseNot(int o1){ + return ~o1; + } + + public int generalBitwiseAnd(int o1, int o2){ + return o1 & o2; + } + + public int generalBitwiseOr(int o1, int o2){ + return o1 | o2; + } + + public int generalBitwiseXor(int o1, int o2){ + return o1 ^ o2; + } + + //converts the input from INTEGER to int!!! + public BINARY_STRING shiftLeft(INTEGER by){ + byte[] copy = new byte[value.length]; + for(int i=0;i= value.length){ + return new BINARY_STRING(new String(copy)); + } + System.arraycopy(value,byValue,copy,0,value.length-byValue); + return new BINARY_STRING(new String(copy)); + } + + //converts the input from INTEGER to int!!! + public BINARY_STRING shiftRight(INTEGER by){ + byte[] copy = new byte[value.length]; + for(int i=0;i= value.length){ + return new BINARY_STRING(new String(copy)); + } + System.arraycopy(value,0,copy,byValue,value.length-byValue); + return new BINARY_STRING(new String(copy)); + } + +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/BITSTRING.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/BITSTRING.java new file mode 100644 index 000000000..cb6801354 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/BITSTRING.java @@ -0,0 +1,55 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +public class BITSTRING extends BINARY_STRING{ + + public BITSTRING(){ + } + + public BITSTRING(String inputvalue) { + super(inputvalue); + Integer.parseInt(inputvalue, 2); //Throws an exception if not legal + } + + public BITSTRING bitwiseNot(){ + return new BITSTRING(Integer.toBinaryString(generalBitwiseNot(fromBitString(value)))); + } + + public BITSTRING bitwiseAnd(BITSTRING b){ + return new BITSTRING(Integer.toBinaryString(generalBitwiseAnd(fromBitString(value), fromBitString(b.value)))); + } + + public BITSTRING bitwiseOr(BITSTRING b){ + return new BITSTRING(Integer.toBinaryString(generalBitwiseOr(fromBitString(value), fromBitString(b.value)))); + } + + public BITSTRING bitwiseXor(BITSTRING b){ + return new BITSTRING(Integer.toBinaryString(generalBitwiseXor(fromBitString(value), fromBitString(b.value)))); + } + + public String toString() { + return toString(""); + } + + public String toString(String tabs){ + if(anyField) return "?"; + if(omitField) return "omit"; + if(anyOrOmitField) return "*"; + return "B'" + new String(value) + "'"; + } + +} \ No newline at end of file diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/BOOLEAN.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/BOOLEAN.java new file mode 100644 index 000000000..da832d6b9 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/BOOLEAN.java @@ -0,0 +1,79 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +public class BOOLEAN extends Comparable{ + + Boolean value; + + public BOOLEAN() { + + } + + public BOOLEAN(boolean value){ + this.value = value; + } + + public BOOLEAN(BOOLEAN value){ + this.value = value.getValue(); + } + + public BOOLEAN equalsWith(BOOLEAN aBoolean) { + return new BOOLEAN(value == aBoolean.value); + } + + public BOOLEAN not(){ + return new BOOLEAN(!value); + } + + public BOOLEAN and(BOOLEAN b){ + return new BOOLEAN(value && b.value); + } + + public BOOLEAN or(BOOLEAN b){ + return new BOOLEAN(value || b.value); + } + + public BOOLEAN xor(BOOLEAN b) { + return new BOOLEAN(value ^ b.value); + } + + public String toString(){ + return toString(""); + } + + public Boolean getValue(){ + return this.value; + } + + public String toString(String tabs){ + if(anyField) return "?"; + if(omitField) return "omit"; + if(anyOrOmitField) return "*"; + return Boolean.toString(value); + } + + public static boolean match(BOOLEAN pattern, BOOLEAN message){ + if(!(message instanceof BOOLEAN)) return false; + if(pattern.omitField&&((BOOLEAN)message).omitField) return true; + if(pattern.anyOrOmitField) return true; + if(pattern.anyField&&!((BOOLEAN)message).omitField) return true; + if(pattern.omitField&&!((BOOLEAN)message).omitField) return false; + if(pattern.anyField&&((BOOLEAN)message).omitField) return false; + return (pattern.value.equals(((BOOLEAN)message).value)); + } + +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/CHARSTRING.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/CHARSTRING.java new file mode 100644 index 000000000..44986f246 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/CHARSTRING.java @@ -0,0 +1,48 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +import java.math.BigInteger; + +public class CHARSTRING extends STRING{ + + public CHARSTRING(String value) { + super(value); + //TODO check whether it really is a charstring + } + + public CHARSTRING() { + super(); + } + + public String toString() { + return toString(""); + } + + + public INTEGER str2int(){ + return new INTEGER(new BigInteger(value.toString())); + } + + //needed even though tabs is not used, since otherwise the method of STRING would run and return null + public String toString(String tabs){ + if(anyField) return "?"; + if(omitField) return "omit"; + if(anyOrOmitField) return "*"; + return "\"" + new String(value) + "\""; + } + +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/Comparable.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/Comparable.java new file mode 100644 index 000000000..823eba44c --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/Comparable.java @@ -0,0 +1,22 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +public abstract class Comparable extends PrimitiveTypeDef { + + public abstract BOOLEAN equalsWith(T t); + +} \ No newline at end of file diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/ComponentDef.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/ComponentDef.java new file mode 100644 index 000000000..632bdebec --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/ComponentDef.java @@ -0,0 +1,76 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; +import org.eclipse.titan.codegenerator.javagen.*; + +public abstract class ComponentDef extends ModuleDef{ + public boolean created = false; //state variable + + public BlockingQueue donequeue = new ArrayBlockingQueue(1024); + public String name; + public Thread thread; + public abstract void prepareforconnection(String thisport, int thisportnum); + public abstract void domap(String thisport, String remotecomp, String remoteport); + public abstract void connect(String port, String ip, String portnum); + public HCType hc; + public String compid; + public BlockingQueue queue = new ArrayBlockingQueue(1024); + private int verdict; //0-none, 1-pass, 2-inconc, 3-fail, 4-error + public BlockingQueue lockqueue = new ArrayBlockingQueue(1024); + + public synchronized void lock(){ + while(!lockqueue.isEmpty()){ + try{ + lockqueue.take(); + }catch(Exception e){} + } + } + + public void unlock(){ + lockqueue.add(true); + } + + public ComponentDef(String n) { + name = n; + setVerdict("none"); + } + + public void setVerdict(String s) { + int v = -1; + if (s == "none") v = 0; + if (s == "pass") v = 1; + if (s == "inconc") v = 2; + if (s == "fail") v = 3; + if (s == "error") v = 4; + if (v > verdict) verdict = v; + } + + public int getVerdictInt(){ + return verdict; + } + + public String getVerdict(){ + if(verdict==0) return "none"; + if(verdict==1) return "pass"; + if(verdict==2) return "inconc"; + if(verdict==3) return "fail"; + if(verdict==4) return "error"; + return ""; + } +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/ENUMERATED.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/ENUMERATED.java new file mode 100644 index 000000000..bb4e9dd44 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/ENUMERATED.java @@ -0,0 +1,82 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +import java.util.HashMap; + +public class ENUMERATED extends Relational { + + protected String value; + public HashMap values; + + public void setValue(String v) throws IndexOutOfBoundsException{ + if(values.keySet().contains(v)) value=v; + else{ + throw new IndexOutOfBoundsException("Illegal ENUMERATED value."); + } + } + + public ENUMERATED(){ + values = new HashMap(); + } + + public String getValue(){ + return value; + } + + public BOOLEAN isGreaterThan(ENUMERATED enumerated) { + return new BOOLEAN(false); + } + + public BOOLEAN isGreaterOrEqualThan(ENUMERATED enumerated) { + return new BOOLEAN(false); + } + + public BOOLEAN isLessThan(ENUMERATED enumerated) { + return new BOOLEAN(false); + } + + public BOOLEAN isLessOrEqualThan(ENUMERATED enumerated) { + return new BOOLEAN(false); + } + + public BOOLEAN equalsWith(ENUMERATED enumerated) { + return new BOOLEAN(false); + } + + public static boolean match(ENUMERATED pattern, Object message){ + if(!(message instanceof ENUMERATED)) return false; + if(pattern.omitField&&((ENUMERATED)message).omitField) return true; + if(pattern.anyOrOmitField) return true; + if(pattern.anyField&&!((ENUMERATED)message).omitField) return true; + if(pattern.omitField&&!((ENUMERATED)message).omitField) return false; + if(pattern.anyField&&((ENUMERATED)message).omitField) return false; + return (pattern.getValue().equals(((ENUMERATED)message).getValue())); + } + + public BOOLEAN equals(ENUMERATED v){ + return new BOOLEAN(this.value.equals(v.getValue())); + } + + public String toString() { + return toString(""); + } + + public String toString(String tabs){ + return getValue(); + } + +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/FLOAT.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/FLOAT.java new file mode 100644 index 000000000..7d7dc9d8f --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/FLOAT.java @@ -0,0 +1,91 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +public class FLOAT extends Arithmetical { + + public Double value; + + public FLOAT() { + + } + + public FLOAT(Double value) { + this.value = value; + } + + public FLOAT plus(FLOAT aFloat) { + return new FLOAT(value + aFloat.value); + } + + public FLOAT minus(FLOAT aFloat) { + return new FLOAT(value - aFloat.value); + } + + public FLOAT multipleBy(FLOAT aFloat) { + return new FLOAT(value * aFloat.value); + } + + public FLOAT divideBy(FLOAT aFloat) { + return new FLOAT(value / aFloat.value); + } + + public BOOLEAN isGreaterThan(FLOAT aFloat) { + return new BOOLEAN(value > aFloat.value); + } + + public BOOLEAN isGreaterOrEqualThan(FLOAT aFloat) { + return new BOOLEAN(value >= aFloat.value); + } + + public BOOLEAN isLessThan(FLOAT aFloat) { + return new BOOLEAN(value < aFloat.value); + } + + public BOOLEAN isLessOrEqualThan(FLOAT aFloat) { + return new BOOLEAN(value <= aFloat.value); + } + + public BOOLEAN equalsWith(FLOAT aFloat) { + return new BOOLEAN(value.equals(aFloat.value)); + } + + public BOOLEAN notEqualsWith(FLOAT aFloat) { + return new BOOLEAN(!value.equals(aFloat.value)); + } + + public static boolean match(FLOAT pattern, FLOAT message){ + if(!(message instanceof FLOAT)) return false; + if(pattern.omitField&&((FLOAT)message).omitField) return true; + if(pattern.anyOrOmitField) return true; + if(pattern.anyField&&!((FLOAT)message).omitField) return true; + if(pattern.omitField&&!((FLOAT)message).omitField) return false; + if(pattern.anyField&&((FLOAT)message).omitField) return false; + return (pattern.value.equals(((FLOAT)message).value)); + } + + public String toString() { + return toString(""); + } + + public String toString(String tabs){ + if(anyField) return "?"; + if(omitField) return "omit"; + if(anyOrOmitField) return "*"; + return value.toString(); + } + +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/HEXSTRING.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/HEXSTRING.java new file mode 100644 index 000000000..2b19af644 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/HEXSTRING.java @@ -0,0 +1,55 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +public class HEXSTRING extends BINARY_STRING { + + public HEXSTRING() { + } + + public HEXSTRING(String value) { + super(value); + Integer.parseInt(value, 16); //throws an exception if not legal + } + + public HEXSTRING bitwiseNot(){ + return new HEXSTRING(Integer.toHexString(generalBitwiseNot(fromHexString(value)))); + } + + public HEXSTRING bitwiseAnd(HEXSTRING b){ + return new HEXSTRING(Integer.toHexString(generalBitwiseAnd(fromHexString(value), fromHexString(b.value)))); + } + + public HEXSTRING bitwiseOr(HEXSTRING b){ + return new HEXSTRING(Integer.toHexString(generalBitwiseOr(fromHexString(value), fromHexString(b.value)))); + } + + public HEXSTRING bitwiseXor(HEXSTRING b){ + return new HEXSTRING(Integer.toHexString(generalBitwiseXor(fromHexString(value), fromHexString(b.value)))); + } + + public String toString() { + return toString(""); + } + + public String toString(String tabs){ + if(anyField) return "?"; + if(omitField) return "omit"; + if(anyOrOmitField) return "*"; + return "H'" + new String(value) + "'"; + } + +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/INTEGER.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/INTEGER.java new file mode 100644 index 000000000..4dff41c1f --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/INTEGER.java @@ -0,0 +1,140 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +import java.math.BigInteger; + +public class INTEGER extends Arithmetical { + + BigInteger value; + + public INTEGER() { + + } + + public INTEGER(BigInteger value) { + this.value = value; + } + + public INTEGER negate() { + return new INTEGER(value.multiply(new BigInteger("-1"))); + } + + public INTEGER rem(INTEGER divider){ + BigInteger val = value.divide(divider.value.multiply((value.divide(divider.value)))); + return new INTEGER(val); + } + + public INTEGER mod(INTEGER divider){ + if(value.compareTo( BigInteger.valueOf(0)) >= 0) { + if (divider.value.compareTo( BigInteger.valueOf(0)) < 0) { + return rem(new INTEGER(divider.value.negate())); + } else { + return rem(divider); + } + } else if (value.compareTo( BigInteger.valueOf(0)) < 0 && rem(this).equalsWith(new INTEGER(BigInteger.valueOf(0))).value) { + return new INTEGER(BigInteger.valueOf(0)); + } else { + return new INTEGER(divider.value.negate()).plus(rem(new INTEGER(divider.value.negate()))); + } + } + + public INTEGER plus(INTEGER integer) { + return new INTEGER(integer.value.add(value)); + } + + public INTEGER minus(INTEGER integer) { + return new INTEGER(value.subtract(integer.value)); + } + + public INTEGER multipleBy(INTEGER integer) { + return new INTEGER(value.multiply(integer.value)); + } + + public INTEGER divideBy(INTEGER integer) { + return new INTEGER(value.divide(integer.value)); + } + + public BOOLEAN isGreaterThan(INTEGER integer) { + if(value.compareTo(integer.value)==1){ + return new BOOLEAN(true); + }else{ + return new BOOLEAN(false); + } + } + + public BOOLEAN isGreaterOrEqualThan(INTEGER integer) { + if(value.compareTo(integer.value)>=0){ + return new BOOLEAN(true); + }else{ + return new BOOLEAN(false); + } + } + + public BOOLEAN isLessThan(INTEGER integer) { + if(value.compareTo(integer.value)==-1){ + return new BOOLEAN(true); + }else{ + return new BOOLEAN(false); + } + } + + public BOOLEAN isLessOrEqualThan(INTEGER integer) { + if(value.compareTo(integer.value)<=0){ + return new BOOLEAN(true); + }else{ + return new BOOLEAN(false); + } + } + + public BOOLEAN equalsWith(INTEGER integer) { + return new BOOLEAN(value.equals(integer.value)); + } + + public BOOLEAN notEqualsWith(INTEGER integer) { + return new BOOLEAN(!value.equals(integer.value)); + } + + public static boolean match(INTEGER pattern, Object message){ + if(!(message instanceof INTEGER)) return false; + if(pattern.omitField&&((INTEGER)message).omitField) return true; + if(pattern.anyOrOmitField) return true; + if(pattern.anyField&&!((INTEGER)message).omitField) return true; + if(pattern.omitField&&!((INTEGER)message).omitField) return false; + if(pattern.anyField&&((INTEGER)message).omitField) return false; + return (pattern.value.equals(((INTEGER)message).value)); + } + + public BOOLEAN equals(INTEGER v){ + return new BOOLEAN(this.value.equals(v.value)); + } + + public CHARSTRING int2str(){ + return new CHARSTRING(value.toString()); + } + + public String toString() { + return toString(""); + } + + public String toString(String tabs){ + if(anyField) return "?"; + if(omitField) return "omit"; + if(anyOrOmitField) return "*"; + return value.toString(); + } + +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/Indexable.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/Indexable.java new file mode 100644 index 000000000..ec027c441 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/Indexable.java @@ -0,0 +1,34 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Meszaros, Mate Robert + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +/** + * This interface imposes an indexability of the object that implements it. + * @param the type of objects that can be retrieved from and set to + */ +public interface Indexable { + /** + * Returns with the value at the specified index of this indexable object. + * @param index the position to be queried + * @return the value at the specified position + */ + T get(int index); + + /** + * Replaces the value at the specified index with the given value + * @param index the position to be replaced + * @param t the value to be set to the given position of this indexable object + */ + void set(int index, T t); +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/MC.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/MC.java new file mode 100644 index 000000000..3cf82399a --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/MC.java @@ -0,0 +1,36 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +/* Main Controller */ +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +public class MC{ + + //these will be retrieved from the config file later. + private static int SERVERPORTNUM = 5557; + private static String MTCIP = "127.0.0.1"; //IP of machine that has to run the MTC + private static int HCNUM = 1; //later from config file + private static boolean DEBUGMODE = false; + private static String TC = "tc_Controller"; //TC to be executed + + private static MCType mc; + + public static void main(String[] args){ + mc = new MCType(DEBUGMODE); + mc.startmc(SERVERPORTNUM, MTCIP, TC, HCNUM); + TTCN3Logger.writeLog("mc", "EXECUTOR", "Main Controller stopped", false); + } + +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/MCType.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/MCType.java new file mode 100644 index 000000000..9de030363 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/MCType.java @@ -0,0 +1,251 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.Vector; + +public class MCType { + + //tables: HCs(listeners, writers, ready, hcips); TComps(componentnames, componentips) + + int ptcid; + Vector listeners; //listener threads + Vector writers; //writers for writing outsockets + Vector componentnames; //component names belonging to listeners/writers + Vector componentips; //component IP addresses + Vector ready; //readers are initialised for all threads + Vector hcips; //host controller IP addresses + Vector compstobedone; //Number of those components that have to be done. + Vector verdicts; + boolean allHCsConnected = false; + boolean debugmode; + + private class HCListener extends Thread { + private MCType mc; + private Socket sock; + private BufferedReader reader; + private boolean debugmode; + + public HCListener(MCType mcont, Socket socket, boolean debugmode){ + mc=mcont; + sock=socket; + this.debugmode=debugmode; + } + + private void sendtocomponenthc(String compname, String message){ + try{ + int index = getcomponenthcindex(compname); + writers.get(index).write(message + "\r\n"); + writers.get(index).flush(); + }catch(Exception e){e.printStackTrace();} + } + + private int getcomponenthcindex(String compname){ + for(int i=0;iHC: " + message, false); + writers.get(i).write(message + "\r\n"); + writers.get(i).flush(); + }catch(Exception e){e.printStackTrace();} + } + } + + public void run(){ + try{ + reader=new BufferedReader(new InputStreamReader(this.sock.getInputStream())); + }catch(Exception e){} + mc.ready.add(true); + try{ + for(;;){ + if(debugmode)TTCN3Logger.writeLog("mc", "EXECUTOR", "Main Controller waiting for message", false); + String message = reader.readLine(); + if(debugmode)TTCN3Logger.writeLog("mc", "EXECUTOR", "Main Controller received " + message, false); + if(message==null) break; //for some reason it does not break when receiving finished mtc but reads another line which is null. + if(message.equals("quit")) break; + if(message.equals("connected")){ + sendtocomponenthc("mtc", "connected"); + } + if(message.equals("mapped")){ + sendtocomponenthc("mtc", "mapped"); + } + String command = message.split(" ")[0]; + if(command.equals("create")){ + String compname = message.split(" ")[1]; + String comptype = message.split(" ")[2]; + String ipaddr = message.split(" ")[3]; + sendtohc(ipaddr, "create " + compname + " " + comptype + " " + Integer.toString(mc.getPTCID())); + if(debugmode)TTCN3Logger.writeLog("mc", "EXECUTOR", "CREATE command forwarded to Host Controller on " + ipaddr, false); + componentnames.add(compname); + componentips.add(ipaddr); + } + if(command.equals("connect")){ + String comp1 = message.split(" ")[1]; + String port1 = message.split(" ")[2]; + String comp2 = message.split(" ")[3]; + String port2 = message.split(" ")[4]; + if(debugmode)TTCN3Logger.writeLog("mc", "EXECUTOR", "Preparing test component port " + comp1 + ":" + port1 + " for connection as RESPONDER", false); + sendtocomponenthc(comp1, "prepareforconnection " + comp1 + " " + port1 + " " + comp2 + " " + port2); + } + if(command.equals("map")){ + String comp1 = message.split(" ")[1]; + String port1 = message.split(" ")[2]; + String comp2 = message.split(" ")[3]; + String port2 = message.split(" ")[4]; + if(comp1.equals("system"))sendtocomponenthc(comp2, "map " + comp2 + " " + port2 + " " + comp1 + " " + port1); + if(comp2.equals("system"))sendtocomponenthc(comp1, "map " + comp1 + " " + port1 + " " + comp2 + " " + port2); + } + if(command.equals("preparedforconnection")){ //this case is defined separately since a different thread will get this message back than the one that has initiated it. + String comp2 = message.split(" ")[1]; + String port2 = message.split(" ")[2]; + String portnum = message.split(" ")[3]; + String comp1 = message.split(" ")[4]; + String comp1ip = hcips.get(getcomponenthcindex(comp1)); + if(debugmode)TTCN3Logger.writeLog("mc", "EXECUTOR", "Preparing test component port " + comp2 + ":" + port2 + " for connection as INITIATOR", false); + sendtocomponenthc(comp2, "connect " + comp2 + " " + port2 + " " + comp1ip + " " + portnum); + } + if(command.equals("start")){ + String component = message.split(" ")[1]; + if(debugmode)TTCN3Logger.writeLog("mc", "EXECUTOR", "Starting function on component " + component, false); + sendtocomponenthc(component, message); + } + if(command.equals("done")){ //mtc hcjatol + if(message.equals("done all component")){ + for(String cn:componentnames) + compstobedone.add(cn); + for(String ip:hcips) + sendtohc(ip, message); + if(debugmode)TTCN3Logger.writeLog("mc", "EXECUTOR", "Adding components to be done " + componentnames, false); + }//otherwise a single component is waited for to be done at one time. this results in blocking + else{ + String what = message.split(" ")[1]; + sendtocomponenthc(what, message); + compstobedone.add(what); + if(debugmode)TTCN3Logger.writeLog("mc", "EXECUTOR", "Adding component to be done " + what, false); + } + } + if(command.equals("finished")){ + String component = message.split(" ")[1]; + int verdict = Integer.parseInt(message.split(" ")[2]); + verdicts.add(verdict); + if(component.equals("mtc")){ + //stopping hcs + for(String ip:hcips){ + sendtohc(ip, "quit"); + } + TTCN3Logger.writeLog("mc", "EXECUTOR", "MTC finished. Global verdict: " + mc.getGlobalVerdict(), true); + break; + }else{ + compstobedone.remove(component); + TTCN3Logger.writeLog("mc", "EXECUTOR", "Component " + component + " is done. Remaining components to be done: " + compstobedone, false); + if(compstobedone.size()==1) if(compstobedone.get(0).equals("mtc")) sendtocomponenthc("mtc", "finished"); //all components which had to be done are done + } + } + } + sock.close(); + }catch(Exception e){e.printStackTrace();} + } + + } + + public synchronized int getPTCID(){ + ptcid++; + return ptcid-1; + } + + public MCType(boolean debugmode){ + listeners = new Vector(); + writers = new Vector(); + componentnames = new Vector(); + componentips = new Vector(); + ready = new Vector(); + hcips = new Vector(); + compstobedone = new Vector(); + verdicts = new Vector(); + ptcid=3; //IDs of PTCs start from 3 + this.debugmode=debugmode; + } + + public String getGlobalVerdict(){ + int verdict=-1; + for(int i=0;iverdict) verdict=v; + } + switch (verdict){ + case 0: return "none"; + case 1: return "pass"; + case 2: return "inconc"; + case 3: return "fail"; + case 4: return "error"; + } + return null; + } + + + public void startmc(int serverportnum, String mtcip, String tc, int hcnum){ + TTCN3Logger.writeLog("mc", "EXECUTOR", "Main Controller started.", false); + try{ + ServerSocket ssock = new ServerSocket(serverportnum); + if(debugmode)TTCN3Logger.writeLog("mc", "EXECUTOR", "Waiting for " + hcnum + " Host Controller(s) to connect on port " + serverportnum, false); + for(int i=0;i inMessages; //input type names of port type + public Set outMessages; //output type names of port type + protected boolean created = false; + public boolean mapped = false; + public MessagePortDef mappedto; + + public List inBuffer; //input buffer + + public MessagePortDef(ComponentDef c, String name) { + component = c; + this.name=name; + inMessages = new TreeSet(); + outMessages = new TreeSet(); + } + + public void enqueue(Object o){ //putting incoming messages to inBuffer + component.lock(); + if (!mapped){ + TTCN3Logger.writeLog(component.name + ":" + name, "PORTEVENT", "Cannot enqueue message--Port not mapped", false);//!uj + return; + } + inBuffer.add(o); + component.queue.add(true); + component.unlock(); + } +} \ No newline at end of file diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/ModuleDef.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/ModuleDef.java new file mode 100644 index 000000000..42ceda042 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/ModuleDef.java @@ -0,0 +1,21 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +import java.io.Serializable; + +public class ModuleDef implements Serializable{ +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/OCTETSTRING.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/OCTETSTRING.java new file mode 100644 index 000000000..f09917795 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/OCTETSTRING.java @@ -0,0 +1,78 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * Meszaros, Mate Robert + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +public class OCTETSTRING extends BINARY_STRING implements Indexable { + + public OCTETSTRING() { + } + + public OCTETSTRING(String value) { + super(value); + Integer.parseInt(value, 16); //throws an exception if not legal + } + + public OCTETSTRING bitwiseNot(){ + return new OCTETSTRING(Integer.toOctalString(generalBitwiseNot(fromOctetString(value)))); + } + + public OCTETSTRING bitwiseAnd(OCTETSTRING b){ + return new OCTETSTRING(Integer.toOctalString(generalBitwiseAnd(fromOctetString(value), fromOctetString(b.value)))); + } + + public OCTETSTRING bitwiseOr(OCTETSTRING b){ + return new OCTETSTRING(Integer.toOctalString(generalBitwiseOr(fromOctetString(value), fromOctetString(b.value)))); + } + + public OCTETSTRING bitwiseXor(OCTETSTRING b){ + return new OCTETSTRING(Integer.toOctalString(generalBitwiseXor(fromOctetString(value), fromOctetString(b.value)))); + } + + public String toString() { + return toString(""); + } + + public String toString(String tabs){ + if(anyField) return "?"; + if(omitField) return "omit"; + if(anyOrOmitField) return "*"; + return "O'" + new String(value) + "'"; + } + + @Override + public OCTETSTRING get(int index) { + return new OCTETSTRING(new String(new byte[]{value[2 * index], value[2 * index + 1]})); + } + + @Override + public void set(int index, OCTETSTRING octetstring) { + value[2 * index] = octetstring.value[0]; + value[2 * index + 1] = octetstring.value[1]; + } + + // TODO : create a unit-test from it + public static void main(String[] args) { + OCTETSTRING o = new OCTETSTRING("AABBCC"); + System.out.println(o); + System.out.println(o.get(0)); + System.out.println(o.get(1)); + System.out.println(o.get(2)); + o.set(0, new OCTETSTRING("DD")); + System.out.println(o.get(0)); + System.out.println(o); + } +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/PortDef.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/PortDef.java new file mode 100644 index 000000000..49263f84c --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/PortDef.java @@ -0,0 +1,25 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +public class PortDef extends ModuleDef { + protected ComponentDef component; //component including port instance + public String name; + + public ComponentDef GetComponent() { + return component; + } +} \ No newline at end of file diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/PrimitiveTypeDef.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/PrimitiveTypeDef.java new file mode 100644 index 000000000..906dc0436 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/PrimitiveTypeDef.java @@ -0,0 +1,20 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +public abstract class PrimitiveTypeDef extends TypeDef{ + +} \ No newline at end of file diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/RecordDef.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/RecordDef.java new file mode 100644 index 000000000..64c9be6d3 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/RecordDef.java @@ -0,0 +1,29 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +public abstract class RecordDef extends StructuredTypeDef { + public List fieldsInOrder; //stores the order of fields of record type + + public RecordDef(){ + fieldsInOrder = new ArrayList(); + } + +} \ No newline at end of file diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/RecordOfDef.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/RecordOfDef.java new file mode 100644 index 000000000..5cb3b5dce --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/RecordOfDef.java @@ -0,0 +1,47 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * Meszaros, Mate Robert + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +import java.util.List; + +public abstract class RecordOfDef extends StructuredTypeDef { + public List value; + + public BOOLEAN equals(RecordOfDef v) { + if (this.value.size() != v.value.size()) return new BOOLEAN(false); + for (int i = 0; i < this.value.size(); i++) + if (!(this.value.get(i).equals(v.value.get(i)))) return new BOOLEAN(false); + return new BOOLEAN(true); + } + + public String toString(){ + return toString(""); + } + + public String toString(String tabs){ + if(anyField) return "?"; + if(omitField) return "omit"; + if(anyOrOmitField) return "*"; + String retv = "["; + for(int i=0;i extends Comparable { + + public abstract BOOLEAN isGreaterThan(T t); + + public abstract BOOLEAN isGreaterOrEqualThan(T t); + + public abstract BOOLEAN isLessThan(T t); + + public abstract BOOLEAN isLessOrEqualThan(T t); + +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/STRING.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/STRING.java new file mode 100644 index 000000000..a94fafc03 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/STRING.java @@ -0,0 +1,83 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +import java.math.BigInteger; + +public class STRING extends Comparable{ + + public byte[] value; + + public STRING() { + value = null; + } + + public STRING(String s) { + this.value = s.getBytes(); + } + + public STRING concatenate(STRING other){ + return new STRING(this.value.toString() + other.value.toString()); + } + + public BOOLEAN equalsWith(STRING string) { + return new BOOLEAN(this.value.equals(string.value)); + } + + //converts the input from INTEGER to int!!! + public STRING rotateLeft(INTEGER by){ + byte[] copy = new byte[value.length]; + int byValue = by.value.intValue() % value.length; + System.arraycopy(value,byValue,copy,0,value.length-byValue); + System.arraycopy(value,0,copy,value.length-byValue,byValue); + return new STRING(new String(copy)); + } + + //converts the input from INTEGER to int!!! + public STRING rotateRight(INTEGER by) { + int byValue = by.value.intValue() % value.length; + return rotateLeft(new INTEGER(BigInteger.valueOf(value.length-byValue))); + } + + public static boolean match(STRING pattern, Object message){ + if(!(message instanceof STRING)) return false; + if(pattern.omitField&&((STRING)message).omitField) return true; + if(pattern.anyOrOmitField) return true; + if(pattern.anyField&&!((STRING)message).omitField) return true; + if(pattern.omitField&&!((STRING)message).omitField) return false; + if(pattern.anyField&&((STRING)message).omitField) return false; + return (pattern.equals(((STRING)message))).getValue(); + } + + public BOOLEAN equals(STRING v){ + for(int i=0;i extends StructuredTypeDef { + public HashSet value; + + public String toString(){ + return toString(""); + } + + public String toString(String tabs){ + if(anyField) return "?"; + if(omitField) return "omit"; + if(anyOrOmitField) return "*"; + String retv = "["; + Iterator i = value.iterator(); + while(i.hasNext()){ + retv += i.next().toString(tabs); + if(i.hasNext()) retv += ","; + } + retv += "]"; + return retv; + } +} \ No newline at end of file diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/StructuredTypeDef.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/StructuredTypeDef.java new file mode 100644 index 000000000..01d920532 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/StructuredTypeDef.java @@ -0,0 +1,20 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +public abstract class StructuredTypeDef extends TypeDef { + +} \ No newline at end of file diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/SubTypeDef.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/SubTypeDef.java new file mode 100644 index 000000000..1462bfcdd --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/SubTypeDef.java @@ -0,0 +1,54 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +import java.util.ArrayList; +import java.util.List; + +public abstract class SubTypeDef extends PrimitiveTypeDef{ + protected List allowedValues; //allowed values of subtype + protected List> allowedIntervals; //allowed intervals of subtype + + public T value; + + public SubTypeDef() { + allowedValues = new ArrayList(); + allowedIntervals = new ArrayList>(); + } + + public SubTypeDef(T val) { + this(); + value = val; + } + + public void checkValue() throws IndexOutOfBoundsException { + if (allowedValues.size() == 0 && allowedIntervals.size() == 0) + return; + for (SubTypeInterval i : allowedIntervals) + if(i.checkValue(value)) return; + for (T i : allowedValues) + if (i.equals(value)) return; + throw new IndexOutOfBoundsException("out of intervals!"); + } + + public String toString(){ + return toString(""); + } + + public String toString(String tabs){ + return value.toString(); + } +} \ No newline at end of file diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/SubTypeInterval.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/SubTypeInterval.java new file mode 100644 index 000000000..623195a19 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/SubTypeInterval.java @@ -0,0 +1,32 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +public class SubTypeInterval { + T lowerbound; + T upperbound; + + public SubTypeInterval(T lower, T upper) { + lowerbound=lower; + upperbound=upper; + } + + boolean checkValue(T value) { + if(lowerbound instanceof Relational) + return ((Relational)lowerbound).isLessOrEqualThan(value).value&&((Relational)upperbound).isGreaterOrEqualThan(value).value; + else throw new IndexOutOfBoundsException("bound is not relational"); + } +} \ No newline at end of file diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/TTCN3Logger.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/TTCN3Logger.java new file mode 100644 index 000000000..da9ad8508 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/TTCN3Logger.java @@ -0,0 +1,83 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.time.LocalDateTime; + +public class TTCN3Logger { + + private static File file=null; + +/* public static void writeLog(int source, String type, String message, boolean output){ + writeLog(source, type, "", 0, "", "", message, output); + }*/ + + public static void writeLog(String source, String type, String message, boolean output){ + writeLog(source, type, "", 0, "", "", message, output); + } + +/* public static void writeLog(int source, String type, String filename, int line, String elementType, String elementName, String message, boolean output){ + writeLog(Integer.toString(source), type, filename, line, elementType, elementName, message, output); + }*/ + + /* + * + * Logger method + * =============== + * + * Parameterization: + * source - source of log entry. mc, hc, mtc or id of ptc + * type - type of log entry. EXECUTOR, TESTCASE, PARALLEL, PORTEVENTE, TIMEROP, USER + * filename - name of ttcn3 file, if applicable (mtc, ptc) + * line - line in ttcn3 file, if applicable (mtc, ptc) + * elementType - element type in ttcn3 file, if applicable (mtc, ptc - function, testcase) + * elementName - element name in ttcn3 file, if applicable (mtc, ptc - function, testcase) + * message - the log message itself + * output - should the message appear on the output too? + * + */ + + public static void writeLog(String source, String type, String filename, int line, String elementType, String elementName, String message, boolean output){ + String codesection = ""; + if(!filename.equals("")) codesection = " " + filename + ":" + Integer.toString(line)+ "("+ elementType + ":" + elementName + ")"; + String s = source + " " + type + codesection + " " + message; + writeLog(s, output); + } + + private static synchronized void writeLog(String s, boolean output){ + try{ + if(file==null){ + file = new File("D:\\TTCN3Log.txt"); + if(!file.exists()){ + file.createNewFile(); + } + } + FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); + BufferedWriter bw = new BufferedWriter(fw); + LocalDateTime time = LocalDateTime.now(); + time.getMonth().toString(); + String logmsg = time.toString().replaceAll("T", " ") + " " + s + "\n"; + bw.write(logmsg); + if(output) System.out.print(logmsg); + bw.close(); + }catch(IOException e){e.printStackTrace();} + } + +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/TTCNJavaAPIException.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/TTCNJavaAPIException.java new file mode 100644 index 000000000..5a452d0cc --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/TTCNJavaAPIException.java @@ -0,0 +1,22 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +public class TTCNJavaAPIException extends Exception { + public TTCNJavaAPIException(String s){ + super(s); + } +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/Timer.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/Timer.java new file mode 100644 index 000000000..b90b3221f --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/Timer.java @@ -0,0 +1,87 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +public class Timer { + + public long starttime; + public long timetorun; + public boolean running; + private boolean set; + + public Timer(FLOAT t) { + set(t); + } + + public Timer(){ + + } + + public void set(FLOAT t){ + set0(t.value); + } + + private void set0(double t) { + timetorun = (long) (t * 1000.0); + running = false; + set = true; + } + + public void start(){ + if (!set) { + System.out.println("Timer not set."); + return; + } else { + starttime = System.currentTimeMillis(); + running = true; + } + } + + public void stop() { + running = false; + } + + public boolean timeout(){ + if (!set) { + System.out.println("Timer not set."); + return false; + } else { + if (running){ + return (System.currentTimeMillis() - starttime > timetorun); + } + else + return false; + } + } + + public FLOAT read(){ + return new FLOAT(read0()); + } + + private double read0(){ + if(!set) return 0.0; + else if(running){ + double retv = (double)(timetorun-(System.currentTimeMillis() - starttime))/1000.0; + return retv>0.0 ? retv : 0.0; + } + else return 0.0; + } + + public boolean running() throws TTCNJavaAPIException{ + return running&&!timeout(); + } + +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/TypeDef.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/TypeDef.java new file mode 100644 index 000000000..ca5c15514 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/TypeDef.java @@ -0,0 +1,26 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +public abstract class TypeDef extends ModuleDef{ + public boolean anyField; //stores if the given data instance has special value ? + public boolean omitField; //stores if the given data instance has special value omit + public boolean anyOrOmitField; //stores if the given data instance has special value * + + public abstract String toString(String tabs); + public abstract String toString(); + +} \ No newline at end of file diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/UNIVERSAL_CHARSTRING.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/UNIVERSAL_CHARSTRING.java new file mode 100644 index 000000000..3b18f1b8e --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/UNIVERSAL_CHARSTRING.java @@ -0,0 +1,29 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +public class UNIVERSAL_CHARSTRING extends CHARSTRING{ + + public UNIVERSAL_CHARSTRING(String s){ + super(s); + //TODO check whether s is correct + } + + public UNIVERSAL_CHARSTRING(){ + + } + +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/UnionDef.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/UnionDef.java new file mode 100644 index 000000000..01df72f36 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/UnionDef.java @@ -0,0 +1,20 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator.TTCN3JavaAPI; + +public abstract class UnionDef extends StructuredTypeDef { + +} \ No newline at end of file diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TestCase_Function_Visit_Handler.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TestCase_Function_Visit_Handler.java new file mode 100644 index 000000000..be2df9eb1 --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/TestCase_Function_Visit_Handler.java @@ -0,0 +1,1533 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + +package org.eclipse.titan.codegenerator; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.titan.designer.AST.ArraySubReference; +import org.eclipse.titan.designer.AST.IVisitableNode; +import org.eclipse.titan.designer.AST.Identifier; +import org.eclipse.titan.designer.AST.ParameterisedSubReference; +import org.eclipse.titan.designer.AST.Reference; +import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const; +import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function; +import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase; +import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Timer; +import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var; +import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template; +import org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter; +import org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.Connect_Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.Definition_Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.Disconnect_Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.If_Clause; +import org.eclipse.titan.designer.AST.TTCN3.statements.If_Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.Map_Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.Operation_Altguard; +import org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.Return_Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.Send_Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.Setverdict_Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock; +import org.eclipse.titan.designer.AST.TTCN3.statements.Timeout_Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.Unknown_Start_Statement; +import org.eclipse.titan.designer.AST.TTCN3.statements.Unknown_Stop_Statement; +import org.eclipse.titan.designer.AST.TTCN3.templates.Any_Value_Template; +import org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template; +import org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance; +import org.eclipse.titan.designer.AST.TTCN3.types.BitString_Type; +import org.eclipse.titan.designer.AST.TTCN3.types.Boolean_Type; +import org.eclipse.titan.designer.AST.TTCN3.types.CharString_Type; +import org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type; +import org.eclipse.titan.designer.AST.TTCN3.types.OctetString_Type; +import org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value; +import org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value; +import org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value; +import org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value; +import org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value; +import org.eclipse.titan.designer.AST.TTCN3.values.Real_Value; +import org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.AddExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.ComponentCreateExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.DivideExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.EqualsExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.GreaterThanExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.GreaterThanOrEqualExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.Int2StrExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.LessThanExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.LessThanOrEqualExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.ModuloExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.MultiplyExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.NotExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.NotequalesExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.RemainderExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.SelfComponentExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.SubstractExpression; +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.SystemComponentExpression; + +public class TestCase_Function_Visit_Handler { + + private static StatementBlock functionStatementBlock = null; + private StatementBlock tcStatementBlock = null; + + private Def_Testcase_Writer currentTestCaseWriter; + private Def_Function_Writer currentFunctionWriter; + + private static String returnType = null; + private static String returnStatementValue = null; + private static String unknownStartReference = null; + private static String runsOnValue = null; + + // Counters + private int tcCreateCounter = -1; + private int tcStartCounter = -1; + private int mapCounter = 0; + private int mapValueCounter = 0; + + private int currentRecordCounter = 0; + + public boolean waitForDefStatement = false; + public static boolean waitForStatementBlock = false; + public static boolean waitForValue = false; + private static boolean waitForRunsOnValue = false; + private static boolean waitForReturnType = false; + private static boolean waitForReturnStatementValue = false; + private static boolean waitForReceiveStatement = false; + private static boolean checkAnyport = false; + private static boolean waitForUnknownStartStatement = false; + private static boolean waitForTypedParam = false; + private static boolean waitForInt2StrExpression = false; + private boolean waitForTC = false; + private boolean waitForAssignmentIdentifiers = false; + private boolean waitForMapIdentifiers = false;; + private boolean waitForTcIfCondition = false; + + private boolean isSendStatement = false; + private boolean waitForTcStartParameter = false; + private boolean waitForTcStopParameter = false; + private boolean isAltGuards = false; + + private boolean waitForAltStatements = false; + private boolean isReceiveValue = false; + private boolean waitForAltTimeout = false; + private boolean isNextValueTemplate = false; + private boolean isNextValueConstant = false; + private boolean waitForTcDisconnectValues = false; + private boolean waitForTcCreateValues = false; + private boolean waitForTcConnectValues = false; + private boolean waitForTcStartValues = false; + private boolean waitForFunction = false; + private boolean waitForStatements = true; + private boolean isAnyValValue = false; + private boolean waitForReceiveAnyValTemplateValue = false; + private boolean isDefinition = false; + private boolean isAssignment = false; + private boolean isIf = false; + public static boolean isThereAFormalParameter = false; + private boolean waitForIndexSetValue = false; + + // Lists + private List nodeVars = new ArrayList(); + private List nodeVarTypes = new ArrayList(); + private List nodeVarValues = new ArrayList(); + private List nodeVarIsAValueReference = new ArrayList(); + private List nodeVarTypeIsAReference = new ArrayList(); + private List nodeVarIsConstant = new ArrayList(); + private List nodeVarIsTemplate = new ArrayList(); + private List nodeVarIsRecord = new ArrayList(); + + private List nodeVarRecordValues = new ArrayList(); + + private List nodeAssignIdentifiers = new ArrayList(); + private List nodeAssignValues = new ArrayList(); + + private List testCaseCreateValues = new ArrayList(); + private List testCaseCreateCounter = new ArrayList(); + private List testCaseCreateRefValues = new ArrayList(); + private List testCaseCreateCharValues = new ArrayList(); + + private List testCaseIfConditions = new ArrayList(); + + private List nodeSendPortReference = new ArrayList(); + private List nodeSendParameter = new ArrayList(); + private List nodeSendParameterType = new ArrayList(); + + private List altGuardConditions = new ArrayList(); + private List altGuardPortReference = new ArrayList(); + private List altGuardReceiveValue = new ArrayList(); + private List altGuardReceiveAnyValValue = new ArrayList(); + private List altGuardReceiveType = new ArrayList(); + private List altGuardTimeout = new ArrayList(); + + private List receivePortReference = new ArrayList(); + private List receiveValue = new ArrayList(); + private List receiveAnyValValue = new ArrayList(); + private List receiveType = new ArrayList(); + + private List testCaseDisconnectValues = new ArrayList(); + + private List testCaseMapValues = new ArrayList(); + private List testCaseMapCounter = new ArrayList(); + + private List testCaseStartValues = new ArrayList(); + private List testCaseStartValueParameters = new ArrayList(); + private List testCaseStartCounter = new ArrayList(); + + private List testCaseStopValues = new ArrayList(); + private List testCaseStopValueParameters = new ArrayList(); + private List testCaseStopCounter = new ArrayList(); + + private List testCaseConnectValues = new ArrayList(); + + private List operatorList = new ArrayList(); + + private List expressionValue = new ArrayList(); + + private List receiveStatements = new ArrayList(); + + private boolean waitForTcStopValues = false; + private int tcStopCounter = -1; + private boolean waitForUnknownStopStatement = false; + private String unknownStopReference = null; + private boolean waitForRecord = false; + private boolean isCreate; + + Statement currentAltGuardStatement = null; + + public void visit(IVisitableNode node) { + + if (node instanceof Def_Function) { + + currentFunctionWriter = Def_Function_Writer.getInstance(((Def_Function) node)); + currentFunctionWriter.clearAltLists(); + myASTVisitor.nodeNameNodeTypeHashMap.put(((Def_Function) node).getIdentifier().toString(), "function"); + + runsOnValue = null; + + waitForReturnType = true; + waitForRunsOnValue = true; + waitForStatementBlock = true; + waitForFunction = true; + + expressionValue.clear(); + } + + if (node instanceof Def_Testcase) { + + currentTestCaseWriter = Def_Testcase_Writer.getInstance(((Def_Testcase) node)); + currentTestCaseWriter.clearAltLists(); + myASTVisitor.nodeNameNodeTypeHashMap.put(((Def_Testcase) node).getIdentifier().toString(), "testcase"); + + AstWalkerJava.testCaseList.add(((Def_Testcase) node).getIdentifier().toString()); + + waitForStatementBlock = true; + waitForRunsOnValue = true; + waitForTC = true; + + expressionValue.clear(); + } + + // Check for TC + visitNodes(node); + + // Check Functions + visitFunctionNodes(node); + + // Check for TC + visitTcNodes(node); + + // Check for TC If cases + visitTcIfCases(node); + + // Check for TC Alt cases + visitAltCases(node); + + if (node instanceof Reference) { + checkReference(node); + } + + if ((currentAltGuardStatement != null) && (currentAltGuardStatement.equals(node))) { + evaluateExpression(); + } + + // testcases + // FormalParameter might come up for other types too, leave it here + if (node instanceof FormalParameter) { + isThereAFormalParameter = true; + } + + if (isThereAFormalParameter && (node instanceof Reference)) { + // TODO: formal parameter reference handling (tpye name) + isThereAFormalParameter = false; + } + + if (isThereAFormalParameter && (node instanceof Identifier)) { + // TODO: formal parameter identifier handling + } + + } + + public void leave(IVisitableNode node) { + + if (waitForTC || waitForFunction) { + if (node instanceof Definition_Statement) { + + if (!waitForRecord) { + nodeVarIsRecord.add(false); + } + waitForValue = false; + + evaluateExpression(); + } + + if ((node instanceof Assignment_Statement) || ((node instanceof If_Clause))) { + waitForValue = false; + + // if assignment is a createExpression + if ((node instanceof Assignment_Statement) + && ((SpecificValue_Template) ((Assignment_Statement) node).getTemplate()) + .getSpecificValue() instanceof ComponentCreateExpression) { + isCreate = true; + } + + evaluateExpression(); + + } + + if ((waitForFunction && (node instanceof Return_Statement)) + || (waitForTC && (node instanceof ComponentCreateExpression)) || (node instanceof Send_Statement) + || (node instanceof Receive_Port_Statement)) { + evaluateExpression(); + } + + if (waitForTcStartValues && (node instanceof Identifier) && myASTVisitor.blockIdListing) { + myASTVisitor.blockIdListing = false; + } + + if (waitForTcStopValues && (node instanceof Identifier) && myASTVisitor.blockIdListing) { + myASTVisitor.blockIdListing = false; + } + + if (node instanceof Connect_Statement) { + waitForTcConnectValues = false; + } + + if (node instanceof Disconnect_Statement) { + waitForTcDisconnectValues = false; + + } + if (node instanceof Unknown_Start_Statement) { + waitForTcStartValues = false; + } + + if (node instanceof Unknown_Stop_Statement) { + waitForTcStopValues = false; + } + + if (node instanceof Definition_Statement) { + waitForDefStatement = false; + if (waitForValue) { + nodeVarValues.add(null); + nodeVarIsAValueReference.add(false); + + waitForValue = false; + } + } + + if (node instanceof Map_Statement) { + waitForMapIdentifiers = false; + } + + if (node instanceof ComponentCreateExpression) { + + // switch first two values + testCaseCreateValues.add(testCaseCreateCharValues.get(0)); + testCaseCreateValues.add(testCaseCreateRefValues.get(0)); + + for (int i = 1; i < testCaseCreateCharValues.size(); i++) { + testCaseCreateValues.add(testCaseCreateCharValues.get(i)); + } + + testCaseCreateCharValues.clear(); + testCaseCreateRefValues.clear(); + waitForTcCreateValues = false; + } + + if (node instanceof Assignment_Statement) { + + waitForAssignmentIdentifiers = false; + waitForValue = true; + } + + if (waitForTcIfCondition && (node instanceof If_Clause)) { + waitForTcIfCondition = false; + + } + + if (waitForTcStartParameter && (node instanceof Unknown_Start_Statement)) { + testCaseStartValueParameters.add(null); + } + + if (waitForTcStopParameter && (node instanceof Unknown_Stop_Statement)) { + testCaseStopValueParameters.add(null); + } + + if (isAltGuards && (node instanceof Operation_Altguard)) { + altGuardConditions.add(null); + } + + if (node instanceof Operation_Altguard) { + + waitForAltStatements = false; + isAltGuards = false; + + isReceiveValue = false; + + } + + handleAltCases(node); + + if (node instanceof Unknown_Start_Statement) { + waitForUnknownStartStatement = false; + } + + if (node instanceof Unknown_Stop_Statement) { + waitForUnknownStopStatement = false; + } + } + + if (node instanceof Def_Testcase) { + handleTestcase(node); + waitForTC = false; + } + + if (node instanceof Def_Function) { + handleFunction(node); + waitForTC = false; + } + + if (waitForAssignmentIdentifiers && (node instanceof ArraySubReference)) { + waitForAssignmentIdentifiers = false; + } + + } + + public void evaluateExpression() { + int size = expressionValue.size() - 1; + boolean arrayOperatorFound = false; + boolean operatorFound = false; + boolean unaryOperatorFound = false; + String rightHand = ""; + String leftHand = ""; + + for (int i = size; i >= 0; i--) { + + if (myASTVisitor.nodeNameNodeTypeHashMap.containsKey(expressionValue.get(i))) { + + if (myASTVisitor.nodeNameNodeTypeHashMap.get(expressionValue.get(i)).equals("constant")) { + expressionValue.set(i, "Constants." + expressionValue.get(i) + "()"); + + } else if (myASTVisitor.nodeNameNodeTypeHashMap.get(expressionValue.get(i)).equals("template")) { + expressionValue.set(i, "Templates." + expressionValue.get(i) + "()"); + + } + } + + if (i <= size - 2) { + leftHand = expressionValue.get(i + 1); + rightHand = expressionValue.get(i + 2); + } + + if (expressionValue.get(i).equals("ArraySubReference")) { + String[] index = expressionValue.get(i + 1).split("\""); + + expressionValue.set(i - 1, expressionValue.get(i - 1) + ".get(" + index[1] + ")"); + arrayOperatorFound = true; + } else if (expressionValue.get(i).equals("NotExpression")) { + expressionValue.set(i, "(" + expressionValue.get(i + 1) + ").not()"); + unaryOperatorFound = true; + } else if (expressionValue.get(i).equals("AddExpression")) { + expressionValue.set(i, "(" + leftHand + ").plus(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("SubstractExpression")) { + expressionValue.set(i, "(" + leftHand + ").minus(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("MultiplyExpression")) { + expressionValue.set(i, "(" + leftHand + ").multipleBy(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("DivideExpression")) { + expressionValue.set(i, "(" + leftHand + ").divideBy(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("ModuloExpression")) { + expressionValue.set(i, "(" + leftHand + ").mod(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("RemainderExpression")) { + expressionValue.set(i, "(" + leftHand + ").rem(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("NotequalesExpression")) { + expressionValue.set(i, "(" + leftHand + ").equalsWith(" + rightHand + ").not()"); + operatorFound = true; + } else if (expressionValue.get(i).equals("LessThanExpression")) { + expressionValue.set(i, "(" + leftHand + ").isLessThan(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("LessThanOrEqualExpression")) { + expressionValue.set(i, "(" + leftHand + ").isLessOrEqualThan(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("GreaterThanExpression")) { + expressionValue.set(i, "(" + leftHand + ").isGreaterThan(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("GreaterThanOrEqualExpression")) { + expressionValue.set(i, "(" + leftHand + ").isGreaterOrEqualThan(" + rightHand + ")"); + operatorFound = true; + } else if (expressionValue.get(i).equals("EqualsExpression")) { + expressionValue.set(i, "(" + leftHand + ").equals(" + rightHand + ")"); + operatorFound = true; + } + + if (arrayOperatorFound) { + arrayOperatorFound = false; + expressionValue.remove(i + 1); + expressionValue.remove(i); + size = expressionValue.size() - 1; + i = size; + } else if (unaryOperatorFound) { + unaryOperatorFound = false; + expressionValue.remove(i + 1); + size = expressionValue.size() - 1; + i = size; + } else if (operatorFound) { + operatorFound = false; + expressionValue.remove(i + 2); + expressionValue.remove(i + 1); + size = expressionValue.size() - 1; + i = size; + } + + } + + String value = null; + + if (expressionValue.size() > 0) { + value = expressionValue.get(0); + } + + if (waitForIndexSetValue) { + value = value + ")"; + waitForIndexSetValue=false; + + } + + // Set value for the appropriate list + if (isCreate) { + testCaseCreateCharValues.addAll(expressionValue); + testCaseCreateCounter.add(String.valueOf(tcCreateCounter)); + } else if (isDefinition) { + + if (isNextValueConstant) { + nodeVarIsConstant.add(true); + } else { + nodeVarIsConstant.add(false); + } + + if (isNextValueTemplate) { + nodeVarIsTemplate.add(true); + } else { + nodeVarIsTemplate.add(false); + } + + if (waitForRecord) { + nodeVarValues.addAll(expressionValue); + waitForRecord = false; + } else { + nodeVarValues.add(value); + } + + nodeVarIsAValueReference.add(true); + + } else if (isAssignment) { + + nodeAssignValues.add(value); + + } else if (isIf) { + + testCaseIfConditions.add(value); + + } else if (isSendStatement) { + nodeSendParameter.add(value); + } else if (isReceiveValue) { + if (waitForAltStatements) { + if (!waitForReceiveAnyValTemplateValue) { + altGuardReceiveValue.add(value); + } + } else { + receiveValue.add(value); + } + } else if (isAltGuards) { + altGuardConditions.add(value); + isAltGuards = false; + + } else if (waitForReturnStatementValue) { + returnStatementValue = value; + } + + if (isAltGuards) { + altGuardConditions.add(null); + isAltGuards = false; + } + + isNextValueTemplate = false; + isNextValueConstant = false; + + waitForReceiveAnyValTemplateValue = false; + + isSendStatement = false; + isReceiveValue = false; + isDefinition = false; + isAssignment = false; + + isCreate = false; + expressionValue.clear(); + } + + public void visitNodes(IVisitableNode node) { + + if (waitForStatementBlock && (node instanceof StatementBlock)) { + functionStatementBlock = (StatementBlock) node; + tcStatementBlock = ((StatementBlock) node); + + waitForRunsOnValue = false; + waitForReturnType = false; + waitForStatementBlock = false; + + waitForStatements = true; + } + + if (waitForAltStatements && (node instanceof StatementBlock)) { + evaluateExpression(); + isReceiveValue = false; + + if (!isAnyValValue) { + altGuardReceiveAnyValValue.add(null); + + } + isAnyValValue = false; + } + + if (waitForStatements) { + visitStatementSelector(node); + } + + if (waitForDefStatement) { + visitDefStatements(node); + } + + if (waitForTC || waitForFunction) { + // Check expression operators + + // Check expression values + if (!waitForAssignmentIdentifiers) { + visitExpressionTypeSelectors(node); + visitExpressionValueSetters(node); + } + } + if (isIf && (node instanceof StatementBlock)) { + // has to be here, If always has a statemnt block + evaluateExpression(); + isIf = false; + + } + + if (waitForTC && (node instanceof Unknown_Start_Statement)) { + waitForTcStartValues = true; + tcStartCounter++; + } + + if (waitForTC && (node instanceof Unknown_Stop_Statement)) { + waitForTcStopValues = true; + tcStopCounter++; + } + + if (waitForTcStartValues) { + visitStartValueSetters(node); + } + + if (waitForTcStopValues) { + visitStopValueSetters(node); + } + + if (waitForTC && (node instanceof Map_Statement)) { + waitForMapIdentifiers = true; + mapCounter++; + mapValueCounter = 0; + } + + if (waitForMapIdentifiers) { + visitMapIdentifiers(node); + } + + if (isSendStatement) { + visitSendStatements(node); + } + + if (waitForTcDisconnectValues) { + visitDisconnectValueSetters(node); + } + + } + + public void visitStatementSelector(IVisitableNode node) { + + if (waitForStatements && (node instanceof Definition_Statement)) { + waitForDefStatement = true; + waitForValue = true; + isDefinition = true; + } + + if (waitForStatements && (node instanceof Send_Statement)) { + isSendStatement = true; + } + + if (waitForStatements && (node instanceof Operation_Altguard)) { + isAltGuards = true; + waitForAltStatements = true; + currentAltGuardStatement = ((Operation_Altguard) node).getGuardStatement(); + waitForValue = true; + + } + + if (waitForStatements && (node instanceof Assignment_Statement)) { + waitForAssignmentIdentifiers = true; + waitForValue = true; + isAssignment = true; + } + + if (waitForStatements && (node instanceof Disconnect_Statement)) { + waitForTcDisconnectValues = true; + } + } + + public void visitDefStatements(IVisitableNode node) { + + if (waitForDefStatement && (node instanceof Def_Var)) { + nodeVars.add(((Def_Var) node).getIdentifier().toString()); + } + + if (waitForDefStatement && (node instanceof Def_Var_Template)) { + nodeVars.add(((Def_Var_Template) node).getIdentifier().toString()); + isNextValueTemplate = true; + + } + + if (waitForDefStatement && (node instanceof Def_Const)) { + // TODO const spec + nodeVars.add(((Def_Const) node).getIdentifier().toString()); + isNextValueConstant = true; + } + + if (waitForDefStatement && (node instanceof BitString_Type)) { + nodeVarTypes.add("BITSTRING"); + nodeVarTypeIsAReference.add(false); + + } + if (waitForDefStatement && (node instanceof Integer_Type)) { + nodeVarTypes.add("INTEGER"); + nodeVarTypeIsAReference.add(false); + } + + if (waitForDefStatement && (node instanceof CharString_Type)) { + nodeVarTypes.add("CHARSTRING"); + nodeVarTypeIsAReference.add(false); + } + + if (waitForDefStatement && (node instanceof OctetString_Type)) { + nodeVarTypes.add("OCTETSTRING"); + waitForValue = true; + nodeVarTypeIsAReference.add(false); + } + + if (waitForDefStatement && (node instanceof Boolean_Type)) { + nodeVarTypes.add("BOOLEAN"); + nodeVarTypeIsAReference.add(false); + } + + if (waitForDefStatement && (node instanceof Def_Timer)) { + nodeVars.add(((Def_Timer) node).getIdentifier().toString()); + nodeVarTypes.add("TIMER"); + waitForDefStatement = false; + nodeVarTypeIsAReference.add(false); + + } + + } + + public void visitExpressionTypeSelectors(IVisitableNode node) { + + if (waitForValue && (node instanceof If_Clause)) { + isIf = true; + } + + if (waitForValue && !waitForAssignmentIdentifiers && (node instanceof ArraySubReference)) { + expressionValue.add("ArraySubReference"); + } + + // Integer_Value + + if (waitForValue && (node instanceof AddExpression)) { + expressionValue.add("AddExpression"); + } + + if (waitForValue && (node instanceof SubstractExpression)) { + expressionValue.add("SubstractExpression"); + } + + if (waitForValue && (node instanceof MultiplyExpression)) { + expressionValue.add("MultiplyExpression"); + } + + if (waitForValue && (node instanceof DivideExpression)) { + expressionValue.add("DivideExpression"); + } + + if (waitForValue && (node instanceof ModuloExpression)) { + expressionValue.add("ModuloExpression"); + } + + if (waitForValue && (node instanceof RemainderExpression)) { + expressionValue.add("RemainderExpression"); + } + + if (waitForValue && (node instanceof NotequalesExpression)) { + expressionValue.add("NotequalesExpression"); + } + + if (waitForValue && (node instanceof LessThanExpression)) { + expressionValue.add("LessThanExpression"); + } + + if (waitForValue && (node instanceof LessThanOrEqualExpression)) { + expressionValue.add("LessThanOrEqualExpression"); + } + + if (waitForValue && (node instanceof GreaterThanExpression)) { + expressionValue.add("GreaterThanExpression"); + } + + if (waitForValue && (node instanceof GreaterThanOrEqualExpression)) { + expressionValue.add("GreaterThanOrEqualExpression"); + } + + if (waitForValue && (node instanceof EqualsExpression)) { + expressionValue.add("EqualsExpression"); + } + + if (waitForValue && (node instanceof NotExpression)) { + expressionValue.add("NotExpression"); + } + + } + + public void visitExpressionValueSetters(IVisitableNode node) { + + if (node instanceof Real_Value) { + + String value = ((Real_Value) node).createStringRepresentation(); + + expressionValue.add(value); + + } + + if (node instanceof Integer_Value) { + + String value = ((Integer_Value) node).toString(); + + if (myASTVisitor.isNextIntegerNegative) { + value = "-" + ((Integer_Value) node).toString(); + } + value = "new INTEGER(new BigInteger(\"" + value + "\"))"; + + expressionValue.add(value); + + if (isSendStatement) { + nodeSendParameterType.add("INTEGER"); + } + + if (isReceiveValue) { + if (waitForAltStatements) { + altGuardReceiveType.add("INTEGER"); + } else { + receiveType.add("INTEGER"); + } + } + + myASTVisitor.isNextIntegerNegative = false; + + } + + if (node instanceof Undefined_LowerIdentifier_Value) { + String value = ((Undefined_LowerIdentifier_Value) node).getIdentifier().toString(); + + if (myASTVisitor.isNextIntegerNegative) { + value = value + ".negate()"; + } + + if (waitForInt2StrExpression) { + value = value + ".int2str()"; + waitForInt2StrExpression = false; + } + + expressionValue.add(value); + + if (isSendStatement) { + nodeSendParameterType.add("IDENTIFIER"); + } + + if (isReceiveValue) { + if (waitForAltStatements) { + altGuardReceiveType.add("IDENTIFIER"); + } else { + receiveType.add("IDENTIFIER"); + } + } + + myASTVisitor.isNextIntegerNegative = false; + + } + + if (node instanceof Boolean_Value) { + + String value = "new BOOLEAN(" + Boolean.toString(((Boolean_Value) node).getValue()) + ")"; + + expressionValue.add(value); + } + + if (node instanceof Charstring_Value) { + String value = ""; + if (isCreate) { + value = ((Charstring_Value) node).getValue(); + } else { + value = "new CHARSTRING(\"" + ((Charstring_Value) node).getValue() + "\")"; + } + expressionValue.add(value); + + if (isSendStatement) { + nodeSendParameterType.add("CHARSTRING"); + } + + if (isReceiveValue) { + if (waitForAltStatements) { + altGuardReceiveType.add("CHARSTRING"); + } else { + receiveType.add("CHARSTRING"); + } + + } + } + + if (node instanceof Octetstring_Value) { + String value = ""; + if (isCreate) { + value = ((Octetstring_Value) node).getValue(); + } else { + value = "new OCTETSTRING(\"" + ((Octetstring_Value) node).getValue() + "\")"; + } + expressionValue.add(value); + + if (isSendStatement) { + nodeSendParameterType.add("OCTETSTRING"); + } + + if (isReceiveValue) { + if (waitForAltStatements) { + altGuardReceiveType.add("OCTETSTRING"); + } else { + receiveType.add("OCTETSTRING"); + } + + } + } + + if (node instanceof Bitstring_Value) { + String value = "(new BITSTRING(\"" + ((Bitstring_Value) node).getValue().toString() + "\"))"; + + expressionValue.add(value); + } + + } + + public void visitStartValueSetters(IVisitableNode node) { + if (waitForTcStartValues && (node instanceof ParameterisedSubReference)) { + testCaseStartValueParameters.add(((ParameterisedSubReference) node).getId().toString()); + myASTVisitor.blockIdListing = true; + waitForTcStartParameter = false; + } + + if (waitForTcStartValues && (node instanceof Identifier) && !myASTVisitor.blockIdListing) { + myASTVisitor.blockIdListing = false; + testCaseStartValues.add(((Identifier) node).toString()); + testCaseStartCounter.add(String.valueOf(tcStartCounter)); + waitForTcStartParameter = true; + } + } + + public void visitStopValueSetters(IVisitableNode node) { + if (waitForTcStopValues && (node instanceof ParameterisedSubReference)) { + testCaseStopValueParameters.add(((ParameterisedSubReference) node).getId().toString()); + myASTVisitor.blockIdListing = true; + waitForTcStopParameter = false; + } + + if (waitForTcStopValues && (node instanceof Identifier) && !myASTVisitor.blockIdListing) { + myASTVisitor.blockIdListing = false; + testCaseStopValues.add(((Identifier) node).toString()); + testCaseStopCounter.add(String.valueOf(tcStopCounter)); + waitForTcStopParameter = true; + } + } + + public void visitDisconnectValueSetters(IVisitableNode node) { + + if (waitForTcDisconnectValues && (node instanceof Identifier)) { + testCaseDisconnectValues.add(((Identifier) node).toString()); + } + + if (waitForTcDisconnectValues && (node instanceof SelfComponentExpression)) { + testCaseDisconnectValues.add("self"); + } + } + + public void visitMapIdentifiers(IVisitableNode node) { + + if (waitForMapIdentifiers && (node instanceof SystemComponentExpression) && (mapValueCounter <= 4)) { + testCaseMapValues.add("system"); + testCaseMapCounter.add(Integer.toString(mapCounter)); + mapValueCounter++; + } + } + + public void checkReference(IVisitableNode node) { + String value = ((Reference) node).getId().toString(); + + if (waitForMapIdentifiers && (mapValueCounter <= 4)) { + testCaseMapValues.add(value); + testCaseMapCounter.add(Integer.toString(mapCounter)); + mapValueCounter++; + } else if (isSendStatement) { + nodeSendPortReference.add(value); + + } else if (waitForTcCreateValues) { + testCaseCreateRefValues.add(value); + testCaseCreateCounter.add(String.valueOf(tcCreateCounter)); + + } else if (waitForReceiveStatement && !waitForTypedParam && !waitForReceiveAnyValTemplateValue) { + + if (waitForAltStatements) { + altGuardPortReference.add(value); + } else { + receivePortReference.add(value); + } + + waitForValue = true; + isReceiveValue = true; + checkAnyport = false; + } else if (waitForTypedParam) { + if (waitForAltStatements) { + altGuardReceiveValue.add(value); + altGuardReceiveType.add("_TYPED_PARAM_"); + } else { + receiveValue.add(value); + receiveType.add("_TYPED_PARAM_"); + } + waitForTypedParam = false; + } else if (waitForReceiveAnyValTemplateValue && !waitForTypedParam) { + + if (waitForAltStatements) { + altGuardReceiveAnyValValue.add(value); + } else { + receiveAnyValValue.add(value); + } + isAnyValValue = true; + + } else if (waitForUnknownStartStatement) { + unknownStartReference = value; + } else if (waitForRunsOnValue && !isThereAFormalParameter) { + runsOnValue = value; + + waitForRunsOnValue = false; + + if (waitForFunction) { + AstWalkerJava.functionRunsOnList.add(value); + } + } else if (waitForUnknownStopStatement) { + unknownStopReference = value; + } else if (waitForAssignmentIdentifiers) { + + nodeAssignIdentifiers.add(value); + + if (((Reference) node).getSubreferences().size() > 1) { + if (((Reference) node).getSubreferences().get(1) instanceof ArraySubReference) { + ArraySubReference subref = (ArraySubReference) ((Reference) node).getSubreferences().get(1); + nodeAssignIdentifiers.set(nodeAssignIdentifiers.size() - 1, + nodeAssignIdentifiers.get(nodeAssignIdentifiers.size() - 1) + ".set(" + + subref.getValue().toString() + ","); + waitForIndexSetValue=true; + } + } else { + + nodeAssignIdentifiers.set(nodeAssignIdentifiers.size() - 1, + nodeAssignIdentifiers.get(nodeAssignIdentifiers.size() - 1) + "="); + + // Only set to false if there are no arraysubrefs + // For arraysubrefs the flag is set to false in the + // arraysubref leave part + waitForAssignmentIdentifiers = false; + } + + } else if (waitForDefStatement) { + nodeVarTypes.add(value); + nodeVarTypeIsAReference.add(true); + if (myASTVisitor.nodeNameNodeTypeHashMap.containsKey(nodeVarTypes.get(nodeVarTypes.size() - 1))) { + if (myASTVisitor.nodeNameNodeTypeHashMap.get(nodeVarTypes.get(nodeVarTypes.size() - 1)) + .equals("record")) { + + if (currentRecordCounter < myASTVisitor.nodeNameChildrenNamesHashMap + .get(nodeVarTypes.get(nodeVarTypes.size() - 1)).length) { + + waitForRecord = true; + nodeVarIsRecord.add(true); + } + } + } + } else if (waitForValue && !isReceiveValue) { + // has to be the last one + // sends the Reference value to be processed as an assignment + // identifier + expressionValue.add(value); + } + + } + + public void visitSendStatements(IVisitableNode node) { + + } + + public void visitTcNodes(IVisitableNode node) { + + if (waitForTC && (node instanceof ComponentCreateExpression)) { + isCreate = true; + waitForTcCreateValues = true; + tcCreateCounter++; + } + + if (waitForTC && (node instanceof Connect_Statement)) { + waitForTcConnectValues = true; + } + + if (waitForTcConnectValues && (node instanceof Identifier)) { + testCaseConnectValues.add(((Identifier) node).toString()); + + } + + if (waitForTcConnectValues && (node instanceof SelfComponentExpression)) { + testCaseConnectValues.add("self"); + + } + + } + + public void visitTcIfCases(IVisitableNode node) { + + if (waitForTC && (node instanceof If_Statement)) { + + waitForValue = true; + isIf = true; + + } + + } + + public void visitAltCases(IVisitableNode node) { + + if (node instanceof Receive_Port_Statement) { + waitForReceiveStatement = true; + checkAnyport = true; + } + + if (waitForReceiveStatement && (node instanceof StatementBlock)) { + + if (!waitForAltStatements) { + receiveStatements.add((StatementBlock) node); + } + waitForReceiveStatement = false; + } + + if (node instanceof TemplateInstance) { + if (((TemplateInstance) node).getType() != null) { + waitForTypedParam = true; + checkAnyport = true; + } + } + + if (checkAnyport && (node instanceof Setverdict_Statement)) { + if (waitForAltStatements) { + altGuardPortReference.add("any port"); + altGuardReceiveValue.add(null); + altGuardReceiveType.add("any port"); + } else { + receivePortReference.add("any port"); + receiveValue.add("null"); + receiveType.add("any port"); + } + + waitForReceiveStatement = false; + + checkAnyport = false; + } + + if ((waitForTC || waitForFunction) && (node instanceof Any_Value_Template)) { + + waitForReceiveAnyValTemplateValue = true; + + checkAnyport = false; + } + + if (waitForAltStatements && (node instanceof Timeout_Statement)) { + + waitForAltTimeout = true; + } + + if (waitForAltTimeout && (node instanceof Identifier)) { + altGuardTimeout.add(((Identifier) node).toString()); + waitForAltTimeout = false; + + } + + } + + public void visitFunctionNodes(IVisitableNode node) { + + if (waitForReturnType && (node instanceof Integer_Type)) { + returnType = "Integer_Type"; + } + + if (waitForReturnType && (node instanceof Boolean_Type)) { + returnType = "Boolean_Type"; + } + + if (waitForFunction && (node instanceof Return_Statement)) { + waitForReturnStatementValue = true; + } + + if (node instanceof Unknown_Start_Statement) { + waitForUnknownStartStatement = true; + } + + if (node instanceof Unknown_Stop_Statement) { + waitForUnknownStopStatement = true; + } + + if (node instanceof Int2StrExpression) { + waitForInt2StrExpression = true; + } + + } + + public void handleFunction(IVisitableNode node) { + Def_Function_Writer functionNode = Def_Function_Writer.getInstance(((Def_Function) node)); + functionNode.clearLists(); + functionNode.setStatementBlock(functionStatementBlock); + + functionNode.runsOnValue = runsOnValue; + functionNode.returnType = returnType; + functionNode.returnStatementValue = returnStatementValue; + + returnType = null; + returnStatementValue = null; + + myASTVisitor.currentFileName = ((Def_Function) node).getIdentifier().toString(); + + functionNode.functionVars.addAll(nodeVars); + functionNode.functionVarTypes.addAll(nodeVarTypes); + functionNode.functionVarValues.addAll(nodeVarValues); + + functionNode.functionVarIsConstant.addAll(nodeVarIsConstant); + functionNode.functionValueIsAValueReference.addAll(nodeVarIsAValueReference); + functionNode.functionAssignIdentifiers.addAll(nodeAssignIdentifiers); + functionNode.functionAssignValues.addAll(nodeAssignValues); + + functionNode.receivePortReference.addAll(receivePortReference); + functionNode.receiveValue.addAll(receiveValue); + functionNode.receiveAnyValValue.addAll(receiveAnyValValue); + functionNode.receiveType.addAll(receiveType); + + functionNode.receiveStatements.addAll(receiveStatements); + + Def_Function_Writer.sendPortReference.addAll(nodeSendPortReference); + Def_Function_Writer.sendParameter.addAll(nodeSendParameter); + Def_Function_Writer.sendParameterType.addAll(nodeSendParameterType); + + functionNode.unknownStartReference = unknownStartReference; + functionNode.unknownStopReference = unknownStopReference; + + if (runsOnValue != null) { + + AstWalkerJava.functionList.add(((Def_Function) node).getIdentifier().toString()); + + myASTVisitor.visualizeNodeToJava(myASTVisitor.importListStrings); + myASTVisitor.visualizeNodeToJava(functionNode.writeFunctionFile()); + myASTVisitor.currentFileName = runsOnValue; + myASTVisitor.deleteLastBracket(myASTVisitor.currentFileName); + + } else { + myASTVisitor.currentFileName = "TTCN_functions"; + myASTVisitor.deleteLastBracket(myASTVisitor.currentFileName); + } + + myASTVisitor.visualizeNodeToJava(functionNode.getJavaSource() + "\r\n}"); + + clearEverything(); + + } + + public void handleTestcase(IVisitableNode node) { + Def_Testcase_Writer testNode = Def_Testcase_Writer.getInstance(((Def_Testcase) node)); + + testNode.clearLists(); + + myASTVisitor.currentFileName = ((Def_Testcase) node).getIdentifier().toString(); + + testNode.testCaseRunsOn = runsOnValue; + testNode.tcMainStatementBlock = tcStatementBlock; + AstWalkerJava.testCaseRunsOnList.add(runsOnValue); + + testNode.tcConnectValues.addAll(testCaseConnectValues); + testNode.tcStartIdentifiers.addAll(testCaseStartValues); + testNode.tcStartCounter.addAll(testCaseStartCounter); + testNode.tcMapValues.addAll(testCaseMapValues); + testNode.tcMapCounter.addAll(testCaseMapCounter); + testNode.tcIfConditions.addAll(testCaseIfConditions); + testNode.tcVars.addAll(nodeVars); + testNode.tcVarTypes.addAll(nodeVarTypes); + testNode.tcVarValues.addAll(nodeVarValues); + testNode.tcAssignIdentifiers.addAll(nodeAssignIdentifiers); + testNode.tcAssignValues.addAll(nodeAssignValues); + testNode.tcValueIsAValueReference.addAll(nodeVarIsAValueReference); + testNode.tcCreateValues.addAll(testCaseCreateValues); + testNode.tcCreateCounter.addAll(testCaseCreateCounter); + Def_Testcase_Writer.sendPortReference.addAll(nodeSendPortReference); + Def_Testcase_Writer.sendParameter.addAll(nodeSendParameter); + Def_Testcase_Writer.sendParameterType.addAll(nodeSendParameterType); + + testNode.tcVarIsConstant.addAll(nodeVarIsConstant); + testNode.tcVarIsTemplate.addAll(nodeVarIsTemplate); + testNode.tcDisconnectValues.addAll(testCaseDisconnectValues); + testNode.testCaseStartValueParameters.addAll(testCaseStartValueParameters); + testNode.tcValueTypeIsAReference.addAll(nodeVarTypeIsAReference); + testNode.tcStopIdentifiers.addAll(testCaseStopValues); + testNode.tcStopCounter.addAll(testCaseStopCounter); + testNode.testCaseStopValueParameters.addAll(testCaseStopValueParameters); + + testNode.receivePortReference.addAll(receivePortReference); + testNode.receiveValue.addAll(receiveValue); + testNode.receiveAnyValValue.addAll(receiveAnyValValue); + testNode.receiveType.addAll(receiveType); + + testNode.receiveStatements.addAll(receiveStatements); + testNode.nodeVarIsRecord.addAll(nodeVarIsRecord); + + myASTVisitor.visualizeNodeToJava(myASTVisitor.importListStrings); + myASTVisitor.visualizeNodeToJava(testNode.writeTestcaseFile((Def_Testcase) node)); + + myASTVisitor.currentFileName = runsOnValue; + myASTVisitor.deleteLastBracket(myASTVisitor.currentFileName); + myASTVisitor.visualizeNodeToJava(testNode.getJavaSource() + "\r\n}"); + + clearEverything(); + + } + + public void handleAltCases(IVisitableNode node) { + + if (waitForTC && (node instanceof Alt_Statement)) { + + currentTestCaseWriter.altStatements + .add(new Def_AltStatement_Writer((Alt_Statement) node, currentTestCaseWriter.nodeName)); + + currentTestCaseWriter.altStatements.get(currentTestCaseWriter.altStatements.size() - 1).setType("TestCase"); + + currentTestCaseWriter.altStatements.get(currentTestCaseWriter.altStatements.size() - 1) + .setParent(currentTestCaseWriter); + + currentTestCaseWriter.altStatements.get(currentTestCaseWriter.altStatements.size() - 1).altGuardConditions + .addAll(altGuardConditions); + + currentTestCaseWriter.altStatements + .get(currentTestCaseWriter.altStatements.size() - 1).altGuardPortReference + .addAll(altGuardPortReference); + + currentTestCaseWriter.altStatements.get(currentTestCaseWriter.altStatements.size() - 1).altGuardReceiveValue + .addAll(altGuardReceiveValue); + + currentTestCaseWriter.altStatements.get(currentTestCaseWriter.altStatements.size() - 1).altGuardReceiveType + .addAll(altGuardReceiveType); + + currentTestCaseWriter.altStatements.get(currentTestCaseWriter.altStatements.size() - 1).altGuardTimeout + .addAll(altGuardTimeout); + + clearAltLists(); + + } + + if (waitForFunction && (node instanceof Alt_Statement)) { + + currentFunctionWriter.altStatements + .add(new Def_AltStatement_Writer((Alt_Statement) node, currentFunctionWriter.nodeName)); + + currentFunctionWriter.altStatements.get(currentFunctionWriter.altStatements.size() - 1).setType("Function"); + currentFunctionWriter.altStatements.get(currentFunctionWriter.altStatements.size() - 1) + .setParent(currentFunctionWriter); + + currentFunctionWriter.altStatements.get(currentFunctionWriter.altStatements.size() - 1).altGuardConditions + .addAll(altGuardConditions); + + currentFunctionWriter.altStatements + .get(currentFunctionWriter.altStatements.size() - 1).altGuardPortReference + .addAll(altGuardPortReference); + + currentFunctionWriter.altStatements.get(currentFunctionWriter.altStatements.size() - 1).altGuardReceiveValue + .addAll(altGuardReceiveValue); + + currentFunctionWriter.altStatements.get(currentFunctionWriter.altStatements.size() - 1).altGuardReceiveType + .addAll(altGuardReceiveType); + + currentFunctionWriter.altStatements.get(currentFunctionWriter.altStatements.size() - 1).altGuardTimeout + .addAll(altGuardTimeout); + + currentFunctionWriter.altStatements + .get(currentFunctionWriter.altStatements.size() - 1).altGuardReceiveAnyValValue + .addAll(altGuardReceiveAnyValValue); + + clearAltLists(); + } + + } + + public void clearAltLists() { + altGuardConditions.clear(); + altGuardPortReference.clear(); + altGuardReceiveValue.clear(); + altGuardReceiveType.clear(); + altGuardTimeout.clear(); + altGuardReceiveAnyValValue.clear(); + } + + public void clearEverything() { + + tcCreateCounter = -1; + tcStartCounter = -1; + mapCounter = 0; + mapValueCounter = 0; + + tcStopCounter = -1; + + waitForTcStopValues = false; + waitForDefStatement = false; + waitForStatementBlock = false; + waitForValue = false; + waitForRunsOnValue = false; + waitForReturnType = false; + waitForReturnStatementValue = false; + waitForReceiveStatement = false; + checkAnyport = false; + waitForUnknownStartStatement = false; + waitForTypedParam = false; + waitForInt2StrExpression = false; + waitForTC = false; + + waitForAssignmentIdentifiers = false; + waitForMapIdentifiers = false; + waitForTcIfCondition = false; + isSendStatement = false; + waitForTcStartParameter = false; + isAltGuards = false; + waitForAltStatements = false; + isReceiveValue = false; + waitForAltTimeout = false; + isNextValueConstant = false; + waitForTcDisconnectValues = false; + waitForTcCreateValues = false; + waitForTcConnectValues = false; + waitForTcStartValues = false; + waitForFunction = false; + + waitForStatements = false; + waitForValue = false; + isAnyValValue = false; + waitForReceiveAnyValTemplateValue = false; + + nodeVars.clear(); + nodeVarTypes.clear(); + nodeVarValues.clear(); + nodeVarIsAValueReference.clear(); + nodeVarTypeIsAReference.clear(); + nodeAssignIdentifiers.clear(); + nodeVarIsConstant.clear(); + nodeVarIsTemplate.clear(); + nodeAssignValues.clear(); + testCaseCreateValues.clear(); + testCaseCreateCounter.clear(); + testCaseCreateRefValues.clear(); + nodeSendParameter.clear(); + testCaseCreateCharValues.clear(); + testCaseIfConditions.clear(); + nodeSendPortReference.clear(); + nodeSendParameterType.clear(); + altGuardConditions.clear(); + altGuardPortReference.clear(); + altGuardReceiveValue.clear(); + altGuardReceiveAnyValValue.clear(); + altGuardReceiveType.clear(); + altGuardTimeout.clear(); + testCaseDisconnectValues.clear(); + testCaseStartValues.clear(); + testCaseMapValues.clear(); + testCaseMapCounter.clear(); + testCaseStartCounter.clear(); + testCaseStartValueParameters.clear(); + testCaseConnectValues.clear(); + operatorList.clear(); + + testCaseStopValues.clear(); + testCaseStopValueParameters.clear(); + testCaseStopCounter.clear(); + + receiveStatements.clear(); + receivePortReference.clear(); + receiveValue.clear(); + receiveAnyValValue.clear(); + receiveType.clear(); + + nodeVarRecordValues.clear(); + nodeVarIsRecord.clear(); + + isIf = false; + isDefinition = false; + isAssignment = false; + + } +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/javagen/HCType.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/javagen/HCType.java new file mode 100644 index 000000000..0b0f1eeae --- /dev/null +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/javagen/HCType.java @@ -0,0 +1,40 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Keremi, Andras + * Eros, Levente + * Kovacs, Gabor + * + ******************************************************************************/ + + +package org.eclipse.titan.codegenerator.javagen; +import org.eclipse.titan.codegenerator.TTCN3JavaAPI.*; +import java.util.HashSet; +import java.util.concurrent.TimeUnit; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.ArrayList; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.net.Socket; +import java.util.Vector; +import java.math.BigInteger; +import java.net.ServerSocket; + +public class HCType { + + + //Empty class, spaceholder so the API doesn't throw an error + //HCType class is generated at runtime + + +} diff --git a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/myASTVisitor.java b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/myASTVisitor.java index 5140db6ec..23c92e823 100644 --- a/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/myASTVisitor.java +++ b/org.eclipse.titan.codegenerator/src/org/eclipse/titan/codegenerator/myASTVisitor.java @@ -10,10 +10,12 @@ * Keremi, Andras * Eros, Levente * Kovacs, Gabor + * Meszaros, Mate Robert * ******************************************************************************/ package org.eclipse.titan.codegenerator; + import java.io.File; import java.io.FileWriter; import java.io.IOException; @@ -28,203 +30,59 @@ import java.util.Set; import org.eclipse.titan.designer.AST.ASTVisitor; import org.eclipse.titan.designer.AST.IVisitableNode; -import org.eclipse.titan.designer.AST.Identifier; -import org.eclipse.titan.designer.AST.Reference; -import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const; -import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function; -import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Port; -import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template; -import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase; -import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Timer; -import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type; -import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var; -import org.eclipse.titan.designer.AST.TTCN3.definitions.TestcaseFormalParameterList; -import org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement; -import org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement; -import org.eclipse.titan.designer.AST.TTCN3.statements.Connect_Statement; -import org.eclipse.titan.designer.AST.TTCN3.statements.Definition_Statement; -import org.eclipse.titan.designer.AST.TTCN3.statements.Done_Statement; -import org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement; -import org.eclipse.titan.designer.AST.TTCN3.statements.Return_Statement; -import org.eclipse.titan.designer.AST.TTCN3.statements.Send_Statement; -import org.eclipse.titan.designer.AST.TTCN3.statements.Setverdict_Statement; -import org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock; -import org.eclipse.titan.designer.AST.TTCN3.statements.Unknown_Start_Statement; -import org.eclipse.titan.designer.AST.TTCN3.templates.AnyOrOmit_Template; -import org.eclipse.titan.designer.AST.TTCN3.templates.Any_Value_Template; -import org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List; -import org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template; -import org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance; -import org.eclipse.titan.designer.AST.TTCN3.types.CharString_Type; -import org.eclipse.titan.designer.AST.TTCN3.types.CompField; -import org.eclipse.titan.designer.AST.TTCN3.types.Component_Type; -import org.eclipse.titan.designer.AST.TTCN3.types.EnumerationItems; +import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar; import org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type; -import org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody; -import org.eclipse.titan.designer.AST.TTCN3.types.Port_Type; -import org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type; -import org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type; -import org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type; -import org.eclipse.titan.designer.AST.TTCN3.types.subtypes.Range_ParsedSubType; -import org.eclipse.titan.designer.AST.TTCN3.types.subtypes.Single_ParsedSubType; -import org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value; import org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value; -import org.eclipse.titan.designer.AST.TTCN3.values.Omit_Value; -import org.eclipse.titan.designer.AST.TTCN3.values.Real_Value; -import org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value; -import org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value; -import org.eclipse.titan.designer.AST.TTCN3.values.expressions.AddExpression; -import org.eclipse.titan.designer.AST.TTCN3.values.expressions.ComponentCreateExpression; -import org.eclipse.titan.designer.AST.TTCN3.values.expressions.Int2StrExpression; -import org.eclipse.titan.designer.parsers.CompilationTimeStamp; - -public class myASTVisitor extends ASTVisitor { +import org.eclipse.titan.designer.AST.TTCN3.values.expressions.UnaryMinusExpression; - public static String currentFileName = ""; +public final class myASTVisitor extends ASTVisitor { - private List compFieldTypes = new ArrayList(); - private List compFieldNames = new ArrayList(); + public static TestCase_Function_Visit_Handler myFunctionTestCaseVisitHandler = new TestCase_Function_Visit_Handler(); + public static Def_Type_Visit_Handler myDefTypeVisitHandler = new Def_Type_Visit_Handler(); + public static Def_Const_Visit_Handler myDefConstVisitHandler = new Def_Const_Visit_Handler(); + public static Def_Template_Visit_Handler myDefTemplateVisitHandler = new Def_Template_Visit_Handler(); - private List enumItems = new ArrayList(); + public static String currentFileName = ""; - private String charstringValue = null; + private static String moduleParNodeType = null; - private int minValue; - private int maxValue; + public static boolean blockIdListing = false; + public static boolean isNextIntegerNegative = false; - private boolean waitForSetOfReference = false; - private String setOfReferenceName = null; - private List inMessageName = new ArrayList(); - private List outMessageName = new ArrayList(); - private List inOutMessageName = new ArrayList(); - private boolean isPortTypeAReferencedType = false; - private boolean waitingForPortAttriburtes = false; + private static boolean waitForModuleParValues = false; - private boolean waitForCompReference = false; - private List compPortTypes = new ArrayList(); - private List compPortNames = new ArrayList(); + private static List moduleParValues = new ArrayList(); - private String parentName = null; public static Map nodeNameChildrenNamesHashMap = new LinkedHashMap(); public static Map nodeNameChildrenTypesHashMap = new LinkedHashMap(); public static Map nodeNameSetOfTypesHashMap = new LinkedHashMap(); + public static Map nodeNameRecordOfTypesHashMap = new LinkedHashMap<>(); public static Map nodeNameNodeTypeHashMap = new LinkedHashMap(); + public static Map portNamePortTypeHashMap = new LinkedHashMap(); + public static Map templateIdValuePairs = new LinkedHashMap(); - private boolean waitForConstValues = false; - private String constNodeType = null; - private List constValues = new ArrayList(); public static Set constOmitHashes = new HashSet(); - // counts the members for each setof - // has to be -3 because the node's name and type increases it by 2 - // should be increased to 0 only at the first constant value - private int constSetOfCounter = -3; - private List constSetOfAmount = new ArrayList(); - private String lastConstName = null; - - private List templateValues = new ArrayList(); - private List templateAllIdentifiers = new ArrayList(); - private boolean waitForTemplateValues = false; - private boolean waitForModifierValue = false; - private String modifierValue=null; - private String lastTemplateName = null; - public static Map templateIdValuePairs = new LinkedHashMap(); public static Set templateIDs = new HashSet(); - public static List componentList = new ArrayList(); - public static List testCaseList = new ArrayList(); - public static List testCaseRunsOnList = new ArrayList(); - public static List functionList = new ArrayList(); - public static List functionRunsOnList = new ArrayList(); - - private boolean blockIdListing = false; - - private boolean waitForStatementBlock = false; - private StatementBlock statementBlock = null; - private boolean waitForRunsOnValue=false; - private boolean waitForReturnType=false; - private String runsOnValue=null; - private String returnType=null; - - private boolean waitForReturnStatementValue=false; - private String returnStatementValue=null; - - private boolean waitForTimerValue=false; - private String timerValue=null; - - private boolean waitForSendStatement=false; - private List sendPortReference = new ArrayList(); - private List sendParameter = new ArrayList(); - private List sendParameterType = new ArrayList(); - - private boolean waitForRecieveStatement=false; - private List recievePortReference = new ArrayList(); - private List recieveParameter = new ArrayList(); - private List recieveParameterType = new ArrayList(); - private List receiveTypedParam = new ArrayList(); - private boolean checkAnyport=false; - private boolean waitForReceivePortStatement=false; - private boolean waitForUnknownStartStatement=false; - private String unknownStartReference=null; - private boolean waitForTimeoutStatement=false; - private boolean waitForTypedParam=false; - private boolean waitForInt2StrExpression=false; - - private boolean waitForAddExpression=false; - private List addValues = new ArrayList(); - - private boolean waitForTcRunsOn=false; - private String testCaseRunsOn=null; - private boolean waitForTcStatementBlock=false; - private StatementBlock tcStatementBlock=null; - private List testCaseVars = new ArrayList(); - private List testCaseVarTypes = new ArrayList(); - - private CompilationTimeStamp compilationCounter = CompilationTimeStamp - .getNewCompilationCounter(); - - private boolean waitForTcDefStatement=false; - - private boolean waitForTC=false; - - private boolean waitForTcAssignmentValues=false; - private List testCaseAssignValues = new ArrayList(); - private List testCaseCreateValues = new ArrayList(); - private List testCaseCreateCounter = new ArrayList(); - private List testCaseCreateRefValues = new ArrayList(); - private List testCaseCreateCharValues = new ArrayList(); - - private int tcCreateCounter=-1; - private boolean waitForTcCreateValues=false; - - private boolean waitForTcConnectValues=false;; - private List testCaseConnectValues = new ArrayList(); - private List testCaseConnectCounter = new ArrayList(); - private int tcConnectCounter=-1; - - private boolean waitForTcStartValues=false;; - private List testCaseStartValues = new ArrayList(); - private List testCaseStartCounter = new ArrayList(); - private int tcStartCounter=-1; - - - - public static String importListStrings = "package org.eclipse.titan.javagen;" + public static String importListStrings = "package org.eclipse.titan.codegenerator.javagen;" + + "\r\n" + + "import org.eclipse.titan.codegenerator.TTCN3JavaAPI.*;" + "\r\n" - + "import org.eclipse.titan.ttcn3java.TTCN3JavaAPI.*;" + + "import java.util.ArrayList;" + "\r\n" + "import java.util.HashSet;" + "\r\n" + + "import java.util.List;" + + "\r\n" + + "import java.util.Vector;" + + "\r\n" + "import java.util.concurrent.TimeUnit;" + "\r\n" + "import java.io.ObjectInputStream;" + "\r\n" + "import java.io.ObjectOutputStream;" + "\r\n" - // + "com.ericsson.titan.ttcn3java.SIP_Definitions.*" - + "\r\n" - + "import java.util.ArrayList;" - + "\r\n" + "import java.io.BufferedReader;" + "\r\n" + "import java.io.BufferedWriter;" @@ -233,27 +91,11 @@ public class myASTVisitor extends ASTVisitor { + "\r\n" + "import java.io.OutputStreamWriter;" + "\r\n" + + "import java.math.BigInteger;" + + "\r\n" + "import java.net.Socket;" + "\r\n" - + "import java.util.Vector;" - + "\r\n" + "import java.net.ServerSocket;" + "\r\n" + "\r\n"; -/* - static { - currentFileName = "Constants"; - visualizeNodeToJava(importListStrings); // erre - visualizeNodeToJava("class Constants{\r\n}\r\n"); - - currentFileName = "Templates"; - - visualizeNodeToJava(importListStrings); // erre - visualizeNodeToJava("class Templates{\r\n}\r\n"); - - currentFileName = "TTCN_functions"; - - visualizeNodeToJava(importListStrings); // erre - visualizeNodeToJava("class TTCN_functions{\r\n}\r\n"); - - }*/ + + "import java.net.ServerSocket;" + "\r\n" + "\r\n"; public static void visualizeNodeToJava(String string) { @@ -268,13 +110,12 @@ public class myASTVisitor extends ASTVisitor { printer.close(); } catch (IOException e) { - // TODO Auto-generated catch block e.printStackTrace(); } - // logger.severe(string); + } - public String changeTypeToJava(String string) { + public static String changeTypeToJava(String string) { if (string.equals("CHARSTRING")) { string = "SubTypeDef"; @@ -291,7 +132,7 @@ public class myASTVisitor extends ASTVisitor { return string; } - public String cutModuleNameFromBeginning(String string) { + public static String cutModuleNameFromBeginning(String string) { String[] parts = string.split("\\."); if (parts.length > 1) { @@ -305,7 +146,7 @@ public class myASTVisitor extends ASTVisitor { return changeTypeToJava(string); } - public void deleteLastBracket(String currentFileName) { + public static void deleteLastBracket(String currentFileName) { try { RandomAccessFile file = new RandomAccessFile( @@ -323,1076 +164,86 @@ public class myASTVisitor extends ASTVisitor { } public int visit(IVisitableNode node) { + // visit* submethods only serve increased readability and + // categorization - if (node instanceof Def_Type) { - Def_Type typeNode = (Def_Type) node; - - CompilationTimeStamp compilationCounter = CompilationTimeStamp - .getNewCompilationCounter(); - - currentFileName = typeNode.getIdentifier().toString(); - - visualizeNodeToJava(importListStrings); // erre - - if (typeNode.getType(compilationCounter).getTypetype().toString() - .equals("TYPE_TTCN3_SEQUENCE")) {// record - - Def_Type_Record recordNode = Def_Type_Record - .getInstance(typeNode); - - nodeNameNodeTypeHashMap.put( - typeNode.getIdentifier().toString(), "record"); - parentName = typeNode.getIdentifier().toString(); - parentName.toString(); - - } else if (typeNode.getType(compilationCounter).getTypetype() - .toString().equals("TYPE_TTCN3_SET")) { - - Def_Type_Set setdNode = Def_Type_Set.getInstance(typeNode); - - nodeNameNodeTypeHashMap.put( - typeNode.getIdentifier().toString(), "set"); - parentName = typeNode.getIdentifier().toString(); - - } else if (typeNode.getType(compilationCounter).getTypetype() - .toString().equals("TYPE_TTCN3_CHOICE")) { - - Def_Type_Union uniondNode = Def_Type_Union - .getInstance(typeNode); - - nodeNameNodeTypeHashMap.put( - typeNode.getIdentifier().toString(), "union"); - parentName = typeNode.getIdentifier().toString(); - - } else if (typeNode.getType(compilationCounter) instanceof Integer_Type) { - - Def_Type_Integer integerNode = Def_Type_Integer - .getInstance(typeNode); + myDefTypeVisitHandler.visit(node); - nodeNameNodeTypeHashMap.put( - typeNode.getIdentifier().toString(), "INTEGER"); - parentName = typeNode.getIdentifier().toString(); + myDefConstVisitHandler.visit(node); - } else if (typeNode.getType(compilationCounter) instanceof CharString_Type) { + myDefTemplateVisitHandler.visit(node); - Def_Type_Charstring charstringNode = Def_Type_Charstring - .getInstance(typeNode); - - nodeNameNodeTypeHashMap.put( - typeNode.getIdentifier().toString(), "CHARSTRING"); - parentName = typeNode.getIdentifier().toString(); - - } else if (typeNode.getType(compilationCounter) instanceof TTCN3_Enumerated_Type) { - - Def_Type_Enum enumTypeNode = Def_Type_Enum - .getInstance(typeNode); - - nodeNameNodeTypeHashMap.put( - typeNode.getIdentifier().toString(), "enum"); - parentName = typeNode.getIdentifier().toString(); - - } else if (typeNode.getType(compilationCounter).getTypetype() - .toString().equals("TYPE_SET_OF")) { - - Def_Type_Set_Of setOfNode = Def_Type_Set_Of - .getInstance(typeNode); - waitForSetOfReference = true; - - nodeNameNodeTypeHashMap.put( - typeNode.getIdentifier().toString(), "setof"); - - nodeNameSetOfTypesHashMap.put(typeNode.getIdentifier() - .toString(), ((Referenced_Type) ((SetOf_Type) typeNode - .getType(compilationCounter)).getOfType()) - .getReference().toString()); - parentName = typeNode.getIdentifier().toString(); - - } else if (typeNode.getType(compilationCounter).getTypetype() - .toString().equals("TYPE_PORT")) { - - Def_Type_Port portNode = Def_Type_Port.getInstance(typeNode); - - waitingForPortAttriburtes = true; - - nodeNameNodeTypeHashMap.put( - typeNode.getIdentifier().toString(), "port"); - parentName = typeNode.getIdentifier().toString(); - - } else if (typeNode.getType(compilationCounter).getTypetype() - .toString().equals("TYPE_COMPONENT")) { - - Def_Type_Component compNode = Def_Type_Component - .getInstance(typeNode); - waitForCompReference = true; - - componentList.add(typeNode.getIdentifier().toString()); - nodeNameNodeTypeHashMap.put( - typeNode.getIdentifier().toString(), "component"); - parentName = typeNode.getIdentifier().toString(); - } - - } - - if (node instanceof Def_Const) { + if (node instanceof Def_ModulePar) { currentFileName = "Constants"; - Def_Const_Writer constNode = Def_Const_Writer - .getInstance(((Def_Const) node)); - nodeNameNodeTypeHashMap.put(((Def_Const) node).getIdentifier() - .toString(), "constant"); - waitForConstValues = true; - constSetOfAmount.add(0); - } - - if (node instanceof Def_Template) { - currentFileName = "Templates"; - - Def_Template_Writer tempNode = Def_Template_Writer - .getInstance(((Def_Template) node)); - - nodeNameNodeTypeHashMap.put(((Def_Template) node).getIdentifier() - .toString(), "template"); - - waitForModifierValue=true; - waitForTemplateValues = true; - - } - - if (node instanceof Def_Function) { - - Def_Function_Writer functionNode = Def_Function_Writer - .getInstance(((Def_Function) node)); - - nodeNameNodeTypeHashMap.put(((Def_Function) node).getIdentifier() - .toString(), "function"); - - runsOnValue=null; - - - waitForReturnType=true; - waitForRunsOnValue=true; - waitForStatementBlock = true; - - } - - if (node instanceof Def_Testcase) { - - Def_Testcase_Writer testcaseNode = Def_Testcase_Writer - .getInstance(((Def_Testcase) node)); - - nodeNameNodeTypeHashMap.put(((Def_Testcase) node).getIdentifier() - .toString(), "testcase"); - - testCaseList.add(((Def_Testcase) node).getIdentifier().toString()); - - waitForStatementBlock = true; - waitForTC=true; - - } - - // ----------children nodes - if (waitForSetOfReference && (node instanceof Reference)) { - - setOfReferenceName = ((Reference) node).getId().toString(); - waitForSetOfReference = false; - } - - if (node instanceof CompField) { // component - - CompField compFieldNode = (CompField) node; - - if (compFieldNode.getType() instanceof Referenced_Type) { - - compFieldTypes.add(((Referenced_Type) compFieldNode.getType()) - .getReference().getId().toString()); - } else { - compFieldTypes.add(cutModuleNameFromBeginning(compFieldNode - .getType().getTypename())); - } - compFieldNames.add(compFieldNode.getIdentifier().toString()); - - } - - if (node instanceof Charstring_Value) {// charstring - - Charstring_Value singleValuedNode = (Charstring_Value) node; - - charstringValue = singleValuedNode.getValue(); - - } - - if (node instanceof Range_ParsedSubType) {// integer - - Range_ParsedSubType rangeValueNode = (Range_ParsedSubType) node; - - minValue = Integer.parseInt(rangeValueNode.getMin().toString()); - maxValue = Integer.parseInt(rangeValueNode.getMax().toString()); - } - - if (node instanceof EnumerationItems) {// enum - - for (int i = 0; i < ((EnumerationItems) node).getItems().size(); i++) { - enumItems.add(((EnumerationItems) node).getItems().get(i) - .getId().toString()); - - } - } - - if (waitingForPortAttriburtes && (node instanceof Referenced_Type)) { - isPortTypeAReferencedType = true; - - } - - if (waitingForPortAttriburtes && (node instanceof PortTypeBody)) { - PortTypeBody body = (PortTypeBody) node; - int inCount = body.getInMessages().getNofTypes(); - int outCount = body.getOutMessage().getNofTypes(); - - for (int i = 0; i < inCount; i++) { - inMessageName.add(cutModuleNameFromBeginning(body - .getInMessages().getTypeByIndex(i).getTypename())); - } - for (int i = 0; i < outCount; i++) { - outMessageName.add(cutModuleNameFromBeginning(body - .getOutMessage().getTypeByIndex(i).getTypename())); - } - - int shorterListSize = inMessageName.size() <= outMessageName.size() ? inMessageName - .size() : outMessageName.size(); - - // check if one of the messages is inout - // if inout delete from both lists and add to inout - for (int i = 0; i < shorterListSize; i++) { - if (inMessageName.size() == shorterListSize) { - for (int j = 0; j < outMessageName.size(); j++) { - if (inMessageName.get(i).equals(outMessageName.get(j))) { - inOutMessageName.add(inMessageName.get(i)); - inMessageName.remove(i); - outMessageName.remove(j); - } - } - } else { - for (int j = 0; j < outMessageName.size(); j++) { - if (outMessageName.get(i).equals(inMessageName.get(j))) { - inOutMessageName.add(outMessageName.get(i)); - inMessageName.remove(i); - outMessageName.remove(j); - } - } - } - } - } - - // component ports - if (node instanceof Def_Port) { - Def_Port port = (Def_Port) node; - compPortNames.add(port.getIdentifier().toString()); - - } - if (waitForCompReference && (node instanceof Reference)) { - - compPortTypes.add(((Reference) node).getId().toString()); - - } - - // constants - - if (waitForConstValues && (node instanceof Identifier)) { - constSetOfCounter++; - if (constSetOfCounter > 0) { - constSetOfAmount.add(0); - } - lastConstName = ((Identifier) node).toString(); - } - - if (waitForConstValues && (node instanceof Charstring_Value)) { - constValues.add(((Charstring_Value) node).getValue()); - - if (constSetOfCounter == -1) { - constSetOfCounter = 0; - } - - constSetOfAmount.set(constSetOfCounter, - constSetOfAmount.get(constSetOfCounter) + 1); - } - - if (waitForConstValues && (node instanceof Integer_Value)) { - constValues.add(Long.toString(((Integer_Value) node).getValue())); - - if (constSetOfCounter == -1) { - constSetOfCounter = 0; - } - - constSetOfAmount.set(constSetOfCounter, - constSetOfAmount.get(constSetOfCounter) + 1); - - } - - if (waitForConstValues && (node instanceof Omit_Value)) { - constValues.add("omit"); - - if (constSetOfCounter == -1) { - constSetOfCounter = 0; - } - - constSetOfAmount.set(constSetOfCounter, - constSetOfAmount.get(constSetOfCounter) + 1); - - constOmitHashes.add(lastConstName); - - } - - if (waitForConstValues && (node instanceof Reference)) { - constNodeType = ((Reference) node).getId().toString(); - } - - // templates - if (waitForTemplateValues && (node instanceof Reference)) { - constNodeType = ((Reference) node).getId().toString(); - } - - if (waitForTemplateValues - && (node instanceof Undefined_LowerIdentifier_Value)) { - - templateIdValuePairs.put(lastTemplateName, - ((Undefined_LowerIdentifier_Value) node).getIdentifier() - .toString()); - blockIdListing = true; - } - - if (waitForTemplateValues && (node instanceof Charstring_Value)) { - - templateIdValuePairs.put(lastTemplateName, - ((Charstring_Value) node).getValue()); - blockIdListing = true; - } - - if (waitForTemplateValues && (node instanceof Omit_Value)) { - - templateIdValuePairs.put(lastTemplateName, "omit"); - blockIdListing = true; - } - - if (waitForTemplateValues && (node instanceof Any_Value_Template)) { - - templateIdValuePairs.put(lastTemplateName, "?"); - blockIdListing = true; - } - - if (waitForTemplateValues && (node instanceof AnyOrOmit_Template)) { - - templateIdValuePairs.put(lastTemplateName, "*"); - blockIdListing = true; - } - - if (waitForTemplateValues && (node instanceof Reference)) { - - templateIdValuePairs.put(lastTemplateName, ((Reference) node) - .toString().toString()); - blockIdListing = true; - } - - if (waitForTemplateValues && (node instanceof Identifier) - && !blockIdListing) { - templateAllIdentifiers.add(((Identifier) node).toString()); - lastTemplateName = ((Identifier) node).toString(); - templateIDs.add(lastTemplateName); - - } - if (waitForModifierValue && (node instanceof Named_Template_List)) { - waitForModifierValue=false;; - - } - if (waitForModifierValue && (node instanceof Reference)) { - modifierValue = ((Reference)node).getId().toString(); - - } -//functions - if (waitForStatementBlock && (node instanceof StatementBlock)) { - statementBlock = (StatementBlock) node; - waitForStatementBlock = false; - } - - if (waitForReturnType && (node instanceof StatementBlock)) { - waitForReturnType=false;; - - } - if (waitForReturnType && (node instanceof Integer_Type)) { - returnType="Integer_Type"; - } - - if (waitForRunsOnValue && (node instanceof StatementBlock)) { - waitForRunsOnValue=false;; - - } - if (waitForRunsOnValue && (node instanceof Reference)) { - runsOnValue = ((Reference)node).getId().toString(); - functionRunsOnList.add(((Reference)node).getId().toString()); - - } - - if(node instanceof Return_Statement){ - waitForReturnStatementValue=true; - } - - if (waitForReturnStatementValue && (node instanceof Integer_Value)) { - returnStatementValue = String.valueOf(((Integer_Value)node).getValue()); - - } - - if(node instanceof Def_Timer){ - waitForTimerValue=true; - } - if (waitForTimerValue && (node instanceof Real_Value)) { - timerValue=((Real_Value)node).createStringRepresentation(); - } - - if(node instanceof Send_Statement){ - waitForSendStatement=true; - } - - if (waitForSendStatement && (node instanceof Reference)) { - sendPortReference.add(((Reference)node).getId().toString()); - + Def_ModulePar_Writer.getInstance(((Def_ModulePar) node)); + nodeNameNodeTypeHashMap.put(((Def_ModulePar) node).getIdentifier() + .toString(), "modulePar"); + waitForModuleParValues = true; } - - if (waitForSendStatement && (node instanceof SpecificValue_Template)) { - if(((SpecificValue_Template)node).getSpecificValue() instanceof Undefined_LowerIdentifier_Value){ - - Undefined_LowerIdentifier_Value tempValue=(Undefined_LowerIdentifier_Value) ((SpecificValue_Template)node).getSpecificValue(); - sendParameter.add(tempValue.getIdentifier().toString()); - sendParameterType.add("Undefined_LowerIdentifier_Value"); - } - - if(((SpecificValue_Template)node).getSpecificValue() instanceof Charstring_Value){ - Charstring_Value tempValue=(Charstring_Value) ((SpecificValue_Template)node).getSpecificValue(); - sendParameter.add(tempValue.getValue()); - sendParameterType.add("Charstring_Value"); - } - } - - if(node instanceof Unknown_Start_Statement){ - waitForUnknownStartStatement=true; - } - if (waitForUnknownStartStatement && (node instanceof Reference)) { - unknownStartReference=((Reference)node).getId().toString(); - + if (node instanceof UnaryMinusExpression) { + myASTVisitor.isNextIntegerNegative = true; } - - if(node instanceof Receive_Port_Statement){ - waitForRecieveStatement=true; - checkAnyport=true; - } - - if(node instanceof TemplateInstance){ - - - if(((TemplateInstance)node).getType()!=null){ - waitForTypedParam=true; - checkAnyport=true; - } - } - if (waitForRecieveStatement && !waitForTypedParam&&(node instanceof Reference)) { - recievePortReference.add(((Reference)node).getId().toString()); - checkAnyport=false; - + // module parameters + visitModuleParNodes(node); - } - if(waitForTypedParam&&(node instanceof Reference)) { - recieveParameter.add(((Reference)node).getId().toString()); - recieveParameterType.add("_TYPED_PARAM_"); - waitForTypedParam=false; - } - - - if(checkAnyport &&(node instanceof Setverdict_Statement)){ - recievePortReference.add("_ANY_"); - recieveParameter.add("_ANY_"); - recieveParameterType.add("_ANY_"); - checkAnyport=false; - } - - - - - if (waitForRecieveStatement && (node instanceof Any_Value_Template)) { - recieveParameter.add("Any_Value_Template"); - recieveParameterType.add("Any_Value_Template"); - checkAnyport=false; - } - - - if (waitForRecieveStatement && (node instanceof SpecificValue_Template)) { - checkAnyport=false; - if(((SpecificValue_Template)node).getSpecificValue() instanceof Undefined_LowerIdentifier_Value){ - - Undefined_LowerIdentifier_Value tempValue=(Undefined_LowerIdentifier_Value) ((SpecificValue_Template)node).getSpecificValue(); - recieveParameter.add(tempValue.getIdentifier().toString()); - recieveParameterType.add("Undefined_LowerIdentifier_Value"); - } - - if(((SpecificValue_Template)node).getSpecificValue() instanceof Charstring_Value){ - Charstring_Value tempValue=(Charstring_Value) ((SpecificValue_Template)node).getSpecificValue(); - recieveParameter.add(tempValue.getValue()); - recieveParameterType.add("Charstring_Value"); - } - } - - if(node instanceof AddExpression){ - waitForAddExpression=true; - } - - if (waitForAddExpression && (node instanceof Undefined_LowerIdentifier_Value)) { - addValues.add(((Undefined_LowerIdentifier_Value)node).getIdentifier().toString()); - } - if (waitForAddExpression && (node instanceof Integer_Value)) { - addValues.add(String.valueOf(((Integer_Value)node).getValue())); - - } - - if(node instanceof Int2StrExpression){ - waitForInt2StrExpression=true; - } - if (waitForInt2StrExpression && (node instanceof Undefined_LowerIdentifier_Value)) { - sendParameter.add(((Undefined_LowerIdentifier_Value)node).getIdentifier().toString()); - sendParameterType.add("Int2StrExpression"); - waitForInt2StrExpression=false; - + // Check for Function & TC nodes + myFunctionTestCaseVisitHandler.visit(node); - } - - if(node instanceof TestcaseFormalParameterList){ - waitForTcRunsOn=true; - } - if(waitForTcRunsOn&&(node instanceof Reference)) { - testCaseRunsOn=((Reference)node).getId().toString(); - waitForTcRunsOn=false; - waitForTcStatementBlock=true; - } - if(waitForTcStatementBlock&&(node instanceof StatementBlock)) { - tcStatementBlock=((StatementBlock)node); - waitForTcStatementBlock=false; - } - - if(waitForTC&&(node instanceof Definition_Statement)){ - waitForTcDefStatement=true; - } - if(waitForTcDefStatement&&(node instanceof Def_Var)) { - testCaseVars.add(((Def_Var)node).getIdentifier().toString()); - } - if(waitForTcDefStatement&&(node instanceof Reference)) { - testCaseVarTypes.add(((Reference)node).getId().toString()); - waitForTcDefStatement=false; - } - - if(waitForTC&&(node instanceof Assignment_Statement)){ - waitForTcAssignmentValues=true; - } - - if(waitForTcAssignmentValues&&(node instanceof Reference)) { - testCaseAssignValues.add(((Reference)node).getId().toString()); - waitForTcAssignmentValues=false; - } - - if(waitForTC&&(node instanceof ComponentCreateExpression)){ - waitForTcCreateValues=true; - tcCreateCounter++; - } - - if(waitForTcCreateValues&&(node instanceof Reference)) { - testCaseCreateRefValues.add(((Reference)node).getId().toString()); - testCaseCreateCounter.add(String.valueOf(tcCreateCounter)); - - } - if(waitForTcCreateValues&&(node instanceof Charstring_Value)) { - testCaseCreateCharValues.add(((Charstring_Value)node).getValue()); - testCaseCreateCounter.add(String.valueOf(tcCreateCounter)); - } - - if(waitForTC&&(node instanceof Connect_Statement)){ - waitForTcConnectValues=true; - tcConnectCounter++; - - } - - if(waitForTcConnectValues&&(node instanceof Identifier)){ - testCaseConnectValues.add(((Identifier)node).toString()); - testCaseConnectCounter.add(String.valueOf(tcConnectCounter)); - } - - if(waitForTC&&(node instanceof Unknown_Start_Statement)){ - waitForTcStartValues=true; - tcStartCounter++; - - } - - if(waitForTcStartValues&&(node instanceof Identifier)){ - testCaseStartValues.add(((Identifier)node).toString()); - testCaseStartCounter.add(String.valueOf(tcStartCounter)); - } - - return V_CONTINUE; } -//TODO - public int leave(IVisitableNode node) { - - /* - * For every type the compFieldTypes and compFieldNames list must be - * emptied of evaluated - */ - - if (node instanceof Def_Type) { - - Def_Type typeNode = (Def_Type) node; - - CompilationTimeStamp compilationCounter = CompilationTimeStamp - .getNewCompilationCounter(); - - currentFileName = typeNode.getIdentifier().toString(); - - if (typeNode.getType(compilationCounter).getTypetype().toString() - .equals("TYPE_TTCN3_SEQUENCE")) {// record - - Def_Type_Record recordNode = Def_Type_Record - .getInstance(typeNode); - - // add component fields - for (int i = 0; i < compFieldTypes.size(); i++) { - - recordNode.addCompFields(compFieldTypes.get(i), - compFieldNames.get(i)); - - } - String[] typeArray = (String[]) compFieldTypes - .toArray(new String[compFieldTypes.size()]); - String[] nameArray = (String[]) compFieldNames - .toArray(new String[compFieldNames.size()]); - - nodeNameChildrenTypesHashMap.put(parentName, typeArray); - nodeNameChildrenNamesHashMap.put(parentName, nameArray); - - compFieldTypes.clear(); - compFieldNames.clear(); - - visualizeNodeToJava(recordNode.getJavaSource()); - - } else if (typeNode.getType(compilationCounter).getTypetype() - .toString().equals("TYPE_TTCN3_SET")) {// set - - Def_Type_Set setdNode = Def_Type_Set.getInstance(typeNode); - - // add component fields - for (int i = 0; i < compFieldTypes.size(); i++) { - - setdNode.addCompFields(compFieldTypes.get(i), - compFieldNames.get(i)); - - } - - String[] typeArray = (String[]) compFieldTypes - .toArray(new String[compFieldTypes.size()]); - String[] nameArray = (String[]) compFieldNames - .toArray(new String[compFieldNames.size()]); - - nodeNameChildrenTypesHashMap.put(parentName, typeArray); - nodeNameChildrenNamesHashMap.put(parentName, nameArray); - - compFieldTypes.clear(); - compFieldNames.clear(); - - visualizeNodeToJava(setdNode.getJavaSource()); - - } else if (typeNode.getType(compilationCounter).getTypetype() - .toString().equals("TYPE_TTCN3_CHOICE")) {// union - - Def_Type_Union uniondNode = Def_Type_Union - .getInstance(typeNode); - - // add component fields - for (int i = 0; i < compFieldTypes.size(); i++) { - uniondNode.addCompFields(compFieldTypes.get(i), - compFieldNames.get(i)); - - } - - String[] typeArray = (String[]) compFieldTypes - .toArray(new String[compFieldTypes.size()]); - String[] nameArray = (String[]) compFieldNames - .toArray(new String[compFieldNames.size()]); - - nodeNameChildrenTypesHashMap.put(parentName, typeArray); - nodeNameChildrenNamesHashMap.put(parentName, nameArray); - - compFieldTypes.clear(); - compFieldNames.clear(); - - visualizeNodeToJava(uniondNode.getJavaSource()); - - } else if (typeNode.getType(compilationCounter) instanceof Integer_Type) { - - Def_Type_Integer integerNode = Def_Type_Integer - .getInstance(typeNode); - integerNode.addMinMaxFields(minValue, maxValue); - minValue = 0; - maxValue = 0; - - visualizeNodeToJava(integerNode.getJavaSource()); - - } else if (typeNode.getType(compilationCounter) instanceof CharString_Type) { - - Def_Type_Charstring charstringNode = Def_Type_Charstring - .getInstance(typeNode); - charstringNode.addCharStringValue(charstringValue); - charstringValue = null; - - visualizeNodeToJava(charstringNode.getJavaSource()); - - } else if (typeNode.getType(compilationCounter) instanceof TTCN3_Enumerated_Type) { - - Def_Type_Enum enumTypeNode = Def_Type_Enum - .getInstance(typeNode); - for (int i = 0; i < enumItems.size(); i++) { - enumTypeNode.addEnumItem(enumItems.get(i)); - } - enumItems.clear(); - - visualizeNodeToJava(enumTypeNode.getJavaSource()); - - } else if (typeNode.getType(compilationCounter).getTypetype() - .toString().equals("TYPE_SET_OF")) { - - Def_Type_Set_Of setOfNode = Def_Type_Set_Of - .getInstance(typeNode); - - setOfNode.addField(setOfReferenceName); - setOfReferenceName = null; - visualizeNodeToJava(setOfNode.getJavaSource()); - - } else if (typeNode.getType(compilationCounter).getTypetype() - .toString().equals("TYPE_PORT")) { - - Def_Type_Port portNode = Def_Type_Port.getInstance(typeNode); - - for (int i = 0; i < inMessageName.size(); i++) { - portNode.addInMessage(inMessageName.get(i)); - } - for (int i = 0; i < outMessageName.size(); i++) { - portNode.addOutMessage(outMessageName.get(i)); - } - for (int i = 0; i < inOutMessageName.size(); i++) { - portNode.addInOutMessage(inOutMessageName.get(i)); - } - portNode.setPortTypeAReferencedType(isPortTypeAReferencedType); - - waitingForPortAttriburtes = false; - isPortTypeAReferencedType = false; - inMessageName.clear(); - outMessageName.clear(); - inOutMessageName.clear(); - visualizeNodeToJava(portNode.getJavaSource()); - - } else if (typeNode.getType(compilationCounter).getTypetype() - .toString().equals("TYPE_COMPONENT")) { - - Def_Type_Component compNode = Def_Type_Component - .getInstance(typeNode); - // add component fields - for (int i = 0; i < compPortTypes.size(); i++) { - - compNode.addCompFields(compPortTypes.get(i), - compPortNames.get(i)); - - } - - compPortTypes.clear(); - compPortNames.clear(); - waitForCompReference = false; - visualizeNodeToJava(compNode.getJavaSource()); - - } - parentName = null; - } - if (node instanceof Def_Const) { - Def_Const_Writer constNode = Def_Const_Writer - .getInstance(((Def_Const) node)); - - constNode.setConstNodeType(constNodeType); - - for (int i = 0; i < constValues.size(); i++) { - constNode.addConstValues(constValues.get(i)); - } - - for (int i = 0; i < constSetOfAmount.size(); i++) { - constNode.setConstSetOfAmount(constSetOfAmount.get(i)); - } - - constValues.clear(); - waitForConstValues = false; - constSetOfCounter = -3; - constSetOfAmount.clear(); - - deleteLastBracket(currentFileName); - visualizeNodeToJava(constNode.getJavaSource() + "\r\n}"); - constOmitHashes.clear(); - - } - - if (waitForTemplateValues - && (node instanceof Undefined_LowerIdentifier_Value)) { - blockIdListing = false; - } - - if (waitForTemplateValues && (node instanceof Charstring_Value)) { - blockIdListing = false; - } - - if (waitForTemplateValues && (node instanceof Omit_Value)) { - blockIdListing = false; + public void visitModuleParNodes(IVisitableNode node) { + if (waitForModuleParValues && (node instanceof Integer_Type)) { + moduleParNodeType = "INTEGER"; } - if (waitForTemplateValues && (node instanceof Any_Value_Template)) { - blockIdListing = false; + if (waitForModuleParValues && (node instanceof Integer_Value)) { + moduleParValues.add(((Integer_Value) node).toString()); } + } - if (waitForTemplateValues && (node instanceof AnyOrOmit_Template)) { - blockIdListing = false; - } + public int leave(IVisitableNode node) { - if (waitForTemplateValues && (node instanceof Reference)) { - blockIdListing = false; - } + myDefTypeVisitHandler.leave(node); + myDefConstVisitHandler.leave(node); + myDefTemplateVisitHandler.leave(node); - if(node instanceof Send_Statement){ - waitForSendStatement=false; + if (node instanceof UnaryMinusExpression) { + myASTVisitor.isNextIntegerNegative = false; } - - if(node instanceof Receive_Port_Statement){ - waitForRecieveStatement=false; - } - - if(node instanceof Unknown_Start_Statement){ - waitForUnknownStartStatement=false; - } - if(node instanceof Receive_Port_Statement){ - waitForAddExpression=false; - } - - if(waitForTC&&(node instanceof Connect_Statement)){ - waitForTcConnectValues=false; - - - } - if(waitForTC&&(node instanceof Unknown_Start_Statement)){ - waitForTcStartValues=false; - - - } - if(waitForTC&&(node instanceof ComponentCreateExpression)){ - //switch first two values - testCaseCreateValues.add(testCaseCreateCharValues.get(0)); - testCaseCreateValues.add(testCaseCreateRefValues.get(0)); - - for(int i=1;i