Browse Source

Beginnings of tidy up of Preprocessor (incl. const -> param change).

git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@792 bbc10eb1-c90d-0410-af57-cb519fbb1720
master
Dave Parker 18 years ago
parent
commit
90ef7cf949
  1. 39
      prism/src/prism/Preprocessor.java

39
prism/src/prism/Preprocessor.java

@ -38,10 +38,6 @@ public class Preprocessor
private final static char DELIMITER = '#'; private final static char DELIMITER = '#';
private final static boolean IGNORE_COMMENTS = true; private final static boolean IGNORE_COMMENTS = true;
// logs
private PrismLog mainLog; // main log
private PrismLog techLog; // tech log
// prism // prism
private Prism prism; private Prism prism;
@ -53,7 +49,6 @@ public class Preprocessor
private String ppExprStrings[]; private String ppExprStrings[];
private String ppExprs[]; private String ppExprs[];
private int ppExprLines[]; private int ppExprLines[];
private int ppExprCols[];
private String lastString; private String lastString;
// interpreter stuff // interpreter stuff
@ -63,23 +58,21 @@ public class Preprocessor
private boolean outputEnabled; // output enabling flag private boolean outputEnabled; // output enabling flag
private Vector varNames, varTypes, varScopes; // variable info private Vector varNames, varTypes, varScopes; // variable info
private Values values; // variable values private Values values; // variable values
private int constCounter; // how many undefined constants found so far
private int paramCounter; // how many paramaters found so far
private String consts[];
private String params[];
// constructor // constructor
public Preprocessor(PrismLog log1, PrismLog log2, Prism p, File mf)
public Preprocessor(Prism p, File mf)
{ {
mainLog = log1;
techLog = log2;
prism = p; prism = p;
modelFile = mf; modelFile = mf;
} }
public void setConstants(String args[])
public void setParameters(String args[])
{ {
consts = args;
params = args;
} }
// main method: do preprocessing // main method: do preprocessing
@ -137,13 +130,12 @@ public class Preprocessor
{ {
BufferedReader in; BufferedReader in;
String s, s1, s2, s3, text, ss[]; String s, s1, s2, s3, text, ss[];
int i, j, n, count, lineNum = 0, colNum = 0;
int i, j, n, count, lineNum = 0;
// allocate arrays // allocate arrays
ppExprStrings = new String[numPPExprs]; ppExprStrings = new String[numPPExprs];
ppExprs = new String[numPPExprs]; ppExprs = new String[numPPExprs];
ppExprLines = new int[numPPExprs]; ppExprLines = new int[numPPExprs];
ppExprCols = new int[numPPExprs];
try { try {
count = 0; count = 0;
@ -217,7 +209,7 @@ public class Preprocessor
varTypes = new Vector(); varTypes = new Vector();
varScopes = new Vector(); varScopes = new Vector();
values = new Values(); values = new Values();
constCounter = 0;
paramCounter = 0;
// main control flow loop // main control flow loop
try{ try{
@ -229,8 +221,12 @@ public class Preprocessor
// process current preprocessing expression // process current preprocessing expression
s = ppExprs[pc].trim(); s = ppExprs[pc].trim();
// constant
if (s.indexOf("const ") == 0) {
// parameter
if (s.indexOf("param int ") == 0) {
s = s.substring(10).trim(); interpretConstant(s);
}
else if (s.indexOf("const ") == 0) {
// old notation - backwards compatability
s = s.substring(6).trim(); interpretConstant(s); s = s.substring(6).trim(); interpretConstant(s);
} }
// for loops // for loops
@ -320,9 +316,9 @@ public class Preprocessor
if (expr != null) { if (expr != null) {
values.addValue(name, new Integer(expr.evaluateInt(null, values))); values.addValue(name, new Integer(expr.evaluateInt(null, values)));
} else { } else {
if (consts.length <= constCounter+1)
if (params.length <= paramCounter+1)
throw new PrismException("No value provided for undefined preprocessor constant \"" + name + "\""); throw new PrismException("No value provided for undefined preprocessor constant \"" + name + "\"");
values.addValue(name, new Integer(Integer.parseInt(consts[++constCounter])));
values.addValue(name, new Integer(Integer.parseInt(params[++paramCounter])));
} }
// move to next statement // move to next statement
pc++; pc++;
@ -340,6 +336,7 @@ public class Preprocessor
if (varNames.contains(fl.getLHS())) if (varNames.contains(fl.getLHS()))
throw new PrismException("Duplicated variable/constant \"" + fl.getLHS() + "\""); throw new PrismException("Duplicated variable/constant \"" + fl.getLHS() + "\"");
fl = (ForLoop)fl.findAllVars(varNames, varTypes); fl = (ForLoop)fl.findAllVars(varNames, varTypes);
fl.typeCheck();
fl.semanticCheck(); fl.semanticCheck();
// set up more info and then put on stack // set up more info and then put on stack
fl.setPC(pc + 1); fl.setPC(pc + 1);
@ -465,8 +462,8 @@ public class Preprocessor
PrismLog pl2 = new PrismFileLog("stdout"); PrismLog pl2 = new PrismFileLog("stdout");
Prism p = new Prism(pl1, pl2); Prism p = new Prism(pl1, pl2);
try { try {
Preprocessor pp = new Preprocessor(pl1, pl2, p, new File(args[0]));
pp.setConstants(args);
Preprocessor pp = new Preprocessor(p, new File(args[0]));
pp.setParameters(args);
String s = pp.preprocess(); String s = pp.preprocess();
if (s == null) { if (s == null) {
System.out.println("Error: No preprocessing information."); System.out.println("Error: No preprocessing information.");

Loading…
Cancel
Save