bool remove_const_function_pointerst::try_resolve_member( const member_exprt &member_expr, expressionst &out_expressions, bool &out_is_const) { expressionst potential_structs; bool is_struct_const; // Get the struct it belongs to bool resolved_struct= try_resolve_expression( member_expr.compound(), potential_structs, is_struct_const); if(resolved_struct) { for(const exprt &potential_struct : potential_structs) { if(potential_struct.id()==ID_struct) { struct_exprt struct_expr=to_struct_expr(potential_struct); const exprt &component_value= get_component_value(struct_expr, member_expr); expressionst resolved_expressions; bool component_const=false; bool resolved= try_resolve_expression( component_value, resolved_expressions, component_const); if(resolved) { out_expressions.insert( out_expressions.end(), resolved_expressions.begin(), resolved_expressions.end()); } else { LOG("Could not resolve component value", component_value); return false; } } else { LOG( "Squashing member access did not resolve in a struct", potential_struct); return false; } } out_is_const=is_struct_const; return true; } else { LOG("Failed to squash struct access", member_expr); return false; } }
void insert_solution(control_programt &program, const control_solutiont &solution) { goto_functionst &gf=program.gf; goto_programt &init=get_body(gf, CPROVER_INIT); const goto_programt::targett pos=get_solution_assignment(init); const symbol_tablet &st=program.st; const source_locationt &loc=pos->source_location; to_code_assign(pos->code).rhs()=to_struct_expr(st, solution, loc); }
void propagate_controller_sizes(const symbol_tablet &st, goto_functionst &gf) { const symbolt &symbol=st.lookup(CEGIS_CONTROL_SOLUTION_VAR_NAME); const struct_exprt &controller_value=to_struct_expr(symbol.value); const namespacet ns(st); const exprt &a_size=get_a_size(ns, controller_value); const exprt &b_size=get_b_size(ns, controller_value); replace_sizes_visitort visitor(a_size, b_size); goto_programt &body=get_entry_body(gf); for (goto_programt::instructiont &instr : body.instructions) { instr.code.visit(visitor); instr.guard.visit(visitor); } }
void goto_convertt::do_java_new( const exprt &lhs, const side_effect_exprt &rhs, goto_programt &dest) { if(lhs.is_nil()) throw "do_java_new without lhs is yet to be implemented"; source_locationt location=rhs.source_location(); assert(rhs.operands().empty()); if(rhs.type().id()!=ID_pointer) throw "do_java_new returns pointer"; typet object_type=rhs.type().subtype(); // build size expression exprt object_size=size_of_expr(object_type, ns); if(object_size.is_nil()) throw "do_java_new got nil object_size"; // we produce a malloc side-effect, which stays side_effect_exprt malloc_expr(ID_malloc); malloc_expr.copy_to_operands(object_size); malloc_expr.type()=pointer_typet(object_type); goto_programt::targett t_n=dest.add_instruction(ASSIGN); t_n->code=code_assignt(lhs, malloc_expr); t_n->source_location=location; // zero-initialize the object dereference_exprt deref(lhs, object_type); exprt zero_object=zero_initializer(object_type, location, ns, get_message_handler()); set_class_identifier(to_struct_expr(zero_object), ns, to_symbol_type(object_type)); goto_programt::targett t_i=dest.add_instruction(ASSIGN); t_i->code=code_assignt(deref, zero_object); t_i->source_location=location; }
void retrieve_heaps(const jsa_counterexamplet &ce, __CPROVER_jsa_abstract_heapt *heaps) { assert(std::is_sorted(ce.begin(), ce.end(), compare_assignment)); size_t index=0; for (const jsa_counterexamplet::value_type &assignment : ce) if (is_heap(assignment)) { const struct_exprt &value=to_struct_expr(assignment.second); __CPROVER_jsa_abstract_heapt &heap=heaps[index++]; struct_exprt::operandst ops(value.operands()); remove_padding(ops, value.type()); assert(NUM_ABSTRACT_HEAP_MEMBERS == ops.size()); read_array(heap.concrete_nodes, ops[CONCRETE_NODES_COMP_INDEX]); read_array(heap.abstract_nodes, ops[ABSTRACT_NODES_COMP_INDEX]); read_array(heap.abstract_ranges, ops[ABSTRACT_RANGES_COMP_INDEX]); read_array(heap.iterators, ops[ITERATORS_COMP_INDEX]); heap.iterator_count=to_integer(ops[ITERATOR_COUNT_COMP_INDEX]); read_array(heap.list_head_nodes, ops[LIST_HEAD_NODES_COMP_INDEX]); heap.list_count=to_integer(ops[LIST_COUNT_COMP_INDEX]); } }
void set_class_identifier( struct_exprt &expr, const namespacet &ns, const symbol_typet &class_type) { const struct_typet &struct_type= to_struct_type(ns.follow(expr.type())); const struct_typet::componentst &components=struct_type.components(); if(components.empty()) return; assert(!expr.operands().empty()); if(components.front().get_name()=="@class_identifier") { assert(expr.op0().id()==ID_constant); expr.op0()=constant_exprt(class_type.get_identifier(), string_typet()); } else { assert(expr.op0().id()==ID_struct); set_class_identifier(to_struct_expr(expr.op0()), ns, class_type); } }