void irept::move_to_sub(irept &irep) { #ifdef SHARING detatch(); #endif get_sub().push_back(get_nil_irep()); get_sub().back().swap(irep); }
const irept &irept::find(const irep_namet &name) const { const named_subt &s= is_comment(name)?get_comments():get_named_sub(); #ifdef SUB_IS_LIST named_subt::const_iterator it=named_subt_lower_bound(s, name); if(it==s.end() || it->first!=name) return get_nil_irep(); #else named_subt::const_iterator it=s.find(name); if(it==s.end()) return get_nil_irep(); #endif return it->second; }
const irept &irept::find(const irep_namet &name) const { const named_subt &s= is_comment(name)?get_comments():get_named_sub(); named_subt::const_iterator it=s.find(name); if(it==s.end()) return get_nil_irep(); return it->second; }
cpp_idt::cpp_idt(): is_member(false), is_method(false), is_static_member(false), is_scope(false), is_constructor(false), id_class(UNKNOWN), this_expr(static_cast<const exprt &>(get_nil_irep())), compound_counter(0), parent(NULL) { }
const struct_union_typet::componentt &struct_union_typet::get_component( const irep_idt &component_name) const { const componentst &c=components(); for(componentst::const_iterator it=c.begin(); it!=c.end(); it++) { if(it->get_name()==component_name) return *it; } return static_cast<const componentt &>(get_nil_irep()); }
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()); }
exprt static_analysis_baset::get_return_lhs(locationt to) { // get predecessor of "to" to--; if(to->is_end_function()) return static_cast<const exprt &>(get_nil_irep()); // must be the function call assert(to->is_function_call()); const code_function_callt &code= to_code_function_call(to->code); return code.lhs(); }
exprt flow_insensitive_abstract_domain_baset::get_return_lhs(locationt to) const { // get predecessor of "to" to--; if(to->is_end_function()) return static_cast<const exprt &>(get_nil_irep()); // must be the function call assert(to->is_function_call()); const code_function_callt &code= to_code_function_call(to_code(to->code)); return code.lhs(); }
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 exprt &methods=static_cast<const exprt&>(type.find(ID_methods)); forall_operands(it, methods) { 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()); }
void ansi_c_convert_typet::read_rec(const typet &type) { if(type.id() == "merged_type") { forall_subtypes(it, type) read_rec(*it); } else if(type.id() == "signed") signed_cnt++; else if(type.id() == "unsigned") unsigned_cnt++; else if(type.id() == "volatile") c_qualifiers.is_volatile = true; else if(type.id() == "const") c_qualifiers.is_constant = true; else if(type.id() == "restricted") c_qualifiers.is_restricted = true; else if(type.id() == "char") char_cnt++; else if(type.id() == "int") int_cnt++; else if(type.id() == "int8") int8_cnt++; else if(type.id() == "int16") int16_cnt++; else if(type.id() == "int32") int32_cnt++; else if(type.id() == "int64") int64_cnt++; else if(type.id() == "ptr32") ptr32_cnt++; else if(type.id() == "ptr64") ptr64_cnt++; else if(type.id() == "short") short_cnt++; else if(type.id() == "long") long_cnt++; else if(type.id() == "double") double_cnt++; else if(type.id() == "float") float_cnt++; else if(type.is_bool()) bool_cnt++; else if(type.id() == "static") c_storage_spec.is_static = true; else if(type.id() == "inline") c_storage_spec.is_inline = true; else if(type.id() == "extern") c_storage_spec.is_extern = true; else if(type.id() == "typedef") c_storage_spec.is_typedef = true; else if(type.id() == "register") c_storage_spec.is_register = true; else if(type.id() == "auto") { // ignore } else if(type == get_nil_irep()) { // ignore } else other.push_back(type); }
void typet::move_to_subtypes(typet &type) { subtypest &sub=subtypes(); sub.push_back(static_cast<const typet &>(get_nil_irep())); sub.back().swap(type); }
exprt c_sizeoft::sizeof_rec(const typet &type) { exprt dest; if(type.id()==ID_signedbv || type.id()==ID_unsignedbv || type.id()==ID_floatbv || type.id()==ID_fixedbv || type.id()==ID_c_enum || type.id()==ID_incomplete_c_enum) { // We round up to bytes. // See special treatment for bit-fields below. unsigned bits=type.get_int(ID_width); unsigned bytes=bits/8; if((bits%8)!=0) bytes++; dest=from_integer(bytes, size_type()); } else if(type.id()==ID_pointer) { // the following is an MS extension if(type.get_bool(ID_C_ptr32)) return from_integer(4, size_type()); unsigned bits=config.ansi_c.pointer_width; unsigned bytes=bits/8; if((bits%8)!=0) bytes++; dest=from_integer(bytes, size_type()); } else if(type.id()==ID_bool) { // We fit booleans into a byte. dest=from_integer(1, size_type()); } else if(type.id()==ID_array) { const exprt &size_expr= to_array_type(type).size(); if(size_expr.is_nil()) { // treated like an empty array dest=from_integer(0, size_type()); } else { exprt tmp_dest=sizeof_rec(type.subtype()); if(tmp_dest.is_nil()) return tmp_dest; mp_integer a, b; if(!to_integer(tmp_dest, a) && !to_integer(size_expr, b)) { dest=from_integer(a*b, size_type()); } else { dest.id(ID_mult); dest.type()=size_type(); dest.copy_to_operands(size_expr); dest.move_to_operands(tmp_dest); c_implicit_typecast(dest.op0(), dest.type(), ns); c_implicit_typecast(dest.op1(), dest.type(), ns); } } } else if(type.id()==ID_struct) { const struct_typet::componentst &components= to_struct_type(type).components(); dest=from_integer(0, size_type()); mp_integer bit_field_width=0; for(struct_typet::componentst::const_iterator it=components.begin(); it!=components.end(); it++) { const typet &sub_type=ns.follow(it->type()); if(it->get_bool(ID_is_type)) { } else if(sub_type.id()==ID_code) { } else if(it->get_is_bit_field()) { // this needs to be a signedbv/unsignedbv/enum if(sub_type.id()!=ID_signedbv && sub_type.id()!=ID_unsignedbv && sub_type.id()!=ID_c_enum) return nil_exprt(); // We just sum them up. // This assumes they are properly padded. bit_field_width+=sub_type.get_int(ID_width); } else { exprt tmp=sizeof_rec(sub_type); if(tmp.is_nil()) return tmp; dest=plus_exprt(dest, tmp); } } if(bit_field_width!=0) dest=plus_exprt(dest, from_integer(bit_field_width/8, size_type())); } else if(type.id()==ID_union) { const irept::subt &components= type.find(ID_components).get_sub(); mp_integer max_size=0; forall_irep(it, components) { if(it->get_bool(ID_is_type)) continue; const typet &sub_type=static_cast<const typet &>(it->find(ID_type)); if(sub_type.id()==ID_code) { } else { exprt tmp=sizeof_rec(sub_type); if(tmp.is_nil()) return tmp; simplify(tmp, ns); mp_integer tmp_int; if(to_integer(tmp, tmp_int)) return static_cast<const exprt &>(get_nil_irep()); if(tmp_int>max_size) max_size=tmp_int; } } dest=from_integer(max_size, size_type()); } else if(type.id()==ID_symbol)