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)
109 error() <<
"void-typed symbol not permitted" <<
eom;
114 symbol_tablet::symbolst::const_iterator old_it=
127 if(old_it->second.is_type!=symbol.
is_type)
131 <<
"' as a different kind of symbol" <<
eom;
150 if(symbol.
type.
id()==ID_code)
163 parameter.set_identifier(
irep_idt());
182 (final_old.
id() == ID_struct &&
184 (final_old.
id() == ID_union &&
to_union_type(final_old).is_incomplete()) ||
189 final_new.
id() == final_old.
id() &&
190 ((final_new.
id() == ID_struct &&
192 (final_new.
id() == ID_union &&
194 (final_new.
id() == ID_c_enum &&
208 error() <<
"conflicting definition of type symbol '"
217 (final_new.
id() == ID_struct &&
219 (final_new.
id() == ID_union &&
221 (final_new.
id() == ID_c_enum &&
224 if(final_old.
id() == final_new.
id())
232 error() <<
"conflicting definition of tag symbol '"
238 final_new.
id()==ID_c_enum && final_old.
id()==ID_c_enum)
245 final_new.
id() == ID_pointer && final_old.
id() == ID_pointer &&
259 <<
"' defined twice:\n"
275 if(old_components.size() != new_components.size())
278 if(old_components.empty())
281 for(std::size_t i = 0; i < old_components.size() - 1; ++i)
283 if(old_components[i].type() != new_components[i].type())
288 old_components.back().type().id() != ID_array ||
289 new_components.back().type().id() != ID_array)
294 const auto &old_array_type =
to_array_type(old_components.back().type());
295 const auto &new_array_type =
to_array_type(new_components.back().type());
297 return old_array_type.element_type() == new_array_type.element_type() &&
298 old_array_type.get_bool(ID_C_flexible_array_member) &&
299 new_array_type.get_bool(ID_C_flexible_array_member) &&
300 (old_array_type.size().is_nil() || old_array_type.size().is_zero());
311 final_old.
id() == ID_array &&
313 initial_new.
id() == ID_array &&
322 final_old.
id() == ID_array &&
to_array_type(final_old).size().is_nil() &&
323 initial_new.
id() == ID_array &&
340 if(old_symbol.
type.
id()==ID_KnR)
343 if(final_new.
id()==ID_code)
346 error() <<
"function type not allowed for K&R function parameter"
356 if(final_new.
id()==ID_code)
358 if(final_old.
id()!=ID_code)
362 <<
"' redefined with a different type:\n"
380 error() <<
"code contract on incomplete function re-declaration" <<
eom;
413 for(
const auto &old_parameter : old_ct.
parameters())
415 const irep_idt &identifier = old_parameter.get_identifier();
417 symbol_tablet::symbolst::const_iterator p_s_it=
427 <<
"' defined twice" <<
eom;
461 auto new_parameters_it = new_ct.
parameters().begin();
464 if(new_parameters_it != new_ct.
parameters().end())
466 new_parameters_it->set_identifier(p.get_identifier());
477 if(final_old!=final_new)
480 final_old.
id() == ID_array &&
to_array_type(final_old).size().is_nil() &&
481 final_new.
id() == ID_array &&
489 final_old.
id() == ID_pointer &&
492 final_new.
id() == ID_pointer &&
501 final_old.
id() == ID_pointer &&
503 final_new.
id() == ID_pointer &&
512 final_old.
id() == ID_struct && final_new.
id() == ID_struct &&
522 <<
"' redefined with a different type:\n"
539 new_symbol.
is_macro && final_new.
id() == ID_c_enum &&
549 <<
"' already has an initial value" <<
eom;
573 if(symbol.
value.
id() != ID_code)
576 error() <<
"function '" << symbol.
name <<
"' is initialized with "
605 error() <<
"branching label '" << label.first
606 <<
"' is not defined in function" <<
eom;
621 if(!asm_label.
empty() &&
625 symbol.
name=asm_label;
629 if(symbol.
name!=orig_name)
632 std::make_pair(orig_name, asm_label)).second)
637 error() <<
"error: replacing asm renaming "
644 else if(asm_label.
empty())
646 asm_label_mapt::const_iterator entry=
650 symbol.
name=entry->second;
655 if(symbol.
name!=orig_name &&
656 symbol.
type.
id()==ID_code &&
663 const irep_idt &p_bn = p.get_base_name();
671 std::make_pair(p_id, p_new_id)).second)
679 std::string &clause_type)
682 expr, ID_old,
CPROVER_PREFIX "old is not allowed in " + clause_type +
".");
686 CPROVER_PREFIX "loop_entry is not allowed in " + clause_type +
".");
689 auto pred = [&](
const exprt &expr) {
709 codet code(ID_static_assert);
729 full_spec|=c_storage_spec;
741 declaration.
to_symbol(declarator, symbol);
752 error() <<
"alias attribute cannot be used with a body"
775 if(asm_name[0] ==
'.')
779 if(primary_section != std::string::npos)
780 asm_name.resize(primary_section);
794 declarator.set_name(identifier);
801 new_symbol.
type.
id() == ID_code &&
815 temporary_parameter_symbols.emplace_back(
819 std::size_t anon_counter = 0;
823 if(p.get_base_name().empty())
827 const irep_idt &base_name = p.get_base_name();
831 p.set_identifier(parameter_identifier);
836 temporary_parameter_symbols.emplace_back(
837 parameter_identifier, p.type());
843 std::string clause_type =
"function pointer preconditions";
850 for(
auto &requires : code_type.
requires())
854 std::string clause_type =
"preconditions";
856 lambda_exprt lambda{temporary_parameter_symbols, requires};
858 requires.
swap(lambda);
862 for(
auto &assigns : code_type.
assigns())
864 std::string clause_type =
"assigns clauses";
866 lambda_exprt lambda{temporary_parameter_symbols, assigns};
868 assigns.
swap(lambda);
883 for(
auto &ensures : code_type.
ensures())
891 lambda_exprt lambda{temporary_parameter_symbols, ensures};
893 ensures.
swap(lambda);
896 for(
const auto ¶meter_sym : temporary_parameter_symbols)
905 contract.
type = code_type;
915 <<
"' already set at " << entry.first.location.
as_string()
924 new_symbol.
type.
remove(ID_C_spec_ensures_contract);
926 new_symbol.
type.
remove(ID_C_spec_requires_contract);
938 unsigned anon_counter = 0;
944 if(p.get_base_name().empty())
947 p.set_base_name(base_name);
951 irep_idt base_name = p.get_base_name();
954 p.set_identifier(identifier);
958 p_symbol.
type = p.type();
959 p_symbol.
name = identifier;
961 p_symbol.
location = p.source_location();
virtual void do_initializer(exprt &initializer, const typet &type, bool force_constant)
const componentst & components() const
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 can_cast_expr< symbol_exprt >(const exprt &base)
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.
bool has_subexpr(const exprt &expr, const std::function< bool(const exprt &)> &pred)
returns true if the expression has a subexpression that satisfies pred
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.
void typecheck_declaration(ansi_c_declarationt &)
virtual std::string to_string(const exprt &expr)
const irept & find(const irep_idt &name) const
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.
void disallow_subexpr_by_id(const exprt &, const irep_idt &, const std::string &) const
Base class for all expressions.
std::vector< componentt > componentst
irep_idt base_name
Base (non-scoped) name.
Thrown when we can't handle something in an input source file.
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.
const exprt::operandst & ensures_contract() const
struct configt::ansi_ct ansi_c
const exprt::operandst & assigns() const
bool get_is_static_assert() const
void set_is_typedef(bool is_typedef)
const irep_idt & get(const irep_idt &name) const
irep_idt pretty_name
Language-specific display name.
void typecheck_redefinition_non_type(symbolt &old_symbol, symbolt &new_symbol)
const codet & to_code(const exprt &expr)
typet & type()
Return the type of the expression.
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
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)
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
std::string expr2c(const exprt &expr, const namespacet &ns, const expr2c_configurationt &configuration)
#define PRECONDITION(CONDITION)
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).
const irep_idt & get_identifier() const
void set_inlined(bool value)
void to_symbol(const ansi_c_declaratort &, symbolt &symbol) const
std::vector< symbol_exprt > variablest
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
virtual std::pair< symbolt &, bool > insert(symbolt symbol) override
Author: Diffblue Ltd.
symbol_tablet & symbol_table
virtual void typecheck_code(codet &code)
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const irep_idt & id() const
void typecheck_redefinition_type(symbolt &old_symbol, symbolt &new_symbol)
const parameterst & parameters() const
id_type_mapt parameter_map
const exprt::operandst & requires_contract() const
static bool is_instantiation_of_flexible_array(const struct_typet &old_type, const struct_typet &new_type)
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 std::string & as_string() const
void set_is_thread_local(bool is_thread_local)
Deprecated expression utility functions.
exprt value
Initial value of symbol.
virtual void typecheck_spec_function_pointer_obeys_contract(exprt &expr)
bool has_contract() const
Structure type, corresponds to C style structs.
void set_is_static(bool is_static)
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
source_locationt location
Source code location of definition of symbol.
std::map< irep_idt, source_locationt > labels_defined
A (mathematical) lambda expression.
void add_parameters_to_symbol_table(symbolt &symbol)
Create symbols for parameter of the code-typed symbol symbol.
const exprt::operandst & ensures() const
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 check_history_expr_return_value(const exprt &expr, std::string &clause_type)
Checks that no history expr or return_value exists in expr.
virtual void typecheck_spec_assigns(exprt::operandst &targets)
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 parameter.
void remove(const irep_idt &name)
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.
const exprt::operandst & requires() const
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.