void c_typecheck_baset::designator_enter( const typet &type, designatort &designator) { designatort::entryt entry; entry.type=type; assert(entry.type.id()!=ID_symbol); if(entry.type.id()==ID_struct) { entry.size=to_struct_type(entry.type).components().size(); if(entry.size!=0) entry.subtype=to_struct_type(entry.type).components().front().type(); else entry.subtype.make_nil(); } else if(entry.type.id()==ID_union) { if(to_union_type(entry.type).components().empty()) { entry.size=0; entry.subtype.make_nil(); } else { entry.size=1; entry.subtype=to_union_type(entry.type).components().front().type(); } } else if(entry.type.id()==ID_array) { mp_integer array_size; if(to_integer(to_array_type(entry.type).size(), array_size)) { err_location(to_array_type(entry.type).size()); str << "array has non-constant size `" << to_string(to_array_type(entry.type).size()) << "'"; throw 0; } entry.size=integer2long(array_size); entry.subtype=entry.type.subtype(); } else if(entry.type.id()==ID_incomplete_array) { entry.size=0; entry.subtype=entry.type.subtype(); } else assert(false); designator.push_entry(entry); }
void c_typecheck_baset::designator_enter( const typet &type, designatort &designator) { designatort::entryt entry; entry.type=type; entry.index=0; const typet &full_type=follow(type); if(full_type.id()==ID_struct) { const struct_typet &struct_type=to_struct_type(full_type); entry.size=struct_type.components().size(); entry.subtype.make_nil(); for(struct_typet::componentst::const_iterator it=struct_type.components().begin(); it!=struct_type.components().end(); ++it) { if(it->type().id()!=ID_code && !it->get_is_padding()) { entry.subtype=it->type(); break; } ++entry.index; } } else if(full_type.id()==ID_union) { const union_typet &union_type=to_union_type(full_type); if(union_type.components().empty()) { entry.size=0; entry.subtype.make_nil(); } else { // The default is to unitialize using the first member of the // union. entry.size=1; entry.subtype=union_type.components().front().type(); } } else if(full_type.id()==ID_array) { const array_typet &array_type=to_array_type(full_type); if(array_type.size().is_nil()) { entry.size=0; entry.subtype=array_type.subtype(); } else { mp_integer array_size; if(to_integer(array_type.size(), array_size)) { err_location(array_type.size()); error() << "array has non-constant size `" << to_string(array_type.size()) << "'" << eom; throw 0; } entry.size=integer2size_t(array_size); entry.subtype=array_type.subtype(); } } else if(full_type.id()==ID_vector) { const vector_typet &vector_type=to_vector_type(full_type); mp_integer vector_size; if(to_integer(vector_type.size(), vector_size)) { err_location(vector_type.size()); error() << "vector has non-constant size `" << to_string(vector_type.size()) << "'" << eom; throw 0; } entry.size=integer2size_t(vector_size); entry.subtype=vector_type.subtype(); } else assert(false); designator.push_entry(entry); }