00001 package edu.ksu.cis.bandera.birc;
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.*;
00036
00037 import java.util.*;
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 public class TransSequence {
00064
00065 Transformation trans;
00066 TransSequence next;
00067
00068 static Hashtable variableBindings = new Hashtable();
00069 static BindingSubstituter substituter =
00070 new BindingSubstituter(variableBindings);
00071
00072
00073
00074
00075
00076 public ActionVector actions() {
00077 ActionVector actions = new ActionVector();
00078 TransSequence seq = this;
00079 while (seq.next != null) {
00080 ActionVector transActions = seq.trans.getActions();
00081 for (int i = 0; i < transActions.size(); i++)
00082 actions.insertElementAt(transActions.elementAt(i), i);
00083 seq = seq.next;
00084 }
00085 return actions;
00086 }
00087
00088
00089
00090
00091 public TransSequence add(Transformation newTrans) {
00092 TransSequence seq = new TransSequence();
00093 seq.trans = newTrans;
00094 seq.next = this;
00095 return seq;
00096 }
00097
00098
00099
00100
00101 public boolean containsLoc(Location loc) {
00102 if (next == null)
00103 return false;
00104 if (loc == trans.getFromLoc())
00105 return true;
00106 return next.containsLoc(loc);
00107 }
00108 public boolean empty() { return next == null; }
00109
00110
00111
00112
00113 public Location fromLoc() {
00114 if (next.next == null)
00115 return trans.getFromLoc();
00116 return next.fromLoc();
00117 }
00118
00119
00120
00121
00122 public Expr guard() {
00123 int count = this.size();
00124 Transformation [] trans = new Transformation[count];
00125 for (TransSequence seq = this; seq.next != null; seq = seq.next)
00126 trans[--count] = seq.trans;
00127 variableBindings.clear();
00128 Expr guard = null;
00129 for (int i = 0; i < trans.length; i++) {
00130 if (trans[i].getGuard() != null) {
00131 trans[i].getGuard().apply(substituter);
00132 Expr expr = (Expr) substituter.getResult();
00133 guard = (guard == null) ? expr : new AndExpr(guard,expr);
00134 }
00135 updateBindings(trans[i]);
00136 }
00137 return guard;
00138 }
00139
00140
00141
00142
00143 public int size() {
00144 int result = 0;
00145 for (TransSequence seq = this; seq.next != null; seq = seq.next)
00146 result++;
00147 return result;
00148 }
00149
00150
00151
00152
00153 public Location toLoc() {
00154 return trans.getToLoc();
00155 }
00156 void updateBindings(Transformation trans) {
00157 ActionVector actions = trans.getActions();
00158 if (actions != null)
00159 for (int j = 0; j < actions.size(); j++)
00160 if (actions.elementAt(j) instanceof AssignAction) {
00161 AssignAction assign =
00162 (AssignAction) actions.elementAt(j);
00163 assign.getRhs().apply(substituter);
00164 variableBindings.put(assign.getLhs(),
00165 substituter.getResult());
00166 }
00167 }
00168 }