Go to the documentation of this file.
24 return expr2c(expr, *
this);
29 return type2c(type, *
this);
40 error() <<
"failed to move symbol '" << symbol.
name <<
"' into symbol table"
48 bool is_function=symbol.
type.
id()==ID_code;
76 warning() <<
"`extern' symbol should not have an initializer" <<
eom;
79 else if(!is_function && symbol.
value.
id()==ID_code)
82 error() <<
"only functions can have a function body" <<
eom;
87 if(symbol.
is_type && final_type.
id() == ID_struct)
91 else if(symbol.
is_type && final_type.
id() == ID_union)
95 else if(symbol.
is_type && final_type.
id() == ID_c_enum)
107 error() <<
"void-typed symbol not permitted" <<
eom;
112 symbol_tablet::symbolst::const_iterator old_it=
125 if(old_it->second.is_type!=symbol.
is_type)
129 <<
"' as a different kind of symbol" <<
eom;
148 if(symbol.
type.
id()==ID_code)
159 parameter.set_identifier(
irep_idt());
178 (final_old.
id() == ID_struct &&
180 (final_old.
id() == ID_union &&
to_union_type(final_old).is_incomplete()) ||
185 final_new.
id() == final_old.
id() &&
186 ((final_new.
id() == ID_struct &&
188 (final_new.
id() == ID_union &&
190 (final_new.
id() == ID_c_enum &&
204 error() <<
"conflicting definition of type symbol '"
213 (final_new.
id() == ID_struct &&
215 (final_new.
id() == ID_union &&
217 (final_new.
id() == ID_c_enum &&
220 if(final_old.
id() == final_new.
id())
228 error() <<
"conflicting definition of tag symbol '"
234 final_new.
id()==ID_c_enum && final_old.
id()==ID_c_enum)
240 final_new.
id()==ID_pointer && final_old.
id()==ID_pointer &&
254 <<
"' defined twice:\n"
270 if(final_old.
id()==ID_array &&
272 initial_new.
id()==ID_array &&
279 else if(final_old.
id()==ID_array &&
281 initial_new.
id()==ID_array &&
297 if(old_symbol.
type.
id()==ID_KnR)
300 if(final_new.
id()==ID_code)
303 error() <<
"function type not allowed for K&R function parameter"
313 if(final_new.
id()==ID_code)
315 if(final_old.
id()!=ID_code)
319 <<
"' redefined with a different type:\n"
362 for(
const auto &old_parameter : old_ct.
parameters())
364 const irep_idt &identifier = old_parameter.get_identifier();
366 symbol_tablet::symbolst::const_iterator p_s_it=
376 <<
"' defined twice" <<
eom;
410 if(final_old!=final_new)
412 if(final_old.
id()==ID_array &&
414 final_new.
id()==ID_array &&
421 final_old.
id() == ID_pointer && final_old.
subtype().
id() == ID_code &&
423 final_new.
id() == ID_pointer && final_new.
subtype().
id() == ID_code)
431 final_old.
id() == ID_pointer && final_old.
subtype().
id() == ID_code &&
432 final_new.
id() == ID_pointer && final_new.
subtype().
id() == ID_code &&
443 <<
"' redefined with a different type:\n"
460 new_symbol.
is_macro && final_new.
id() == ID_c_enum &&
470 <<
"' already has an initial value" <<
eom;
494 if(symbol.
value.
id() != ID_code)
497 error() <<
"function '" << symbol.
name <<
"' is initialized with "
514 unsigned anon_counter=0;
520 if(p.get_base_name().empty())
523 p.set_base_name(base_name);
527 irep_idt base_name = p.get_base_name();
530 p.set_identifier(identifier);
534 p_symbol.
type = p.type();
535 p_symbol.
name=identifier;
537 p_symbol.
location = p.source_location();
552 error() <<
"branching label '" << label.first
553 <<
"' is not defined in function" <<
eom;
568 if(!asm_label.
empty() &&
572 symbol.
name=asm_label;
576 if(symbol.
name!=orig_name)
579 std::make_pair(orig_name, asm_label)).second)
584 error() <<
"error: replacing asm renaming "
591 else if(asm_label.
empty())
593 asm_label_mapt::const_iterator entry=
597 symbol.
name=entry->second;
602 if(symbol.
name!=orig_name &&
603 symbol.
type.
id()==ID_code &&
610 const irep_idt &p_bn = p.get_base_name();
618 std::make_pair(p_id, p_new_id)).second)
629 codet code(ID_static_assert);
649 full_spec|=c_storage_spec;
661 declaration.
to_symbol(declarator, symbol);
672 error() <<
"alias attribute cannot be used with a body"
695 if(asm_name[0] ==
'.')
699 if(primary_section != std::string::npos)
700 asm_name.resize(primary_section);
714 declarator.set_name(identifier);
720 if(new_symbol.
type.
id() == ID_code)
727 if(!
as_const(code_type).requires().empty())
729 for(
auto &requires : code_type.requires())
744 if(
as_const(code_type).assigns().is_not_nil())
746 for(
auto &op : code_type.assigns().operands())
750 if(!
as_const(code_type).ensures().empty())
757 for(
auto &ensures : code_type.ensures())
virtual void do_initializer(exprt &initializer, const typet &type, bool force_constant)
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
void typecheck_new_symbol(symbolt &symbol)
const union_typet & to_union_type(const typet &type)
Cast a typet to a union_typet.
bool has_ellipsis() const
const code_with_contract_typet & to_code_with_contract_type(const typet &type)
Cast a typet to a code_with_contract_typet.
const typet & subtype() const
ANSI-CC Language Type Checking.
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.
The type of an expression, extends irept.
ANSI-C Language Type Checking.
void typecheck_declaration(ansi_c_declarationt &)
std::string expr2c(const exprt &expr, const namespacet &ns)
virtual std::string to_string(const exprt &expr)
typet type
Type of symbol.
static symbol_exprt typeless(const irep_idt &id)
Generate a symbol_exprt without a proper type.
const c_enum_typet & to_c_enum_type(const typet &type)
Cast a typet to a c_enum_typet.
const irept & find(const irep_namet &name) const
void disallow_subexpr_by_id(const exprt &, const irep_idt &, const std::string &) 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.
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)
void typecheck_redefinition_non_type(symbolt &old_symbol, symbolt &new_symbol)
std::string type2c(const typet &type, const namespacet &ns)
typet & type()
Return the type of the expression.
asm_label_mapt asm_label_map
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
irep_idt mode
Language mode.
const T & as_const(T &value)
Return a reference to the same object but ensures the type is const.
void set_is_register(bool is_register)
void typecheck_function_body(symbolt &symbol)
virtual void implicit_typecast_bool(exprt &expr)
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
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 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)
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
virtual void erase(const symbolst::const_iterator &entry) override
Remove a symbol from the symbol table.
Symbol table entry of function parameterThis is a symbol generated as part of type checking.
source_locationt & add_source_location()
unsignedbv_typet size_type()
irep_idt module
Name of module the symbol belongs to.
mstreamt & warning() const
const source_locationt & source_location() 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.