UNPKG

@joergmittaglawo/dmvconfig

Version:

DMV Configuration scripts for Lawo V__matrix Distributed Multiviewers.

1 lines 3.46 kB
Object.defineProperty(exports,"__esModule",{value:!0}),exports.find_subtree=exports.find_keyword=exports.find_branch=exports.annotate=exports.children_of_atomic_subtree=exports.children_of_subtree=void 0;const e=require("./node_util");function t(t,r){if("children"in r)return r.children;{e.assert(r.type_identifier);const s=t.typedefs[r.type_identifier];return e.assert("subtree"===s.data_type),"children"in s?s.children:(e.assert(!1),[])}}function r(t,r){if("children"in r)return r.children;{e.assert(r.type_identifier);const s=t.typedefs[r.type_identifier];return"atomic subtree"===s.data_type&&"children"in s?s.children:(e.assert(!1),[])}}function s(e,t){const r=t.split(".");for(const s of e.keywords)if(s.sys_name===r[0]){let e=s;if(1===r.length)return e;for(let s=1;s<r.length-1;++s)for(const n of e.children)if(n.sys_name===r[s]){if("subtree"===n.data_type){e=n;break}throw new Error("Unable to look up "+t)}const n=r[r.length-1].replace(/_(command|status)$/,"");for(const t of e.children)if(t.sys_name===r[r.length-1]&&"subtree"===t.data_type||"subtree"!==t.data_type&&("duplex"===t.kw_type&&t.sys_name===n||"duplex"!==t.kw_type&&t.sys_name===r[r.length-1]))return t}throw new Error("Unknown component "+r[0])}exports.children_of_subtree=t,exports.children_of_atomic_subtree=r,exports.annotate=function(s,n){var o;const i=t=>{if("string"==typeof t){const r=t.split("::");e.assert(2===r.length);const n=s.get_constant(r[0],r[1]);return e.assert("number"==typeof n),n}return t},a=(t,s,o)=>{const _=r(n,t);e.assert(_);const l=_.map(e=>{var t;return"atomic subtree"===e.data_type?a(e,s,o):{...e,has_index:void 0!==e.array_size,local_multiplicity:i(null!==(t=e.array_size)&&void 0!==t?t:1)}});let c=!1,d=1;return"array_size"in t&&(c=!0,d=i(t.array_size)),{...t,children:l,has_index:c,local_multiplicity:d}},_=(r,s,o,l)=>{var c;const d=t(n,r);e.assert(d);let u=!0,p=1;"array_size"in r?p=i(r.array_size):"table_size"in r?p=i(r.table_size):u=!1;const y=o*p;let f=[],h={},b=s;const m=(t,r)=>{e.assert(!h.hasOwnProperty(t)),h[t]=b,b+=r?y:o},w=(e,t)=>{switch(t){case"duplex":m(e+"_command",!0),m(e+"_status",!0);break;default:m(e,!0)}};e.assert(!l||"table_size"in r),"table_size"in r&&(m("rowMask",!1),m("create_row",!1),m("created_row",!1),m("syslog_level",!1),m("table_cmd",!1),l&&(m("row_cmd",!0),m("row_name_command",!0),m("row_name_status",!0)));for(const e of d)if("atomic subtree"===e.data_type)w(e.sys_name,e.kw_type),f.push(a(e,b,y));else if("subtree"===e.data_type){const[t,r]=_(e,b,y,"table_size"in e&&e.named_rows);f.push(t),h[e.sys_name]=b,b=r}else w(e.sys_name,e.kw_type),f.push({...e,has_index:"array_size"in e,local_multiplicity:i(null!==(c=e.array_size)&&void 0!==c?c:1)});return[{...r,children:f,starting_index:h,stride:y,local_multiplicity:p,has_index:u},b]};let l=0,c=[];for(const t of n.keywords){let r=!0;for(const n of null!==(o=t.bound_to)&&void 0!==o?o:[]){const t=n.split("::");e.assert(2===t.length);const o=s.get_constant(t[0],t[1]);e.assert("boolean"==typeof o),!1===o&&(r=!1)}if(!r)continue;const[n,i]=_(t,l,1,!1);c.push({...t,...n}),l=i}return{...n,keywords:c}},exports.find_branch=s,exports.find_keyword=function(e,t,r){const n=s(e,`${t}.${r}`);if("subtree"===n.data_type)throw new Error(`Mistyped result (${t} should have been a keyword, but is a subtree)`);return n},exports.find_subtree=function(e,t){const r=s(e,t);if("subtree"!==r.data_type)throw new Error(`Mistyped result (${t} should have been a subtree)}`);return r};