25 return expr2c(expr, *
this);
30 return type2c(type, *
this);
41 error() <<
"failed to move symbol '" << symbol.
name <<
"' into symbol table"
49 bool is_function=symbol.
type.
id()==ID_code;
77 warning() <<
"`extern' symbol should not have an initializer" <<
eom;
80 else if(!is_function && symbol.
value.
id()==ID_code)
83 error() <<
"only functions can have a function body" <<
eom;
88 if(symbol.
is_type && final_type.
id() == ID_struct)
92 else if(symbol.
is_type && final_type.
id() == ID_union)
96 else if(symbol.
is_type && final_type.
id() == ID_c_enum)
108 error() <<
"void-typed symbol not permitted" <<
eom;
113 symbol_tablet::symbolst::const_iterator old_it=
126 if(old_it->second.is_type!=symbol.
is_type)
130 <<
"' as a different kind of symbol" <<
eom;
149 if(symbol.
type.
id()==ID_code)
160 parameter.set_identifier(
irep_idt());
179 (final_old.
id() == ID_struct &&
181 (final_old.
id() == ID_union &&
to_union_type(final_old).is_incomplete()) ||
186 final_new.
id() == final_old.
id() &&
187 ((final_new.
id() == ID_struct &&
189 (final_new.
id() == ID_union &&
191 (final_new.
id() == ID_c_enum &&
205 error() <<
"conflicting definition of type symbol '"
214 (final_new.
id() == ID_struct &&
216 (final_new.
id() == ID_union &&
218 (final_new.
id() == ID_c_enum &&
221 if(final_old.
id() == final_new.
id())
229 error() <<
"conflicting definition of tag symbol '"
235 final_new.
id()==ID_c_enum && final_old.
id()==ID_c_enum)
242 final_new.
id() == ID_pointer && final_old.
id() == ID_pointer &&
256 <<
"' defined twice:\n"
273 final_old.
id() == ID_array &&
275 initial_new.
id() == ID_array &&
284 final_old.
id() == ID_array &&
to_array_type(final_old).size().is_nil() &&
285 initial_new.
id() == ID_array &&
302 if(old_symbol.
type.
id()==ID_KnR)
305 if(final_new.
id()==ID_code)
308 error() <<
"function type not allowed for K&R function parameter"
318 if(final_new.
id()==ID_code)
320 if(final_old.
id()!=ID_code)
324 <<
"' redefined with a different type:\n"
367 for(
const auto &old_parameter : old_ct.
parameters())
369 const irep_idt &identifier = old_parameter.get_identifier();
371 symbol_tablet::symbolst::const_iterator p_s_it=
381 <<
"' defined twice" <<
eom;
415 if(final_old!=final_new)
418 final_old.
id() == ID_array &&
to_array_type(final_old).size().is_nil() &&
419 final_new.
id() == ID_array &&
427 final_old.
id() == ID_pointer &&
430 final_new.
id() == ID_pointer &&
439 final_old.
id() == ID_pointer &&
441 final_new.
id() == ID_pointer &&
453 <<
"' redefined with a different type:\n"
470 new_symbol.
is_macro && final_new.
id() == ID_c_enum &&
480 <<
"' already has an initial value" <<
eom;
504 if(symbol.
value.
id() != ID_code)
507 error() <<
"function '" << symbol.
name <<
"' is initialized with "
524 unsigned anon_counter=0;
530 if(p.get_base_name().empty())
533 p.set_base_name(base_name);
537 irep_idt base_name = p.get_base_name();
540 p.set_identifier(identifier);
544 p_symbol.
type = p.type();
545 p_symbol.
name=identifier;
547 p_symbol.
location = p.source_location();
562 error() <<
"branching label '" << label.first
563 <<
"' is not defined in function" <<
eom;
578 if(!asm_label.
empty() &&
582 symbol.
name=asm_label;
586 if(symbol.
name!=orig_name)
589 std::make_pair(orig_name, asm_label)).second)
594 error() <<
"error: replacing asm renaming "
601 else if(asm_label.
empty())
603 asm_label_mapt::const_iterator entry=
607 symbol.
name=entry->second;
612 if(symbol.
name!=orig_name &&
613 symbol.
type.
id()==ID_code &&
620 const irep_idt &p_bn = p.get_base_name();
628 std::make_pair(p_id, p_new_id)).second)
639 codet code(ID_static_assert);
659 full_spec|=c_storage_spec;
671 declaration.
to_symbol(declarator, symbol);
682 error() <<
"alias attribute cannot be used with a body"
705 if(asm_name[0] ==
'.')
709 if(primary_section != std::string::npos)
710 asm_name.resize(primary_section);
724 declarator.set_name(identifier);
730 if(new_symbol.
type.
id() == ID_code)
737 for(
auto &
requires : code_type.requires())
753 if(!
as_const(code_type).ensures().empty())
760 for(
auto &ensures : code_type.ensures())
ANSI-CC Language Type Checking.
const T & as_const(T &value)
Return a reference to the same object but ensures the type is const.
void base_type(typet &type, const namespacet &ns)
ANSI-C Language Type Checking.
unsignedbv_typet size_type()
const c_enum_typet & to_c_enum_type(const typet &type)
Cast a typet to a c_enum_typet.
const union_typet & to_union_type(const typet &type)
Cast a typet to a union_typet.
const code_with_contract_typet & to_code_with_contract_type(const typet &type)
Cast a typet to a code_with_contract_typet.
static void make_already_typechecked(typet &type)
void set_is_thread_local(bool is_thread_local)
void set_is_weak(bool is_weak)
const declaratorst & declarators() const
void set_is_register(bool is_register)
void set_is_inline(bool is_inline)
typet full_type(const ansi_c_declaratort &) const
void to_symbol(const ansi_c_declaratort &, symbolt &symbol) const
void set_is_extern(bool is_extern)
void set_is_used(bool is_used)
void set_is_typedef(bool is_typedef)
bool get_is_static_assert() const
void set_is_static(bool is_static)
void typecheck_function_body(symbolt &symbol)
std::map< irep_idt, source_locationt > labels_used
virtual void typecheck_expr(exprt &expr)
virtual void do_initializer(exprt &initializer, const typet &type, bool force_constant)
virtual void typecheck_code(codet &code)
void move_symbol(symbolt &symbol, symbolt *&new_symbol)
void disallow_subexpr_by_id(const exprt &, const irep_idt &, const std::string &) const
void apply_asm_label(const irep_idt &asm_label, symbolt &symbol)
symbol_tablet & symbol_table
virtual std::string to_string(const exprt &expr)
void typecheck_declaration(ansi_c_declarationt &)
void typecheck_new_symbol(symbolt &symbol)
asm_label_mapt asm_label_map
virtual void adjust_function_parameter(typet &type) const
void typecheck_redefinition_type(symbolt &old_symbol, symbolt &new_symbol)
void typecheck_redefinition_non_type(symbolt &old_symbol, symbolt &new_symbol)
virtual void typecheck_spec_assigns(exprt::operandst &targets)
id_type_mapt parameter_map
virtual void implicit_typecast_bool(exprt &expr)
virtual void typecheck_type(typet &type)
void typecheck_symbol(symbolt &symbol)
std::map< irep_idt, source_locationt > labels_defined
void set_inlined(bool value)
const parameterst & parameters() const
const typet & return_type() const
bool has_ellipsis() const
Data structure for representing an arbitrary statement in a program.
struct configt::ansi_ct ansi_c
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
const source_locationt & find_source_location() const
Get a source_locationt from the expression or from its operands (non-recursively).
bool is_constant() const
Return whether the expression is a constant.
typet & type()
Return the type of the expression.
const source_locationt & source_location() const
source_locationt & add_source_location()
const irept & find(const irep_idt &name) const
const irep_idt & get(const irep_idt &name) const
const irep_idt & id() const
source_locationt source_location
mstreamt & warning() const
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
Symbol table entry of function parameterThis is a symbol generated as part of type checking.
static symbol_exprt typeless(const irep_idt &id)
Generate a symbol_exprt without a proper type.
symbolt & get_writeable_ref(const irep_idt &name)
Find a symbol in the symbol table for read-write access.
const symbolst & symbols
Read-only field, used to look up symbols given their names.
virtual void erase(const symbolst::const_iterator &entry) override
Remove a symbol from the symbol table.
virtual bool move(symbolt &symbol, symbolt *&new_symbol) override
Move a symbol into the symbol table.
irep_idt base_name
Base (non-scoped) name.
irep_idt module
Name of module the symbol belongs to.
source_locationt location
Source code location of definition of symbol.
typet type
Type of symbol.
irep_idt name
The unique identifier.
irep_idt pretty_name
Language-specific display name.
const irep_idt & display_name() const
Return language specific display name if present.
exprt value
Initial value of symbol.
irep_idt mode
Language mode.
The type of an expression, extends irept.
std::string expr2c(const exprt &expr, const namespacet &ns, const expr2c_configurationt &configuration)
std::string type2c(const typet &type, const namespacet &ns, const expr2c_configurationt &configuration)
Deprecated expression utility functions.
const std::string & id2string(const irep_idt &d)
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
const codet & to_code(const exprt &expr)
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.