00001 package edu.ksu.cis.bandera.bir; 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 ca.mcgill.sable.util.*; 00036 00037 import java.io.*; 00038 import java.util.*; 00039 00040 /** 00041 * A Location represents a control point in a thread from which 00042 * guarded transformations may be taken. 00043 * <p> 00044 * Each location has: 00045 * <ul> 00046 * <li> An integer id (this is negative before the locations are numbered, 00047 * positive afterwards). 00048 * <li> An optional label for printing (constructed from the id if absent). 00049 * <li> The thread to which it belongs. 00050 * <li> An integer mark for use in searches. 00051 * <li> Vectors of transformations into and out of the location. 00052 * <li> A vector of local state variables that are live at the location. 00053 * </ul> 00054 */ 00055 00056 public class Location { 00057 00058 int id; // location id 00059 BirThread thread; // thread we're contained in 00060 TransVector inTrans; // incoming Transformations 00061 TransVector outTrans; // outgoing Transformations 00062 StateVarVector liveVars; 00063 int mark; // Location mark (for DFS) 00064 String label; 00065 00066 static int markCount = 0; // mark generator 00067 static int locCount = 0; 00068 00069 public Location(BirThread thread) { 00070 this.thread = thread; 00071 this.inTrans = new TransVector(); 00072 this.outTrans = new TransVector(); 00073 this.mark = 0; 00074 this.id = - (++locCount); 00075 } 00076 /** 00077 * Add a transformation out of the location. 00078 * @param toLoc target of transformation 00079 * @param guard guard expression 00080 * @param actions vector of actions 00081 * @return the new transformation 00082 */ 00083 public Transformation addTrans(Location toLoc, Expr guard, 00084 ActionVector actions) { 00085 Transformation trans = 00086 new Transformation(this, toLoc, guard, actions); 00087 outTrans.addElement(trans); 00088 toLoc.inTrans.addElement(trans); 00089 thread.getSystem().addTrans(trans); 00090 return trans; 00091 } 00092 // Accessors 00093 public int getId() { return id; } 00094 public TransVector getInTrans() { return inTrans; } 00095 public String getLabel() { return (label != null) ? label : "s" + id; } 00096 public StateVarVector getLiveVars() { return liveVars; } 00097 public int getMark() { return mark; } 00098 public static int getNewMark() { return ++markCount; } 00099 public TransVector getOutTrans() { return outTrans; } 00100 public BirThread getThread() { return thread; } 00101 /** 00102 * A location is visible if: 00103 * <ul> 00104 * <li> it has no incoming transformations, or 00105 * <li> it has no outgoing transformations, or 00106 * <li> some incoming transformation is visible. 00107 * </ul> 00108 */ 00109 public boolean isVisible() { 00110 if (inTrans.size() == 0) 00111 return true; 00112 if (outTrans.size() == 0) 00113 return true; 00114 for (int i = 0; i < inTrans.size(); i++) 00115 if (inTrans.elementAt(i).isVisible()) 00116 return true; 00117 return false; 00118 } 00119 public void setId(int id) { this.id = id; } 00120 public void setLabel(String label) { this.label = label; } 00121 public void setLiveVars(StateVarVector liveVars) { 00122 this.liveVars = liveVars; 00123 } 00124 public void setMark(int mark) { this.mark = mark; } 00125 // Printing 00126 public String toString() { 00127 return "<Loc " + id + ">"; 00128 } 00129 }