Signal types, pin role expectations, and a doctest suite.
Domain - Signal carries a SignalType (Power/GndShield/Other), auto-inferred from the name in Signal::Signal via infer_signal_type. Override with the new `set-signal-type` command. - SignalType extracted to its own header so Pin can store an `expected_signal_type` without a pins↔signals include cycle. - pin_role(connector_type, pin_name) → SignalType lookup, called from set-type to populate each Pin's expected_signal_type. The VPX 3U table is currently a stub (returns Other). - New `verify` command walks typed parts and reports pins whose connected signal's type doesn't match the expectation. - ODS importer no longer drops pins with empty signal column — they stay in the part as NC, matching the rule "a pin is either NC or connected to a signal". - persist: new S tag for non-default signal type overrides. Tests - doctest v2.4.11 via FetchContent (with CMAKE_POLICY_VERSION_MINIMUM shim, doctest's CMakeLists has a too-old floor for current CMake). - Source files moved into a static library `essim_lib` so both `essim` and `essim_tests` reuse the same compilation. main.cpp is the only file kept out of the lib. - Layer 1 (pure helpers): ToLower, LongestCommonPrefix, Tokenize, NaturalLess (numeric/case/leading-zero edge cases + total-order invariants), signal_type round-trips and infer_signal_type families, VpxTransform registry + symmetry + reference-table mapping for connector P0 row 1, IdentityTransform same-name wiring. - Layer 2 (round-trip): build a synthetic 2-module system in code, save → restore → assert modules / parts / connector_types / NC pins / signal type overrides / connections + pin_map are all preserved. - Tui::Tokenize moved to a free function in tui_helpers so tests can call it without dragging ftxui into the unit-test layer. - 27 test cases, 123 assertions, ~150 ms. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
#include "system/modules.hpp"
|
||||
#include "system/parts.hpp"
|
||||
#include "system/persist.hpp"
|
||||
#include "system/pin_role.hpp"
|
||||
#include "system/pins.hpp"
|
||||
#include "system/signals.hpp"
|
||||
#include "system/system.hpp"
|
||||
#include "system/transform.hpp"
|
||||
@@ -152,6 +154,66 @@ void Tui::RegisterCommands() {
|
||||
"replace the current system with a saved snapshot",
|
||||
};
|
||||
|
||||
commands["verify"] = { {}, [this](auto &) {
|
||||
if (!sys) { Print("no system: run 'new' first."); return; }
|
||||
int checked = 0;
|
||||
int mismatches = 0;
|
||||
for (auto &mkv : *sys->modules()) {
|
||||
Module *mod = mkv.second;
|
||||
for (auto &pkv : *mod) {
|
||||
Part *prt = pkv.second;
|
||||
if (prt->connector_type.empty()) continue;
|
||||
for (auto &nkv : *prt) {
|
||||
Pin *pin = nkv.second;
|
||||
++checked;
|
||||
SignalType expected = pin->expected_signal_type;
|
||||
if (expected == SignalType::Other) continue;
|
||||
Signal *s = pin->signal();
|
||||
SignalType actual = s ? s->type : SignalType::Other;
|
||||
if (actual == expected) continue;
|
||||
++mismatches;
|
||||
std::string sig_label = s ? s->name : std::string("(NC)");
|
||||
Print(" " + mod->name + "/" + prt->name + "/" + pin->name
|
||||
+ ": expected " + signal_type_name(expected)
|
||||
+ ", got " + signal_type_name(actual)
|
||||
+ " (signal: " + sig_label + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
Print("verify: " + std::to_string(mismatches) + " mismatch(es) over "
|
||||
+ std::to_string(checked) + " typed pin(s).");
|
||||
}, true,
|
||||
"check that each pin's connected signal matches its connector_type's expected role" };
|
||||
|
||||
commands["set-signal-type"] = {
|
||||
{{"module", Completion::None},
|
||||
{"signal name", Completion::None},
|
||||
{"type [power|gnd|other]", Completion::None}},
|
||||
[this](const std::vector<std::string> &args) {
|
||||
if (!sys) { Print("no system: run 'new' first."); return; }
|
||||
Module *mod;
|
||||
try { mod = sys->modules()->get(args[0]); }
|
||||
catch (const std::exception &) {
|
||||
Print("unknown module: " + args[0]); return;
|
||||
}
|
||||
Signal *sig;
|
||||
try { sig = mod->signals->get(args[1]); }
|
||||
catch (const std::exception &) {
|
||||
Print("unknown signal: " + mod->name + "/" + args[1]); return;
|
||||
}
|
||||
SignalType t;
|
||||
if (!signal_type_from_name(args[2], t)) {
|
||||
Print("type must be one of: power, gnd, other (got: " + args[2] + ")");
|
||||
return;
|
||||
}
|
||||
sig->type = t;
|
||||
Print(mod->name + "/" + sig->name + ": signal type = "
|
||||
+ signal_type_name(t));
|
||||
},
|
||||
/*prompt_for_missing=*/ true,
|
||||
"override the auto-detected signal type (power | gnd | other)",
|
||||
};
|
||||
|
||||
commands["set-type"] = {
|
||||
{{"module", Completion::None},
|
||||
{"part (name or pattern)", Completion::None},
|
||||
@@ -205,6 +267,8 @@ void Tui::RegisterCommands() {
|
||||
return;
|
||||
}
|
||||
prt->connector_type = args[2];
|
||||
for (auto &kv : *prt)
|
||||
kv.second->expected_signal_type = pin_role(args[2], kv.first);
|
||||
Print(mod->name + "/" + prt->name + ": connector_type = "
|
||||
+ (args[2].empty() ? "(none)" : args[2]));
|
||||
},
|
||||
|
||||
@@ -106,7 +106,7 @@ Component Tui::BuildExploreScreen() {
|
||||
std::vector<std::pair<std::string, std::string>> rows;
|
||||
for (auto &pin_kv : *p) {
|
||||
Signal *s = pin_kv.second->signal();
|
||||
rows.emplace_back(pin_kv.first, s ? s->name : std::string("—"));
|
||||
rows.emplace_back(pin_kv.first, s ? s->name : std::string("(NC)"));
|
||||
}
|
||||
std::sort(rows.begin(), rows.end(),
|
||||
[](const auto &a, const auto &b) { return NaturalLess(a.first, b.first); });
|
||||
@@ -123,7 +123,7 @@ Component Tui::BuildExploreScreen() {
|
||||
Signal *s = cur_mod->signals->get(cname);
|
||||
explore_header = cur_mod->name + "/" + s->name
|
||||
+ " — " + std::to_string(s->size())
|
||||
+ " pins";
|
||||
+ " pins • type: " + signal_type_name(s->type);
|
||||
std::vector<std::string> rows;
|
||||
for (auto &pin_kv : *s) {
|
||||
Pin *pin = pin_kv.second;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#include "system/modules.hpp"
|
||||
#include "system/parts.hpp"
|
||||
#include "system/pin_role.hpp"
|
||||
#include "system/pins.hpp"
|
||||
#include "system/system.hpp"
|
||||
#include "system/transform_vpx.hpp"
|
||||
|
||||
@@ -51,6 +53,8 @@ Component Tui::BuildSettypeScreen() {
|
||||
return;
|
||||
}
|
||||
prt->connector_type = settype_type;
|
||||
for (auto &kv : *prt)
|
||||
kv.second->expected_signal_type = pin_role(settype_type, kv.first);
|
||||
std::string msg = mod->name + "/" + prt->name + " = "
|
||||
+ (settype_type.empty() ? "(none)" : settype_type);
|
||||
settype_status = "applied: " + msg;
|
||||
|
||||
@@ -41,22 +41,6 @@ void Tui::CancelPending() {
|
||||
Print("(cancelled)");
|
||||
}
|
||||
|
||||
std::vector<std::string> Tui::Tokenize(const std::string &s) {
|
||||
std::vector<std::string> out;
|
||||
std::string cur;
|
||||
bool in_q = false;
|
||||
for (char c : s) {
|
||||
if (c == '"') { in_q = !in_q; continue; }
|
||||
if (!in_q && std::isspace((unsigned char)c)) {
|
||||
if (!cur.empty()) { out.push_back(std::move(cur)); cur.clear(); }
|
||||
} else {
|
||||
cur.push_back(c);
|
||||
}
|
||||
}
|
||||
if (!cur.empty()) out.push_back(std::move(cur));
|
||||
return out;
|
||||
}
|
||||
|
||||
void Tui::Submit() {
|
||||
if (!pending.empty()) {
|
||||
if (input.empty()) { Print("(empty — Esc to cancel)"); return; }
|
||||
|
||||
@@ -117,7 +117,6 @@ private:
|
||||
void LoadHistory();
|
||||
void AppendHistory(const std::string &cmd);
|
||||
void Source(const std::string &filename);
|
||||
static std::vector<std::string> Tokenize(const std::string &s);
|
||||
|
||||
// Completion (completion.cpp)
|
||||
void CompleteCommand(size_t start = 0);
|
||||
|
||||
@@ -52,3 +52,19 @@ std::string LongestCommonPrefix(const std::vector<std::string> &v) {
|
||||
}
|
||||
return lcp;
|
||||
}
|
||||
|
||||
std::vector<std::string> Tokenize(const std::string &s) {
|
||||
std::vector<std::string> out;
|
||||
std::string cur;
|
||||
bool in_q = false;
|
||||
for (char c : s) {
|
||||
if (c == '"') { in_q = !in_q; continue; }
|
||||
if (!in_q && std::isspace((unsigned char)c)) {
|
||||
if (!cur.empty()) { out.push_back(std::move(cur)); cur.clear(); }
|
||||
} else {
|
||||
cur.push_back(c);
|
||||
}
|
||||
}
|
||||
if (!cur.empty()) out.push_back(std::move(cur));
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -14,4 +14,7 @@ bool NaturalLess(const std::string &a, const std::string &b);
|
||||
|
||||
std::string LongestCommonPrefix(const std::vector<std::string> &v);
|
||||
|
||||
// Whitespace tokeniser with `"…"` quoting (preserved-as-content).
|
||||
std::vector<std::string> Tokenize(const std::string &s);
|
||||
|
||||
#endif // _TUI_HELPERS_HPP_
|
||||
|
||||
Reference in New Issue
Block a user