void addtrans(Graph *col, char *from, Node *op, char *to) { State *b; Transition *t; t = (Transition *) tl_emalloc(sizeof(Transition)); t->name = tl_lookup(to); t->cond = Prune(dupnode(op)); if (tl_verbose) { printf("\n%s <<\t", from); dump(op); printf("\n\t"); dump(t->cond); printf(">> %s\n", t->name->name); } if (t->cond) t->cond = rewrite(t->cond); for (b = never; b; b = b->nxt) if (!strcmp(b->name->name, from)) { t->nxt = b->trans; b->trans = t; return; } b = (State *) tl_emalloc(sizeof(State)); b->name = tl_lookup(from); b->colors = col; b->trans = t; if (!strncmp(from, "accept", 6)) b->accepting = 1; b->nxt = never; never = b; }
Symbol * getsym(Symbol *s) { Symbol *n = (Symbol *) tl_emalloc(sizeof(Symbol)); n->name = s->name; return n; }
void mk_alternating(tl_Node *p) /* generates an alternating automaton for p */ { if (tl_stats) { getrusage(RUSAGE_SELF, &tr_debut); } node_size = calculate_node_size(p) + 1; /* number of states in the automaton */ label = (tl_Node **) tl_emalloc(node_size * sizeof(tl_Node *)); transition = (ATrans **) tl_emalloc(node_size * sizeof(ATrans *)); node_size = node_size / (8 * sizeof(int)) + 1; sym_size = calculate_sym_size(p); /* number of predicates */ if (sym_size) { sym_table = (char **) tl_emalloc(sym_size * sizeof(char *)); } sym_size = sym_size / (8 * sizeof(int)) + 1; final_set = make_set(-1, 0); transition[0] = boolean(p); /* generates the alternating automaton */ if (tl_verbose) { fprintf(tl_out, "\nAlternating automaton before simplification\n"); print_alternating(); } if (tl_simp_diff) { simplify_astates(); /* keeps only accessible states */ if (tl_verbose) { fprintf(tl_out, "\nAlternating automaton after simplification\n"); print_alternating(); } } if (tl_stats) { getrusage(RUSAGE_SELF, &tr_fin); fprintf(tl_out, "\n%i states, %i transitions\n", astate_count, atrans_count); } releasenode(1, p); tfree(label); }
Symbol * tl_lookup(char *s) { Symbol *sp; int h = hash(s); for (sp = symtab[h]; sp; sp = sp->next) if (strcmp(sp->name, s) == 0) return sp; sp = (Symbol *) tl_emalloc(sizeof(Symbol)); sp->name = (char *) tl_emalloc(strlen(s) + 1); strcpy(sp->name, s); sp->next = symtab[h]; symtab[h] = sp; return sp; }
Node * tl_nn(int t, Node *ll, Node *rl) { Node *n = (Node *) tl_emalloc(sizeof(Node)); n->ntyp = (short) t; n->lft = ll; n->rgt = rl; return n; }
void mk_alternating(Node *p) /* generates an alternating automaton for p */ { if(tl_stats) getrusage(RUSAGE_SELF, &tr_debut); node_size = calculate_node_size(p) + 1; /* number of states in the automaton */ label = (Node **) tl_emalloc(node_size * sizeof(Node *)); transition = (ATrans **) tl_emalloc(node_size * sizeof(ATrans *)); node_size = node_size / (8 * sizeof(int)) + 1; sym_size = calculate_sym_size(p); /* number of predicates */ if(sym_size) sym_table = (char **) tl_emalloc(sym_size * sizeof(char *)); sym_size = sym_size / (8 * sizeof(int)) + 1; final_set = make_set(-1, 0); transition[0] = boolean(p); /* generates the alternating automaton */ if(tl_verbose) { fprintf(tl_out, "\nAlternating automaton before simplification\n"); print_alternating(); } if(tl_simp_diff) { simplify_astates(); /* keeps only accessible states */ if(tl_verbose) { fprintf(tl_out, "\nAlternating automaton after simplification\n"); print_alternating(); } } #ifndef __MINGW__ if(tl_stats) { getrusage(RUSAGE_SELF, &tr_fin); timeval_subtract (&t_diff, &tr_fin.ru_utime, &tr_debut.ru_utime); fprintf(tl_out, "\nBuilding and simplification of the alternating automaton: %i.%06is", t_diff.tv_sec, t_diff.tv_usec); fprintf(tl_out, "\n%i states, %i transitions\n", astate_count, atrans_count); } #endif releasenode(1, p); tfree(label); }
Node * getnode(Node *p) { Node *n; if (!p) return p; n = (Node *) tl_emalloc(sizeof(Node)); n->ntyp = p->ntyp; n->sym = p->sym; /* same name */ n->lft = p->lft; n->rgt = p->rgt; return n; }
static void ng(Symbol *s, Symbol *in, Node *isnew, Node *isold, Node *next) { Graph *g = (Graph *) tl_emalloc(sizeof(Graph)); if (s) g->name = s; else g->name = tl_lookup(newname()); if (in) g->incoming = dupSlist(in); if (isnew) g->New = flatten(isnew); if (isold) g->Old = Duplicate(isold); if (next) g->Next = flatten(next); push_stack(g); }
int *list_set(int *l, int type) /* transforms a set into a list */ { int i, j, size = 1, *list; for(i = 0; i < set_size(type); i++) for(j = 0; j < mod; j++) if(l[i] & (1 << j)) size++; list = (int *)tl_emalloc(size * sizeof(int)); list[0] = size; size = 1; for(i = 0; i < set_size(type); i++) for(j = 0; j < mod; j++) if(l[i] & (1 << j)) list[size++] = mod * i + j; return list; }
Node * cached(Node *n) { Cache *d; Node *m; if (!n) return n; if ((m = in_cache(n)) != ZN) return m; Caches++; d = (Cache *) tl_emalloc(sizeof(Cache)); d->before = dupnode(n); d->after = Canonical(n); /* n is released */ if (ismatch(d->before, d->after)) { d->same = 1; releasenode(1, d->after); d->after = d->before; } d->nxt = stored; stored = d; return dupnode(d->after); }
static int not_new(Graph *g) { Graph *q1; Node *tmp, *n1, *n2; Mapping *map; tmp = flatten(g->Old); /* duplicate, collapse, normalize */ g->Other = g->Old; /* non normalized full version */ g->Old = tmp; g->oldstring = DoDump(g->Old); tmp = flatten(g->Next); g->nxtstring = DoDump(tmp); if (tl_verbose) dump_graph(g); Debug2("\tformula-old: [%s]\n", g->oldstring?g->oldstring->name:"true"); Debug2("\tformula-nxt: [%s]\n", g->nxtstring?g->nxtstring->name:"true"); for (q1 = Nodes_Set; q1; q1 = q1->nxt) { Debug2(" compare old to: %s", q1->name->name); Debug2(" [%s]", q1->oldstring?q1->oldstring->name:"true"); Debug2(" compare nxt to: %s", q1->name->name); Debug2(" [%s]", q1->nxtstring?q1->nxtstring->name:"true"); if (q1->oldstring != g->oldstring || q1->nxtstring != g->nxtstring) { Debug(" => different\n"); continue; } Debug(" => match\n"); if (g->incoming) q1->incoming = catSlist(g->incoming, q1->incoming); /* check if there's anything in g->Other that needs adding to q1->Other */ for (n2 = g->Other; n2; n2 = n2->nxt) { for (n1 = q1->Other; n1; n1 = n1->nxt) if (isequal(n1, n2)) break; if (!n1) { Node *n3 = dupnode(n2); /* don't mess up n2->nxt */ n3->nxt = q1->Other; q1->Other = n3; } } map = (Mapping *) tl_emalloc(sizeof(Mapping)); map->from = g->name->name; map->to = q1; map->nxt = Mapped; Mapped = map; for (n1 = g->Other; n1; n1 = n2) { n2 = n1->nxt; releasenode(1, n1); } for (n1 = g->Old; n1; n1 = n2) { n2 = n1->nxt; releasenode(1, n1); } for (n1 = g->Next; n1; n1 = n2) { n2 = n1->nxt; releasenode(1, n1); } return 1; } if (newstates) tl_verbose=1; Debug2(" New Node %s [", g->name->name); for (n1 = g->Old; n1; n1 = n1->nxt) { Dump(n1); Debug(", "); } Debug2("] nr %d\n", Base); if (newstates) tl_verbose=0; Base++; g->nxt = Nodes_Set; Nodes_Set = g; return 0; }
int *new_set(int type) /* creates a new set */ { return (int *)tl_emalloc(set_size(type) * sizeof(int)); }