00001 package edu.ksu.cis.bandera.bui.session;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 import java.io.*;
00036 import edu.ksu.cis.bandera.bui.session.datastructure.*;
00037 import edu.ksu.cis.bandera.bui.session.analysis.*;
00038 import edu.ksu.cis.bandera.bui.session.lexer.*;
00039 import edu.ksu.cis.bandera.bui.session.node.*;
00040 import edu.ksu.cis.bandera.bui.session.parser.*;
00041 import edu.ksu.cis.bandera.jjjc.util.*;
00042 import java.util.*;
00043 import edu.ksu.cis.bandera.bui.BUI;
00044 import edu.ksu.cis.bandera.bui.JPFOption;
00045 public class SessionsSaverLoader extends DepthFirstAdapter {
00046 private static Sessions sessions;
00047 private Session session;
00048 private StringBuffer buffer;
00049
00050
00051
00052
00053 public void caseASession(ASession node) {
00054 session = new Session(node.getId().toString().trim());
00055 Object temp[] = node.getResource().toArray();
00056 for (int i = 0; i < temp.length; i++) {
00057 ((PResource) temp[i]).apply(this);
00058 }
00059 sessions.putSession(session);
00060 }
00061
00062
00063
00064
00065 public void caseAStringResource(AStringResource node) {
00066 String key = node.getId().toString().trim();
00067 buffer = new StringBuffer();
00068 node.getStrings().apply(this);
00069
00070 if ("source".equals(key)) {
00071 session.setFilename(buffer.toString());
00072 } else if ("classpath".equals(key)) {
00073 session.setClasspath(buffer.toString().replace('+', File.pathSeparatorChar));
00074 } else if ("included".equals(key)) {
00075 StringTokenizer t = new StringTokenizer(buffer.toString(), "+");
00076 String[] included = new String[t.countTokens()];
00077 for (int i = 0; t.hasMoreTokens(); i++) {
00078 included[i] = t.nextToken();
00079 }
00080 session.setIncludedPackagesOrTypes(included);
00081 } else if ("output".equals(key)) {
00082 session.setOutputName(buffer.toString());
00083 } else if ("directory".equals(key)) {
00084 session.setWorkingDirectory(buffer.toString());
00085 } else if ("description".equals(key)) {
00086 session.setDescription(buffer.toString());
00087 } else if ("components".equals(key)) {
00088 for (StringTokenizer tokenizer = new StringTokenizer(buffer.toString(), "+ ");
00089 tokenizer.hasMoreTokens();) {
00090 String s = tokenizer.nextToken().toLowerCase();
00091 if ("slicer".equals(s)) {
00092 session.setDoSlicer(true);
00093 } else if ("slabs".equals(s) || "babs".equals(s)) {
00094 session.setDoSLABS(true);
00095 } else if ("checker".equals(s)) {
00096 session.setDoChecker(true);
00097 }
00098 }
00099 } else if ("specification".equals(key)) {
00100 session.setSpecFilename(buffer.toString());
00101 } else if ("temporal".equals(key)) {
00102 session.setActiveTemporal(buffer.toString());
00103 } else if ("assertion".equals(key)) {
00104 for (StringTokenizer tokenizer = new StringTokenizer(buffer.toString(), "+ ");
00105 tokenizer.hasMoreTokens();) {
00106 session.addActiveAssertion(tokenizer.nextToken());
00107 }
00108 } else if ("abstraction".equals(key)) {
00109 session.setAbsFilename(buffer.toString());
00110 } else if ("birc".equals(key)) {
00111 session.setBIRCOption(buffer.toString());
00112 } else if ("spin".equals(key)) {
00113 session.setSpinOptions(buffer.toString());
00114 session.setUseSPIN(true);
00115 } else if ("jpf".equals(key)) {
00116 session.setJpfOptions(buffer.toString());
00117 session.setUseJPF(true);
00118 } else if ("smv".equals(key)) {
00119 session.setSmvOptions(buffer.toString());
00120 session.setUseSMV(true);
00121 } else if ("dspin".equals(key)) {
00122 session.setDspinOptions(buffer.toString());
00123 session.setUseDSPIN(true);
00124 } else if ("birbounds".equals(key)) {
00125 StringTokenizer tok = new StringTokenizer(buffer.toString(), ",");
00126 int minInt, maxInt, maxArr, maxIns;
00127 try {
00128 minInt = Integer.parseInt(tok.nextToken().trim());
00129 maxInt = Integer.parseInt(tok.nextToken().trim());
00130 if (minInt > maxInt)
00131 {
00132 System.out.println("WARNING: Illegal integer values detected!");
00133 throw new Exception();
00134 }
00135 maxArr = Integer.parseInt(tok.nextToken().trim());
00136 maxIns = Integer.parseInt(tok.nextToken().trim());
00137 } catch (Exception e)
00138 {
00139 System.out.println("WARNING: BIR bounds setting is not acceptable. Revert to default value!");
00140 minInt = edu.ksu.cis.bandera.util.DefaultValues.birMinIntRange;
00141 maxInt = edu.ksu.cis.bandera.util.DefaultValues.birMaxIntRange;
00142 maxArr = edu.ksu.cis.bandera.util.DefaultValues.birMaxArrayLen;
00143 maxIns = edu.ksu.cis.bandera.util.DefaultValues.birMaxInstances;
00144 }
00145 session.setBirMinIntRange(minInt);
00146 session.setBirMaxIntRange(maxInt);
00147 session.setBirMaxArrayLen(maxArr);
00148 session.setBirMaxInstances(maxIns);
00149 } else {
00150 session.putResource(key, buffer.toString());
00151 }
00152 }
00153
00154
00155
00156
00157 public void caseAStringsStrings(AStringsStrings node) {
00158 node.getStrings().apply(this);
00159 buffer.append(Util.decodeString(node.getStringLiteral().toString().trim()));
00160 }
00161
00162
00163
00164
00165 public void caseAStringStrings(AStringStrings node) {
00166 buffer.append(Util.decodeString(node.getStringLiteral().toString().trim()));
00167 }
00168
00169
00170
00171
00172
00173 public static Sessions load(String filename) throws Exception {
00174 sessions = new Sessions();
00175 new Parser(new Lexer(new PushbackReader(new FileReader(filename)))).parse().apply(new SessionsSaverLoader());
00176 sessions.setFilename(filename);
00177 return sessions;
00178 }
00179
00180
00181
00182
00183 public static void save(Sessions sessions) throws Exception {
00184 if (sessions.getActiveSession() != null) sessions.getActiveSession().saveOptions();
00185 PrintWriter pw = new PrintWriter(new FileWriter(sessions.getFilename()), true);
00186 for (Enumeration e = sessions.getSessions().elements(); e.hasMoreElements();) {
00187 Session s = (Session) e.nextElement();
00188 pw.println(s.getStringRepresentation());
00189 }
00190 sessions.setSaved(true);
00191 }
00192 }