Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

SmvVar.java

00001 package edu.ksu.cis.bandera.smv;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Bandera, a Java(TM) analysis and transformation toolkit           *
00005  * Copyright (C) 1998, 1999   James Corbett (corbett@hawaii.edu)     *
00006  * All rights reserved.                                              *
00007  *                                                                   *
00008  * This work was done as a project in the SAnToS Laboratory,         *
00009  * Department of Computing and Information Sciences, Kansas State    *
00010  * University, USA (http://www.cis.ksu.edu/santos).                  *
00011  * It is understood that any modification not identified as such is  *
00012  * not covered by the preceding statement.                           *
00013  *                                                                   *
00014  * This work is free software; you can redistribute it and/or        *
00015  * modify it under the terms of the GNU Library General Public       *
00016  * License as published by the Free Software Foundation; either      *
00017  * version 2 of the License, or (at your option) any later version.  *
00018  *                                                                   *
00019  * This work is distributed in the hope that it will be useful,      *
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00022  * Library General Public License for more details.                  *
00023  *                                                                   *
00024  * You should have received a copy of the GNU Library General Public *
00025  * License along with this toolkit; if not, write to the             *
00026  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00027  * Boston, MA  02111-1307, USA.                                      *
00028  *                                                                   *
00029  * Java is a trademark of Sun Microsystems, Inc.                     *
00030  *                                                                   *
00031  * To submit a bug report, send a comment, or get the latest news on *
00032  * this project and other SAnToS projects, please visit the web-site *
00033  *                http://www.cis.ksu.edu/santos                      *
00034  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00035 import edu.ksu.cis.bandera.bir.StateVar;
00036 
00037 import java.util.*;
00038 
00039 /**
00040  * An SMV variable.
00041  */
00042 
00043 public class SmvVar implements SmvExpr {
00044 
00045     String name;
00046     String type;           // null if this var is an aggregate
00047     StateVar source;
00048     SmvLit initValue;      // Initial value (or null if none)
00049     SmvVar aggregate;      // Aggregate var we're nested in
00050     Vector components;     // Components (if this var is aggregate)
00051     boolean constrained;   // Will a TRANS be generated for this var?
00052     SmvVar deadFlag;       // Variable live only if this var is true
00053     String printForm;      // Special form for variable when printed 
00054 
00055     SmvExpr updateExpr;    // TRANS expression for variable updates
00056     SmvNaryExpr updates;   // Conjunction of conditional updates
00057     SmvNaryExpr negUpdateConds;  // Conjunction of negated conditions
00058 
00059     /**
00060      * Create a temp SmvVar used only to hold a prefix of a name 
00061      * (not declared).
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      * Add conditional update to variable.
00081      * <p>
00082      * The expression "cond -> assign" is added to the conjunction of
00083      * updates, and the negated condition is recorded in negUpdateConds
00084      * (which forms the condition of the "variable unchanged" update).
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      * Build the update expression (TRANS formula) for the variable
00103      * <p>
00104      * This must be called after all conditional updates have been added.
00105      * <p>
00106      * To form the update expression, we use the conjunction of all the
00107      * negated conditions to build one last update, specifying the 
00108      * variable is unchanged if none of the update conditions is true.
00109      * We then add this last update to the update conjunction, which
00110      * becomes the update expression.  Finally, if there is a dead flag,
00111      * then we allow the formula to be true if that variable is false
00112      * OR the update expression is true.
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)   // If no special print form, just use name
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 }

Generated at Thu Feb 7 06:55:19 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001