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]));
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user