/// Print the contents of the symbol table /// \param out: The ostream to direct output to void symbol_tablet::show(std::ostream &out) const { out << "\n" << "Symbols:" << "\n"; forall_symbols(it, symbols) out << it->second; }
void linkingt::typecheck() { // we inspect all the symbols in src_context forall_symbols(it, src_context.symbols) inspect_src_symbol(it->first); }
void jsil_typecheckt::typecheck() { // The hash table iterators are not stable, // and we might add new symbols. std::vector<irep_idt> identifiers; identifiers.reserve(symbol_table.symbols.size()); forall_symbols(s_it, symbol_table.symbols) identifiers.push_back(s_it->first); // We first check all type symbols, // recursively doing base classes first. for(const irep_idt &id : identifiers) { symbolt &symbol=symbol_table.symbols[id]; if(symbol.is_type) typecheck_type_symbol(symbol); } // We now check all non-type symbols for(const irep_idt &id : identifiers) { symbolt &symbol=symbol_table.symbols[id]; if(!symbol.is_type) typecheck_non_type_symbol(symbol); } }
bool static_lifetime_init( symbol_tablet &symbol_table, const source_locationt &source_location, message_handlert &message_handler) { namespacet ns(symbol_table); symbol_tablet::symbolst::iterator s_it= symbol_table.symbols.find(INITIALIZE_FUNCTION); if(s_it==symbol_table.symbols.end()) return false; symbolt &init_symbol=s_it->second; init_symbol.value=code_blockt(); init_symbol.value.add_source_location()=source_location; code_blockt &dest=to_code_block(to_code(init_symbol.value)); // add the magic label to hide dest.add(code_labelt("__CPROVER_HIDE", code_skipt())); // do assignments based on "value" // sort alphabetically for reproducible results std::set<std::string> symbols; forall_symbols(it, symbol_table.symbols) symbols.insert(id2string(it->first)); for(const std::string &id : symbols) { const symbolt &symbol=ns.lookup(id); const irep_idt &identifier=symbol.name; if(!symbol.is_static_lifetime) continue; if(symbol.is_type || symbol.is_macro) continue; // special values if(identifier==CPROVER_PREFIX "constant_infinity_uint" || identifier==CPROVER_PREFIX "memory" || identifier=="__func__" || identifier=="__FUNCTION__" || identifier=="__PRETTY_FUNCTION__" || identifier=="argc'" || identifier=="argv'" || identifier=="envp'" || identifier=="envp_size'") continue; // just for linking if(has_prefix(id, CPROVER_PREFIX "architecture_")) continue; const typet &type=ns.follow(symbol.type); // check type if(type.id()==ID_code || type.id()==ID_empty) continue; // We won't try to initialize any symbols that have // remained incomplete. if(symbol.value.is_nil() && symbol.is_extern) // Compilers would usually complain about these // symbols being undefined. continue; if(type.id()==ID_array && to_array_type(type).size().is_nil()) { // C standard 6.9.2, paragraph 5 // adjust the type to an array of size 1 symbol_tablet::symbolst::iterator it= symbol_table.symbols.find(identifier); assert(it!=symbol_table.symbols.end()); it->second.type=type; it->second.type.set(ID_size, from_integer(1, size_type())); } if(type.id()==ID_incomplete_struct || type.id()==ID_incomplete_union) continue; // do not initialize if(symbol.value.id()==ID_nondet) continue; // do not initialize exprt rhs; if(symbol.value.is_nil()) { try { namespacet ns(symbol_table); rhs=zero_initializer(symbol.type, symbol.location, ns, message_handler); assert(rhs.is_not_nil()); } catch(...) { return true; } } else rhs=symbol.value; code_assignt code(symbol.symbol_expr(), rhs); code.add_source_location()=symbol.location; dest.move_to_operands(code); } // call designated "initialization" functions for(const std::string &id : symbols) { const symbolt &symbol=ns.lookup(id); if(symbol.type.id()==ID_code && to_code_type(symbol.type).return_type().id()==ID_constructor) { code_function_callt function_call; function_call.function()=symbol.symbol_expr(); function_call.add_source_location()=source_location; dest.move_to_operands(function_call); } } return false; }
void show_symbol_table_plain( const goto_modelt &goto_model, std::ostream &out) { out << '\n' << "Symbols:" << '\n' << '\n'; // we want to sort alphabetically std::set<std::string> symbols; forall_symbols(it, goto_model.symbol_table.symbols) symbols.insert(id2string(it->first)); const namespacet ns(goto_model.symbol_table); for(const std::string &id : symbols) { const symbolt &symbol=ns.lookup(id); languaget *ptr; if(symbol.mode=="") ptr=get_default_language(); else { ptr=get_language_from_mode(symbol.mode); if(ptr==NULL) throw "symbol "+id2string(symbol.name)+" has unknown mode"; } std::unique_ptr<languaget> p(ptr); std::string type_str, value_str; if(symbol.type.is_not_nil()) p->from_type(symbol.type, type_str, ns); if(symbol.value.is_not_nil()) p->from_expr(symbol.value, value_str, ns); out << "Symbol......: " << symbol.name << '\n' << std::flush; out << "Pretty name.: " << symbol.pretty_name << '\n'; out << "Module......: " << symbol.module << '\n'; out << "Base name...: " << symbol.base_name << '\n'; out << "Mode........: " << symbol.mode << '\n'; out << "Type........: " << type_str << '\n'; out << "Value.......: " << value_str << '\n'; out << "Flags.......:"; if(symbol.is_lvalue) out << " lvalue"; if(symbol.is_static_lifetime) out << " static_lifetime"; if(symbol.is_thread_local) out << " thread_local"; if(symbol.is_file_local) out << " file_local"; if(symbol.is_type) out << " type"; if(symbol.is_extern) out << " extern"; if(symbol.is_input) out << " input"; if(symbol.is_output) out << " output"; if(symbol.is_macro) out << " macro"; if(symbol.is_parameter) out << " parameter"; if(symbol.is_auxiliary) out << " auxiliary"; if(symbol.is_weak) out << " weak"; if(symbol.is_property) out << " property"; if(symbol.is_state_var) out << " state_var"; if(symbol.is_exported) out << " exported"; if(symbol.is_volatile) out << " volatile"; out << '\n'; out << "Location....: " << symbol.location << '\n'; out << '\n' << std::flush; } }