Go to the documentation of this file.
26 return expr2c(expr, *
this);
31 return type2c(type, *
this);
42 error() <<
"failed to move symbol '" << symbol.
name <<
"' into symbol table"
50 bool is_function=symbol.
type.
id()==ID_code;
78 warning() <<
"`extern' symbol should not have an initializer" <<
eom;
81 else if(!is_function && symbol.
value.
id()==ID_code)
84 error() <<
"only functions can have a function body" <<
eom;
89 if(symbol.
is_type && final_type.
id() == ID_struct)
93 else if(symbol.
is_type && final_type.
id() == ID_union)
97 else if(symbol.
is_type && final_type.
id() == ID_c_enum)
107 symbol_tablet::symbolst::const_iterator old_it=
120 if(old_it->second.is_type!=symbol.
is_type)
124 <<
"' as a different kind of symbol" <<
eom;
143 if(symbol.
type.
id()==ID_code)
154 parameter.set_identifier(
irep_idt());
173 (final_old.
id() == ID_struct &&
175 (final_old.
id() == ID_union &&
to_union_type(final_old).is_incomplete()) ||
180 final_new.
id() == final_old.
id() &&
181 ((final_new.
id() == ID_struct &&
183 (final_new.
id() == ID_union &&
185 (final_new.
id() == ID_c_enum &&
199 error() <<
"conflicting definition of type symbol '"
208 (final_new.
id() == ID_struct &&
210 (final_new.
id() == ID_union &&
212 (final_new.
id() == ID_c_enum &&
215 if(final_old.
id() == final_new.
id())
223 error() <<
"conflicting definition of tag symbol '"
229 final_new.
id()==ID_c_enum && final_old.
id()==ID_c_enum)
235 final_new.
id()==ID_pointer && final_old.
id()==ID_pointer &&
249 <<
"' defined twice:\n"
265 if(final_old.
id()==ID_array &&
267 initial_new.
id()==ID_array &&
274 else if(final_old.
id()==ID_array &&
276 initial_new.
id()==ID_array &&
292 if(old_symbol.
type.
id()==ID_KnR)
295 if(final_new.
id()==ID_code)
298 error() <<
"function type not allowed for K&R function parameter"
308 if(final_new.
id()==ID_code)
310 if(final_old.
id()!=ID_code)
314 <<
"' redefined with a different type:\n"
357 for(
const auto &old_parameter : old_ct.
parameters())
359 const irep_idt &identifier = old_parameter.get_identifier();
361 symbol_tablet::symbolst::const_iterator p_s_it=
371 <<
"' defined twice" <<
eom;
405 if(final_old!=final_new)
407 if(final_old.
id()==ID_array &&
409 final_new.
id()==ID_array &&
416 final_old.
id() == ID_pointer && final_old.
subtype().
id() == ID_code &&
418 final_new.
id() == ID_pointer && final_new.
subtype().
id() == ID_code)
426 final_old.
id() == ID_pointer && final_old.
subtype().
id() == ID_code &&
427 final_new.
id() == ID_pointer && final_new.
subtype().
id() == ID_code &&
438 <<
"' redefined with a different type:\n"
466 new_symbol.
is_macro && final_new.
id() == ID_c_enum &&
476 <<
"' already has an initial value" <<
eom;
515 unsigned anon_counter=0;
521 if(p.get_base_name().empty())
524 p.set_base_name(base_name);
528 irep_idt base_name = p.get_base_name();
531 p.set_identifier(identifier);
535 p_symbol.
type = p.type();
536 p_symbol.
name=identifier;
538 p_symbol.
location = p.source_location();
553 error() <<
"branching label '" << label.first
554 <<
"' is not defined in function" <<
eom;
569 if(!asm_label.
empty() &&
573 symbol.
name=asm_label;
577 if(symbol.
name!=orig_name)
580 std::make_pair(orig_name, asm_label)).second)
585 error() <<
"error: replacing asm renaming "
592 else if(asm_label.
empty())
594 asm_label_mapt::const_iterator entry=
598 symbol.
name=entry->second;
603 if(symbol.
name!=orig_name &&
604 symbol.
type.
id()==ID_code &&
611 const irep_idt &p_bn = p.get_base_name();
619 std::make_pair(p_id, p_new_id)).second)
649 contract.
add(ID_C_spec_assigns).
swap(spec_assigns);
652 contract.
add(ID_C_spec_ensures).
swap(spec_ensures);
655 contract.
add(ID_C_spec_requires).
swap(spec_requires);
662 full_spec|=c_storage_spec;
674 declaration.
to_symbol(declarator, symbol);
685 error() <<
"alias attribute cannot be used with a body"
708 if(asm_name[0] ==
'.')
712 if(primary_section != std::string::npos)
713 asm_name.resize(primary_section);
727 declarator.set_name(identifier);
743 static_cast<codet &
>(contract), ID_C_spec_assigns);
747 if(new_symbol.
type.
id()==ID_code)
750 if(ret_type.
id()!=ID_empty)
755 irept assigns_to_add = contract.
find(ID_C_spec_assigns);
757 new_symbol.
type.
add(ID_C_spec_assigns) = assigns_to_add;
758 irept requires_to_add = contract.
find(ID_C_spec_requires);
760 new_symbol.
type.
add(ID_C_spec_requires) = requires_to_add;
761 irept ensures_to_add = contract.
find(ID_C_spec_ensures);
763 new_symbol.
type.
add(ID_C_spec_ensures) = ensures_to_add;
virtual void do_initializer(exprt &initializer, const typet &type, bool force_constant)
virtual void typecheck_assigns_exprs(codet &code, const irep_idt &spec)
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
void typecheck_new_symbol(symbolt &symbol)
bool has_ellipsis() const
const exprt & spec_requires() const
const typet & subtype() const
const declaratorst & declarators() const
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
const irep_idt & display_name() const
Return language specific display name if present.
const c_enum_typet & to_c_enum_type(const typet &type)
Cast a typet to a c_enum_typet.
The type of an expression, extends irept.
ANSI-C Language Type Checking.
void typecheck_declaration(ansi_c_declarationt &)
virtual std::string to_string(const exprt &expr)
typet type
Type of symbol.
irept & add(const irep_namet &name)
static symbol_exprt typeless(const irep_idt &id)
Generate a symbol_exprt without a proper type.
const irept & find(const irep_namet &name) const
Base class for all expressions.
irep_idt base_name
Base (non-scoped) name.
void move_symbol(symbolt &symbol, symbolt *&new_symbol)
virtual void typecheck_type(typet &type)
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
virtual void typecheck_spec_expr(codet &code, const irep_idt &spec)
struct configt::ansi_ct ansi_c
bool get_is_static_assert() const
void set_is_typedef(bool is_typedef)
irep_idt pretty_name
Language-specific display name.
const codet & to_code(const exprt &expr)
const binary_exprt & to_binary_expr(const exprt &expr)
Cast an exprt to a binary_exprt.
void typecheck_redefinition_non_type(symbolt &old_symbol, symbolt &new_symbol)
typet & type()
Return the type of the expression.
bool get_bool(const irep_namet &name) const
bool can_cast_type< code_typet >(const typet &type)
Check whether a reference to a typet is a code_typet.
asm_label_mapt asm_label_map
virtual void typecheck_assigns(const code_typet &function_declarator, const irept &spec)
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
irep_idt mode
Language mode.
void set_is_register(bool is_register)
void typecheck_function_body(symbolt &symbol)
symbolt & get_writeable_ref(const irep_idt &name)
Find a symbol in the symbol table for read-write access.
const std::string & id2string(const irep_idt &d)
void set_is_weak(bool is_weak)
source_locationt source_location
std::string expr2c(const exprt &expr, const namespacet &ns, const expr2c_configurationt &configuration)
void typecheck_symbol(symbolt &symbol)
const source_locationt & find_source_location() const
Get a source_locationt from the expression or from its operands (non-recursively).
void set_inlined(bool value)
void to_symbol(const ansi_c_declaratort &, symbolt &symbol) const
symbol_tablet & symbol_table
virtual void typecheck_code(codet &code)
const irep_idt & id() const
void typecheck_redefinition_type(symbolt &old_symbol, symbolt &new_symbol)
const exprt & spec_assigns() const
const parameterst & parameters() const
id_type_mapt parameter_map
std::map< irep_idt, source_locationt > labels_used
virtual bool move(symbolt &symbol, symbolt *&new_symbol) override
Move a symbol into the symbol table.
virtual void typecheck_expr(exprt &expr)
const exprt & spec_ensures() const
void set_is_thread_local(bool is_thread_local)
exprt value
Initial value of symbol.
void set_is_static(bool is_static)
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
const irep_idt & get(const irep_namet &name) const
source_locationt location
Source code location of definition of symbol.
std::map< irep_idt, source_locationt > labels_defined
const symbolst & symbols
Read-only field, used to look up symbols given their names.
bool is_constant() const
Return whether the expression is a constant.
void set_is_extern(bool is_extern)
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
typet full_type(const ansi_c_declaratort &) const
static void make_already_typechecked(typet &type)
const typet & return_type() const
There are a large number of kinds of tree structured or tree-like data in CPROVER.
virtual void erase(const symbolst::const_iterator &entry) override
Remove a symbol from the symbol table.
std::string type2c(const typet &type, const namespacet &ns, const expr2c_configurationt &configuration)
Symbol table entry of function parameterThis is a symbol generated as part of type checking.
const union_typet & to_union_type(const typet &type)
Cast a typet to a union_typet.
unsignedbv_typet size_type()
irep_idt module
Name of module the symbol belongs to.
mstreamt & warning() const
irep_idt name
The unique identifier.
void apply_asm_label(const irep_idt &asm_label, symbolt &symbol)
void set_is_inline(bool is_inline)
void set_is_used(bool is_used)
virtual void adjust_function_parameter(typet &type) const
Data structure for representing an arbitrary statement in a program.