exprt gen_one(const typet &type) { const std::string &type_id=type.id_string(); exprt result=exprt("constant", type); if(type_id=="bool" || type_id=="rational" || type_id=="real" || type_id=="integer" || type_id=="natural" || type_id=="complex") { result.value("1"); } else if(type_id=="unsignedbv" || type_id=="signedbv") { std::string value; for(int i=0; i<atoi(type.width().c_str())-1; i++) value+='0'; value+='1'; result.value(value); } else if(type_id=="fixedbv") { fixedbvt fixedbv; fixedbv.spec=to_fixedbv_type(type); fixedbv.from_integer(1); result=fixedbv.to_expr(); } else if(type_id=="floatbv") { std::cerr << "floatbv unsupported, sorry" << std::endl; abort(); } else result.make_nil(); return result; }
void ansi_c_convert_typet::write(typet &type) { type.clear(); // first, do "other" if(!other.empty()) { if( double_cnt || float_cnt || signed_cnt || unsigned_cnt || int_cnt || bool_cnt || short_cnt || char_cnt || int8_cnt || int16_cnt || int32_cnt || int64_cnt || ptr32_cnt || ptr64_cnt || long_cnt) { err_location(location); error("illegal type modifier for defined type"); throw 0; } if(other.size() != 1) { err_location(location); error("illegal combination of defined types"); throw 0; } type.swap(other.front()); } else if(double_cnt || float_cnt) { if( signed_cnt || unsigned_cnt || int_cnt || bool_cnt || int8_cnt || int16_cnt || int32_cnt || int64_cnt || ptr32_cnt || ptr64_cnt || short_cnt || char_cnt) { err_location(location); error("cannot conbine integer type with float"); throw 0; } if(double_cnt && float_cnt) { err_location(location); error("conflicting type modifiers"); throw 0; } if(long_cnt == 0) { if(double_cnt != 0) type = double_type(); else type = float_type(); } else if(long_cnt == 1 || long_cnt == 2) { if(double_cnt != 0) type = long_double_type(); else { err_location(location); error("conflicting type modifiers"); throw 0; } } else { err_location(location); error("illegal type modifier for float"); throw 0; } } else if(bool_cnt) { if( signed_cnt || unsigned_cnt || int_cnt || short_cnt || int8_cnt || int16_cnt || int32_cnt || int64_cnt || ptr32_cnt || ptr64_cnt || char_cnt || long_cnt) { err_location(location); error("illegal type modifier for boolean type"); throw 0; } type.id("bool"); } else if(ptr32_cnt || ptr64_cnt) { type.id("pointer"); type.subtype() = typet("empty"); } else { // it is integer -- signed or unsigned? if(signed_cnt && unsigned_cnt) { err_location(location); error("conflicting type modifiers"); throw 0; } if(unsigned_cnt) type.id("unsignedbv"); else if(signed_cnt) type.id("signedbv"); else { if(char_cnt) type.id(config.ansi_c.char_is_unsigned ? "unsignedbv" : "signedbv"); else type.id("signedbv"); } // get width unsigned width; if(int8_cnt || int16_cnt || int32_cnt || int64_cnt) { if(long_cnt || char_cnt || short_cnt) { err_location(location); error("conflicting type modifiers"); throw 0; } if(int8_cnt) width = 1 * 8; else if(int16_cnt) width = 2 * 8; else if(int32_cnt) width = 4 * 8; else if(int64_cnt) width = 8 * 8; else abort(); } else if(short_cnt) { if(long_cnt || char_cnt) { err_location(location); error("conflicting type modifiers"); throw 0; } width = config.ansi_c.short_int_width; } else if(char_cnt) { if(long_cnt) { err_location(location); error("illegal type modifier for char type"); throw 0; } width = config.ansi_c.char_width; } else if(long_cnt == 0) { width = config.ansi_c.int_width; } else if(long_cnt == 1) { width = config.ansi_c.long_int_width; } else if(long_cnt == 2) { width = config.ansi_c.long_long_int_width; } else { err_location(location); error("illegal type modifier for integer type"); throw 0; } type.width(width); } c_qualifiers.write(type); }
unsigned bv_width(const typet &type) { return atoi(type.width().c_str()); }