/** * Conveniece function -- is the type unsigned? */ bool is_unsigned(const typet &t) { return t.id()==ID_bv || t.id()==ID_unsignedbv || t.id()==ID_pointer || t.id()==ID_bool; }
bool is_string_type(const typet &t) const { return (t.id()==ID_pointer || t.id()==ID_array) && (t.subtype().id()==ID_signedbv || t.subtype().id()==ID_unsignedbv) && (to_bitvector_type(t.subtype()).get_width()==config.ansi_c.char_width); }
/** * Convenience function -- is the type a bitvector of some kind? */ bool is_bitvector(const typet &t) { return t.id() == ID_bv || t.id() == ID_signedbv || t.id() == ID_unsignedbv || t.id() == ID_pointer || t.id() == ID_bool; }
void cpp_declarationt::name_anon_struct_union(typet &dest) { // We name any anon struct/unions according to the first // declarator. No need to do anon enums, which get // a name based on the enum elements. if(dest.id()==ID_struct || dest.id()==ID_union) { if(dest.find(ID_tag).is_nil()) { // it's anonymous const declaratorst &d=declarators(); if(!d.empty() && d.front().name().is_simple_name()) { // Anon struct/unions without declarator are pretty // useless, but still possible. irep_idt base_name="anon-"+id2string(d.front().name().get_base_name()); dest.set(ID_tag, cpp_namet(base_name)); dest.set(ID_C_is_anonymous, true); } } } else if(dest.id()==ID_merged_type) { Forall_subtypes(it, dest) name_anon_struct_union(*it); } }
bool type_eq(const typet &type1, const typet &type2, const namespacet &ns) { if(type1 == type2) return true; if(type1.id() == "symbol") { const symbolt &symbol = ns.lookup(type1); if(!symbol.is_type) throw "symbol " + id2string(symbol.name) + " is not a type"; return type_eq(symbol.type, type2, ns); } if(type2.id() == "symbol") { const symbolt &symbol = ns.lookup(type2); if(!symbol.is_type) throw "symbol " + id2string(symbol.name) + " is not a type"; return type_eq(type1, symbol.type, ns); } return false; }
void java_bytecode_parsert::get_class_refs_rec(const typet &src) { if(src.id()==ID_code) { const code_typet &ct=to_code_type(src); const typet &rt=ct.return_type(); get_class_refs_rec(rt); for(const auto &p : ct.parameters()) get_class_refs_rec(p.type()); } else if(src.id()==ID_symbol) { irep_idt name=src.get(ID_C_base_name); if(has_prefix(id2string(name), "array[")) { const typet &element_type= static_cast<const typet &>(src.find(ID_C_element_type)); get_class_refs_rec(element_type); } else parse_tree.class_refs.insert(name); } else if(src.id()==ID_struct) { const struct_typet &struct_type=to_struct_type(src); for(const auto &c : struct_type.components()) get_class_refs_rec(c.type()); } else if(src.id()==ID_pointer) get_class_refs_rec(src.subtype()); }
void c_storage_spect::read(const typet &type) { if(type.id()==ID_merged_type || type.id()==ID_code) { forall_subtypes(it, type) read(*it); } else if(type.id()==ID_static) is_static=true; else if(type.id()==ID_thread_local) is_thread_local=true; else if(type.id()==ID_inline) is_inline=true; else if(type.id()==ID_extern) is_extern=true; else if(type.id()==ID_typedef) is_typedef=true; else if(type.id()==ID_register) is_register=true; else if(type.id()==ID_weak) is_weak=true; else if(type.id()==ID_auto) { // ignore } else if(type.id()==ID_msc_declspec) { const exprt &as_expr= static_cast<const exprt &>(static_cast<const irept &>(type)); forall_operands(it, as_expr) if(it->id()==ID_thread) is_thread_local=true; } else if(type.id()==ID_alias &&
static bool is_a_bv_type(const typet &type) { return type.id()==ID_unsignedbv || type.id()==ID_signedbv || type.id()==ID_bv || type.id()==ID_fixedbv || type.id()==ID_floatbv || type.id()==ID_c_enum_tag; }
void base_type_rec( typet &type, const namespacet &ns, std::set<irep_idt> &symb) { if(type.id()==ID_symbol || type.id()==ID_c_enum_tag || type.id()==ID_struct_tag || type.id()==ID_union_tag) { const symbolt *symbol; if(!ns.lookup(type.get(ID_identifier), symbol) && symbol->is_type && !symbol->type.is_nil()) { type=symbol->type; base_type_rec(type, ns, symb); // recursive call return; } } else if(type.id()==ID_array) { base_type_rec(to_array_type(type).subtype(), ns, symb); } else if(type.id()==ID_struct || type.id()==ID_union) { struct_union_typet::componentst &components= to_struct_union_type(type).components(); for(auto &component : components) base_type_rec(component.type(), ns, symb); } else if(type.id()==ID_pointer) { typet &subtype=to_pointer_type(type).subtype(); // we need to avoid running into an infinite loop if(subtype.id()==ID_symbol || subtype.id()==ID_c_enum_tag || subtype.id()==ID_struct_tag || subtype.id()==ID_union_tag) { const irep_idt &id=subtype.get(ID_identifier); if(symb.find(id)!=symb.end()) return; symb.insert(id); base_type_rec(subtype, ns, symb); symb.erase(id); } else base_type_rec(subtype, ns, symb); } }
bv_semt bv_sem(const typet &type) { if(type.id()==ID_bv) return BV_NONE; else if(type.id()==ID_unsignedbv) return BV_UNSIGNED; else if(type.id()==ID_signedbv) return BV_SIGNED; return BV_UNKNOWN; }
void bv_spect::from_type(const typet &type) { if(type.id()==ID_unsignedbv) is_signed=false; else if(type.id()==ID_signedbv) is_signed=true; else assert(0); width=atoi(type.get(ID_width).c_str()); }
static std::string type_max(const typet &src) { if(src.id()==ID_signedbv) return integer2string( power(2, to_signedbv_type(src).get_width()-1)-1); else if(src.id()==ID_unsignedbv) return integer2string( power(2, to_unsignedbv_type(src).get_width()-1)-1); else assert(false); }
void bv_spect::from_type(const typet &type) { if(type.id()==ID_unsignedbv) is_signed=false; else if(type.id()==ID_signedbv) is_signed=true; else assert(0); width=unsafe_string2unsigned(type.get_string(ID_width)); }
exprt c_typecheck_baset::do_initializer_list( const exprt &value, const typet &type, bool force_constant) { assert(value.id()==ID_initializer_list); if(type.id()==ID_symbol) return do_initializer_list( value, follow(type), force_constant); exprt result; if(type.id()==ID_struct || type.id()==ID_array || type.id()==ID_union) { // start with zero everywhere result=zero_initializer(type, value.location()); } else if(type.id()==ID_incomplete_array) { // start with empty array result=exprt(ID_array, type); result.location()=value.location(); } else { // The initializer for a scalar shall be a single expression, // * optionally enclosed in braces. * if(value.operands().size()==1) return do_initializer_rec(value.op0(), type, force_constant); err_location(value); str << "cannot initialize `" << to_string(type) << "' with " "an initializer list"; throw 0; } designatort current_designator; designator_enter(type, current_designator); forall_operands(it, value) { do_designated_initializer( result, current_designator, *it, force_constant); // increase designator -- might go up increment_designator(current_designator); }
bool jsil_is_subtype(const typet &type1, const typet &type2) { if(type2.id()==ID_union) { const jsil_union_typet &type2_union=to_jsil_union_type(type2); if(type1.id()==ID_union) return to_jsil_union_type(type1).is_subtype(type2_union); else return jsil_union_typet(type1).is_subtype(type2_union); } else return type1.id()==type2.id(); }
exprt pointer_logict::pointer_expr( const pointert &pointer, const typet &type) const { if(pointer.object==null_object) // NULL? { if(pointer.offset==0) { constant_exprt result(type); result.set_value(ID_NULL); return result; } else { constant_exprt null(type); null.set_value(ID_NULL); return plus_exprt(null, from_integer(pointer.offset, pointer_diff_type())); } } else if(pointer.object==invalid_object) // INVALID? { constant_exprt result(type); result.set_value("INVALID"); return result; } if(pointer.object>=objects.size()) { constant_exprt result(type); result.set_value("INVALID-"+std::to_string(pointer.object)); return result; } const exprt &object_expr=objects[pointer.object]; exprt deep_object=object_rec(pointer.offset, type, object_expr); exprt result; if(type.id()==ID_pointer) result=exprt(ID_address_of, type); else if(type.id()==ID_reference) result=exprt("reference_to", type); else assert(0); result.copy_to_operands(deep_object); return result; }
/// \par parameters: a type /// \return Boolean telling whether the type is that of java string bool refined_string_typet::is_java_string_type(const typet &type) { if(type.id()==ID_symbol) { irep_idt tag=to_symbol_type(type).get_identifier(); return tag=="java::java.lang.String"; } else if(type.id()==ID_struct) { irep_idt tag=to_struct_type(type).get_tag(); return tag=="java.lang.String"; } return false; }
bool refined_string_typet::is_c_string_type(const typet &type) { if (type.id() == ID_struct) { irep_idt tag = to_struct_type(type).get_tag(); return (tag == irep_idt("__CPROVER_string")); } else return false; }
void c_typecheck_baset::do_initializer( exprt &initializer, const typet &type, bool force_constant) { exprt result=do_initializer_rec(initializer, type, force_constant); if(type.id()==ID_array) { // any arrays must have a size const typet &result_type=follow(result.type()); assert(result_type.id()==ID_array && to_array_type(result_type).size().is_not_nil()); // we don't allow initialisation with symbols of array type if(result.id()!=ID_array) { err_location(result); error() << "invalid array initializer " << to_string(result) << eom; throw 0; } } initializer=result; }
void c_typecheck_baset::typecheck_c_bit_field_type(typet &type) { typecheck_type(type.subtype()); exprt &width_expr=static_cast<exprt &>(type.add(ID_size)); typecheck_expr(width_expr); make_constant_index(width_expr); mp_integer i; if(to_integer(width_expr, i)) { err_location(type); throw "failed to convert bit field width"; } if(i<0) { err_location(type); throw "bit field width is negative"; } const typet &base_type=follow(type.subtype()); if(base_type.id()==ID_bool) { if(i>1) { err_location(type); throw "bit field width too large"; } // We don't use bool, as it's really a byte long. type.id(ID_unsignedbv); type.set(ID_width, integer2long(i)); } else if(base_type.id()==ID_signedbv || base_type.id()==ID_unsignedbv || base_type.id()==ID_c_enum) { unsigned width=base_type.get_int(ID_width); if(i>width) { err_location(type); throw "bit field width too large"; } typet tmp(base_type); type.swap(tmp); type.set(ID_width, integer2string(i)); } else { err_location(type); str << "bit field with non-integer type: " << to_string(base_type); throw 0; } }
c_typecastt::c_typet c_typecastt::minimum_promotion( const typet &type) const { c_typet c_type=get_c_type(type); // 6.3.1.1, par 2 // "If an int can represent all values of the original type, the // value is converted to an int; otherwise, it is converted to // an unsigned int." c_typet max_type=std::max(c_type, INT); // minimum promotion // The second case can arise if we promote any unsigned type // that is as large as unsigned int. if(config.ansi_c.short_int_width==config.ansi_c.int_width && max_type==USHORT) max_type=UINT; else if(config.ansi_c.char_width==config.ansi_c.int_width && max_type==UCHAR) max_type=UINT; else max_type=std::max(max_type, INT); if(max_type==UINT && type.id()==ID_c_bit_field && to_c_bit_field_type(type).get_width()<config.ansi_c.int_width) max_type=INT; return max_type; }
exprt from_integer(const mp_integer &int_value, const typet &type) { exprt expr; expr.clear(); expr.type() = type; expr.id("constant"); const irep_idt &type_id = type.id(); if(type_id == "unsignedbv" || type_id == "signedbv") { expr.value(integer2binary(int_value, bv_width(type))); return expr; } if(type_id == "bool") { if(int_value == 0) { expr.make_false(); return expr; } if(int_value == 1) { expr.make_true(); return expr; } } expr.make_nil(); return expr; }
code_function_callt get_destructor( const namespacet &ns, const typet &type) { if(type.id()==ID_symbol) { return get_destructor(ns, ns.follow(type)); } else if(type.id()==ID_struct) { const struct_typet &struct_type=to_struct_type(type); const struct_typet::componentst &components= struct_type.components(); for(struct_typet::componentst::const_iterator it=components.begin(); it!=components.end(); it++) { if(it->type().id()==ID_code) { const code_typet &code_type=to_code_type(it->type()); if(code_type.return_type().id()==ID_destructor && code_type.parameters().size()==1) { const typet &arg_type=code_type.parameters().front().type(); if(arg_type.id()==ID_pointer && ns.follow(arg_type.subtype())==type) { exprt symbol_expr(ID_symbol, it->type()); symbol_expr.set(ID_identifier, it->get(ID_name)); code_function_callt function_call; function_call.function()=symbol_expr; return function_call; } } } } } return static_cast<const code_function_callt &>(get_nil_irep()); }
bool refined_string_typet::is_java_string_type(const typet &type) { if(type.id() == ID_pointer) { pointer_typet pt = to_pointer_type(type); typet subtype = pt.subtype(); return is_java_deref_string_type(subtype); } else return false; }
bool refined_string_typet::is_java_deref_string_type(const typet &type) { if(type.id() == ID_struct) { irep_idt tag = to_struct_type(type).get_tag(); return (tag == irep_idt("java.lang.String")); } else return false; }
void ranking_synthesis_satt::adjust_type(typet &type) const { if(type.id()=="bool") { type=uint_type(); type.set("width", 1); } }
void boolbvt::convert_with( const typet &type, const exprt &op1, const exprt &op2, const bvt &prev_bv, bvt &next_bv) { // we only do that on arrays, bitvectors, structs, and unions next_bv.resize(prev_bv.size()); if(type.id()==ID_array) return convert_with_array(to_array_type(type), op1, op2, prev_bv, next_bv); else if(type.id()==ID_bv || type.id()==ID_unsignedbv || type.id()==ID_signedbv) return convert_with_bv(type, op1, op2, prev_bv, next_bv); else if(type.id()==ID_struct) return convert_with_struct(to_struct_type(type), op1, op2, prev_bv, next_bv); else if(type.id()==ID_union) return convert_with_union(to_union_type(type), op1, op2, prev_bv, next_bv); else if(type.id()==ID_symbol) return convert_with(ns.follow(type), op1, op2, prev_bv, next_bv); error().source_location=type.source_location(); error() << "unexpected with type: " << type.id(); throw 0; }
bool is_jsa_heap(const typet &type) { const irep_idt &type_id=type.id(); if (ID_symbol == type_id) return id2string(to_symbol_type(type).get_identifier()) == JSA_HEAP_TAG; if (ID_struct != type_id) return false; const irep_idt tag(to_struct_type(type).get_tag()); return id2string(tag) == JSA_HEAP_TAG; }
/// \par parameters: a type /// \return Boolean telling whether the type is that of java string pointers bool refined_string_typet::is_java_string_pointer_type(const typet &type) { if(type.id()==ID_pointer) { const pointer_typet &pt=to_pointer_type(type); const typet &subtype=pt.subtype(); return is_java_string_type(subtype); } return false; }
typet fence_insertert::type_component(std::list<std::string>::const_iterator it, std::list<std::string>::const_iterator end, const typet& type) { if(it==end) return type; if(type.id()==ID_struct) { const struct_union_typet& str=to_struct_union_type(type); typet comp_type=str.component_type(*it); ++it; return type_component(it, end, comp_type); } if(type.id()==ID_symbol) { return type; } assert(0); }