Forall_symbol_list(it, symbol_list) { symbolt &symbol = **it; adjust_type(symbol.type); if(symbol.is_type) continue; adjust_symbol(symbol); }
std::pair<exprt,exprt> ranking_synthesis_qbf_bitwiset::ite_template() { exprt function; replace_mapt pre_replace_map; unsigned state_size = get_state_size(); unsigned bits=log((double)state_size)/log(2.0) + 1; symbol_exprt const_sym(CONSTANT_COEFFICIENT_ID, unsignedbv_typet(bits)); const_coefficient=coefficient(const_sym); unsigned cnt=0; for(bodyt::variable_mapt::const_iterator it=body.variable_map.begin(); it!=body.variable_map.end(); it++) { if(used_variables.find(it->first)==used_variables.end()) continue; exprt postsym=symbol_exprt(it->first, ns.lookup(it->first).type); exprt presym=symbol_exprt(it->second, ns.lookup(it->second).type); pre_replace_map[postsym] = presym; // save the corresponding pre-var exprt var=postsym; adjust_type(var.type()); unsigned vwidth = safe_width(var, ns); for(unsigned i=0; i<vwidth; i++) { exprt t(ID_extractbit, bool_typet()); t.copy_to_operands(var); t.copy_to_operands(from_integer(i, typet(ID_natural))); if(it==body.variable_map.begin() && i==0) function = t; else { function = if_exprt(equal_exprt(const_coefficient, from_integer(cnt, const_coefficient.type())), t, function); } cnt++; } } exprt pre_function=function; replace_expr(pre_replace_map, pre_function); return std::pair<exprt,exprt>(pre_function, function); }
bool clang_c_adjust::adjust() { // warning! hash-table iterators are not stable symbol_listt symbol_list; context.Foreach_operand( [&symbol_list](symbolt &s) { symbol_list.push_back(&s); }); // Adjust types first, so that symbolic-type resolution always receives // fixed up types. Forall_symbol_list(it, symbol_list) { symbolt &symbol = **it; if(symbol.is_type) adjust_type(symbol.type); }
std::pair<exprt,exprt> ranking_synthesis_qbf_bitwiset::affine_template( const irep_idt &termOp, const irep_idt &coefOp) { exprt function; replace_mapt pre_replace_map; for(bodyt::variable_mapt::const_iterator it=body.variable_map.begin(); it!=body.variable_map.end(); it++) { if(used_variables.find(it->first)==used_variables.end()) continue; exprt postsym=symbol_exprt(it->first, ns.lookup(it->first).type); exprt presym=symbol_exprt(it->second, ns.lookup(it->second).type); pre_replace_map[postsym] = presym; // save the corresponding pre-var exprt var=postsym; adjust_type(var.type()); exprt co = coefficient(var); irep_idt bitop = (coefOp==ID_and) ? ID_bitand : (coefOp==ID_or) ? ID_bitor : (coefOp==ID_notequal) ? ID_bitxor : ""; exprt varblock(bitop, var.type()); varblock.copy_to_operands(var, co); exprt bchain = bitwise_chain(termOp, varblock); if(it==body.variable_map.begin()) // first one function=bchain; else { if(termOp==ID_notequal) { exprt t(ID_equal, bool_typet()); t.move_to_operands(function); t.move_to_operands(bchain); function=not_exprt(t); } else { exprt t(termOp, bool_typet()); t.move_to_operands(function); t.move_to_operands(bchain); function=t; } } } // ... and a constant coefficient symbol_exprt const_sym(CONSTANT_COEFFICIENT_ID, bool_typet()); const_coefficient=coefficient(const_sym); if(termOp==ID_notequal) { exprt t(ID_equal, bool_typet()); t.move_to_operands(function); t.copy_to_operands(const_coefficient); function = not_exprt(t); } else { exprt t(termOp, bool_typet()); t.move_to_operands(function); t.copy_to_operands(const_coefficient); function = t; } exprt pre_function=function; replace_expr(pre_replace_map, pre_function); return std::pair<exprt,exprt>(pre_function, function); }
exprt ranking_synthesis_satt::instantiate(void) { find_largest_constant(body.body_relation); binary_relation_exprt toplevel_and("and"); toplevel_and.lhs() = body.body_relation; // that's R(x,x') exprt function; replace_mapt pre_replace_map; bool first=true; for(bodyt::variable_mapt::const_iterator it=body.variable_map.begin(); it!=body.variable_map.end(); it++) { if(used_variables.find(it->first)==used_variables.end()) continue; exprt var=symbol_exprt(it->first, ns.lookup(it->first).type); pre_replace_map[var] = // save the corresponding pre-var symbol_exprt(it->second, ns.lookup(it->second).type); adjust_type(var.type()); const typet type=var.type(); exprt coef=coefficient(var); unsigned width=safe_width(var, ns); assert(width!=0); exprt term("*", typet("")); term.copy_to_operands(coef, var); if(first) { function=term; first=false; } else { // cast_up(function, term); exprt t("+", typet("")); t.move_to_operands(function, term); function = t; } } if(first) // non of the interesting variables was used - bail out! { debug("Completely non-deterministic template; " "this loop does not terminate."); return false_exprt(); } // if(!largest_constant.is_zero()) // { // // add the largest constant // symbol_exprt lc_sym("termination::LC", largest_constant.type()); // exprt lc=largest_constant; // exprt lcc=coefficient(lc_sym); //// cast_up(lc, lcc); // exprt m("*", typet("")); // m.move_to_operands(lcc, lc); // //// cast_up(function, m); // exprt t("+", typet("")); // t.move_to_operands(function, m); // function = t; // } // add a constant term symbol_exprt const_sym("termination::constant", signedbv_typet(2)); exprt cc=coefficient(const_sym); // cast_up(function, cc); exprt t2("+", typet("")); t2.move_to_operands(function, cc); function=t2; contextt context; ansi_c_parse_treet pt; rankfunction_typecheckt typecheck(pt, context, ns, *message_handler); try { typecheck.typecheck_expr(function); } catch (...) { throw "TC ERROR"; } exprt pre_function = function; replace_expr(pre_replace_map, pre_function); // save the relation for later rank_relation = binary_relation_exprt(function, "<", pre_function); // base_type(rank_relation, ns); toplevel_and.rhs()=not_exprt(rank_relation); return toplevel_and; }