25 return expr2c(expr, *
this);
30 return type2c(type, *
this);
41 error() <<
"failed to move symbol `" << symbol.
name 42 <<
"' into symbol table" <<
eom;
49 bool is_function=symbol.
type.
id()==ID_code;
71 else if(!is_function && symbol.
value.
id()==ID_code)
74 error() <<
"only functions can have a function body" <<
eom;
80 (final_type.
id()==ID_struct ||
81 final_type.
id()==ID_incomplete_struct))
86 (final_type.
id()==ID_union ||
87 final_type.
id()==ID_incomplete_union))
92 (final_type.
id()==ID_c_enum ||
93 final_type.
id()==ID_incomplete_c_enum))
103 symbol_tablet::symbolst::const_iterator old_it=
116 if(old_it->second.is_type!=symbol.
is_type)
120 <<
"' as a different kind of symbol" <<
eom;
139 if(symbol.
type.
id()==ID_code)
148 for(code_typet::parameterst::iterator
170 if(final_old.
id()==ID_incomplete_struct ||
171 final_old.
id()==ID_incomplete_union ||
172 final_old.
id()==ID_incomplete_c_enum)
188 error() <<
"conflicting definition of type symbol `" 197 if(final_new.
id()==ID_incomplete_struct ||
198 final_new.
id()==ID_incomplete_union ||
199 final_new.
id()==ID_incomplete_c_enum)
209 error() <<
"conflicting definition of tag symbol `" 216 final_new.
id()==ID_c_enum && final_old.
id()==ID_c_enum)
222 final_new.
id()==ID_pointer && final_old.
id()==ID_pointer &&
235 error() <<
"type symbol `" 252 if(final_old.
id()==ID_array &&
254 initial_new.
id()==ID_array &&
261 else if(final_old.
id()==ID_array &&
263 initial_new.
id()==ID_array &&
280 if(old_symbol.
type.
id()==ID_KnR)
283 if(final_new.
id()==ID_code)
286 error() <<
"function type not allowed for K&R function parameter" 296 if(final_new.
id()==ID_code)
302 if(final_old.
id()!=ID_code)
305 error() <<
"error: function symbol `" 307 <<
"' redefined with a different type:\n" 323 old_symbol.
type.
set(ID_C_inlined,
true);
324 new_symbol.
type.
set(ID_C_inlined,
true);
349 for(code_typet::parameterst::const_iterator
354 const irep_idt &identifier=p_it->get_identifier();
356 symbol_tablet::symbolst::const_iterator p_s_it=
366 <<
"' defined twice" <<
eom;
400 if(final_old!=final_new)
402 if(final_old.
id()==ID_array &&
404 final_new.
id()==ID_array &&
412 else if((final_old.
id()==ID_incomplete_c_enum ||
413 final_old.
id()==ID_c_enum) &&
414 (final_new.
id()==ID_incomplete_c_enum ||
415 final_new.
id()==ID_c_enum))
419 else if(final_old.
id()==ID_pointer &&
422 final_new.
id()==ID_pointer &&
430 else if(final_old.
id()==ID_pointer &&
432 final_new.
id()==ID_pointer &&
444 <<
"' redefined with a different type:\n" 472 (final_new.
id()==ID_incomplete_c_enum ||
473 final_new.
id()==ID_c_enum) &&
484 <<
"' already has an initial value" <<
eom;
523 unsigned anon_counter=0;
527 for(code_typet::parameterst::iterator
528 p_it=parameters.begin();
529 p_it!=parameters.end();
533 if(p_it->get_base_name().empty())
536 p_it->set_base_name(base_name);
540 irep_idt base_name=p_it->get_base_name();
543 p_it->set_identifier(identifier);
547 p_symbol.
type=p_it->type();
548 p_symbol.
name=identifier;
550 p_symbol.
location=p_it->source_location();
560 if(symbol.
name==ID_main)
564 for(std::map<irep_idt, source_locationt>::const_iterator
570 error() <<
"branching label `" << it->first
571 <<
"' is not defined in function" <<
eom;
586 if(!asm_label.
empty() &&
590 symbol.
name=asm_label;
594 if(symbol.
name!=orig_name)
597 std::make_pair(orig_name, asm_label)).second)
602 error() <<
"error: replacing asm renaming " 609 else if(asm_label.
empty())
611 asm_label_mapt::const_iterator entry=
615 symbol.
name=entry->second;
620 if(symbol.
name!=orig_name &&
621 symbol.
type.
id()==ID_code &&
626 for(code_typet::parameterst::const_iterator
631 const irep_idt &p_bn=p_it->get_base_name();
639 std::make_pair(p_id, p_new_id)).second)
650 assert(declaration.
operands().size()==2);
669 static_cast<const exprt&
>(declaration.
find(ID_C_spec_requires));
670 contract.
add(ID_C_spec_requires).
swap(spec_requires);
673 static_cast<const exprt&
>(declaration.
find(ID_C_spec_ensures));
674 contract.
add(ID_C_spec_ensures).
swap(spec_ensures);
678 for(ansi_c_declarationt::declaratorst::iterator
684 full_spec|=c_storage_spec;
702 if(!full_spec.alias.empty())
707 error() <<
"alias attribute cannot be used with a body" 715 const auto &renaming_entry =
asm_label_map.find(full_spec.alias);
723 if(full_spec.section.empty())
728 std::string asm_name =
id2string(full_spec.section);
730 if(asm_name[0] ==
'.')
734 if(primary_section != std::string::npos)
735 asm_name.resize(primary_section);
740 if(!full_spec.asm_label.empty())
741 asm_name+=
id2string(full_spec.asm_label);
749 d_it->set_name(identifier);
761 if(new_symbol.
type.
id()==ID_code)
764 if(ret_type.
id()!=ID_empty)
769 if(contract.find(ID_C_spec_requires).is_not_nil())
770 new_symbol.
type.
add(ID_C_spec_requires)=
771 contract.
find(ID_C_spec_requires);
772 if(contract.find(ID_C_spec_ensures).is_not_nil())
773 new_symbol.
type.
add(ID_C_spec_ensures)=
774 contract.
find(ID_C_spec_ensures);
void typecheck_redefinition_type(symbolt &old_symbol, symbolt &new_symbol)
bool get_is_static_assert() const
The type of an expression.
irep_idt name
The unique identifier.
std::map< irep_idt, source_locationt > labels_used
struct configt::ansi_ct ansi_c
virtual void typecheck_spec_expr(codet &code, const irep_idt &spec)
void typecheck_declaration(ansi_c_declarationt &)
const std::string & id2string(const irep_idt &d)
asm_label_mapt asm_label_map
Symbol table entry of function parameterThis is a symbol generated as part of type checking...
void set_is_used(bool is_used)
irep_idt mode
Language mode.
void move_symbol(symbolt &symbol, symbolt *&new_symbol)
bool has_ellipsis() const
const code_typet & to_code_type(const typet &type)
Cast a generic typet to a code_typet.
std::vector< parametert > parameterst
exprt value
Initial value of symbol.
id_type_mapt parameter_map
void to_symbol(const ansi_c_declaratort &, symbolt &symbol) const
irep_idt module
Name of module the symbol belongs to.
irep_idt pretty_name
Language-specific display name.
unsignedbv_typet size_type()
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)
typet full_type(const ansi_c_declaratort &) const
symbol_tablet & symbol_table
mstreamt & warning() const
void set_is_weak(bool is_weak)
virtual symbolt * get_writeable(const irep_idt &name) override
Find a symbol in the symbol table for read-write access.
const irep_idt & id() const
void set_is_thread_local(bool is_thread_local)
const declaratorst & declarators() const
void typecheck_new_symbol(symbolt &symbol)
void apply_asm_label(const irep_idt &asm_label, symbolt &symbol)
ANSI-C Language Type Checking.
virtual bool move(symbolt &symbol, symbolt *&new_symbol) override
Move a symbol into the symbol table.
const source_locationt & find_source_location() const
void make_already_typechecked(typet &dest)
source_locationt source_location
const irep_idt & get(const irep_namet &name) const
#define PRECONDITION(CONDITION)
std::string type2c(const typet &type, const namespacet &ns)
const exprt & size() const
virtual void typecheck_expr(exprt &expr)
void set_is_register(bool is_register)
const typet & follow(const typet &) const
dstringt has one field, an unsigned integer no which is an index into a static table of strings...
virtual void erase(const symbolst::const_iterator &entry) override
Remove a symbol from the symbol table.
void typecheck_redefinition_non_type(symbolt &old_symbol, symbolt &new_symbol)
virtual void adjust_function_parameter(typet &type) const
const irep_idt & display_name() const
void set_is_static(bool is_static)
typet type
Type of symbol.
source_locationt location
Source code location of definition of symbol.
void set_is_extern(bool is_extern)
const array_typet & to_array_type(const typet &type)
Cast a generic typet to an array_typet.
Base class for all expressions.
void add_argc_argv(const symbolt &main_symbol)
const parameterst & parameters() const
irep_idt base_name
Base (non-scoped) name.
std::string to_string(const string_constraintt &expr)
Used for debug printing.
irept & add(const irep_namet &name)
std::map< irep_idt, source_locationt > labels_defined
std::string expr2c(const exprt &expr, const namespacet &ns)
void typecheck_symbol(symbolt &symbol)
const std::string & id_string() const
const codet & to_code(const exprt &expr)
void set_is_typedef(bool is_typedef)
void typecheck_function_body(symbolt &symbol)
Expression to hold a symbol (variable)
virtual void typecheck_type(typet &type)
virtual void do_initializer(exprt &initializer, const typet &type, bool force_constant)
A statement in a programming language.
void set_is_inline(bool is_inline)
const typet & subtype() const
const irept & find(const irep_namet &name) const
const typet & return_type() const
void set(const irep_namet &name, const irep_idt &value)
virtual void typecheck_code(codet &code)