internal static ATrans merge_trans(ATrans trans1, ATrans trans2) /* merges two transitions */ { ATrans result = mem.emalloc_atrans(); do_merge_trans(ref result, trans1, trans2); return(result); }
//public static ulong All_mem; //static ATrans atrans_list = null; //static GTrans gtrans_list = null; //static BTrans btrans_list = null; //static int aallocs = 0, afrees = 0, apool = 0; //static int gallocs = 0, gfrees = 0, gpool = 0; //static int ballocs = 0, bfrees = 0, bpool = 0; //static M[] freelist = new M[util.A_LARGE]; //static long[] req = new long[util.A_LARGE]; //static long[,] event1 = new long[util.NREVENT, util.A_LARGE]; internal static ATrans emalloc_atrans() { ATrans result = new ATrans(); result.pos = set.new_set(1); result.neg = set.new_set(1); result.to = set.new_set(0); return result; }
//public static ulong All_mem; //static ATrans atrans_list = null; //static GTrans gtrans_list = null; //static BTrans btrans_list = null; //static int aallocs = 0, afrees = 0, apool = 0; //static int gallocs = 0, gfrees = 0, gpool = 0; //static int ballocs = 0, bfrees = 0, bpool = 0; //static M[] freelist = new M[util.A_LARGE]; //static long[] req = new long[util.A_LARGE]; //static long[,] event1 = new long[util.NREVENT, util.A_LARGE]; internal static ATrans emalloc_atrans() { ATrans result = new ATrans(); result.pos = set.new_set(1); result.neg = set.new_set(1); result.to = set.new_set(0); return(result); }
internal static ATrans dup_trans(ATrans trans) /* returns the copy of a transition */ { ATrans result; if (trans == null) { return(trans); } result = mem.emalloc_atrans(); set.copy_set(trans.to, result.to, 0); set.copy_set(trans.pos, result.pos, 1); set.copy_set(trans.neg, result.neg, 1); return(result); }
internal static void simplify_atrans(ref ATrans trans) /* simplifies the transitions */ { ATrans t, father = null; for (t = trans; t != null;) { ATrans t1; for (t1 = trans; t1 != null; t1 = t1.nxt) { if ((t1 != t) && set.included_set(t1.to, t.to, 0) != 0 && set.included_set(t1.pos, t.pos, 1) != 0 && set.included_set(t1.neg, t.neg, 1) != 0) { break; } } if (t1 != null) { if (father != null) { father.nxt = t.nxt; } else { trans = t.nxt; } mem.free_atrans(t, 0); if (father != null) { t = father.nxt; } else { t = trans; } continue; } atrans_count++; father = t; t = t.nxt; } }
internal static void do_merge_trans(ref ATrans result, ATrans trans1, ATrans trans2) { /* merges two transitions */ if (trans1 == null || trans2 == null) { mem.free_atrans(result, 0); result = null; return; } if (result == null) { result = mem.emalloc_atrans(); } set.do_merge_sets((result).to, trans1.to, trans2.to, 0); set.do_merge_sets((result).pos, trans1.pos, trans2.pos, 1); set.do_merge_sets((result).neg, trans1.neg, trans2.neg, 1); if (set.empty_intersect_sets((result).pos, (result).neg, 1) == 0) { mem.free_atrans(result, 0); result = null; } }
internal static void free_atrans(ATrans t, int rec) { }
/* simplifies the transitions */ internal static void simplify_atrans(ref ATrans trans) { ATrans t, father = null; for(t = trans; t != null;) { ATrans t1; for(t1 = trans; t1 != null; t1 = t1.nxt) { if((t1 != t) && set.included_set(t1.to, t.to, 0) != 0 && set.included_set(t1.pos, t.pos, 1) != 0 && set.included_set(t1.neg, t.neg, 1) != 0) break; } if(t1 != null) { if (father != null) father.nxt = t.nxt; else trans = t.nxt; mem.free_atrans(t, 0); if (father != null) t = father.nxt; else t = trans; continue; } atrans_count++; father = t; t = t.nxt; } }
/* merges two transitions */ internal static ATrans merge_trans(ATrans trans1, ATrans trans2) { ATrans result = mem.emalloc_atrans(); do_merge_trans(ref result, trans1, trans2); return result; }
/* returns the copy of a transition */ internal static ATrans dup_trans(ATrans trans) { ATrans result; if (trans == null) return trans; result = mem.emalloc_atrans(); set.copy_set(trans.to, result.to, 0); set.copy_set(trans.pos, result.pos, 1); set.copy_set(trans.neg, result.neg, 1); return result; }
internal static void do_merge_trans(ref ATrans result, ATrans trans1, ATrans trans2) { /* merges two transitions */ if (trans1 == null || trans2 == null) { mem.free_atrans(result, 0); result = null; return; } if (result == null) result = mem.emalloc_atrans(); set.do_merge_sets((result).to, trans1.to, trans2.to, 0); set.do_merge_sets((result).pos, trans1.pos, trans2.pos, 1); set.do_merge_sets((result).neg, trans1.neg, trans2.neg, 1); if (set.empty_intersect_sets((result).pos, (result).neg, 1) == 0) { mem.free_atrans(result, 0); result = null; } }
/*is the transition final for i ?*/ internal static int is_final(int[] from, ATrans at, int i) { ATrans t; int in_to; if((main.tl_fjtofj != 0 && set.in_set(at.to, i) == 0) || (main.tl_fjtofj == 0 && set.in_set(from, i) == 0)) return 1; in_to = set.in_set(at.to, i); set.rem_set(at.to, i); for(t = alternating.transition[i]; t != null; t = t.nxt) if(set.included_set(t.to, at.to, 0) != 0 && set.included_set(t.pos, at.pos, 1) != 0 && set.included_set(t.neg, at.neg, 1) != 0) { if(in_to != 0) set.add_set(at.to, i); return 1; } if(in_to != 0) set.add_set(at.to, i); return 0; }
internal static ATrans build_alternating(Node p) /* builds an alternating automaton for p */ { ATrans t1, t2, t = null; int node = already_done(p); if (node >= 0) { return(transition[node]); } switch (p.ntyp) { case (short)Operator.TRUE: t = mem.emalloc_atrans(); set.clear_set(t.to, 0); set.clear_set(t.pos, 1); set.clear_set(t.neg, 1); break; case (short)Operator.FALSE: break; case (short)Operator.PREDICATE: t = mem.emalloc_atrans(); set.clear_set(t.to, 0); set.clear_set(t.pos, 1); set.clear_set(t.neg, 1); set.add_set(t.pos, get_sym_id(p.sym.name)); break; case (short)Operator.NOT: t = mem.emalloc_atrans(); set.clear_set(t.to, 0); set.clear_set(t.pos, 1); set.clear_set(t.neg, 1); set.add_set(t.neg, get_sym_id(p.lft.sym.name)); break; case (short)Operator.NEXT: t = boolean(p.lft); break; case (short)Operator.U_OPER: /* p U q <. q || (p && X (p U q)) */ for (t2 = build_alternating(p.rgt); t2 != null; t2 = t2.nxt) { ATrans tmp = dup_trans(t2); /* q */ tmp.nxt = t; t = tmp; } for (t1 = build_alternating(p.lft); t1 != null; t1 = t1.nxt) { ATrans tmp = dup_trans(t1); /* p */ set.add_set(tmp.to, node_id); /* X (p U q) */ tmp.nxt = t; t = tmp; } set.add_set(final_set, node_id); break; case (short)Operator.V_OPER: /* p V q <. (p && q) || (p && X (p V q)) */ for (t1 = build_alternating(p.rgt); t1 != null; t1 = t1.nxt) { ATrans tmp; for (t2 = build_alternating(p.lft); t2 != null; t2 = t2.nxt) { tmp = merge_trans(t1, t2); /* p && q */ if (tmp != null) { tmp.nxt = t; t = tmp; } } tmp = dup_trans(t1); /* p */ set.add_set(tmp.to, node_id); /* X (p V q) */ tmp.nxt = t; t = tmp; } break; case (short)Operator.AND: t = null; for (t1 = build_alternating(p.lft); t1 != null; t1 = t1.nxt) { for (t2 = build_alternating(p.rgt); t2 != null; t2 = t2.nxt) { ATrans tmp = merge_trans(t1, t2); if (tmp != null) { tmp.nxt = t; t = tmp; } } } break; case (short)Operator.OR: t = null; for (t1 = build_alternating(p.lft); t1 != null; t1 = t1.nxt) { ATrans tmp = dup_trans(t1); tmp.nxt = t; t = tmp; } for (t1 = build_alternating(p.rgt); t1 != null; t1 = t1.nxt) { ATrans tmp = dup_trans(t1); tmp.nxt = t; t = tmp; } break; default: break; } transition[node_id] = t; label[node_id++] = p; return(t); }
internal static ATrans boolean(Node p) /* computes the transitions to boolean nodes . next & init */ { ATrans t1, t2, lft, rgt, result = null; int id; switch (p.ntyp) { case (short)Operator.TRUE: result = mem.emalloc_atrans(); set.clear_set(result.to, 0); set.clear_set(result.pos, 1); set.clear_set(result.neg, 1); break; case (short)Operator.FALSE: break; case (short)Operator.AND: lft = boolean(p.lft); rgt = boolean(p.rgt); for (t1 = lft; t1 != null; t1 = t1.nxt) { for (t2 = rgt; t2 != null; t2 = t2.nxt) { ATrans tmp = merge_trans(t1, t2); if (tmp != null) { tmp.nxt = result; result = tmp; } } } mem.free_atrans(lft, 1); mem.free_atrans(rgt, 1); break; case (short)Operator.OR: lft = boolean(p.lft); for (t1 = lft; t1 != null; t1 = t1.nxt) { ATrans tmp = dup_trans(t1); tmp.nxt = result; result = tmp; } mem.free_atrans(lft, 1); rgt = boolean(p.rgt); for (t1 = rgt; t1 != null; t1 = t1.nxt) { ATrans tmp = dup_trans(t1); tmp.nxt = result; result = tmp; } mem.free_atrans(rgt, 1); break; default: build_alternating(p); result = mem.emalloc_atrans(); set.clear_set(result.to, 0); set.clear_set(result.pos, 1); set.clear_set(result.neg, 1); set.add_set(result.to, already_done(p)); break; } return(result); }