void print_results (void) { state_number i; /* We used to use just .out if SPEC_NAME_PREFIX (-p) was used, but that conflicts with Posix. */ FILE *out = xfopen (spec_verbose_file, "w"); reduce_output (out); grammar_rules_partial_print (out, _("Rules never reduced"), rule_never_reduced_p); conflicts_output (out); print_grammar (out); /* If the whole state item sets, not only the kernels, are wanted, `closure' will be run, which needs memory allocation/deallocation. */ if (report_flag & report_itemsets) new_closure (nritems); /* Storage for print_reductions. */ shift_set = bitset_create (ntokens, BITSET_FIXED); look_ahead_set = bitset_create (ntokens, BITSET_FIXED); for (i = 0; i < nstates; i++) print_state (out, states[i]); bitset_free (shift_set); bitset_free (look_ahead_set); if (report_flag & report_itemsets) free_closure (); xfclose (out); }
void reduce_free (void) { bitset_free (N); bitset_free (V); bitset_free (V1); bitset_free (P); }
void conflicts_free (void) { free (conflicts); bitset_free (shift_set); bitset_free (lookahead_set); obstack_free (&solved_conflicts_obstack, NULL); obstack_free (&solved_conflicts_xml_obstack, NULL); }
void networkReadCallbackPerRead(NetworkAddress networkAddr, ADDRINT start, size_t length, void *v) { int tag; bitset *s = bitset_init(NUMBER_OF_TAINT_MARKS); assert(taintGen); tag = taintGen->nextTaintMark(); //taint entire buffer with 1 mark bitset_set_bit(s, tag); ADDRINT end = start + length; for(ADDRINT addr = start; addr < end; addr++) { memTaintMap[addr] = bitset_copy(s); } bitset_free(s); taintAssignmentLog << tag << " - [" << networkAddr.strAddress << "] -> " << std::hex << start << "-" << std::hex << end - 1<< "\n"; taintAssignmentLog.flush(); #ifdef TRACE if(tracing) { log << "\t" << std::hex << start << "-" << std::hex << end - 1 << " <- read(" << tag << ")\n"; log.flush(); } #endif }
int DbgMasterSignalInfo(int tid, int nargs, char **args) { int res; int len; unsigned char * buf; proxy_msg * msg; bitset * set; DEBUG_PRINTA(DEBUG_LEVEL_MASTER, "DbgMasterSignalInfo", nargs, args); set = bitset_decode((unsigned char *)args[0], NULL); if (set == NULL) { DbgSetError(DBGERR_PROCSET, NULL); return DBGRES_ERR; } msg = new_proxy_msg(DBG_SIGNALINFO_CMD, tid); proxy_msg_add_args(msg, --nargs, &args[1]); proxy_serialize_msg(msg, &buf, &len); res = send_command(bitset_to_idset(set), DBG_EV_WAITALL, buf, len, NULL); bitset_free(set); free_proxy_msg(msg); return res; }
/** * Internal destructor for a conversation struct. * * @param conv is the conversation to delete. */ static void conv_del(struct conv *conv) { if (conv->proc) { closure_unref(conv->proc); } if (conv->keywords) { int i; for (i = 0; i < conv->n_keywords; i++) { if (conv->keywords[i]) { free(conv->keywords[i]); } } free(conv->keywords); } if (conv->marked) { bitset_free(conv->marked); } free(conv); }
int main (int argc, char **argv) { int i,j; for (i=1; i<SBS_NUM_TESTS; i++) { uint32_t nbits = i; bitset_set_max_num_elements(nbits); printf ("\n\ni=%d nb=%d\n", i, nbits); uint32_t num_bs = SBS_NUM_TESTS; BitSet *bs; // = (BitSet *) my_malloc(sizeof(BitSet) * num_bs); bs = bitset_new(); /* for (j=0; j<num_bs; j++) { bs[j] = bitset_new(); } */ for (j=0; j<nbits * SBS_DUNNO ; j++) { printf ("j=%d\n", j); int element = rand() % nbits; printf ("set %d\n", element); bitset_add(bs,element); assert (bitset_member(bs,element)); bitset_spit(bs); printf ("\n"); element = rand() % nbits; printf ("unset %d\n", element); bitset_remove(bs,element); assert (!(bitset_member(bs,element))); bitset_spit(bs); printf ("\n"); } bitset_free(bs); } }
int DbgStartSession(session *s, char *exe, char *path, char *args) { int res; int len; unsigned char * buf; bitset * procs = bitset_new(s->sess_procs); proxy_msg * msg = new_proxy_msg(DBG_STARTSESSION_CMD, 0); proxy_msg_add_int(msg, SERVER_TIMEOUT); proxy_msg_add_string(msg, exe); proxy_msg_add_string(msg, path); proxy_msg_add_string(msg, args); proxy_serialize_msg(msg, &buf, &len); /* * Create a bitset containing all processes */ bitset_invert(procs); res = send_command(procs, DBG_EV_WAITALL, buf, len, NULL); free_proxy_msg(msg); bitset_free(procs); return res; }
/** * \post * - \c *follow_kernel_itemsp and \c *always_followsp were computed by * \c ielr_compute_follow_kernel_items and * \c ielr_compute_always_follows. * - Iff <tt>predecessorsp != NULL</tt>, then \c *predecessorsp was computed * by \c ielr_compute_predecessors. */ static void ielr_compute_auxiliary_tables (bitsetv *follow_kernel_itemsp, bitsetv *always_followsp, state ****predecessorsp) { goto_number **edges; int *edge_counts; { bitset ritem_sees_lookahead_set = ielr_compute_ritem_sees_lookahead_set (); ielr_compute_internal_follow_edges (ritem_sees_lookahead_set, &edges, &edge_counts); ielr_compute_follow_kernel_items (ritem_sees_lookahead_set, edges, follow_kernel_itemsp); bitset_free (ritem_sees_lookahead_set); } ielr_compute_always_follows (&edges, edge_counts, always_followsp); { int i; for (i = 0; i < ngotos; ++i) free (edges[i]); } free (edges); free (edge_counts); if (predecessorsp) *predecessorsp = ielr_compute_predecessors (); }
void networkReadCallbackPerByte(NetworkAddress networkAddr, ADDRINT start, size_t length, void *v) { int tag; assert(taintGen); bitset *s = bitset_init(NUMBER_OF_TAINT_MARKS); ADDRINT end = start + length; for(ADDRINT addr = start; addr < end; addr++) { tag = taintGen->nextTaintMark(); bitset_set_bit(s, tag); memTaintMap[addr] = bitset_copy(s); bitset_reset(s); } bitset_free(s); ADDRINT currAddress = start; while (currAddress < end) { taintAssignmentLog << tag << " - [" << networkAddr.strAddress << "] -> " << std::hex << currAddress++ << "\n"; } taintAssignmentLog.flush(); #ifdef TRACE if(tracing) { log << "\t" << std::hex << start << "-" << std::hex << end - 1 << " <- read\n"; log.flush(); } #endif }
int main(int argc, char **argv) { bitset *set; set = bitset_new(50); if (set == NULL) return 0; init_array(); printf("A: \n"); print_array(A, 20); printf("B: \n"); print_array(B, 20); int i, j, common[20]; for (i = 0; i < 20; i++) { bitset_set(set, A[i], 1); } j = 0; for (i = 0; i < 20; i++) { if (bitset_get(set, B[i])) { common[j++] = B[i]; } } printf("Common: \n"); print_array(common, j); bitset_free(set); return 0; }
static void fdevent_linux_rtsig_free(fdevents * ev) { free(ev->pollfds); if (ev->unused.ptr) free(ev->unused.ptr); bitset_free(ev->sigbset); }
void output_red (state const *s, reductions const *reds, FILE *fout) { bitset no_reduce_set; int j; int source = s->number; /* Two obstacks are needed: one for the enabled reductions, and one for the disabled reductions, because in the end we want two separate edges, even though in most cases only one will actually be printed. */ struct obstack dout; struct obstack eout; no_reduce_bitset_init (s, &no_reduce_set); obstack_init (&dout); obstack_init (&eout); for (j = 0; j < reds->num; ++j) { bool defaulted = false; bool firstd = true; bool firste = true; rule_number ruleno = reds->rules[j]->number; rule *default_reduction = NULL; if (yydefact[s->number] != 0) default_reduction = &rules[yydefact[s->number] - 1]; /* Build the lookahead tokens lists, one for enabled transitions and one for disabled transistions. */ if (default_reduction && default_reduction == reds->rules[j]) defaulted = true; if (reds->lookahead_tokens) { int i; for (i = 0; i < ntokens; i++) if (bitset_test (reds->lookahead_tokens[j], i)) { if (bitset_test (no_reduce_set, i)) firstd = print_token (&dout, firstd, symbols[i]->tag); else { if (! defaulted) firste = print_token (&eout, firste, symbols[i]->tag); bitset_set (no_reduce_set, i); } } } /* Do the actual output. */ conclude_red (&dout, source, ruleno, false, firstd, fout); conclude_red (&eout, source, ruleno, true, firste && !defaulted, fout); } obstack_free (&dout, 0); obstack_free (&eout, 0); bitset_free (no_reduce_set); }
// free this labelset (assumes no ptrs held) static SB_INLINE void labelset_free(LabelSet *ls) { if (ls == NULL) return; assert (ls->count > 0); ls->count--; if (ls->count == 0) { // ref count went to zero -- really free bitset_free(*(ls->set)); my_free(ls, sizeof(LabelSet), poolid_label_set); } }
/*ARGSUSED*/ int bitset(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) { bitset_t *bs; bs = bitset_get(addr); if (bs == NULL) return (DCMD_ERR); bitset_print(bs, "label", 80); bitset_free(bs); return (DCMD_OK); }
static bitset_t * bitset_get(uintptr_t bsaddr) { bitset_t *bs; bs = mdb_zalloc(sizeof (*bs), UM_SLEEP); if (mdb_vread(bs, sizeof (*bs), bsaddr) == -1) { mdb_warn("couldn't read bitset 0x%p", bsaddr); bitset_free(bs); return (NULL); } bsaddr = (uintptr_t)bs->bs_set; bs->bs_set = mdb_alloc(bs->bs_words * sizeof (ulong_t), UM_SLEEP); if (mdb_vread(bs->bs_set, bs->bs_words * sizeof (ulong_t), bsaddr) == -1) { mdb_warn("couldn't read bitset bs_set 0x%p", bsaddr); bitset_free(bs); return (NULL); } return (bs); }
void print_xml (void) { int level = 0; FILE *out = xfopen (spec_xml_file, "w"); fputs ("<?xml version=\"1.0\"?>\n\n", out); xml_printf (out, level, "<bison-xml-report version=\"%s\" bug-report=\"%s\"" " url=\"%s\">", xml_escape_n (0, VERSION), xml_escape_n (1, PACKAGE_BUGREPORT), xml_escape_n (2, PACKAGE_URL)); fputc ('\n', out); xml_printf (out, level + 1, "<filename>%s</filename>", xml_escape (grammar_file)); /* print grammar */ print_grammar (out, level + 1); new_closure (nritems); no_reduce_set = bitset_create (ntokens, BITSET_FIXED); /* print automaton */ fputc ('\n', out); xml_puts (out, level + 1, "<automaton>"); { state_number i; for (i = 0; i < nstates; i++) print_state (out, level + 2, states[i]); } xml_puts (out, level + 1, "</automaton>"); bitset_free (no_reduce_set); free_closure (); xml_puts (out, 0, "</bison-xml-report>"); { int i; for (i = 0; i < num_escape_bufs; ++i) free (escape_bufs[i].ptr); } xfclose (out); }
static void useless_nonterminals (void) { bitset Np, Ns; rule_number r; /* N is set as built. Np is set being built this iteration. P is set of all productions which have a RHS all in N. */ Np = bitset_create (nvars, BITSET_FIXED); /* The set being computed is a set of nonterminals which can derive the empty string or strings consisting of all terminals. At each iteration a nonterminal is added to the set if there is a production with that nonterminal as its LHS for which all the nonterminals in its RHS are already in the set. Iterate until the set being computed remains unchanged. Any nonterminals not in the set at that point are useless in that they will never be used in deriving a sentence of the language. This iteration doesn't use any special traversal over the productions. A set is kept of all productions for which all the nonterminals in the RHS are in useful. Only productions not in this set are scanned on each iteration. At the end, this set is saved to be used when finding useful productions: only productions in this set will appear in the final grammar. */ while (1) { bitset_copy (Np, N); for (r = 0; r < nrules; r++) if (!bitset_test (P, r) && useful_production (r, N)) { bitset_set (Np, rules[r].lhs->number - ntokens); bitset_set (P, r); } if (bitset_equal_p (N, Np)) break; Ns = Np; Np = N; N = Ns; } bitset_free (N); N = Np; }
int main(int argc, char** argv) { int show_details = 0; printf("\nShow details,run: %s details.\n",argv[0]); if(argc > 1) { if(strcmp("details",argv[1]) == 0) { show_details = 1; } } bitset *s = bitset_init(200); bitset_set_bit(s, 0); bitset_set_bit(s, 1); bitset_set_bit(s, 2); bitset_set_bit(s, 3); bitset_set_bit(s, 4); bitset_set_bit(s, 5); bitset_set_bit(s, 6); bitset_set_bit(s, 7); bitset_set_bit(s, 8); bitset_set_bit(s, 9); bitset_set_bit(s, 10); bitset_print(s); bitset_clear_bit(s, 1); bitset_clear_bit(s, 4); bitset_clear_bit(s, 7); bitset_print(s); size_t pos = bitset_get_first_unused_bit_pos(s); printf("pos : %d\n", pos); bitset_set_bit(s, pos); pos = bitset_get_first_unused_bit_pos(s); printf("pos : %d\n", pos); bitset_free(s); run(1); return (EXIT_SUCCESS); }
int DbgQuit(session *s) { int res; int len; unsigned char * buf; bitset * procs = bitset_new(s->sess_procs); proxy_msg * msg = new_proxy_msg(DBG_QUIT_CMD, 0); proxy_serialize_msg(msg, &buf, &len); bitset_invert(procs); res = send_command(procs, DBG_EV_WAITALL, buf, len, NULL); free_proxy_msg(msg); bitset_free(procs); return res; }
/** * \pre * - \c follow_kernel_items, \c always_follows, and \c predecessors * were computed by \c ielr_compute_auxiliary_tables. * \post * - Each of <tt>*inadequacy_listsp</tt> and <tt>*annotation_listsp</tt> * points to a new array of size \c ::nstates. * - For <tt>0 <= i < ::nstates</tt>: * - <tt>(*inadequacy_listsp)[i]</tt> contains the \c InadequacyList head * node for <tt>states[i]</tt>. * - <tt>(*annotation_listsp)[i]</tt> contains the \c AnnotationList head * node for <tt>states[i]</tt>. * - <tt>*max_annotationsp</tt> is the maximum number of annotations per * state. */ static void ielr_compute_annotation_lists (bitsetv follow_kernel_items, bitsetv always_follows, state ***predecessors, AnnotationIndex *max_annotationsp, InadequacyList ***inadequacy_listsp, AnnotationList ***annotation_listsp, struct obstack *annotations_obstackp) { bitset **item_lookahead_sets = xnmalloc (nstates, sizeof *item_lookahead_sets); AnnotationIndex *annotation_counts = xnmalloc (nstates, sizeof *annotation_counts); ContributionIndex max_contributions = 0; unsigned int total_annotations = 0; state_number i; *inadequacy_listsp = xnmalloc (nstates, sizeof **inadequacy_listsp); *annotation_listsp = xnmalloc (nstates, sizeof **annotation_listsp); for (i = 0; i < nstates; ++i) { item_lookahead_sets[i] = NULL; (*inadequacy_listsp)[i] = NULL; (*annotation_listsp)[i] = NULL; annotation_counts[i] = 0; } { InadequacyListNodeCount inadequacy_list_node_count = 0; for (i = 0; i < nstates; ++i) AnnotationList__compute_from_inadequacies ( states[i], follow_kernel_items, always_follows, predecessors, item_lookahead_sets, *inadequacy_listsp, *annotation_listsp, annotation_counts, &max_contributions, annotations_obstackp, &inadequacy_list_node_count); } *max_annotationsp = 0; for (i = 0; i < nstates; ++i) { if (annotation_counts[i] > *max_annotationsp) *max_annotationsp = annotation_counts[i]; total_annotations += annotation_counts[i]; } if (trace_flag & trace_ielr) { for (i = 0; i < nstates; ++i) { fprintf (stderr, "Inadequacy annotations for state %d:\n", i); AnnotationList__debug ((*annotation_listsp)[i], states[i]->nitems, 2); } fprintf (stderr, "Number of LR(0)/LALR(1) states: %d\n", nstates); fprintf (stderr, "Average number of annotations per state: %f\n", (float)total_annotations/nstates); fprintf (stderr, "Max number of annotations per state: %d\n", *max_annotationsp); fprintf (stderr, "Max number of contributions per annotation: %d\n", max_contributions); } for (i = 0; i < nstates; ++i) if (item_lookahead_sets[i]) { size_t j; for (j = 0; j < states[i]->nitems; ++j) if (item_lookahead_sets[i][j]) bitset_free (item_lookahead_sets[i][j]); free (item_lookahead_sets[i]); } free (item_lookahead_sets); free (annotation_counts); }
void FreeDbgEvent(dbg_event *e) { switch (e->event_id) { case DBGEV_OK: break; case DBGEV_OUTPUT: free(e->dbg_event_u.output); break; case DBGEV_SUSPEND: switch (e->dbg_event_u.suspend_event.reason) { case DBGEV_SUSPEND_SIGNAL: if (e->dbg_event_u.suspend_event.ev_u.sig != NULL) { FreeSignalInfo(e->dbg_event_u.suspend_event.ev_u.sig); } break; case DBGEV_SUSPEND_INT: case DBGEV_SUSPEND_STEP: break; case DBGEV_SUSPEND_BPHIT: break; } if (e->dbg_event_u.suspend_event.frame != NULL) { FreeStackframe(e->dbg_event_u.suspend_event.frame); } if (e->dbg_event_u.suspend_event.changed_vars != NULL) { DestroyList(e->dbg_event_u.suspend_event.changed_vars, free); } break; case DBGEV_EXIT: switch (e->dbg_event_u.suspend_event.reason) { case DBGEV_EXIT_SIGNAL: if (e->dbg_event_u.suspend_event.ev_u.sig != NULL) { FreeSignalInfo(e->dbg_event_u.suspend_event.ev_u.sig); } break; case DBGEV_EXIT_NORMAL: break; } break; case DBGEV_FRAMES: if (e->dbg_event_u.list != NULL) { DestroyList(e->dbg_event_u.list, FreeStackframe); } break; case DBGEV_DATA: if (e->dbg_event_u.data_event.data != NULL) { AIFFree(e->dbg_event_u.data_event.data); } if (e->dbg_event_u.data_event.type_desc != NULL) { free(e->dbg_event_u.data_event.type_desc); } if (e->dbg_event_u.data_event.name != NULL) { free(e->dbg_event_u.data_event.name); } break; case DBGEV_TYPE: if (e->dbg_event_u.type_desc != NULL) { free(e->dbg_event_u.type_desc); } break; case DBGEV_THREAD_SELECT: if (e->dbg_event_u.thread_select_event.frame != NULL) { FreeStackframe(e->dbg_event_u.thread_select_event.frame); } break; case DBGEV_THREADS: if (e->dbg_event_u.threads_event.list != NULL) { DestroyList(e->dbg_event_u.threads_event.list, free); } break; case DBGEV_DATAR_MEM: if (e->dbg_event_u.meminfo != NULL) { FreeMemoryInfo(e->dbg_event_u.meminfo); } break; case DBGEV_ARGS: case DBGEV_VARS: if (e->dbg_event_u.list != NULL) { DestroyList(e->dbg_event_u.list, free); } break; case DBGEV_SIGNALS: if (e->dbg_event_u.list != NULL) { DestroyList(e->dbg_event_u.list, FreeSignalInfo); } break; case DBGEV_BPSET: if (e->dbg_event_u.bpset_event.bp != NULL) { FreeBreakpoint(e->dbg_event_u.bpset_event.bp); } break; case DBGEV_ERROR: if (e->dbg_event_u.error_event.error_msg != NULL) { free(e->dbg_event_u.error_event.error_msg); } } if (e->procs != NULL) { bitset_free(e->procs); } free(e); }
/* * Convert an array of strings (as a result of deserializing a proxy message) * into a debug event. This is used on the client end, so the event will include * a bitset. */ int DbgDeserializeEvent(int id, int nargs, char **args, dbg_event **ev) { dbg_event * e = NULL; bitset * procs = NULL; proxy_get_bitset((unsigned char *)*args++, &procs); nargs--; e = NewDbgEvent(id); switch (id) { case DBGEV_OK: break; case DBGEV_ERROR: dbg_str_to_int(&args, &nargs, &e->dbg_event_u.error_event.error_code); dbg_copy_str(&args, &nargs, &e->dbg_event_u.error_event.error_msg); break; case DBGEV_OUTPUT: dbg_copy_str(&args, &nargs, &e->dbg_event_u.output); break; case DBGEV_SUSPEND: dbg_str_to_int(&args, &nargs, &e->dbg_event_u.suspend_event.reason); switch (e->dbg_event_u.suspend_event.reason) { case DBGEV_SUSPEND_BPHIT: dbg_str_to_int(&args, &nargs, &e->dbg_event_u.suspend_event.ev_u.bpid); dbg_str_to_int(&args, &nargs, &e->dbg_event_u.suspend_event.thread_id); dbg_str_to_int(&args, &nargs, &e->dbg_event_u.suspend_event.depth); dbg_str_to_list(&args, &nargs, &e->dbg_event_u.suspend_event.changed_vars); break; case DBGEV_SUSPEND_SIGNAL: dbg_str_to_signalinfo(&args, &nargs, &e->dbg_event_u.suspend_event.ev_u.sig); dbg_str_to_stackframe(&args, &nargs, &e->dbg_event_u.suspend_event.frame); dbg_str_to_int(&args, &nargs, &e->dbg_event_u.suspend_event.thread_id); dbg_str_to_int(&args, &nargs, &e->dbg_event_u.suspend_event.depth); dbg_str_to_list(&args, &nargs, &e->dbg_event_u.suspend_event.changed_vars); break; case DBGEV_SUSPEND_STEP: case DBGEV_SUSPEND_INT: dbg_str_to_stackframe(&args, &nargs, &e->dbg_event_u.suspend_event.frame); dbg_str_to_int(&args, &nargs, &e->dbg_event_u.suspend_event.thread_id); dbg_str_to_int(&args, &nargs, &e->dbg_event_u.suspend_event.depth); dbg_str_to_list(&args, &nargs, &e->dbg_event_u.suspend_event.changed_vars); break; default: goto error_out; } break; case DBGEV_BPSET: dbg_str_to_int(&args, &nargs, &e->dbg_event_u.bpset_event.bpid); dbg_str_to_breakpoint(&args, &nargs, &e->dbg_event_u.bpset_event.bp); break; case DBGEV_SIGNALS: dbg_str_to_signals(&args, &nargs, &e->dbg_event_u.list); break; case DBGEV_EXIT: dbg_str_to_int(&args, &nargs, &e->dbg_event_u.exit_event.reason); switch (e->dbg_event_u.exit_event.reason) { case DBGEV_EXIT_NORMAL: dbg_str_to_int(&args, &nargs, &e->dbg_event_u.exit_event.ev_u.exit_status); break; case DBGEV_EXIT_SIGNAL: dbg_str_to_signalinfo(&args, &nargs, &e->dbg_event_u.exit_event.ev_u.sig); break; default: goto error_out; } break; case DBGEV_FRAMES: dbg_str_to_stackframes(&args, &nargs, &e->dbg_event_u.list); break; case DBGEV_THREAD_SELECT: dbg_str_to_int(&args, &nargs, &e->dbg_event_u.thread_select_event.thread_id); dbg_str_to_stackframe(&args, &nargs, &e->dbg_event_u.thread_select_event.frame); break; case DBGEV_THREADS: dbg_str_to_int(&args, &nargs, &e->dbg_event_u.threads_event.thread_id); dbg_str_to_list(&args, &nargs, &e->dbg_event_u.threads_event.list); break; case DBGEV_STACK_DEPTH: dbg_str_to_int(&args, &nargs, &e->dbg_event_u.stack_depth); break; case DBGEV_DATAR_MEM: dbg_str_to_memoryinfo(&args, &nargs, &e->dbg_event_u.meminfo); break; case DBGEV_VARS: dbg_str_to_list(&args, &nargs, &e->dbg_event_u.list); break; case DBGEV_ARGS: dbg_str_to_list(&args,&nargs, &e->dbg_event_u.list); break; case DBGEV_TYPE: dbg_copy_str(&args, &nargs, &e->dbg_event_u.type_desc); break; case DBGEV_DATA: dbg_str_to_aif(&args, &nargs, &e->dbg_event_u.data_event.data); dbg_copy_str(&args, &nargs, &e->dbg_event_u.data_event.type_desc); dbg_copy_str(&args, &nargs, &e->dbg_event_u.data_event.name); break; default: goto error_out; } e->procs = procs; *ev = e; return 0; error_out: if (procs != NULL) bitset_free(procs); if (e != NULL) FreeDbgEvent(e); return -1; }
/** * \pre: * - \c ritem_sees_lookahead_set was computed by * \c ielr_compute_ritem_sees_lookahead_set. * \post: * - Each of \c *edgesp and \c *edge_countsp is a new array of size * \c ::ngotos. * - <tt>(*edgesp)[i]</tt> points to a \c goto_number array of size * <tt>(*edge_countsp)[i]+1</tt>. * - In such a \c goto_number array, the last element is \c ::END_NODE. * - All remaining elements are the indices of the gotos to which there is an * internal follow edge from goto \c i. * - There is an internal follow edge from goto \c i to goto \c j iff both: * - The from states of gotos \c i and \c j are the same. * - The transition nonterminal for goto \c i appears as the first RHS * symbol of at least one production for which both: * - The LHS is the transition symbol of goto \c j. * - All other RHS symbols are nullable nonterminals. * - In other words, the follows of goto \c i include the follows of * goto \c j and it's an internal edge because the from states are the * same. */ static void ielr_compute_internal_follow_edges (bitset ritem_sees_lookahead_set, goto_number ***edgesp, int **edge_countsp) { *edgesp = xnmalloc (ngotos, sizeof **edgesp); *edge_countsp = xnmalloc (ngotos, sizeof **edge_countsp); { bitset sources = bitset_create (ngotos, BITSET_FIXED); goto_number i; for (i = 0; i < ngotos; ++i) (*edge_countsp)[i] = 0; for (i = 0; i < ngotos; ++i) { int nsources = 0; { rule **rulep; for (rulep = derives[states[to_state[i]]->accessing_symbol - ntokens]; *rulep; ++rulep) { /* If there is at least one RHS symbol, if the first RHS symbol is a nonterminal, and if all remaining RHS symbols (if any) are nullable nonterminals, create an edge from the LHS symbol's goto to the first RHS symbol's goto such that the RHS symbol's goto will be the source of the edge after the eventual relation_transpose below. Unlike in ielr_compute_always_follows, I use a bitset for edges rather than an array because it is possible that multiple RHS's with the same first symbol could fit and thus that we could end up with redundant edges. With the possibility of redundant edges, it's hard to know ahead of time how large to make such an array. Another possible redundancy is that source and destination might be the same goto. Eliminating all these possible redundancies now might possibly help performance a little. I have not proven any of this, but I'm guessing the bitset shouldn't entail much of a performance penalty, if any. */ if (bitset_test (ritem_sees_lookahead_set, (*rulep)->rhs - ritem)) { goto_number source = map_goto (from_state[i], item_number_as_symbol_number (*(*rulep)->rhs)); if (i != source && !bitset_test (sources, source)) { bitset_set (sources, source); ++nsources; ++(*edge_countsp)[source]; } } } } if (nsources == 0) (*edgesp)[i] = NULL; else { (*edgesp)[i] = xnmalloc (nsources + 1, sizeof *(*edgesp)[i]); { bitset_iterator biter_source; bitset_bindex source; int j = 0; BITSET_FOR_EACH (biter_source, sources, source, 0) (*edgesp)[i][j++] = source; } (*edgesp)[i][nsources] = END_NODE; } bitset_zero (sources); } bitset_free (sources); } relation_transpose (edgesp, ngotos); if (trace_flag & trace_ielr) { fprintf (stderr, "internal_follow_edges:\n"); relation_print (*edgesp, ngotos, stderr); } }
static void fdevent_freebsd_kqueue_free(fdevents * ev) { close(ev->kq_fd); free(ev->kq_results); bitset_free(ev->kq_bevents); }
static void inaccessable_symbols (void) { bitset Vp, Vs, Pp; /* Find out which productions are reachable and which symbols are used. Starting with an empty set of productions and a set of symbols which only has the start symbol in it, iterate over all productions until the set of productions remains unchanged for an iteration. For each production which has a LHS in the set of reachable symbols, add the production to the set of reachable productions, and add all of the nonterminals in the RHS of the production to the set of reachable symbols. Consider only the (partially) reduced grammar which has only nonterminals in N and productions in P. The result is the set P of productions in the reduced grammar, and the set V of symbols in the reduced grammar. Although this algorithm also computes the set of terminals which are reachable, no terminal will be deleted from the grammar. Some terminals might not be in the grammar but might be generated by semantic routines, and so the user might want them available with specified numbers. (Is this true?) However, the nonreachable terminals are printed (if running in verbose mode) so that the user can know. */ Vp = bitset_create (nsyms, BITSET_FIXED); Pp = bitset_create (nrules, BITSET_FIXED); /* If the start symbol isn't useful, then nothing will be useful. */ if (bitset_test (N, accept->number - ntokens)) { bitset_set (V, accept->number); while (1) { rule_number r; bitset_copy (Vp, V); for (r = 0; r < nrules; r++) { if (!bitset_test (Pp, r) && bitset_test (P, r) && bitset_test (V, rules[r].lhs->number)) { item_number *rhsp; for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++) if (ISTOKEN (*rhsp) || bitset_test (N, *rhsp - ntokens)) bitset_set (Vp, *rhsp); bitset_set (Pp, r); } } if (bitset_equal_p (V, Vp)) break; Vs = Vp; Vp = V; V = Vs; } } bitset_free (V); V = Vp; /* Tokens 0, 1, and 2 are internal to Bison. Consider them useful. */ bitset_set (V, endtoken->number); /* end-of-input token */ bitset_set (V, errtoken->number); /* error token */ bitset_set (V, undeftoken->number); /* some undefined token */ bitset_free (P); P = Pp; nuseful_productions = bitset_count (P); nuseless_productions = nrules - nuseful_productions; nuseful_nonterminals = 0; { symbol_number i; for (i = ntokens; i < nsyms; i++) if (bitset_test (V, i)) nuseful_nonterminals++; } nuseless_nonterminals = nvars - nuseful_nonterminals; /* A token that was used in %prec should not be warned about. */ { rule_number r; for (r = 0; r < nrules; ++r) if (rules[r].precsym != 0) bitset_set (V1, rules[r].precsym->number); } }