30 return expr2c(expr, *
this);
35 return type2c(type, *
this);
46 error() <<
"failed to move symbol '" << symbol.
name <<
"' into symbol table"
54 bool is_function=symbol.
type.
id()==ID_code;
80 warning() <<
"'extern' symbol '" << new_name
81 <<
"' should not have an initializer" <<
eom;
84 else if(!is_function && symbol.
value.
id()==ID_code)
87 error() <<
"only functions can have a function body" <<
eom;
112 error() <<
"void-typed symbol not permitted" <<
eom;
117 symbol_table_baset::symbolst::const_iterator old_it =
130 if(old_it->second.is_type!=symbol.
is_type)
134 <<
"' as a different kind of symbol" <<
eom;
145 symbol.
type.
id() != ID_code)
149 <<
"' with no linkage" <<
eom;
165 if(symbol.
type.
id()==ID_code)
178 parameter.set_identifier(
irep_idt());
192 const typet &final_old = old_symbol.
type;
193 const typet &final_new = new_symbol.
type;
197 (final_old.
id() == ID_struct &&
199 (final_old.
id() == ID_union &&
to_union_type(final_old).is_incomplete()) ||
204 final_new.
id() == final_old.
id() &&
205 ((final_new.
id() == ID_struct &&
207 (final_new.
id() == ID_union &&
209 (final_new.
id() == ID_c_enum &&
223 error() <<
"conflicting definition of type symbol '"
232 (final_new.
id() == ID_struct &&
234 (final_new.
id() == ID_union &&
236 (final_new.
id() == ID_c_enum &&
239 if(final_old.
id() == final_new.
id())
247 error() <<
"conflicting definition of tag symbol '"
253 final_new.
id()==ID_c_enum && final_old.
id()==ID_c_enum)
260 final_new.
id() == ID_pointer && final_old.
id() == ID_pointer &&
270 if(new_symbol.
type != old_symbol.
type)
274 <<
"' defined twice:\n"
290 if(old_components.size() != new_components.size())
293 if(old_components.empty())
296 for(std::size_t i = 0; i < old_components.size() - 1; ++i)
298 if(old_components[i].type() != new_components[i].type())
303 old_components.back().type().id() != ID_array ||
304 new_components.back().type().id() != ID_array)
309 const auto &old_array_type =
to_array_type(old_components.back().type());
310 const auto &new_array_type =
to_array_type(new_components.back().type());
312 return old_array_type.element_type() == new_array_type.element_type() &&
313 old_array_type.get_bool(ID_C_flexible_array_member) &&
314 new_array_type.get_bool(ID_C_flexible_array_member) &&
315 (old_array_type.size().is_nil() || old_array_type.size().is_zero());
322 const typet &final_old = old_symbol.
type;
323 const typet &initial_new = new_symbol.
type;
326 final_old.
id() == ID_array &&
328 initial_new.
id() == ID_array &&
337 final_old.
id() == ID_array &&
to_array_type(final_old).size().is_nil() &&
338 initial_new.
id() == ID_array &&
352 const typet &final_new = new_symbol.
type;
355 if(old_symbol.
type.
id()==ID_KnR)
358 if(final_new.
id()==ID_code)
361 error() <<
"function type not allowed for K&R function parameter"
371 if(final_new.
id()==ID_code)
373 if(final_old.
id()!=ID_code)
377 <<
"' redefined with a different type:\n"
388 !old_ct.
get_bool(ID_C_incomplete) &&
402 "' redefined with a different type:\n" +
417 error() <<
"code contract on incomplete function re-declaration" <<
eom;
450 for(
const auto &old_parameter : old_ct.
parameters())
452 const irep_idt &identifier = old_parameter.get_identifier();
454 symbol_table_baset::symbolst::const_iterator p_s_it =
464 <<
"' defined twice" <<
eom;
498 auto new_parameters_it = new_ct.
parameters().begin();
501 if(new_parameters_it != new_ct.
parameters().end())
503 new_parameters_it->set_identifier(p.get_identifier());
514 if(final_old!=final_new)
517 final_old.
id() == ID_array &&
to_array_type(final_old).size().is_nil() &&
518 final_new.
id() == ID_array &&
526 final_old.
id() == ID_pointer &&
529 final_new.
id() == ID_pointer &&
538 final_old.
id() == ID_pointer &&
540 final_new.
id() == ID_pointer &&
549 final_old.
id() == ID_struct_tag && final_new.
id() == ID_struct_tag &&
560 <<
"' redefined with a different type:\n"
577 new_symbol.
is_macro && final_new.
id() == ID_c_enum &&
587 <<
"' already has an initial value" <<
eom;
611 if(symbol.
value.
id() != ID_code)
614 error() <<
"function '" << symbol.
name <<
"' is initialized with "
649 error() <<
"branching label '" << label.first
650 <<
"' is not defined in function" <<
eom;
665 if(!asm_label.
empty() &&
669 symbol.
name=asm_label;
673 if(symbol.
name!=orig_name)
676 std::make_pair(orig_name, asm_label)).second)
682 <<
" by " << asm_label <<
eom;
687 else if(asm_label.
empty())
689 asm_label_mapt::const_iterator entry=
693 symbol.
name=entry->second;
698 if(symbol.
name!=orig_name &&
699 symbol.
type.
id()==ID_code &&
706 const irep_idt &p_bn = p.get_base_name();
714 std::make_pair(p_id, p_new_id)).second)
724 std::string &clause_type)
727 expr, ID_old,
CPROVER_PREFIX "old is not allowed in " + clause_type +
".");
731 CPROVER_PREFIX "loop_entry is not allowed in " + clause_type +
".");
734 auto pred = [&](
const exprt &expr) {
751 std::string &clause_type)
755 auto pred = [&](
const exprt &expr) {
765 id2string(
id) +
" is not allowed in " + clause_type +
".",
775 codet code(ID_static_assert);
795 full_spec|=c_storage_spec;
816 error() <<
"alias attribute cannot be used with a body"
838 symbolt symbol_for_renaming = symbol;
853 if(asm_name[0] ==
'.')
857 if(primary_section != std::string::npos)
858 asm_name.resize(primary_section);
872 declarator.set_name(identifier);
879 new_symbol.
type.
id() == ID_code &&
893 temporary_parameter_symbols.emplace_back(
897 std::size_t anon_counter = 0;
901 if(p.get_base_name().empty())
905 const irep_idt &base_name = p.get_base_name();
909 p.set_identifier(parameter_identifier);
914 temporary_parameter_symbols.emplace_back(
915 parameter_identifier, p.type());
918 for(
auto &c_requires : code_type.
c_requires())
922 std::string clause_type =
"preconditions";
925 lambda_exprt lambda{temporary_parameter_symbols, c_requires};
927 c_requires.
swap(lambda);
931 for(
auto &assigns : code_type.
c_assigns())
933 std::string clause_type =
"assigns clauses";
935 lambda_exprt lambda{temporary_parameter_symbols, assigns};
937 assigns.
swap(lambda);
941 for(
auto &frees : code_type.
c_frees())
943 lambda_exprt lambda{temporary_parameter_symbols, frees};
948 for(
auto &ensures : code_type.
c_ensures())
956 lambda_exprt lambda{temporary_parameter_symbols, ensures};
958 ensures.
swap(lambda);
961 for(
const auto ¶meter_sym : temporary_parameter_symbols)
970 contract.
type = code_type;
980 <<
"' already set at " << entry.first.location.
as_string()
1002 unsigned anon_counter = 0;
1008 if(p.get_base_name().empty())
1011 p.set_base_name(base_name);
1015 irep_idt base_name = p.get_base_name();
1018 p.set_identifier(identifier);
1022 p_symbol.
type = p.type();
1023 p_symbol.
name = identifier;
1025 p_symbol.
location = p.source_location();
ANSI-CC Language Type Checking.
static bool is_instantiation_of_flexible_array(const struct_typet &old_type, const struct_typet &new_type)
ANSI-C Language Type Checking.
const c_enum_typet & to_c_enum_type(const typet &type)
Cast a typet to a c_enum_typet.
const code_with_contract_typet & to_code_with_contract_type(const typet &type)
Cast a typet to a code_with_contract_typet.
const union_typet & to_union_type(const typet &type)
Cast a typet to a union_typet.
static void make_already_typechecked(typet &type)
void set_is_thread_local(bool is_thread_local)
void set_is_weak(bool is_weak)
symbolt to_symbol(const ansi_c_declaratort &) const
void set_is_register(bool is_register)
void set_is_inline(bool is_inline)
typet full_type(const ansi_c_declaratort &) const
const declaratorst & declarators() const
void set_is_extern(bool is_extern)
void set_is_typedef(bool is_typedef)
bool get_is_static_assert() const
void set_is_static(bool is_static)
std::vector< symbol_exprt > variablest
symbol_table_baset & symbol_table
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.
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)
virtual void check_was_freed(const exprt &expr, std::string &clause_type)
Checks that no occurence of the CPROVER_PREFIX was_freed predicate is found in expr.
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)
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 add_parameters_to_symbol_table(symbolt &symbol)
Create symbols for parameter of the code-typed symbol symbol.
void typecheck_redefinition_non_type(symbolt &old_symbol, symbolt &new_symbol)
virtual void typecheck_spec_frees(exprt::operandst &targets)
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
const typet & return_type() const
void set_inlined(bool value)
bool has_ellipsis() const
const parameterst & parameters() const
const exprt::operandst & c_assigns() const
const exprt::operandst & c_requires() const
const exprt::operandst & c_frees() const
const exprt::operandst & c_ensures() const
bool has_contract() const
Data structure for representing an arbitrary statement in a program.
struct configt::ansi_ct ansi_c
Mangle identifiers by hashing their working directory with djb2 hash.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
const std::string & as_string() const
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).
source_locationt & add_source_location()
const source_locationt & source_location() const
typet & type()
Return the type of the expression.
bool is_constant() const
Return whether the expression is a constant.
Thrown when we can't handle something in an input source file.
bool get_bool(const irep_idt &name) const
const irep_idt & get(const irep_idt &name) const
void remove(const irep_idt &name)
const irep_idt & id() const
A (mathematical) lambda expression.
source_locationt source_location
mstreamt & warning() const
const union_typet & follow_tag(const union_tag_typet &) const
Follow type tag of union type.
Symbol table entry of function parameterThis is a symbol generated as part of type checking.
const irep_idt & get_file() const
Structure type, corresponds to C style structs.
const componentst & components() const
std::vector< componentt > componentst
static symbol_exprt typeless(const irep_idt &id)
Generate a symbol_exprt without a proper type.
const irep_idt & get_identifier() const
virtual bool move(symbolt &symbol, symbolt *&new_symbol)=0
symbolt & get_writeable_ref(const irep_idt &name)
Find a symbol in the symbol table for read-write access.
virtual void erase(const symbolst::const_iterator &entry)=0
Remove a symbol from the symbol table.
const symbolst & symbols
Read-only field, used to look up symbols given their names.
virtual std::pair< symbolt &, bool > insert(symbolt symbol)=0
Move or copy a new symbol to the symbol table.
irep_idt base_name
Base (non-scoped) name.
const irep_idt & display_name() const
Return language specific display name if present.
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.
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)
bool has_subexpr(const exprt &expr, const std::function< bool(const exprt &)> &pred)
returns true if the expression has a subexpression that satisfies pred
Deprecated expression utility functions.
bool has_contract(const irep_idt &function_identifier, const namespacet &ns)
const std::string & id2string(const irep_idt &d)
API to expression classes for 'mathematical' expressions.
Mangle names of file-local functions to make them unique.
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
#define CHECK_RETURN(CONDITION)
#define PRECONDITION(CONDITION)
const codet & to_code(const exprt &expr)
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
bool can_cast_expr< symbol_exprt >(const exprt &base)
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
bool can_cast_type< code_typet >(const typet &type)
Check whether a reference to a typet is a code_typet.
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.