circuitscript 0.1.31 → 0.1.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/dist/cjs/BaseVisitor.js +37 -3
  2. package/dist/cjs/RefdesAnnotationVisitor.js +27 -10
  3. package/dist/cjs/antlr/CircuitScriptParser.js +990 -831
  4. package/dist/cjs/draw_symbols.js +38 -34
  5. package/dist/cjs/environment.js +24 -4
  6. package/dist/cjs/execute.js +107 -68
  7. package/dist/cjs/globals.js +4 -2
  8. package/dist/cjs/graph.js +14 -12
  9. package/dist/cjs/helpers.js +85 -16
  10. package/dist/cjs/layout.js +50 -25
  11. package/dist/cjs/main.js +16 -18
  12. package/dist/cjs/objects/ClassComponent.js +199 -30
  13. package/dist/cjs/objects/types.js +5 -1
  14. package/dist/cjs/regenerate-tests.js +3 -3
  15. package/dist/cjs/render.js +5 -3
  16. package/dist/cjs/rules-check/no-connect-on-connected-pin.js +9 -8
  17. package/dist/cjs/rules-check/rules.js +7 -2
  18. package/dist/cjs/rules-check/unconnected-pins.js +10 -8
  19. package/dist/cjs/utils.js +2 -1
  20. package/dist/cjs/validate/SymbolValidatorVisitor.js +0 -10
  21. package/dist/cjs/visitor.js +284 -191
  22. package/dist/esm/BaseVisitor.js +37 -3
  23. package/dist/esm/RefdesAnnotationVisitor.js +27 -10
  24. package/dist/esm/antlr/CircuitScriptParser.js +989 -830
  25. package/dist/esm/antlr/CircuitScriptVisitor.js +1 -0
  26. package/dist/esm/draw_symbols.js +38 -34
  27. package/dist/esm/environment.js +21 -1
  28. package/dist/esm/execute.js +108 -69
  29. package/dist/esm/globals.js +2 -0
  30. package/dist/esm/graph.js +14 -12
  31. package/dist/esm/helpers.js +86 -17
  32. package/dist/esm/layout.js +51 -26
  33. package/dist/esm/main.js +16 -18
  34. package/dist/esm/objects/ClassComponent.js +201 -30
  35. package/dist/esm/objects/types.js +7 -1
  36. package/dist/esm/regenerate-tests.js +3 -3
  37. package/dist/esm/render.js +5 -3
  38. package/dist/esm/rules-check/no-connect-on-connected-pin.js +9 -8
  39. package/dist/esm/rules-check/rules.js +7 -2
  40. package/dist/esm/rules-check/unconnected-pins.js +10 -8
  41. package/dist/esm/utils.js +2 -1
  42. package/dist/esm/validate/SymbolValidatorVisitor.js +0 -10
  43. package/dist/esm/visitor.js +185 -92
  44. package/dist/types/BaseVisitor.d.ts +15 -5
  45. package/dist/types/RefdesAnnotationVisitor.d.ts +2 -0
  46. package/dist/types/antlr/CircuitScriptParser.d.ts +32 -14
  47. package/dist/types/antlr/CircuitScriptVisitor.d.ts +2 -0
  48. package/dist/types/environment.d.ts +7 -1
  49. package/dist/types/execute.d.ts +4 -1
  50. package/dist/types/globals.d.ts +2 -0
  51. package/dist/types/graph.d.ts +2 -2
  52. package/dist/types/helpers.d.ts +2 -1
  53. package/dist/types/layout.d.ts +5 -4
  54. package/dist/types/objects/ClassComponent.d.ts +34 -9
  55. package/dist/types/objects/types.d.ts +19 -3
  56. package/dist/types/validate/SymbolValidatorVisitor.d.ts +0 -4
  57. package/dist/types/visitor.d.ts +7 -1
  58. package/package.json +1 -1
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const fs_1 = __importDefault(require("fs"));
7
7
  const helpers_js_1 = require("./helpers.js");
8
8
  const environment_js_1 = require("./environment.js");
9
- const mainDir = './__tests__/renderData/';
9
+ const mainDir = './__tests__/testData/renderData/';
10
10
  const env = new environment_js_1.NodeScriptEnvironment();
11
11
  environment_js_1.NodeScriptEnvironment.setInstance(env);
