1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-01 22:41:32 +00:00

Makes provision for pretty-printed key names.

i.e. keys that don't fit C++ naming rules.
This commit is contained in:
Thomas Harte 2021-04-04 22:20:35 -04:00
parent 27eddf6dff
commit 18d6197d6c
4 changed files with 27 additions and 1 deletions

View File

@ -195,6 +195,18 @@ State::Registers::Registers() {
}
}
std::unordered_map<std::string, std::string> State::Registers::pretty_names() const {
return {
{ "afDash", "af'" },
{ "bcDash", "bc'" },
{ "deDash", "de'" },
{ "hlDash", "hl'" },
{ "program_counter", "pc" },
{ "stack_pointer", "sp" },
{ "interrupt_mode", "im" },
};
}
State::ExecutionState::ExecutionState() {
if(needs_declare()) {
DeclareField(is_halted);

View File

@ -38,6 +38,8 @@ struct State: public Reflection::StructImpl<State> {
int interrupt_mode;
bool iff1, iff2;
std::unordered_map<std::string, std::string> pretty_names() const override;
Registers();
} registers;

View File

@ -205,6 +205,7 @@ void Reflection::Struct::append(std::ostringstream &stream, const std::string &k
std::string Reflection::Struct::description() const {
std::ostringstream stream;
const auto name_map = pretty_names();
stream << "{";
@ -212,7 +213,10 @@ std::string Reflection::Struct::description() const {
for(const auto &key: all_keys()) {
if(!is_first) stream << ", ";
is_first = false;
stream << key << ": ";
// Use the pretty name for this key, if defined.
const auto mapped_key = name_map.find(key);
stream << (mapped_key != name_map.end() ? mapped_key->second : key) << ": ";
const auto count = count_of(key);
const auto type = type_of(key);

View File

@ -27,6 +27,14 @@ namespace Reflection {
#define DeclareField(Name) declare(&Name, #Name)
struct Struct {
/*!
Maps from internal key names to more human-friendly ones; e.g. might contain
a mapping from afDash to af'.
*/
virtual std::unordered_map<std::string, std::string> pretty_names() const {
return {};
}
virtual std::vector<std::string> all_keys() const = 0;
virtual const std::type_info *type_of(const std::string &name) const = 0;
virtual size_t count_of(const std::string &name) const = 0;