34 if(type.
id()==ID_array)
38 assert(result_type.
id()==ID_array &&
42 if(result.
id()!=ID_array)
62 if(full_type.
id()==ID_incomplete_struct)
66 <<
"' is still incomplete -- cannot initialize" <<
eom;
70 if(value.
id()==ID_initializer_list)
73 if(value.
id()==ID_array &&
74 value.
get_bool(ID_C_string_constant) &&
75 full_type.
id()==ID_array &&
77 full_type.
subtype().
id()==ID_unsignedbv) &&
88 if(full_type.
id()==ID_array &&
96 error() <<
"array size needs to be constant, got " 104 error() <<
"array size must not be negative" <<
eom;
131 if(value.
id()==ID_string_constant &&
132 full_type.
id()==ID_array &&
133 (full_type.
subtype().
id()==ID_signedbv ||
134 full_type.
subtype().
id()==ID_unsignedbv) &&
145 if(full_type.
id()==ID_array &&
153 error() <<
"array size needs to be constant, got " 161 error() <<
"array size must not be negative" <<
eom;
188 if(full_type.
id()==ID_array &&
193 <<
"' cannot be initialized with `" <<
to_string(value)
198 if(value.
id()==ID_designated_initializer)
202 <<
"' cannot be initialized with designated initializer" 263 if(full_type.
id()==ID_struct)
272 for(struct_typet::componentst::const_iterator
277 if(it->type().id()!=ID_code &&
278 !it->get_is_padding())
287 else if(full_type.
id()==ID_union)
304 else if(full_type.
id()==ID_array)
320 error() <<
"array has non-constant size `" 329 else if(full_type.
id()==ID_vector)
338 error() <<
"vector has non-constant size `" 357 const exprt &initializer_list,
358 exprt::operandst::const_iterator init_it,
362 exprt value=*init_it;
364 assert(!designator.
empty());
366 if(value.
id()==ID_designated_initializer)
372 designator.front().type,
373 static_cast<const exprt &
>(value.
find(ID_designator)));
375 assert(!designator.empty());
379 result, designator, value, value.
operands().begin(), force_constant);
387 for(
size_t i=0; i<designator.
size(); i++)
389 size_t index=designator[i].index;
390 const typet &type=designator[i].type;
393 if(full_type.
id()==ID_array ||
394 full_type.
id()==ID_vector)
398 if(full_type.
id()==ID_array &&
416 error() <<
"array index designator " << index
417 <<
" out of bounds (" << dest->
operands().size()
425 else if(full_type.
id()==ID_struct)
433 error() <<
"structure member designator " << index
434 <<
" out of bounds (" << dest->
operands().size()
439 assert(index<components.size());
440 assert(components[index].type().
id()!=ID_code &&
441 !components[index].get_is_padding());
445 else if(full_type.
id()==ID_union)
452 assert(index<components.size());
456 if(dest->
id()==ID_union &&
457 dest->
get(ID_component_name)==component.get_name())
493 assert(full_type.
id()!=ID_symbol);
496 if(full_type.
id()!=ID_struct &&
497 full_type.
id()!=ID_union &&
498 full_type.
id()!=ID_array &&
499 full_type.
id()!=ID_vector)
504 if(value.
id()==ID_initializer_list &&
517 if(full_type.
id()==ID_union)
524 if(!components.empty())
543 if(value.
id()==ID_initializer_list)
548 else if(value.
id()==ID_string_constant)
553 if(full_type.
id()==ID_array &&
566 if(full_type.
id()==ID_struct ||
567 full_type.
id()==ID_union ||
568 full_type.
id()==ID_vector)
575 assert(full_type.
id()==ID_struct ||
576 full_type.
id()==ID_union ||
577 full_type.
id()==ID_array ||
578 full_type.
id()==ID_vector);
582 const typet dest_type=full_type;
591 warning() <<
"initialisation of " << full_type.
id()
592 <<
" requires initializer list, found " 593 << value.
id() <<
" instead" <<
eom;
598 dest_type.id()==ID_array &&
602 value.
id(ID_initializer_list);
604 for( ; init_it!=initializer_list.
operands().end(); ++init_it)
613 error() <<
"cannot initialize type `" 614 <<
to_string(dest_type) <<
"' using value `" 630 assert(!designator.
empty());
639 if(full_type.
id()==ID_array &&
643 if(full_type.
id()==ID_struct &&
651 assert(components.size()==entry.
size);
655 (components[entry.
index].get_is_padding() ||
656 components[entry.
index].type().id()==ID_code))
666 if(designator.
size()==1)
672 assert(!designator.
empty());
677 const typet &src_type,
687 const exprt &d_op=*it;
691 if(full_type.
id()==ID_array)
693 if(d_op.
id()!=ID_index)
696 error() <<
"expected array index designator" <<
eom;
709 error() <<
"expected constant array index designator" <<
eom;
718 error() <<
"expected constant array size" <<
eom;
726 else if(full_type.
id()==ID_struct ||
727 full_type.
id()==ID_union)
732 if(d_op.
id()!=ID_member)
735 error() <<
"expected member designator" <<
eom;
739 const irep_idt &component_name=d_op.
get(ID_component_name);
753 bool found=
false, repeat;
763 for(struct_union_typet::componentst::const_iterator
764 c_it=components.begin();
765 c_it!=components.end();
768 if(c_it->get_name()==component_name)
772 entry.
size=components.size();
776 else if(c_it->get_anonymous() &&
777 (
follow(c_it->type()).
id()==ID_struct ||
778 follow(c_it->type()).
id()==ID_union) &&
780 c_it->type(), component_name, *
this))
783 entry.
size=components.size();
798 error() <<
"failed to find struct component `" 799 << component_name <<
"' in initialization of `" 808 error() <<
"designated initializers cannot initialize `" 817 assert(!designator.
empty());
827 assert(value.
id()==ID_initializer_list);
832 if(full_type.id()==ID_struct ||
833 full_type.id()==ID_union ||
834 full_type.id()==ID_vector)
841 else if(full_type.id()==ID_array)
846 result=
exprt(ID_array, full_type);
860 value.
op0().
id()==ID_string_constant &&
861 (full_type.subtype().id()==ID_signedbv ||
862 full_type.subtype().id()==ID_unsignedbv) &&
863 full_type.subtype().get(ID_width)==
char_type().
get(ID_width))
868 warning() <<
"ignoring excess initializers" <<
eom;
884 <<
"' with an initializer list" <<
eom;
893 for(exprt::operandst::const_iterator it=operands.begin();
894 it!=operands.end(); )
897 result, current_designator, value, it, force_constant);
904 if(full_type.id()==ID_struct)
910 if(full_type.id()==ID_array &&
914 size_t size=result.
operands().size();
915 result.
type().
id(ID_array);
const irep_idt & get_name() const
The type of an expression.
irep_idt name
The unique identifier.
const typet & follow(const typet &src) const
Linking: Zero Initialization.
const std::string & id2string(const irep_idt &d)
virtual void make_constant(exprt &expr)
const union_typet & to_union_type(const typet &type)
Cast a generic typet to a union_typet.
void copy_to_operands(const exprt &expr)
std::vector< componentt > componentst
void push_entry(const entryt &entry)
exprt value
Initial value of symbol.
const componentst & components() const
bool has_component_rec(const typet &type, const irep_idt &component_name, const namespacet &ns)
Symbol table entry.This is a symbol in the symbol table, stored in an object of type symbol_tablet...
static mstreamt & eom(mstreamt &m)
bool get_bool(const irep_namet &name) const
virtual std::string to_string(const exprt &expr)
virtual exprt::operandst::const_iterator do_designated_initializer(exprt &result, designatort &designator, const exprt &initializer_list, exprt::operandst::const_iterator init_it, bool force_constant)
const struct_union_typet & to_struct_union_type(const typet &type)
Cast a generic typet to a struct_union_typet.
const irep_idt & id() const
const array_typet & to_array_type(const typet &type)
Cast a generic typet to an array_typet.
exprt zero_initializer(const typet &type, const source_locationt &source_location, const namespacet &ns, message_handlert &message_handler)
ANSI-C Language Type Checking.
const entryt & back() const
const source_locationt & find_source_location() const
source_locationt source_location
A constant-size array type.
union constructor from single element
const irep_idt & get(const irep_namet &name) const
void increment_designator(designatort &designator)
const exprt & size() const
const exprt & size() const
virtual void typecheck_expr(exprt &expr)
#define forall_operands(it, expr)
void err_location(const source_locationt &loc)
array_exprt to_array_expr() const
convert string into array constant
bitvector_typet index_type()
void designator_enter(const typet &type, designatort &designator)
virtual exprt do_initializer_rec(const exprt &value, const typet &type, bool force_constant)
initialize something of type `type' with given value `value'
bool has_component(const irep_idt &component_name) const
std::vector< exprt > operandst
bool has_prefix(const std::string &s, const std::string &prefix)
const struct_typet & to_struct_type(const typet &type)
Cast a generic typet to a struct_typet.
virtual void implicit_typecast(exprt &expr, const typet &type)
typet type
Type of symbol.
message_handlert & get_message_handler()
Base type of C structs and unions, and C++ classes.
const string_constantt & to_string_constant(const exprt &expr)
Base class for all expressions.
std::size_t component_number(const irep_idt &component_name) const
const source_locationt & source_location() const
virtual void make_constant_index(exprt &expr)
designatort make_designator(const typet &type, const exprt &src)
virtual exprt do_initializer_list(const exprt &value, const typet &type, bool force_constant)
#define Forall_operands(it, expr)
void set_component_name(const irep_idt &component_name)
source_locationt & add_source_location()
virtual void do_initializer(exprt &initializer, const typet &type, bool force_constant)
std::size_t integer2size_t(const mp_integer &n)
const typet & subtype() const
const vector_typet & to_vector_type(const typet &type)
Cast a generic typet to a vector_typet.
const irept & find(const irep_namet &name) const
bitvector_typet char_type()
void set(const irep_namet &name, const irep_idt &value)
C Language Type Checking.