sem_elem_t liftWeight(WFA const & UNUSED_PARAMETER(original_wfa), Key source, Key symbol, Key target, sem_elem_t UNUSED_PARAMETER(weight)) const { std::stringstream ss; ss << key2str(source) << " --" << key2str(symbol) << "--> " << key2str(target); return new StringWeight(ss.str()); }
sem_elem_t liftAcceptWeight(WFA const & original_wfa, Key state, sem_elem_t UNUSED_PARAMETER(original_accept_weight)) const { std::stringstream ss; if (original_wfa.isFinalState(state)) { ss << key2str(state); } return new StringWeight(ss.str()); }
int check_key_bindings(command_definition_t *cp, char *buf, size_t bufsize) { int i; int retval = 0; if (cp == NULL) cp = cmds; for (i = 0; cp[i].name; i++) cp[i].flags &= ~COMMAND_KEY_CONFLICT; for (i = 0; cp[i].name; i++) { int j; command_t cmd; for(j=0; j<MAX_COMMAND_KEYS; j++) { if (cp[i].keys[j] && (cmd = find_key_command(cp[i].keys[j],cp)) != cp[i].command) { if (buf) { g_snprintf(buf, bufsize, _("Key %s assigned to %s and %s"), key2str(cp[i].keys[j]), get_key_command_name(cp[i].command), get_key_command_name(cmd)); } else { fprintf(stderr, _("Key %s assigned to %s and %s"), key2str(cp[i].keys[j]), get_key_command_name(cp[i].command), get_key_command_name(cmd)); fputc('\n', stderr); } cp[i].flags |= COMMAND_KEY_CONFLICT; set_key_flags(cp, cmd, COMMAND_KEY_CONFLICT); retval = -1; } } } return retval; }
const char * get_key_names(command_t command, bool all) { for (int i = 0; cmds[i].description; i++) { if (cmds[i].command == command) { static char keystr[80]; g_strlcpy(keystr, key2str(cmds[i].keys[0]), sizeof(keystr)); if (!all) return keystr; for (int j = 1; j < MAX_COMMAND_KEYS && cmds[i].keys[j] > 0; j++) { g_strlcat(keystr, " ", sizeof(keystr)); g_strlcat(keystr, key2str(cmds[i].keys[j]), sizeof(keystr)); } return keystr; } } return NULL; }
void MenuVItem::setKeyValue(int value) { this->keyValue = value; this->keyValueString = key2str(value); }
NwaRefPtr assemble_nwa(ProcedureMap const & procedures, boost::function<void (Nwa &, State, State)> call_inserter, boost::function<void (Nwa &, State, State, State)> return_inserter) { NwaRefPtr finalnwa = new Nwa(); std::map<std::string, std::set<State> > entries_map; std::map<std::string, std::set<State> > exits_map; //////// // We will set up the states, then fix up the transitions. // First, combine all of the procedures (to get all the states // and transitions.) for (ProcedureMap::const_iterator proc = procedures.begin(); proc != procedures.end(); ++proc) { NwaRefPtr min = minimize_internal_nwa(proc->second); //NwaRefPtr min = proc->second; entries_map[proc->first] = min->getInitialStates(); exits_map[proc->first] = min->getFinalStates(); if (proc->first != "main") { min->clearInitialStates(); min->clearFinalStates(); } finalnwa->combineWith(*min); } //////// // Now set up the transitions // Now, find each of the transitions on a symbol __call__*. These // are the transitions we will replace. Nwa::Internals fake_call_transitions; for (Nwa::InternalIterator trans=finalnwa->beginInternalTrans(); trans != finalnwa->endInternalTrans(); ++trans) { std::string symbol = key2str(trans->second); if (string_starts_with(symbol, call_prefix)) { fake_call_transitions.insert(*trans); } } // Okay, now we have to do two things with each of those // transitions. The simpler one is to remove it. The more // complicated one is add a call and a return transition. The // call transition goes from the source to the entry of the // procedure that corresponds to the transition's symbol. The // return goes from the exit of that procedure to the return // node, with the call node as the predecessor. // // Schematically: // C ------------------> R // __call__foo // turns into // C R // | /\ . // call | | return (C as call predecessor) // | | // V | // entry_foo exit_foo // for (Nwa::Internals::iterator fake_call = fake_call_transitions.begin(); fake_call != fake_call_transitions.end(); ++fake_call) { // Remove the fake call. finalnwa->removeInternalTrans(*fake_call); // Prepare for the call and return transitions Key call_site = fake_call->first; Key return_site = fake_call->third; std::string symbol = key2str(fake_call->second); std::string callee_name = remove_prefix(symbol, call_prefix); assert(entries_map.find(callee_name) != entries_map.end()); assert(exits_map.find(callee_name) != exits_map.end()); std::set<State> const & entries = entries_map[callee_name]; std::set<State> const & exits = exits_map[callee_name]; // I don't think these assertions are necessary for the below // to work, but they do apply in my setting. TODO: consider // removing them when I make this code more general. -Evan // 3/10/11 (Actually change to >= 1 instead of remove // entirely.) assert(entries.size() == 1); // Now add the call transition(s) for (std::set<State>::const_iterator entry = entries.begin(); entry != entries.end(); ++entry) { call_inserter(*finalnwa, call_site, *entry); //finalnwa->addCallTrans(call_site, call_key, *entry); //finalnwa->addInternalTrans(call_site, EPSILON, *entry); } // Now add the return transition(s) for (std::set<State>::const_iterator exit = exits.begin(); exit != exits.end(); ++exit) { return_inserter(*finalnwa, *exit, call_site, return_site); //finalnwa->addReturnTrans(*exit, call_site, return_key, return_site); //finalnwa->addInternalTrans(*exit, EPSILON, return_site); } } // Finally, we remove the __call__ symbols from the automaton. std::set<Symbol> to_remove; for (Nwa::SymbolIterator symiter = finalnwa->beginSymbols(); symiter != finalnwa->endSymbols(); ++symiter) { Symbol symbol = *symiter; if (string_starts_with(key2str(symbol), call_prefix)) { // It shouldn't be used in any transitions. Check that. assert(query::getSources_Sym(*finalnwa, symbol).size() == 0); assert(query::getCallSites_Sym(*finalnwa, symbol).size() == 0); assert(query::getExits_Sym(*finalnwa, symbol).size() == 0); // Now schedule it for removal to_remove.insert(symbol); } } for (std::set<Symbol>::iterator s=to_remove.begin(); s!=to_remove.end(); ++s){ finalnwa->removeSymbol(*s); } return finalnwa; } // end assemble_nwa()