/** * @brief Returns all local variables, including parameters. */ VarSet VarsHandler::getLocalVars() const { VarSet result; for (const auto &p : localVars) { result.insert(p.second); } return result; }
VarSet WhySemiring::getVars() const { VarSet res; for (auto ws : val) { res.insert(ws.begin(), ws.end()); } return res; }
void RIFActVarBind::getVars(VarSet &vars, const bool include_act_var) const throw() { if (include_act_var) { vars.insert(this->var); } if (this->frame != NULL) { this->frame->getVars(vars); } }
WhySemiring::WhySemiring(std::string str_val) { if(0 == str_val.compare("1")) { this->val = WhySet(); val.insert(VarSet()); } else if (0 == str_val.compare("0")) { this->val = WhySet(); } else { this->val = WhySet(); VarSet tmp = VarSet(); tmp.insert(Var::GetVarId(str_val)); val.emplace(tmp); } }
void RIFTerm::getVars(VarSet &vars) const throw() { if (this->type == VARIABLE) { RIFVar *v = (RIFVar*)this->state; RIFVar v2 = *v; vars.insert(v2); } else if (this->type == FUNCTION) { func_state *f = (func_state*) this->state; if (f->args != NULL) { RIFTerm *mark = f->args->dptr(); RIFTerm *end = mark + f->args->size(); for (; mark != end; ++mark) { mark->getVars(vars); } } } }
/** * @brief Precomputes @c funcInfo->isAlwaysModifiedBeforeRead for @c traversedFunc. */ void OptimFuncInfoCFGTraversal::precomputeAlwaysModifiedVarsBeforeRead() { // Initialization. funcInfo->varsAlwaysModifiedBeforeRead.clear(); // Global variables which are read during the computation. VarSet readVars; // Currently, we only traverse the function's body up to the first compound // statement. Moreover, we only consider global variables as the computed // piece of information is useless for local variables. // TODO Use a CFG traversal for this to improve the analysis. ShPtr<Statement> stmt(traversedFunc->getBody()); while (stmt) { if (stmt->isCompound()) { // As we are not using a CFG traversal, this is the end of the // computation. break; } ShPtr<ValueData> stmtData(va->getValueData(stmt)); // Handle directly read variables. addToSet(stmtData->getDirReadVars(), readVars); // Handle function calls (indirectly accessed variables). for (auto i = stmtData->call_begin(), e = stmtData->call_end(); i != e; ++i) { ShPtr<CallInfo> callInfo(cio->computeCallInfo(*i, traversedFunc)); for (const auto &var : globalVars) { if (callInfo->mayBeRead(var)) { readVars.insert(var); } } } // Handle directly written variables. for (auto i = stmtData->dir_written_begin(), e = stmtData->dir_written_end(); i != e; ++i) { if (hasItem(globalVars, *i) && !hasItem(readVars, *i)) { // This global variable is modified before read. funcInfo->varsAlwaysModifiedBeforeRead.insert(*i); } } // TODO What about indirectly accessed variables? stmt = stmt->getSuccessor(); } }
void ParityAggrLit::index(Grounder *g, Groundable *gr, VarSet &bound) { (void)g; if(assign_) { VarSet vars; VarVec bind; lower_->vars(vars); std::set_difference(vars.begin(), vars.end(), bound.begin(), bound.end(), std::back_insert_iterator<VarVec>(bind)); if(bind.size() > 0) { bound.insert(bind.begin(), bind.end()); return; } } gr->instantiator()->append(new MatchIndex(this)); }
/* Convert cell vector of Matlab sets to vector<VarSet> */ vector<VarSet> mx2VarSets(const mxArray *vs, const FactorGraph &fg, long verbose, vector<Permute> &perms) { vector<VarSet> varsets; int n1 = mxGetM(vs); int n2 = mxGetN(vs); if( n2 != 1 && n1 != 1 ) mexErrMsgTxt("varsets should be a Nx1 or 1xN cell matrix."); size_t nr_vs = n1; if( n1 == 1 ) nr_vs = n2; // interpret vs, linear cell array of varsets varsets.reserve( nr_vs ); perms.clear(); perms.reserve( nr_vs ); for( size_t cellind = 0; cellind < nr_vs; cellind++ ) { if( verbose >= 3 ) cerr << "reading varset " << cellind << ": " << endl; mxArray *cell = mxGetCell(vs, cellind); if( verbose >= 3 ) cerr << " got cell " << endl; size_t nr_mem = mxGetN(cell); if( verbose >= 3 ) cerr << " number members: " << nr_mem << endl; double *members = mxGetPr(cell); if( verbose >= 3 ) cerr << " got them! " << endl; // add variables VarSet vsvars; if( verbose >= 3 ) cerr << " vars: "; vector<long> labels(nr_mem,0); vector<size_t> dims(nr_mem,0); for( size_t mi = 0; mi < nr_mem; mi++ ) { labels[mi] = (long)members[mi]; dims[mi] = fg.var(labels[mi]).states(); if( verbose >= 3 ) cerr << labels[mi] << " "; vsvars.insert( fg.var(labels[mi]) ); } if( verbose >= 3 ) cerr << endl; DAI_ASSERT( nr_mem == vsvars.size() ); varsets.push_back(vsvars); // calculate permutation matrix vector<size_t> perm(nr_mem,0); VarSet::iterator j = vsvars.begin(); for( size_t mi = 0; mi < nr_mem; mi++,j++ ) { long gezocht = j->label(); vector<long>::iterator piet = find(labels.begin(),labels.end(),gezocht); perm[mi] = piet - labels.begin(); } if( verbose >= 3 ) { cerr << endl << " perm: "; for( vector<size_t>::iterator r=perm.begin(); r!=perm.end(); r++ ) cerr << *r << " "; cerr << endl; } // create Permute object vector<size_t> di(nr_mem,0); size_t prod = 1; for( size_t k = 0; k < nr_mem; k++ ) { di[k] = dims[k]; prod *= dims[k]; } Permute permindex( di, perm ); perms.push_back( permindex ); } if( verbose >= 3 ) { for(vector<VarSet>::const_iterator I=varsets.begin(); I!=varsets.end(); I++ ) cerr << *I << endl; } return( varsets ); }
void VarTerm::vars(VarSet &vars) const { vars.insert(index_); }
void Variable::getVars(VarSet &vars) const { vars.insert(uid_); }