12
12
  async function regenerateTests(extra = "") {
@@ -14,7 +14,7 @@ async function regenerateTests(extra = "") {
14
14
  const cstFiles = [];
15
15
  const files = fs_1.default.readdirSync(mainDir);
16
16
  files.forEach(file => {
17
- if (file.endsWith('.cst')) {
17
+ if (file.endsWith('.cst') && file.startsWith('script')) {
18
18
  cstFiles.push(file);
19
19
  }
20
20
  });
@@ -24,7 +24,7 @@ async function regenerateTests(extra = "") {
24
24
  const scriptData = fs_1.default.readFileSync(inputPath, { encoding: 'utf-8' });
25
25
  const outputPath = mainDir + 'svgs/' + file + extra + '.svg';
26
26
  env.setModuleDirectory(mainDir);
27
- env.setDefaultLibsPath(mainDir + '../../libs/');
27
+ env.setDefaultLibsPath(mainDir + '../../../libs/');
28
28
  await (0, helpers_js_1.renderScript)(scriptData, outputPath, {
29
29
  dumpNets: false,
30
30
  dumpData: false,
@@ -42,10 +42,11 @@ function renderSheetsToSVG(sheetFrames, logger) {
42
42
  const frameComponent = sheet.frame.frame.parameters
43
43
  .get(Frame_js_1.FrameParamKeys.SheetType);
44
44
  if (frameComponent) {
45
- if (frameComponent.displayProp === null) {
45
+ const frameComponentUnit = frameComponent.getUnit();
46
+ if (frameComponentUnit.displayProp === null) {
46
47
  throw 'Invalid graphic object for sheet frame';
47
48
  }
48
- const frameRects = (0, layout_js_1.ExtractDrawingRects)(frameComponent.displayProp) ?? [];
49
+ const frameRects = (0, layout_js_1.ExtractDrawingRects)(frameComponentUnit.displayProp) ?? [];
49
50
  let originalWidthMM = (0, ParamDefinition_js_1.numeric)(0);
50
51
  let originalHeightMM = (0, ParamDefinition_js_1.numeric)(0);
51
52
  let widthMM = (0, ParamDefinition_js_1.numeric)(0);
@@ -334,7 +335,8 @@ function drawSheetFrameBorder(frameGroup, frame) {
334
335
  const frameParams = frame.frame.parameters;
335
336
  if (frameParams.has(Frame_js_1.FrameParamKeys.SheetType)) {
336
337
  const frameComponent = frameParams.get(Frame_js_1.FrameParamKeys.SheetType);
337
- const { displayProp = null } = frameComponent ?? {};
338
+ const frameComponentUnit = frameComponent.getUnit();
339
+ const { displayProp = null } = frameComponentUnit ?? {};
338
340
  if (displayProp) {
339
341
  const sheetFrameGroup = frameGroup.group();
340
342
  const symbol = new draw_symbols_js_1.SymbolPlaceholder(displayProp);
@@ -11,25 +11,26 @@ function RuleCheck_NoConnectOnConnectedPin(graph, nets) {
11
11
  const makeComponentPinHash = (instanceName, pin) => {
12
12
  return instanceName + '-' + pin.getHashValue();
13
13
  };
14
- nets.forEach(item => {
15
- const [component, pin, net] = item;
14
+ for (const [component, pin, net] of nets) {
16
15
  if (!netComponentPins.has(net)) {
17
16
  netComponentPins.set(net, []);
18
17
  }
19
18
  const items = netComponentPins.get(net);
19
+ const unit = component.getUnitForPin(pin);
20
20
  items.push([
21
- component.instanceName,
21
+ unit.instanceName,
22
22
  pin
23
23
  ]);
24
24
  netComponentPins.set(net, items);
25
- pinMapping.set(makeComponentPinHash(component.instanceName, pin), net);
26
- });
27
- allNodes.forEach(node => {
25
+ pinMapping.set(makeComponentPinHash(unit.instanceName, pin), net);
26
+ }
27
+ ;
28
+ for (const node of allNodes) {
28
29
  const nodeInfo = graph.node(node);
29
30
  if (nodeInfo[0] === graph_js_1.RenderItemType.Component) {
30
31
  const { component } = nodeInfo[1];
31
32
  if (component.hasParam('no_connect')) {
32
- const instanceName = component.instanceName;
33
+ const instanceName = component.getUnit().instanceName;
33
34
  const edges = graph.nodeEdges(node);
34
35
  const otherNodes = [];
35
36
  edges.forEach(edge => {
@@ -75,7 +76,7 @@ function RuleCheck_NoConnectOnConnectedPin(graph, nets) {
75
76
  });
76
77
  }
77
78
  }
78
- });
79
+ }
79
80
  return items;
80
81
  }
81
82
  exports.RuleCheck_NoConnectOnConnectedPin = RuleCheck_NoConnectOnConnectedPin;
@@ -25,7 +25,7 @@ function EvaluateERCRules(visitor, graph, nets) {
25
25
  reportItems.push({
26
26
  type,
27
27
  start: token,
28
- message: `Unconnected pin ${item.pin} for component`
28
+ message: `Unconnected pin: ${instance.assignedRefDes} pin ${item.pin}`
29
29
  });
30
30
  }
31
31
  }
@@ -47,12 +47,17 @@ function EvaluateERCRules(visitor, graph, nets) {
47
47
  case ERC_Rules.NoConnectOnConnectedPin:
48
48
  {
49
49
  const instance = item.instance;
50
+ const { instance: targetComponent, pin: targetPin } = item.target;
51
+ let extra = '';
52
+ if (targetComponent && targetComponent.assignedRefDes) {
53
+ extra = `: ${targetComponent.assignedRefDes} pin ${targetPin}`;
54
+ }
50
55
  const token = getComponentFirstCtxToken(instance);
51
56
  if (token) {
52
57
  reportItems.push({
53
58
  type,
54
59
  start: token,
55
- message: `No connect on connected pin`
60
+ message: `No connect on connected pin${extra}`
56
61
  });
57
62
  }
58
63
  }
@@ -6,13 +6,15 @@ const rules_js_1 = require("./rules.js");
6
6
  function RuleCheck_UnconnectedPinsWires(graph) {
7
7
  const items = [];
8
8
  const allNodes = graph.nodes();
9
- allNodes.forEach(node => {
9
+ for (const node of allNodes) {
10
10
  const nodeInfo = graph.node(node);
11
11
  if (nodeInfo[0] === graph_js_1.RenderItemType.Component) {
12
- const { component } = nodeInfo[1];
12
+ const renderComponent = nodeInfo[1];
13
+ const { component, unitId } = renderComponent;
13
14
  const edges = graph.nodeEdges(node);
14
- const instanceName = component.instanceName;
15
- const connectedPins = [];
15
+ const componentUnit = component.getUnit(unitId);
16
+ const instanceName = componentUnit.instanceName;
17
+ const connectedUnitPins = [];
16
18
  edges.forEach(edge => {
17
19
  const edgeInfo = graph.edge(edge.v, edge.w);
18
20
  let pin;
@@ -22,12 +24,12 @@ function RuleCheck_UnconnectedPinsWires(graph) {
22
24
  else if (edge.w === instanceName) {
23
25
  pin = edgeInfo[3];
24
26
  }
25
- connectedPins.push(pin.getHashValue());
27
+ connectedUnitPins.push(pin.getHashValue());
26
28
  });
27
- const pinIds = Array.from(component.pins.keys());
29
+ const pinIds = Array.from(componentUnit.pins.keys());
28
30
  pinIds.forEach(pinId => {
29
31
  const hashValue = pinId.getHashValue();
30
- if (connectedPins.indexOf(hashValue) === -1) {
32
+ if (connectedUnitPins.indexOf(hashValue) === -1) {
31
33
  items.push({
32
34
  type: rules_js_1.ERC_Rules.UnconnectedPin,
33
35
  instance: component,
@@ -46,7 +48,7 @@ function RuleCheck_UnconnectedPinsWires(graph) {
46
48
  });
47
49
  }
48
50
  }
49
- });
51
+ }
50
52
  return items;
51
53
  }
52
54
  exports.RuleCheck_UnconnectedPinsWires = RuleCheck_UnconnectedPinsWires;
package/dist/cjs/utils.js CHANGED
@@ -66,7 +66,8 @@ function getBoundsSize(bounds) {
66
66
  }
67
67
  exports.getBoundsSize = getBoundsSize;
68
68
  function getPortType(component) {
69
- const drawingCommands = component.displayProp;
69
+ const targetUnit = component.getUnit();
70
+ const drawingCommands = targetUnit.displayProp;
70
71
  let foundPinType = null;
71
72
  const commands = drawingCommands.getCommands();
72
73
  commands.some(item => {
@@ -12,7 +12,6 @@ class SymbolValidatorVisitor extends BaseVisitor_js_1.BaseVisitor {
12
12
  constructor() {
13
13
  super(...arguments);
14
14
  this.symbolTable = new SymbolTable_js_2.SymbolTable();
15
- this.filePathStack = [];
16
15
  this.visitImport_simple = async (ctx) => {
17
16
  await this.importCommon(ctx, types_js_1.ImportFunctionHandling.AllWithNamespace);
18
17
  };
@@ -113,15 +112,6 @@ class SymbolValidatorVisitor extends BaseVisitor_js_1.BaseVisitor {
113
112
  });
114
113
  };
115
114
  }
116
- enterFile(filePath) {
117
- this.filePathStack.push(filePath);
118
- }
119
- exitFile() {
120
- this.filePathStack.pop();
121
- }
122
- getCurrentFile() {
123
- return this.filePathStack[this.filePathStack.length - 1];
124
- }
125
115
  addSymbolVariable(token, name, value, executor = null) {
126
116
  const useExecutor = executor === null ? this.getExecutor() : executor;
127
117
  this.symbolTable.addVariable(token, this.getCurrentFile(), useExecutor, name, value);