00001 package edu.ksu.cis.bandera.smv;
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 edu.ksu.cis.bandera.bir.StateVar;
00036
00037 import java.util.*;
00038
00039
00040
00041
00042
00043 public class SmvVar implements SmvExpr {
00044
00045 String name;
00046 String type;
00047 StateVar source;
00048 SmvLit initValue;
00049 SmvVar aggregate;
00050 Vector components;
00051 boolean constrained;
00052 SmvVar deadFlag;
00053 String printForm;
00054
00055 SmvExpr updateExpr;
00056 SmvNaryExpr updates;
00057 SmvNaryExpr negUpdateConds;
00058
00059
00060
00061
00062
00063 public SmvVar(String name) {
00064 this.name = name;
00065 }
00066 public SmvVar(String name, String type, StateVar source, SmvLit initVal,
00067 boolean constrained, SmvVar deadFlag) {
00068 this.name = name;
00069 this.type = type;
00070 this.source = source;
00071 this.initValue = initVal;
00072 this.constrained = constrained;
00073 this.deadFlag = deadFlag;
00074 this.components = new Vector();
00075 updates = new SmvNaryExpr("&",new SmvLit("1"),true);
00076 negUpdateConds = new SmvNaryExpr("&",new SmvLit("1"),true);
00077 }
00078 public void addComponent(SmvVar var) { components.addElement(var); }
00079
00080
00081
00082
00083
00084
00085
00086
00087 public void addUpdate(SmvExpr cond, SmvExpr assign) {
00088 SmvBinaryExpr update = new SmvBinaryExpr("->",cond,assign);
00089 updates.add(update);
00090 negUpdateConds.add(new SmvUnaryExpr("!",cond));
00091 }
00092 public SmvVar getComponent(int i) {
00093 return (SmvVar) components.elementAt(i);
00094 }
00095 public Vector getComponents() { return components; }
00096 public SmvVar getDeadFlag() { return deadFlag; }
00097 public SmvLit getInitValue() { return initValue; }
00098 public String getName() { return name; }
00099 public StateVar getSource() { return source; }
00100 public String getType() { return type; }
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 public SmvExpr getUpdateExpr() {
00116 if (updateExpr == null) {
00117 updates.add(new SmvBinaryExpr("->",negUpdateConds,
00118 SmvTrans.becomes(this,this)));
00119 if (deadFlag != null) {
00120 updateExpr = new SmvUnaryExpr("!",new SmvNextExpr(deadFlag));
00121 updateExpr = new SmvBinaryExpr("|",updateExpr,updates);
00122 } else
00123 updateExpr = updates;
00124 }
00125 return updateExpr;
00126 }
00127 public boolean isBig() { return false; }
00128 public boolean isConstrained() { return constrained; }
00129 public void print(SmvTrans out) {
00130 if (printForm != null)
00131 out.print(printForm);
00132 else
00133 out.print(name);
00134 }
00135 public void setAggregate(SmvVar var) { this.aggregate = var; }
00136 public void setPrintForm(String printForm) { this.printForm = printForm; }
00137 public String toString() { return name; }
00138 }