|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | +Module: Show Modules |
| 4 | +
|
| 5 | +Author: Daniel Kroening, [email protected] |
| 6 | +
|
| 7 | +\*******************************************************************/ |
| 8 | + |
| 9 | +#include "show_modules.h" |
| 10 | + |
| 11 | +#include <util/json_irep.h> |
| 12 | +#include <util/symbol_table_base.h> |
| 13 | +#include <util/xml_irep.h> |
| 14 | + |
| 15 | +void show_modulest::xml(std::ostream &out) const |
| 16 | +{ |
| 17 | + std::size_t count = 0; |
| 18 | + |
| 19 | + for(const auto &module : modules) |
| 20 | + { |
| 21 | + count++; |
| 22 | + |
| 23 | + xmlt xml("module"); |
| 24 | + xml.new_element("number").data = std::to_string(count); // will go away |
| 25 | + xml.set_attribute("number", std::to_string(count)); |
| 26 | + |
| 27 | + xmlt &l = xml.new_element(); |
| 28 | + convert(module.source_location, l); |
| 29 | + l.name = "location"; |
| 30 | + |
| 31 | + // these go away |
| 32 | + xml.new_element("identifier").data = id2string(module.identifier); |
| 33 | + xml.new_element("mode").data = id2string(module.mode); |
| 34 | + xml.new_element("name").data = id2string(module.display_name); |
| 35 | + |
| 36 | + // these stay |
| 37 | + xml.set_attribute("identifier", id2string(module.identifier)); |
| 38 | + xml.set_attribute("mode", id2string(module.mode)); |
| 39 | + xml.set_attribute("name", id2string(module.display_name)); |
| 40 | + |
| 41 | + out << xml; |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +void show_modulest::plain_text(std::ostream &out) const |
| 46 | +{ |
| 47 | + std::size_t count = 0; |
| 48 | + |
| 49 | + for(const auto &module : modules) |
| 50 | + { |
| 51 | + count++; |
| 52 | + |
| 53 | + out << "Module " << count << ":" << '\n'; |
| 54 | + |
| 55 | + out << " Location: " << module.source_location << '\n'; |
| 56 | + out << " Mode: " << module.mode << '\n'; |
| 57 | + out << " Identifier: " << module.identifier << '\n'; |
| 58 | + out << " Name: " << module.display_name << '\n' << '\n'; |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +void show_modulest::json(std::ostream &out) const |
| 63 | +{ |
| 64 | + json_arrayt json_modules; |
| 65 | + |
| 66 | + for(const auto &module : modules) |
| 67 | + { |
| 68 | + json_objectt json_module; |
| 69 | + json_module["location"] = ::json(module.source_location); |
| 70 | + json_module["identifier"] = json_stringt{id2string(module.identifier)}; |
| 71 | + json_module["mode"] = json_stringt{id2string(module.mode)}; |
| 72 | + json_module["name"] = json_stringt{id2string(module.display_name)}; |
| 73 | + |
| 74 | + json_modules.push_back(std::move(json_module)); |
| 75 | + } |
| 76 | + |
| 77 | + out << json_modules; |
| 78 | +} |
| 79 | + |
| 80 | +show_modulest |
| 81 | +show_modulest::from_symbol_table(const symbol_table_baset &symbol_table) |
| 82 | +{ |
| 83 | + show_modulest show_modules; |
| 84 | + |
| 85 | + for(const auto &s : symbol_table.symbols) |
| 86 | + { |
| 87 | + const symbolt &symbol = s.second; |
| 88 | + |
| 89 | + if(symbol.type.id() == ID_module) |
| 90 | + { |
| 91 | + show_modules.modules.emplace_back( |
| 92 | + symbol.name, symbol.display_name(), symbol.mode, symbol.location); |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + return show_modules; |
| 97 | +} |
0 commit comments