circuitscript 0.0.21 → 0.0.24

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 (163) hide show
  1. package/dist/cjs/antlr/CircuitScriptLexer.js +288 -0
  2. package/dist/cjs/antlr/CircuitScriptParser.js +4905 -0
  3. package/dist/cjs/antlr/CircuitScriptVisitor.js +6 -0
  4. package/{src/draw_symbols.ts → dist/cjs/draw_symbols.js} +303 -614
  5. package/dist/cjs/execute.js +780 -0
  6. package/{src/export.ts → dist/cjs/export.js} +34 -56
  7. package/dist/cjs/fonts.js +4 -0
  8. package/dist/cjs/geometry.js +430 -0
  9. package/dist/cjs/globals.js +60 -0
  10. package/dist/cjs/helpers.js +99 -0
  11. package/dist/cjs/index.js +29 -0
  12. package/{src/layout.ts → dist/cjs/layout.js} +413 -1002
  13. package/dist/cjs/lexer.js +114 -0
  14. package/dist/cjs/logger.js +17 -0
  15. package/dist/cjs/main.js +87 -0
  16. package/dist/cjs/objects/ClassComponent.js +142 -0
  17. package/dist/cjs/objects/ExecutionScope.js +134 -0
  18. package/dist/cjs/objects/Frame.js +22 -0
  19. package/{src/objects/Net.ts → dist/cjs/objects/Net.js} +9 -24
  20. package/dist/cjs/objects/ParamDefinition.js +42 -0
  21. package/dist/cjs/objects/PinDefinition.js +31 -0
  22. package/dist/cjs/objects/PinTypes.js +11 -0
  23. package/dist/cjs/objects/Wire.js +9 -0
  24. package/dist/cjs/objects/types.js +9 -0
  25. package/dist/cjs/parser.js +299 -0
  26. package/dist/cjs/regenerate-tests.js +23 -0
  27. package/dist/cjs/render.js +155 -0
  28. package/{src/server.ts → dist/cjs/server.js} +15 -21
  29. package/dist/cjs/sizing.js +105 -0
  30. package/{src/utils.ts → dist/cjs/utils.js} +25 -35
  31. package/{src/visitor.ts → dist/cjs/visitor.js} +392 -948
  32. package/{build/src/antlr/CircuitScriptLexer.js → dist/esm/antlr/CircuitScriptLexer.mjs} +90 -91
  33. package/{build/src/antlr/CircuitScriptParser.js → dist/esm/antlr/CircuitScriptParser.mjs} +138 -136
  34. package/{build/src/draw_symbols.js → dist/esm/draw_symbols.mjs} +11 -11
  35. package/{build/src/execute.js → dist/esm/execute.mjs} +9 -8
  36. package/{build/src/export.js → dist/esm/export.mjs} +2 -2
  37. package/{build/src/geometry.js → dist/esm/geometry.mjs} +3 -7
  38. package/{build/src/helpers.js → dist/esm/helpers.mjs} +27 -7
  39. package/dist/esm/index.mjs +13 -0
  40. package/{build/src/layout.js → dist/esm/layout.mjs} +11 -11
  41. package/{build/src/lexer.js → dist/esm/lexer.mjs} +2 -2
  42. package/{build/src/main.js → dist/esm/main.mjs} +5 -5
  43. package/{build/src/objects/ClassComponent.js → dist/esm/objects/ClassComponent.mjs} +3 -3
  44. package/{build/src/objects/PinDefinition.js → dist/esm/objects/PinDefinition.mjs} +1 -1
  45. package/dist/esm/parser.mjs +269 -0
  46. package/{build/src/regenerate-tests.js → dist/esm/regenerate-tests.mjs} +1 -1
  47. package/{build/src/render.js → dist/esm/render.mjs} +7 -24
  48. package/{build/src/sizing.js → dist/esm/sizing.mjs} +22 -8
  49. package/{build/src/visitor.js → dist/esm/visitor.mjs} +10 -29
  50. package/dist/types/antlr/CircuitScriptLexer.d.ts +71 -0
  51. package/dist/types/antlr/CircuitScriptParser.d.ts +675 -0
  52. package/dist/types/antlr/CircuitScriptVisitor.d.ts +115 -0
  53. package/dist/types/draw_symbols.d.ts +162 -0
  54. package/dist/types/execute.d.ts +85 -0
  55. package/dist/types/export.d.ts +2 -0
  56. package/dist/types/fonts.d.ts +1 -0
  57. package/dist/types/geometry.d.ts +84 -0
  58. package/dist/types/globals.d.ts +50 -0
  59. package/dist/types/helpers.d.ts +9 -0
  60. package/dist/types/index.d.ts +13 -0
  61. package/dist/types/layout.d.ts +147 -0
  62. package/dist/types/lexer.d.ts +19 -0
  63. package/dist/types/logger.d.ts +6 -0
  64. package/dist/types/main.d.ts +2 -0
  65. package/dist/types/objects/ClassComponent.d.ts +40 -0
  66. package/dist/types/objects/ExecutionScope.d.ts +64 -0
  67. package/dist/types/objects/Frame.d.ts +15 -0
  68. package/dist/types/objects/Net.d.ts +10 -0
  69. package/dist/types/objects/ParamDefinition.d.ts +20 -0
  70. package/dist/types/objects/PinDefinition.d.ts +24 -0
  71. package/dist/types/objects/PinTypes.d.ts +7 -0
  72. package/dist/types/objects/Wire.d.ts +11 -0
  73. package/dist/types/objects/types.d.ts +49 -0
  74. package/dist/types/parser.d.ts +38 -0
  75. package/dist/types/regenerate-tests.d.ts +1 -0
  76. package/dist/types/render.d.ts +10 -0
  77. package/dist/types/server.d.ts +1 -0
  78. package/dist/types/sizing.d.ts +15 -0
  79. package/dist/types/utils.d.ts +19 -0
  80. package/dist/types/visitor.d.ts +135 -0
  81. package/package.json +30 -12
  82. package/.editorconfig +0 -15
  83. package/.eslintignore +0 -1
  84. package/.eslintrc.json +0 -27
  85. package/.gitlab-ci.yml +0 -81
  86. package/.prettierignore +0 -8
  87. package/.prettierrc +0 -16
  88. package/__tests__/expectedResults.ts +0 -657
  89. package/__tests__/helpers.ts +0 -82
  90. package/__tests__/parseScripts.ts +0 -593
  91. package/__tests__/renderData/script1.cst +0 -58
  92. package/__tests__/renderData/script1.cst.svg +0 -1
  93. package/__tests__/renderData/script2.cst +0 -16
  94. package/__tests__/renderData/script2.cst.svg +0 -1
  95. package/__tests__/renderData/script3.cst +0 -30
  96. package/__tests__/renderData/script3.cst.svg +0 -1
  97. package/__tests__/renderData/script4.cst +0 -54
  98. package/__tests__/renderData/script4.cst.svg +0 -1
  99. package/__tests__/renderData/script5.cst +0 -23
  100. package/__tests__/renderData/script5.cst.svg +0 -1
  101. package/__tests__/renderData/script6.cst +0 -28
  102. package/__tests__/renderData/script6.cst.svg +0 -1
  103. package/__tests__/renderData/script7.cst +0 -26
  104. package/__tests__/renderData/script7.cst.svg +0 -1
  105. package/__tests__/renderData/script8.cst +0 -37
  106. package/__tests__/renderData/script8.cst.svg +0 -1
  107. package/__tests__/testCLI.ts +0 -68
  108. package/__tests__/testMathOps.ts +0 -36
  109. package/__tests__/testMergeWires.ts +0 -141
  110. package/__tests__/testParse.ts +0 -263
  111. package/__tests__/testRender.ts +0 -38
  112. package/build/src/parser.js +0 -69
  113. package/documentation.md +0 -238
  114. package/examples/example_arduino_uno.cst +0 -1146
  115. package/examples/example_garden_pump.cst +0 -567
  116. package/examples/lib.cst +0 -185
  117. package/fonts/Inter-Bold.ttf +0 -0
  118. package/fonts/Inter-Regular.ttf +0 -0
  119. package/fonts/OpenSans-Regular.ttf +0 -0
  120. package/fonts/Roboto-Regular.ttf +0 -0
  121. package/jest.config.js +0 -23
  122. package/libs/lib.cst +0 -185
  123. package/refresh.html +0 -42
  124. package/server.cjs +0 -50
  125. package/src/antlr/CircuitScript.g4 +0 -209
  126. package/src/antlr/CircuitScriptLexer.ts +0 -317
  127. package/src/antlr/CircuitScriptParser.ts +0 -4979
  128. package/src/antlr/CircuitScriptVisitor.ts +0 -420
  129. package/src/execute.ts +0 -1227
  130. package/src/fonts.ts +0 -1
  131. package/src/geometry.ts +0 -638
  132. package/src/globals.ts +0 -67
  133. package/src/helpers.ts +0 -114
  134. package/src/lexer.ts +0 -151
  135. package/src/logger.ts +0 -17
  136. package/src/main.ts +0 -105
  137. package/src/objects/ClassComponent.ts +0 -223
  138. package/src/objects/ExecutionScope.ts +0 -201
  139. package/src/objects/Frame.ts +0 -20
  140. package/src/objects/ParamDefinition.ts +0 -49
  141. package/src/objects/PinDefinition.ts +0 -49
  142. package/src/objects/PinTypes.ts +0 -7
  143. package/src/objects/Wire.ts +0 -19
  144. package/src/objects/types.ts +0 -66
  145. package/src/parser.ts +0 -106
  146. package/src/regenerate-tests.ts +0 -25
  147. package/src/render.ts +0 -260
  148. package/src/sizing.ts +0 -96
  149. package/tsconfig.json +0 -26
  150. package/tsconfig.release.json +0 -8
  151. /package/{build/src/antlr/CircuitScriptVisitor.js → dist/esm/antlr/CircuitScriptVisitor.mjs} +0 -0
  152. /package/{build/src/fonts.js → dist/esm/fonts.mjs} +0 -0
  153. /package/{build/src/globals.js → dist/esm/globals.mjs} +0 -0
  154. /package/{build/src/logger.js → dist/esm/logger.mjs} +0 -0
  155. /package/{build/src/objects/ExecutionScope.js → dist/esm/objects/ExecutionScope.mjs} +0 -0
  156. /package/{build/src/objects/Frame.js → dist/esm/objects/Frame.mjs} +0 -0
  157. /package/{build/src/objects/Net.js → dist/esm/objects/Net.mjs} +0 -0
  158. /package/{build/src/objects/ParamDefinition.js → dist/esm/objects/ParamDefinition.mjs} +0 -0
  159. /package/{build/src/objects/PinTypes.js → dist/esm/objects/PinTypes.mjs} +0 -0
  160. /package/{build/src/objects/Wire.js → dist/esm/objects/Wire.mjs} +0 -0
  161. /package/{build/src/objects/types.js → dist/esm/objects/types.mjs} +0 -0
  162. /package/{build/src/server.js → dist/esm/server.mjs} +0 -0
  163. /package/{build/src/utils.js → dist/esm/utils.mjs} +0 -0
@@ -1,1044 +1,702 @@
1
- import { ParseTreeVisitor, ParserRuleContext } from 'antlr4';
2
-
3
- import { readFileSync } from 'fs';
4
- import { join } from 'path';
5
-
6
- import {
7
- Add_component_exprContext,
8
- AdditionExprContext,
9
- Assignment_exprContext,
10
- At_blockContext,
11
- At_block_pin_exprContext,
12
- At_block_pin_expression_complexContext,
13
- At_block_pin_expression_simpleContext,
14
- At_component_exprContext,
15
- Atom_exprContext,
16
- BinaryOperatorExprContext,
17
- Blank_exprContext,
18
- Path_blocksContext,
19
- Component_select_exprContext,
20
- Create_component_exprContext,
21
- Create_graphic_exprContext,
22
- DataExprContext,
23
- Data_expr_with_assignmentContext,
24
- Double_dot_property_set_exprContext,
25
- ExpressionContext,
26
- Frame_exprContext,
27
- Function_args_exprContext,
28
- Function_def_exprContext,
29
- Function_exprContext,
30
- Function_return_exprContext,
31
- Import_exprContext,
32
- Keyword_assignment_exprContext,
33
- MultiplyExprContext,
34
- Nested_propertiesContext,
35
- Net_namespace_exprContext,
36
- ParametersContext,
37
- Pin_select_expr2Context,
38
- Pin_select_exprContext,
39
- Point_exprContext,
40
- Property_exprContext,
41
- Property_key_exprContext,
42
- Property_set_exprContext,
43
- RoundedBracketsExprContext,
44
- ScriptContext,
45
- Single_line_propertyContext,
46
- Sub_exprContext,
47
- To_component_exprContext,
48
- Value_exprContext,
49
- Wire_exprContext,
50
- ValueAtomExprContext,
51
- UnaryOperatorExprContext,
52
- } from './antlr/CircuitScriptParser.js';
53
- import { ExecutionContext } from './execute.js';
54
- import { ClassComponent } from './objects/ClassComponent.js';
55
- import {
56
- NumericValue,
57
- ParamDefinition,
58
- PercentageValue,
59
- PinBlankValue,
60
- } from './objects/ParamDefinition.js';
61
- import { PinDefinition, PinIdType } from './objects/PinDefinition.js';
62
- import { PinTypes } from './objects/PinTypes.js';
63
- import { ExecutionScope } from './objects/ExecutionScope.js';
64
- import { CFunctionOptions, CallableParameter, ComplexType, ComponentPin,
65
- ComponentPinNet, FunctionDefinedParameter, ReferenceType, UndeclaredReference, ValueType } from './objects/types.js';
66
- import { Logger } from './logger.js';
67
- import { BlockTypes, ComponentTypes, NoNetText } from './globals.js';
68
- import { Net } from './objects/Net.js';
69
- import { SubExpressionCommand, SymbolDrawingCommands } from './draw_symbols.js';
70
- import { parseFileWithVisitor } from './parser.js';
71
-
72
- export class MainVisitor extends ParseTreeVisitor<any> {
73
- // See class CircuitScriptVisitor (generated by antlr4) to find method names
74
-
75
- // Contains the methods here, so that it is function based instead
76
- // of just lambdas/callbacks...
77
-
78
- indentLevel = 0;
79
- startingContext: ExecutionContext;
80
- executionStack: ExecutionContext[];
81
-
82
- // If true, then do not print out anything
83
- silent = false;
84
-
85
- logger: Logger;
86
-
87
- printStream: string[] = [];
88
- printToConsole = true;
89
-
90
- acceptedDirections = ['left', 'right', 'up', 'down'];
91
-
92
- pinTypesList: string[] = [
93
- PinTypes.Any,
94
- PinTypes.Input,
95
- PinTypes.Output,
96
- PinTypes.IO,
97
- PinTypes.Power,
98
- ];
99
-
100
- onImportFile = (visitor: MainVisitor, filePath:string): {hasError:boolean, hasParseError: boolean} => {
101
- throw "Import file not implemented"
102
- }
103
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VisitorExecutionException = exports.MainVisitor = void 0;
4
+ const antlr4_1 = require("antlr4");
5
+ const fs_1 = require("fs");
6
+ const path_1 = require("path");
7
+ const execute_js_1 = require("./execute.js");
8
+ const ClassComponent_js_1 = require("./objects/ClassComponent.js");
9
+ const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
10
+ const PinDefinition_js_1 = require("./objects/PinDefinition.js");
11
+ const PinTypes_js_1 = require("./objects/PinTypes.js");
12
+ const types_js_1 = require("./objects/types.js");
13
+ const logger_js_1 = require("./logger.js");
14
+ const globals_js_1 = require("./globals.js");
15
+ const draw_symbols_js_1 = require("./draw_symbols.js");
16
+ const parser_js_1 = require("./parser.js");
17
+ class MainVisitor extends antlr4_1.ParseTreeVisitor {
104
18
  constructor(silent = false) {
105
19
  super();
106
- this.logger = new Logger();
107
-
108
- this.startingContext = new ExecutionContext(
109
- '__',
110
- '__.',
111
- '/',
112
- 0, 0, silent,
113
- this.logger);
114
-
20
+ this.indentLevel = 0;
21
+ this.silent = false;
22
+ this.printStream = [];
23
+ this.printToConsole = true;
24
+ this.acceptedDirections = ['left', 'right', 'up', 'down'];
25
+ this.pinTypesList = [
26
+ PinTypes_js_1.PinTypes.Any,
27
+ PinTypes_js_1.PinTypes.Input,
28
+ PinTypes_js_1.PinTypes.Output,
29
+ PinTypes_js_1.PinTypes.IO,
30
+ PinTypes_js_1.PinTypes.Power,
31
+ ];
32
+ this.onImportFile = (visitor, filePath) => {
33
+ throw "Import file not implemented";
34
+ };
35
+ this.pinTypes = [
36
+ PinTypes_js_1.PinTypes.Any,
37
+ PinTypes_js_1.PinTypes.IO,
38
+ PinTypes_js_1.PinTypes.Input,
39
+ PinTypes_js_1.PinTypes.Output,
40
+ PinTypes_js_1.PinTypes.Power,
41
+ ];
42
+ this.logger = new logger_js_1.Logger();
43
+ this.startingContext = new execute_js_1.ExecutionContext('__', '__.', '/', 0, 0, silent, this.logger);
115
44
  this.setupPrintFunction(this.startingContext);
116
-
117
45
  this.executionStack = [this.startingContext];
118
- this.startingContext.resolveNet =
46
+ this.startingContext.resolveNet =
119
47
  this.createNetResolver(this.executionStack);
120
-
121
48
  this.silent = silent;
122
49
  }
123
-
124
- getExecutor(): ExecutionContext {
50
+ getExecutor() {
125
51
  return this.executionStack[this.executionStack.length - 1];
126
52
  }
127
-
128
- visit(ctx: ParserRuleContext): any {
53
+ visit(ctx) {
129
54
  if (Array.isArray(ctx)) {
130
55
  return ctx.map(function (child) {
131
56
  try {
132
57
  return child.accept(this);
133
- } catch (err) {
58
+ }
59
+ catch (err) {
134
60
  this.handleError(child, err);
135
61
  }
136
62
  }, this);
137
- } else {
63
+ }
64
+ else {
138
65
  try {
139
66
  return ctx.accept(this);
140
- } catch (err) {
67
+ }
68
+ catch (err) {
141
69
  this.handleError(ctx, err);
142
70
  }
143
71
  }
144
72
  }
145
-
146
- handleError(ctx: ParserRuleContext, err: string | VisitorExecutionException): void {
73
+ handleError(ctx, err) {
147
74
  if (!(err instanceof VisitorExecutionException)) {
148
75
  throw new VisitorExecutionException(ctx, err);
149
- } else {
76
+ }
77
+ else {
150
78
  throw err;
151
79
  }
152
80
  }
153
-
154
- visitScript(ctx: ScriptContext): any {
81
+ visitScript(ctx) {
155
82
  this.print('===', 'start', '===');
156
83
  const result = this.visitChildren(ctx);
157
84
  this.print('===', 'end', '===');
158
85
  return result;
159
86
  }
160
-
161
- visitParameters(ctx: ParametersContext): CallableParameter[] {
87
+ visitParameters(ctx) {
162
88
  const dataExpressions = ctx.data_expr_list();
163
89
  const keywordAssignmentExpressions = ctx.keyword_assignment_expr_list();
164
-
165
- const returnList: CallableParameter[] = [];
166
-
90
+ const returnList = [];
167
91
  dataExpressions.forEach((item, index) => {
168
92
  const value = this.visit(item);
169
93
  returnList.push(['position', index, value]);
170
94
  });
171
-
172
95
  keywordAssignmentExpressions.forEach((item) => {
173
96
  const [key, value] = this.visit(item);
174
97
  returnList.push(['keyword', key, value]);
175
98
  });
176
-
177
99
  return returnList;
178
100
  }
179
-
180
- visitKeyword_assignment_expr(ctx: Keyword_assignment_exprContext):
181
- [key: string, value: any] {
101
+ visitKeyword_assignment_expr(ctx) {
182
102
  const id = ctx.ID().getText();
183
103
  const value = this.visit(ctx.data_expr());
184
104
  return [id, value];
185
105
  }
186
-
187
- visitAssignment_expr(ctx: Assignment_exprContext): ComplexType {
106
+ visitAssignment_expr(ctx) {
188
107
  const atomStr = ctx.atom_expr().getText();
189
-
190
- // Do not allow the atom to have any parentheses in the assignment
191
108
  if (atomStr.indexOf('(') !== -1 || atomStr.indexOf(')') !== -1) {
192
109
  throw "Invalid assignment expression!";
193
110
  }
194
-
195
111
  const reference = this.visit(ctx.atom_expr());
196
- const value = this.visit(ctx.data_expr()) as ComplexType;
197
-
198
- if (value instanceof ClassComponent) {
199
- // If value is a class component, then update the instance name
112
+ const value = this.visit(ctx.data_expr());
113
+ if (value instanceof ClassComponent_js_1.ClassComponent) {
200
114
  const instances = this.getExecutor().scope.instances;
201
- const tmpComponent: ClassComponent = value;
202
-
115
+ const tmpComponent = value;
203
116
  const oldName = tmpComponent.instanceName;
204
-
205
- // Rename to new name
206
117
  tmpComponent.instanceName = reference.name;
207
-
208
118
  instances.delete(oldName);
209
119
  instances.set(reference.name, tmpComponent);
210
-
211
- this.getExecutor().print(
212
- `assigned '${reference.name}' to ClassComponent`,
213
- );
214
- } else {
215
- // Otherwise, assign variable name to value
120
+ this.getExecutor().print(`assigned '${reference.name}' to ClassComponent`);
121
+ }
122
+ else {
216
123
  const trailers = reference.trailers ?? [];
217
-
218
- if (trailers.length === 0){
219
- // No trailers, directly assign the reference name
124
+ if (trailers.length === 0) {
220
125
  this.getExecutor().scope.variables.set(reference.name, value);
221
-
222
- } else if (reference.value instanceof ClassComponent) {
126
+ }
127
+ else if (reference.value instanceof ClassComponent_js_1.ClassComponent) {
223
128
  this.setInstanceParam(reference.value, trailers, value);
224
129
  }
225
130
  }
226
-
227
131
  return value;
228
132
  }
229
-
230
- setInstanceParam(object: ClassComponent, trailers: string[], value: any): void {
133
+ setInstanceParam(object, trailers, value) {
231
134
  const paramName = trailers[0].slice(1);
232
135
  object.setParam(paramName, value);
233
-
234
- this.getExecutor().print(
235
- `set instance ${object.instanceName} param ${paramName} to ${value}`);
136
+ this.getExecutor().print(`set instance ${object.instanceName} param ${paramName} to ${value}`);
236
137
  }
237
-
238
- visitValue_expr(ctx: Value_exprContext): ValueType {
138
+ visitValue_expr(ctx) {
239
139
  const sign = ctx.Minus() ? -1 : 1;
240
-
241
140
  if (ctx.INTEGER_VALUE() || ctx.DECIMAL_VALUE() || ctx.NUMERIC_VALUE()) {
242
141
  if (ctx.INTEGER_VALUE()) {
243
142
  return sign * Number(ctx.INTEGER_VALUE().getText());
244
-
245
- } else if (ctx.DECIMAL_VALUE()) {
143
+ }
144
+ else if (ctx.DECIMAL_VALUE()) {
246
145
  return sign * Number(ctx.DECIMAL_VALUE().getText());
247
-
248
- } else if (ctx.NUMERIC_VALUE()) {
146
+ }
147
+ else if (ctx.NUMERIC_VALUE()) {
249
148
  const textExtra = ctx.Minus() ? '-' : '';
250
- return new NumericValue(textExtra + ctx.NUMERIC_VALUE().getText());
251
-
149
+ return new ParamDefinition_js_1.NumericValue(textExtra + ctx.NUMERIC_VALUE().getText());
252
150
  }
253
- } else {
151
+ }
152
+ else {
254
153
  if (sign === -1) {
255
154
  throw "Invalid value!";
256
155
  }
257
156
  }
258
-
259
157
  if (ctx.BOOLEAN_VALUE()) {
260
158
  const stringValue = ctx.BOOLEAN_VALUE().getText();
261
159
  if (stringValue === 'true') {
262
160
  return true;
263
- } else if (stringValue === 'false') {
161
+ }
162
+ else if (stringValue === 'false') {
264
163
  return false;
265
164
  }
266
-
267
- } else if (ctx.STRING_VALUE()) {
165
+ }
166
+ else if (ctx.STRING_VALUE()) {
268
167
  return this.prepareStringValue(ctx.STRING_VALUE().getText());
269
-
270
- } else if (ctx.PERCENTAGE_VALUE()) {
271
- return new PercentageValue(ctx.PERCENTAGE_VALUE().getText());
272
-
273
- } else if (ctx.blank_expr()) {
168
+ }
169
+ else if (ctx.PERCENTAGE_VALUE()) {
170
+ return new ParamDefinition_js_1.PercentageValue(ctx.PERCENTAGE_VALUE().getText());
171
+ }
172
+ else if (ctx.blank_expr()) {
274
173
  return this.visit(ctx.blank_expr());
275
174
  }
276
175
  }
277
-
278
- visitBlank_expr(ctx: Blank_exprContext): PinBlankValue {
279
- // There must be an integer value, otherwise the rule wouldn't match.
280
- return new PinBlankValue(Number(ctx.INTEGER_VALUE().getText()));
176
+ visitBlank_expr(ctx) {
177
+ return new ParamDefinition_js_1.PinBlankValue(Number(ctx.INTEGER_VALUE().getText()));
281
178
  }
282
-
283
- visitPin_select_expr(ctx: Pin_select_exprContext): string | number | null {
179
+ visitPin_select_expr(ctx) {
284
180
  if (ctx.INTEGER_VALUE()) {
285
181
  return Number(ctx.INTEGER_VALUE().getText());
286
-
287
- } else if (ctx.STRING_VALUE()) {
182
+ }
183
+ else if (ctx.STRING_VALUE()) {
288
184
  return this.prepareStringValue(ctx.STRING_VALUE().getText());
289
185
  }
290
-
291
186
  return null;
292
187
  }
293
-
294
- visitAdd_component_expr(ctx: Add_component_exprContext): ComponentPin {
295
- // The component is always the last item
296
- const [component, pinValue] =
297
- this.visit(ctx.data_expr_with_assignment());
298
-
299
- if (ctx.ID()){
300
- this.setComponentOrientation(
301
- component, pinValue, ctx.ID().getText());
302
- }
303
-
188
+ visitAdd_component_expr(ctx) {
189
+ const [component, pinValue] = this.visit(ctx.data_expr_with_assignment());
190
+ if (ctx.ID()) {
191
+ this.setComponentOrientation(component, pinValue, ctx.ID().getText());
192
+ }
304
193
  return this.getExecutor().addComponentExisting(component, pinValue);
305
194
  }
306
-
307
- visitAt_component_expr(ctx: At_component_exprContext): ComponentPin {
195
+ visitAt_component_expr(ctx) {
308
196
  if (ctx.Point()) {
309
197
  this.getExecutor().atPointBlock();
310
-
311
- } else {
198
+ }
199
+ else {
312
200
  const [component, pin] = this.visit(ctx.component_select_expr());
313
-
314
201
  const currentPoint = this.getExecutor().atComponent(component, pin, {
315
202
  addSequence: true,
316
203
  cloneNetComponent: true
317
204
  });
318
-
319
205
  if (ctx.ID()) {
320
- // If there is ID specified, then it can only be for the
321
- // component orientation.
322
- this.setComponentOrientation(currentPoint[0],
323
- currentPoint[1], ctx.ID().getText())
206
+ this.setComponentOrientation(currentPoint[0], currentPoint[1], ctx.ID().getText());
324
207
  }
325
208
  }
326
-
327
209
  return this.getExecutor().getCurrentPoint();
328
210
  }
329
-
330
- visitTo_component_expr(ctx: To_component_exprContext): ComponentPin {
331
- let currentPoint: ComponentPin;
332
-
211
+ visitTo_component_expr(ctx) {
212
+ let currentPoint;
333
213
  if (ctx.Point()) {
334
214
  this.getExecutor().toPointBlock();
335
-
336
- } else {
215
+ }
216
+ else {
337
217
  ctx.component_select_expr_list().forEach((item) => {
338
218
  const [component, pin] = this.visit(item);
339
219
  currentPoint = this.getExecutor().toComponent(component, pin, {
340
220
  addSequence: true, cloneNetComponent: true
341
221
  });
342
222
  });
343
-
344
223
  if (ctx.ID()) {
345
- // If there is ID specified, then it can only be for the
346
- // component orientation.
347
- this.setComponentOrientation(currentPoint[0],
348
- currentPoint[1], ctx.ID().getText())
224
+ this.setComponentOrientation(currentPoint[0], currentPoint[1], ctx.ID().getText());
349
225
  }
350
226
  }
351
-
352
227
  return this.getExecutor().getCurrentPoint();
353
228
  }
354
-
355
- visitComponent_select_expr(ctx: Component_select_exprContext): ComponentPin {
229
+ visitComponent_select_expr(ctx) {
356
230
  if (ctx.data_expr_with_assignment()) {
357
231
  return this.visit(ctx.data_expr_with_assignment());
358
- } else {
232
+ }
233
+ else {
359
234
  const component = this.getExecutor().scope.currentComponent;
360
- let pinId: number | string | null = null;
361
-
235
+ let pinId = null;
362
236
  if (ctx.pin_select_expr()) {
363
237
  pinId = this.visit(ctx.pin_select_expr());
364
238
  }
365
239
  return [component, pinId];
366
240
  }
367
241
  }
368
-
369
- visitPath_blocks(ctx: Path_blocksContext): ComponentPin {
242
+ visitPath_blocks(ctx) {
370
243
  const blocks = ctx.path_block_inner_list();
371
-
372
- let blockIndex = 0; // Tracks the index of the block with the given type
373
- let blockType = BlockTypes.Branch;
244
+ let blockIndex = 0;
245
+ let blockType = globals_js_1.BlockTypes.Branch;
374
246
  let prevBlockType = null;
375
-
376
247
  blocks.forEach((block, index) => {
377
248
  if (block.Branch()) {
378
- blockType = BlockTypes.Branch
379
- } else if (block.Join()) {
380
- blockType = BlockTypes.Join;
381
- } else if (block.Parallel()) {
382
- blockType = BlockTypes.Parallel;
383
- } else if (block.Point()) {
384
- blockType = BlockTypes.Point;
249
+ blockType = globals_js_1.BlockTypes.Branch;
250
+ }
251
+ else if (block.Join()) {
252
+ blockType = globals_js_1.BlockTypes.Join;
253
+ }
254
+ else if (block.Parallel()) {
255
+ blockType = globals_js_1.BlockTypes.Parallel;
256
+ }
257
+ else if (block.Point()) {
258
+ blockType = globals_js_1.BlockTypes.Point;
385
259
  }
386
-
387
260
  if (prevBlockType !== blockType) {
388
- if (index > 0) {
389
- // If not the first block, then exit the
390
- // group of blocks.
261
+ if (index > 0) {
391
262
  this.getExecutor().exitBlocks();
392
263
  }
393
-
394
264
  this.getExecutor().enterBlocks(blockType);
395
- blockIndex = 0; // Reset counter.
265
+ blockIndex = 0;
396
266
  }
397
-
398
267
  this.getExecutor().enterBlock(blockIndex);
399
268
  this.visit(block);
400
269
  this.getExecutor().exitBlock(blockIndex);
401
270
  blockIndex += 1;
402
-
403
271
  prevBlockType = blockType;
404
272
  });
405
-
406
273
  this.getExecutor().exitBlocks();
407
274
  return this.getExecutor().getCurrentPoint();
408
275
  }
409
-
410
- visitBreak_keyword(): number {
411
- // When the break keyword is encountered inside a branch, then leave the branch
412
- // without storing the final state. If used, the break should be
413
- // the last expression in the branch, any expressions after the break
414
- // will be skipped
415
-
276
+ visitBreak_keyword() {
416
277
  this.getExecutor().breakBranch();
417
278
  return -1;
418
279
  }
419
-
420
- visitCreate_component_expr(ctx: Create_component_exprContext): ClassComponent {
280
+ visitCreate_component_expr(ctx) {
421
281
  const properties = this.getPropertyExprList(ctx.property_expr_list());
422
-
423
- const pins: PinDefinition[] = this.parseCreateComponentPins(
424
- properties.get('pins'),
425
- );
426
-
427
- // Use a unique instance name in the context for now
282
+ const pins = this.parseCreateComponentPins(properties.get('pins'));
428
283
  let instanceName = this.getExecutor().getUniqueInstanceName('');
429
-
430
284
  const propParams = properties.get('params');
431
- const params: ParamDefinition[] =
432
- this.parseCreateComponentParams(propParams);
433
-
285
+ const params = this.parseCreateComponentParams(propParams);
434
286
  if (params.length > 0) {
435
- // Always append the first value
436
- // to the generated name.
437
287
  const firstParam = params[0];
438
288
  const paramValue = firstParam.paramValue;
439
289
  let appendValue = paramValue.toString();
440
-
441
- if (paramValue instanceof NumericValue) {
290
+ if (paramValue instanceof ParamDefinition_js_1.NumericValue) {
442
291
  appendValue = paramValue.value;
443
292
  }
444
-
445
293
  instanceName += '_' + appendValue;
446
294
  }
447
-
448
295
  const arrange = properties.has('arrange') ?
449
296
  properties.get('arrange') : null;
450
-
451
297
  const display = properties.has('display') ?
452
298
  properties.get('display') : null;
453
-
454
299
  const type = properties.has('type') ?
455
300
  properties.get('type') : null;
456
-
457
301
  const width = properties.has('width') ?
458
302
  properties.get('width') : null;
459
-
460
303
  const props = {
461
304
  arrange,
462
305
  display,
463
306
  type,
464
307
  width,
465
- }
466
-
467
- return this.getExecutor().createComponent(instanceName,
468
- pins, params, props);
308
+ };
309
+ return this.getExecutor().createComponent(instanceName, pins, params, props);
469
310
  }
470
-
471
- visitCreate_graphic_expr(ctx: Create_graphic_exprContext):
472
- SymbolDrawingCommands {
473
-
311
+ visitCreate_graphic_expr(ctx) {
474
312
  const commands = ctx.sub_expr_list().reduce((accum, item) => {
475
313
  const [commandName, parameters] = this.visit(item);
476
-
477
- const keywordParams = new Map<string, any>();
478
- const positionParams = parameters.reduce(
479
- (accum, [argType, name, value]) => {
480
- if (argType === 'position') {
481
- accum.push(value);
482
- } else {
483
- keywordParams.set(name, value);
484
- }
485
- return accum;
486
- }, [] as any[]);
487
-
314
+ const keywordParams = new Map();
315
+ const positionParams = parameters.reduce((accum, [argType, name, value]) => {
316
+ if (argType === 'position') {
317
+ accum.push(value);
318
+ }
319
+ else {
320
+ keywordParams.set(name, value);
321
+ }
322
+ return accum;
323
+ }, []);
488
324
  accum.push([commandName, positionParams, keywordParams]);
489
325
  return accum;
490
- }, [] as SubExpressionCommand[]);
491
-
492
- return new SymbolDrawingCommands(commands);
493
- }
494
-
495
- visitSub_expr(ctx: Sub_exprContext):
496
- [id: string, parameters: CallableParameter[]] {
497
- let commandName: string = null;
326
+ }, []);
327
+ return new draw_symbols_js_1.SymbolDrawingCommands(commands);
328
+ }
329
+ visitSub_expr(ctx) {
330
+ let commandName = null;
498
331
  if (ctx.ID()) {
499
332
  commandName = ctx.ID().getText();
500
- } else if (ctx.Pin()) {
333
+ }
334
+ else if (ctx.Pin()) {
501
335
  commandName = ctx.Pin().getText();
502
- } else {
336
+ }
337
+ else {
503
338
  throw "Invalid command!";
504
339
  }
505
-
506
- const parameters: CallableParameter[] = this.visit(ctx.parameters());
340
+ const parameters = this.visit(ctx.parameters());
507
341
  return [commandName, parameters];
508
342
  }
509
-
510
- visitProperty_expr(ctx: Property_exprContext): Map<string, any> {
343
+ visitProperty_expr(ctx) {
511
344
  const keyName = this.visit(ctx.property_key_expr());
512
345
  const value = this.visit(ctx.property_value_expr());
513
-
514
- const map = new Map<string, any>();
346
+ const map = new Map();
515
347
  map.set(keyName, value);
516
-
517
348
  return map;
518
349
  }
519
-
520
- visitSingle_line_property(ctx: Single_line_propertyContext): any | any[] {
350
+ visitSingle_line_property(ctx) {
521
351
  let value;
522
352
  if (ctx.data_expr_list().length === 1) {
523
353
  value = this.visit(ctx.data_expr(0));
524
- } else {
354
+ }
355
+ else {
525
356
  value = ctx.data_expr_list().map(item => {
526
357
  return this.visit(item);
527
358
  });
528
359
  }
529
360
  return value;
530
361
  }
531
-
532
- visitNested_properties(ctx: Nested_propertiesContext): Map<string, any> {
533
- const result = new Map<string, any>();
362
+ visitNested_properties(ctx) {
363
+ const result = new Map();
534
364
  ctx.property_expr_list().forEach((item) => {
535
- const property: Map<string, any> = this.visit(item);
536
-
537
- // Get out all items, by default
365
+ const property = this.visit(item);
538
366
  for (const [key, value] of property) {
539
367
  result.set(key, value);
540
368
  }
541
369
  });
542
-
543
370
  return result;
544
371
  }
545
-
546
- visitProperty_key_expr(ctx: Property_key_exprContext): string | number {
372
+ visitProperty_key_expr(ctx) {
547
373
  if (ctx.ID()) {
548
374
  return ctx.ID().getText();
549
- } else if (ctx.INTEGER_VALUE()) {
375
+ }
376
+ else if (ctx.INTEGER_VALUE()) {
550
377
  return Number(ctx.INTEGER_VALUE().getText());
551
- } else if (ctx.STRING_VALUE()) {
378
+ }
379
+ else if (ctx.STRING_VALUE()) {
552
380
  return this.prepareStringValue(ctx.STRING_VALUE().getText());
553
381
  }
554
382
  }
555
-
556
- visitData_expr_with_assignment(ctx: Data_expr_with_assignmentContext):
557
- [component: ComplexType, pin: string | number | null] {
558
-
559
- let component: ComplexType;
383
+ visitData_expr_with_assignment(ctx) {
384
+ let component;
560
385
  if (ctx.data_expr()) {
561
386
  component = this.visit(ctx.data_expr());
562
-
563
387
  if (component === null || component === undefined) {
564
388
  throw "Could not find component: " + ctx.data_expr().getText();
565
389
  }
566
-
567
- } else if (ctx.assignment_expr()) {
568
- component = this.visit(ctx.assignment_expr())
569
390
  }
570
-
571
- let pinValue: number | string = null;
391
+ else if (ctx.assignment_expr()) {
392
+ component = this.visit(ctx.assignment_expr());
393
+ }
394
+ let pinValue = null;
572
395
  if (ctx.pin_select_expr()) {
573
396
  pinValue = this.visit(ctx.pin_select_expr());
574
- } else {
575
- pinValue = (component as ClassComponent).getDefaultPin();
576
397
  }
577
-
398
+ else {
399
+ pinValue = component.getDefaultPin();
400
+ }
578
401
  return [component, pinValue];
579
402
  }
580
-
581
- visitValueAtomExpr(ctx: ValueAtomExprContext): ComplexType {
582
- let value: ComplexType;
583
-
403
+ visitValueAtomExpr(ctx) {
404
+ let value;
584
405
  if (ctx.value_expr()) {
585
- value = this.visit(ctx.value_expr()) as ValueType;
586
-
587
- } else if (ctx.atom_expr()) {
406
+ value = this.visit(ctx.value_expr());
407
+ }
408
+ else if (ctx.atom_expr()) {
588
409
  const reference = this.visit(ctx.atom_expr());
589
-
590
410
  if (!reference.found) {
591
- value = new UndeclaredReference(reference);
592
- } else {
593
- // This is the returned component from the function call
411
+ value = new types_js_1.UndeclaredReference(reference);
412
+ }
413
+ else {
594
414
  value = reference.value;
595
415
  }
596
416
  }
597
-
598
417
  return value;
599
418
  }
600
-
601
- visitUnaryOperatorExpr(ctx: UnaryOperatorExprContext): ComplexType {
419
+ visitUnaryOperatorExpr(ctx) {
602
420
  const value = this.visit(ctx.data_expr());
603
-
604
421
  const unaryOp = ctx.unary_operator();
605
422
  if (unaryOp) {
606
423
  if (unaryOp.Not()) {
607
424
  if (typeof value === "boolean") {
608
425
  value = !value;
609
- } else {
426
+ }
427
+ else {
610
428
  throw "Failed to do Not operator";
611
429
  }
612
- } else if (unaryOp.Minus()) {
430
+ }
431
+ else if (unaryOp.Minus()) {
613
432
  if (typeof value === 'number') {
614
433
  return -value;
615
- } else {
434
+ }
435
+ else {
616
436
  throw "Failed to do Negation operator";
617
437
  }
618
438
  }
619
439
  }
620
-
621
440
  return value;
622
441
  }
623
-
624
- visitDataExpr(ctx: DataExprContext): ComplexType {
625
- let value: ComplexType;
626
-
442
+ visitDataExpr(ctx) {
443
+ let value;
627
444
  if (ctx.create_component_expr()) {
628
- value = this.visit(ctx.create_component_expr()) as ClassComponent;
629
-
630
- } else if (ctx.create_graphic_expr()) {
631
- value = this.visit(ctx.create_graphic_expr()) as ClassComponent;
445
+ value = this.visit(ctx.create_component_expr());
446
+ }
447
+ else if (ctx.create_graphic_expr()) {
448
+ value = this.visit(ctx.create_graphic_expr());
632
449
  }
633
-
634
450
  return value;
635
451
  }
636
-
637
- visitBinaryOperatorExpr(ctx: BinaryOperatorExprContext): boolean | number {
452
+ visitBinaryOperatorExpr(ctx) {
638
453
  const value1 = this.visit(ctx.data_expr(0));
639
454
  const value2 = this.visit(ctx.data_expr(1));
640
-
641
455
  const binaryOperatorType = ctx.binary_operator();
642
-
643
456
  if (binaryOperatorType.Equals()) {
644
- return value1 == value2; // Boolean result
645
- } else if (binaryOperatorType.NotEquals()) {
457
+ return value1 == value2;
458
+ }
459
+ else if (binaryOperatorType.NotEquals()) {
646
460
  return value1 != value2;
647
461
  }
648
462
  }
649
-
650
- visitMultiplyExpr(ctx: MultiplyExprContext): number {
651
- const value1 = this.visit(ctx.data_expr(0)) as number;
652
- const value2 = this.visit(ctx.data_expr(1)) as number;
653
-
463
+ visitMultiplyExpr(ctx) {
464
+ const value1 = this.visit(ctx.data_expr(0));
465
+ const value2 = this.visit(ctx.data_expr(1));
654
466
  if (ctx.Multiply()) {
655
467
  return value1 * value2;
656
- } else if (ctx.Divide()) {
468
+ }
469
+ else if (ctx.Divide()) {
657
470
  return value1 / value2;
658
471
  }
659
472
  }
660
-
661
- visitAdditionExpr(ctx: AdditionExprContext): number {
662
- const value1 = this.visit(ctx.data_expr(0)) as number;
663
- const value2 = this.visit(ctx.data_expr(1)) as number;
664
-
473
+ visitAdditionExpr(ctx) {
474
+ const value1 = this.visit(ctx.data_expr(0));
475
+ const value2 = this.visit(ctx.data_expr(1));
665
476
  if (ctx.Addition()) {
666
477
  return value1 + value2;
667
- } else if (ctx.Minus()) {
478
+ }
479
+ else if (ctx.Minus()) {
668
480
  return value1 - value2;
669
481
  }
670
482
  }
671
-
672
- visitFunction_args_expr(ctx: Function_args_exprContext):
673
- FunctionDefinedParameter[] {
674
-
483
+ visitFunction_args_expr(ctx) {
675
484
  const defaultValuesProvided = ctx.value_expr_list();
676
- // The last <defaultValuesProvided> IDs have default values
677
- const IDs = ctx.ID_list(); // Do in reverse
678
-
485
+ const IDs = ctx.ID_list();
679
486
  const boundary = IDs.length - defaultValuesProvided.length;
680
-
681
487
  return IDs.map((id, index) => {
682
488
  if (index >= boundary) {
683
- const defaultValue =
684
- this.visit(defaultValuesProvided[index - boundary]);
489
+ const defaultValue = this.visit(defaultValuesProvided[index - boundary]);
685
490
  return [id.getText(), defaultValue];
686
- } else {
491
+ }
492
+ else {
687
493
  return [id.getText()];
688
494
  }
689
495
  });
690
496
  }
691
-
692
- createNetResolver(executionStack: ExecutionContext[]):
693
- (netName: string, netNamespace: string) => {found: boolean, net?: Net} {
694
- const resolveNet = (netName: string, netNamespace: string):
695
- {found: boolean, net?: Net} => {
696
- // netNamespace is the current netNamespace where the net name is
697
- // searching from.
698
-
497
+ createNetResolver(executionStack) {
498
+ const resolveNet = (netName, netNamespace) => {
699
499
  this.print('find net', netNamespace, netName);
700
500
  const reversed = [...executionStack].reverse();
701
-
702
501
  for (let i = 0; i < reversed.length; i++) {
703
502
  const context = reversed[i];
704
503
  const net = context.scope.getNetWithName(netName);
705
-
706
504
  if (net !== null && net.namespace === netNamespace) {
707
505
  return {
708
506
  found: true,
709
507
  net,
710
- }
508
+ };
711
509
  }
712
510
  }
713
-
714
511
  return {
715
512
  found: false
716
- }
717
- }
718
-
513
+ };
514
+ };
719
515
  return resolveNet;
720
516
  }
721
-
722
- visitFunction_def_expr(ctx: Function_def_exprContext): void {
517
+ visitFunction_def_expr(ctx) {
723
518
  const functionName = ctx.ID().getText();
724
-
725
- // These are the defined arguments for the function
726
- let funcDefinedParameters: FunctionDefinedParameter[] = [];
519
+ let funcDefinedParameters = [];
727
520
  if (ctx.function_args_expr()) {
728
521
  funcDefinedParameters = this.visit(ctx.function_args_expr());
729
522
  }
730
-
731
523
  const executionStack = this.executionStack;
732
524
  const functionCounter = { counter: 0 };
733
-
734
525
  const resolveNet = this.createNetResolver(this.executionStack);
735
-
736
- const __runFunc = (passedInParameters:CallableParameter[],
737
- options: CFunctionOptions): [
738
- executionContext: ExecutionContext,
739
- result: ComplexType | null] => {
740
-
741
- const {netNamespace = ""} = options;
742
-
743
- // Create a new execution context, so that the commands are executed only
744
- // within this context. Components and nets will be local to this context for now.
745
- const currentExecutionContext =
746
- executionStack[executionStack.length - 1];
526
+ const __runFunc = (passedInParameters, options) => {
527
+ const { netNamespace = "" } = options;
528
+ const currentExecutionContext = executionStack[executionStack.length - 1];
747
529
  const executionLevel = currentExecutionContext.executionLevel;
748
-
749
- const executionContextName =
750
- functionName + '_' + functionCounter['counter'];
530
+ const executionContextName = functionName + '_' + functionCounter['counter'];
751
531
  const executionContextNamespace = currentExecutionContext.namespace
752
532
  + executionContextName + ".";
753
-
754
533
  functionCounter['counter'] += 1;
755
-
756
- const newExecutor = new ExecutionContext(
757
- executionContextName,
758
- executionContextNamespace,
759
- netNamespace,
760
- executionLevel + 1,
761
- this.getExecutor().scope.indentLevel + 1,
762
- currentExecutionContext.silent,
763
- currentExecutionContext.logger,
764
- );
765
-
534
+ const newExecutor = new execute_js_1.ExecutionContext(executionContextName, executionContextNamespace, netNamespace, executionLevel + 1, this.getExecutor().scope.indentLevel + 1, currentExecutionContext.silent, currentExecutionContext.logger);
766
535
  this.setupPrintFunction(newExecutor);
767
-
768
536
  newExecutor.resolveNet = resolveNet;
769
-
770
- // Add the execution context to the end of the execution stack
771
537
  executionStack.push(newExecutor);
772
-
773
- // Setup the params in the execution scope if there
774
- // are any function parameters
775
-
776
- this.setupDefinedParameters(
777
- functionName,
778
- funcDefinedParameters,
779
- passedInParameters,
780
- newExecutor
781
- );
782
-
783
- const returnValue = this.runExpressions(newExecutor,
784
- ctx.function_expr_list());
785
-
786
- // Function execution is completed, get the last executor
538
+ this.setupDefinedParameters(functionName, funcDefinedParameters, passedInParameters, newExecutor);
539
+ const returnValue = this.runExpressions(newExecutor, ctx.function_expr_list());
787
540
  const lastExecution = executionStack.pop();
788
-
789
- // Merge what ever was created in the scope with the outer scope
790
541
  const nextLastExecution = executionStack[executionStack.length - 1];
791
- nextLastExecution.mergeScope(
792
- lastExecution.scope,
793
- executionContextName,
794
- );
795
-
796
- // Return the last execution context and the final return value of the function
542
+ nextLastExecution.mergeScope(lastExecution.scope, executionContextName);
797
543
  return [lastExecution, returnValue];
798
544
  };
799
-
800
545
  this.getExecutor().createFunction(functionName, __runFunc);
801
546
  }
802
-
803
- private setupDefinedParameters(
804
- functionName: string,
805
- funcDefinedParameters: FunctionDefinedParameter[],
806
- passedInParameters: CallableParameter[],
807
- executor: ExecutionContext): void {
808
-
809
- // Check if the arguments match up
547
+ setupDefinedParameters(functionName, funcDefinedParameters, passedInParameters, executor) {
810
548
  for (let i = 0; i < funcDefinedParameters.length; i++) {
811
549
  const tmpFuncArg = funcDefinedParameters[i];
812
-
813
550
  if (i < passedInParameters.length) {
814
551
  const tmpPassedInArgs = passedInParameters[i];
815
-
816
552
  if (tmpPassedInArgs[0] === 'position') {
817
- // If value is passed in as function parameter, then
818
- // use it in the scope.
819
553
  const variableName = tmpFuncArg[0];
820
- executor.print(
821
- 'set variable in scope, var name: ',
822
- variableName,
823
- );
824
- executor.scope.variables.set(
825
- variableName,
826
- tmpPassedInArgs[2],
827
- );
828
-
829
- if (tmpPassedInArgs[2] instanceof ClassComponent) {
830
- const component = tmpPassedInArgs[2];
831
-
832
- // Add the component nets into the local scope
833
- for(const [pinNumber, net] of component.pinNets){
554
+ executor.print('set variable in scope, var name: ', variableName);
555
+ executor.scope.variables.set(variableName, tmpPassedInArgs[2]);
556
+ if (tmpPassedInArgs[2] instanceof ClassComponent_js_1.ClassComponent) {
557
+ const component = tmpPassedInArgs[2];
558
+ for (const [pinNumber, net] of component.pinNets) {
834
559
  executor.scope.setNet(component, pinNumber, net);
835
560
  }
836
561
  }
837
562
  }
838
- } else if (tmpFuncArg.length === 2) {
839
- // Value was not provided to function, but a default
840
- // value is provided.
563
+ }
564
+ else if (tmpFuncArg.length === 2) {
841
565
  const variableName = tmpFuncArg[0];
842
566
  const defaultValue = tmpFuncArg[1];
843
- executor.print(
844
- 'set variable in scope, var name: ',
845
- variableName,
846
- );
847
- executor.scope.variables.set(
848
- variableName, defaultValue,
849
- );
850
- } else {
851
- throw `Invalid arguments for function '${functionName}', got: `
567
+ executor.print('set variable in scope, var name: ', variableName);
568
+ executor.scope.variables.set(variableName, defaultValue);
569
+ }
570
+ else {
571
+ throw `Invalid arguments for function '${functionName}', got: `
852
572
  + passedInParameters;
853
573
  }
854
574
  }
855
575
  }
856
-
857
- visitFunction_return_expr(ctx: Function_return_exprContext): ComplexType {
576
+ visitFunction_return_expr(ctx) {
858
577
  const executor = this.getExecutor();
859
578
  executor.print('return from function');
860
- const returnValue = this.visit(ctx.data_expr()) as ComplexType;
861
-
579
+ const returnValue = this.visit(ctx.data_expr());
862
580
  executor.stopFurtherExpressions = true;
863
581
  executor.returnValue = returnValue;
864
-
865
582
  return returnValue;
866
583
  }
867
-
868
- visitAtom_expr(ctx: Atom_exprContext): ReferenceType {
584
+ visitAtom_expr(ctx) {
869
585
  const executor = this.getExecutor();
870
-
871
586
  const atomId = ctx.ID().getText();
872
-
873
- let passedNetNamespace = null; // Assumed empty by default
874
-
875
- if (ctx.net_namespace_expr()){
587
+ let passedNetNamespace = null;
588
+ if (ctx.net_namespace_expr()) {
876
589
  passedNetNamespace = this.visit(ctx.net_namespace_expr());
877
590
  }
878
-
879
- let currentReference: ReferenceType;
880
-
881
- // Check if it is hardcoded values, like the pin types.
591
+ let currentReference;
882
592
  if (this.pinTypesList.indexOf(atomId) !== -1) {
883
- // Not sure if just returning the string is enough...
884
593
  currentReference = {
885
594
  found: true,
886
595
  value: atomId
887
- }
888
- } else {
889
- currentReference = executor.resolveVariable(
890
- this.executionStack, atomId);
596
+ };
597
+ }
598
+ else {
599
+ currentReference = executor.resolveVariable(this.executionStack, atomId);
891
600
  }
892
-
893
601
  if (currentReference.found && currentReference.type === 'instance') {
894
- const tmpComponent = currentReference.value as ClassComponent;
895
-
896
- // Copy the nets into the local net
602
+ const tmpComponent = currentReference.value;
897
603
  for (const [pinId, net] of tmpComponent.pinNets) {
898
604
  executor.scope.setNet(tmpComponent, pinId, net);
899
605
  }
900
606
  }
901
-
902
607
  if (ctx.trailer_expr_list().length > 0) {
903
- // Resolve all elements in the trailer expression list
904
-
905
608
  if (!currentReference.found) {
906
609
  throw "Could not find reference! " + atomId;
907
610
  }
908
-
909
611
  currentReference.trailers = [];
910
-
911
612
  ctx.trailer_expr_list().forEach(item => {
912
613
  const itemValue = item.getText();
913
614
  if (item.OPEN_PAREN() && item.CLOSE_PAREN()) {
914
- let parameters: CallableParameter[] = [];
615
+ let parameters = [];
915
616
  if (item.parameters()) {
916
617
  parameters = this.visit(item.parameters());
917
618
  }
918
-
919
- const useNetNamespace = this.getNetNamespace(
920
- executor.netNamespace,
921
- passedNetNamespace,
922
- )
923
-
924
- const [, functionResult] =
925
- executor.callFunction(
926
- currentReference.name,
927
- parameters,
928
- this.executionStack,
929
- useNetNamespace);
930
-
619
+ const useNetNamespace = this.getNetNamespace(executor.netNamespace, passedNetNamespace);
620
+ const [, functionResult] = executor.callFunction(currentReference.name, parameters, this.executionStack, useNetNamespace);
931
621
  currentReference = {
932
622
  found: true,
933
623
  value: functionResult,
934
- type: (functionResult instanceof ClassComponent) ?
624
+ type: (functionResult instanceof ClassComponent_js_1.ClassComponent) ?
935
625
  'instance' : 'value',
936
- }
937
-
938
- } else {
626
+ };
627
+ }
628
+ else {
939
629
  currentReference.trailers.push(itemValue);
940
630
  }
941
631
  });
942
632
  }
943
-
944
633
  return currentReference;
945
634
  }
946
-
947
- visitPin_select_expr2(ctx: Pin_select_expr2Context): string | number {
635
+ visitPin_select_expr2(ctx) {
948
636
  if (ctx.STRING_VALUE()) {
949
637
  return this.prepareStringValue(ctx.STRING_VALUE().getText());
950
- } else if (ctx.INTEGER_VALUE()) {
638
+ }
639
+ else if (ctx.INTEGER_VALUE()) {
951
640
  return Number(ctx.INTEGER_VALUE().getText());
952
641
  }
953
642
  }
954
-
955
- visitAt_block_pin_expr(ctx: At_block_pin_exprContext): ComponentPin {
956
- const atPin: number | string = this.visit(ctx.pin_select_expr2());
957
-
643
+ visitAt_block_pin_expr(ctx) {
644
+ const atPin = this.visit(ctx.pin_select_expr2());
958
645
  const executor = this.getExecutor();
959
-
960
646
  const currentComponent = executor.scope.currentComponent;
961
647
  const currentPin = executor.scope.currentPin;
962
-
963
648
  executor.atComponent(currentComponent, atPin, {
964
649
  addSequence: true
965
650
  });
966
-
967
651
  executor.print('at block pin expressions');
968
-
969
652
  if (ctx.at_block_pin_expression_simple()) {
970
653
  this.visit(ctx.at_block_pin_expression_simple());
971
- } else if (ctx.at_block_pin_expression_complex()) {
654
+ }
655
+ else if (ctx.at_block_pin_expression_complex()) {
972
656
  this.visit(ctx.at_block_pin_expression_complex());
973
657
  }
974
-
975
658
  executor.print('end at block pin expressions');
976
-
977
- // Go back to the original position
978
659
  return executor.atComponent(currentComponent, currentPin);
979
660
  }
980
-
981
- visitAt_block(ctx: At_blockContext): ComponentPin {
661
+ visitAt_block(ctx) {
982
662
  const executor = this.getExecutor();
983
663
  executor.print('entering at block');
984
-
985
664
  this.visit(ctx.at_component_expr());
986
-
987
665
  const currentComponent = executor.scope.currentComponent;
988
666
  const currentPin = executor.scope.currentPin;
989
-
990
667
  executor.scope.indentLevel += 1;
991
-
992
668
  ctx.at_block_expressions_list().forEach(expression => {
993
669
  this.visit(expression);
994
670
  });
995
-
996
671
  executor.scope.indentLevel -= 1;
997
-
998
- // Once all done, then restore
999
672
  executor.scope.currentComponent = currentComponent;
1000
673
  executor.scope.currentPin = currentPin;
1001
-
1002
674
  executor.print('leaving at block');
1003
-
1004
675
  return executor.getCurrentPoint();
1005
676
  }
1006
-
1007
- visitAt_block_pin_expression_simple(ctx: At_block_pin_expression_simpleContext): void {
677
+ visitAt_block_pin_expression_simple(ctx) {
1008
678
  if (ctx.expression()) {
1009
- // Handle any expressions within
1010
679
  this.visit(ctx.expression());
1011
- } else if (ctx.NOT_CONNECTED()) {
1012
- // Do nothing
680
+ }
681
+ else if (ctx.NOT_CONNECTED()) {
1013
682
  return;
1014
683
  }
1015
684
  }
1016
-
1017
- visitAt_block_pin_expression_complex(ctx: At_block_pin_expression_complexContext): ComponentPin {
685
+ visitAt_block_pin_expression_complex(ctx) {
1018
686
  ctx.expression_list().forEach(item => {
1019
687
  this.visit(item);
1020
- })
1021
-
688
+ });
1022
689
  return this.getExecutor().getCurrentPoint();
1023
690
  }
1024
-
1025
- visitWire_expr(ctx: Wire_exprContext): void {
1026
- const segments: [string, number?][] = [];
1027
-
1028
- // Ignore 'wire'
691
+ visitWire_expr(ctx) {
692
+ const segments = [];
1029
693
  const parts = ctx.children.slice(1);
1030
-
1031
694
  for (let i = 0; i < parts.length; i++) {
1032
695
  const textValue = parts[i].getText();
1033
-
1034
696
  if (this.acceptedDirections.indexOf(textValue) !== -1) {
1035
- // If a direction is specified, then the value
1036
- // must also be specified, otherwise throw an error
1037
- const segment: [string, number?] = [textValue];
1038
-
697
+ const segment = [textValue];
1039
698
  let skipNext = false;
1040
699
  let invalidValue = true;
1041
-
1042
700
  if (i + 1 < parts.length) {
1043
701
  const nextValue = parts[i + 1].getText();
1044
702
  const nextValueNumber = Number(nextValue);
@@ -1048,316 +706,218 @@ export class MainVisitor extends ParseTreeVisitor<any> {
1048
706
  skipNext = true;
1049
707
  }
1050
708
  }
1051
-
1052
709
  if (invalidValue) {
1053
710
  throw `Invalid value provided for direction ${textValue} in wire`;
1054
711
  }
1055
-
1056
712
  segments.push(segment);
1057
-
1058
713
  if (skipNext) {
1059
714
  i += 1;
1060
715
  }
1061
- } else if (textValue === "auto" || textValue === "auto_") {
1062
- // Two different auto modes to decide how to form the
1063
- // connecting wire
716
+ }
717
+ else if (textValue === "auto" || textValue === "auto_") {
1064
718
  segments.push([textValue]);
1065
719
  }
1066
720
  }
1067
-
1068
721
  this.getExecutor().addWire(segments);
1069
722
  }
1070
-
1071
- visitPoint_expr(ctx: Point_exprContext): ComponentPin {
723
+ visitPoint_expr(ctx) {
1072
724
  const ID = ctx.ID();
1073
725
  return this.getExecutor().addPoint(ID.getText());
1074
726
  }
1075
-
1076
- visitImport_expr(ctx: Import_exprContext): void {
1077
- const ID = ctx.ID().toString(); // filename
727
+ visitImport_expr(ctx) {
728
+ const ID = ctx.ID().toString();
1078
729
  this.print('import', ID);
1079
- const {hasError,hasParseError} = this.onImportFile(this, ID);
1080
-
1081
- if (hasError || hasParseError){
730
+ const { hasError, hasParseError } = this.onImportFile(this, ID);
731
+ if (hasError || hasParseError) {
1082
732
  this.print('import', ID, 'failed');
1083
733
  throw `import ${ID} failed`;
1084
- }
1085
-
734
+ }
1086
735
  this.print('done import', ID);
1087
736
  }
1088
-
1089
- visitProperty_set_expr(ctx: Property_set_exprContext): void {
737
+ visitProperty_set_expr(ctx) {
1090
738
  const result = this.visit(ctx.data_expr());
1091
-
1092
- // To check if this works
1093
739
  const resolvedProperty = this.visit(ctx.atom_expr());
1094
-
1095
- // TODO: check if this works correctly
1096
740
  this.getExecutor().setProperty(resolvedProperty, result);
1097
741
  }
1098
-
1099
- visitDouble_dot_property_set_expr(ctx: Double_dot_property_set_exprContext) {
742
+ visitDouble_dot_property_set_expr(ctx) {
1100
743
  const result = this.visit(ctx.data_expr());
1101
744
  const propertyName = ctx.ID().getText();
1102
745
  this.getExecutor().setProperty('..' + propertyName, result);
1103
746
  }
1104
-
1105
- visitRoundedBracketsExpr(ctx: RoundedBracketsExprContext) {
747
+ visitRoundedBracketsExpr(ctx) {
1106
748
  return this.visit(ctx.data_expr());
1107
749
  }
1108
-
1109
- visitFrame_expr(ctx: Frame_exprContext): void {
750
+ visitFrame_expr(ctx) {
1110
751
  const frameId = this.getExecutor().enterFrame();
1111
752
  this.runExpressions(this.getExecutor(), ctx.expression_list());
1112
753
  this.getExecutor().exitFrame(frameId);
1113
754
  }
1114
-
1115
- visitNet_namespace_expr(ctx: Net_namespace_exprContext): string {
1116
- let dataValue: ComplexType = null;
1117
-
755
+ visitNet_namespace_expr(ctx) {
756
+ let dataValue = null;
1118
757
  let netNamespace = null;
1119
758
  const hasPlus = ctx.Addition();
1120
-
1121
759
  if (ctx.data_expr()) {
1122
- dataValue = this.visit(ctx.data_expr()) as ComplexType;
1123
-
1124
- if (dataValue instanceof UndeclaredReference) {
760
+ dataValue = this.visit(ctx.data_expr());
761
+ if (dataValue instanceof types_js_1.UndeclaredReference) {
1125
762
  netNamespace = "/" + dataValue.reference.name;
1126
- } else if (typeof dataValue === "string") {
763
+ }
764
+ else if (typeof dataValue === "string") {
1127
765
  netNamespace = "/" + dataValue;
1128
- } else {
766
+ }
767
+ else {
1129
768
  throw "Failed to resolve net namespace value";
1130
769
  }
1131
-
1132
- } else {
1133
- // If no net namespace specified, then the global namespace
1134
- // is assumed.
770
+ }
771
+ else {
1135
772
  netNamespace = "/";
1136
773
  }
1137
-
1138
774
  return (hasPlus ? "+" : "") + netNamespace;
1139
775
  }
1140
-
1141
- pinTypes = [
1142
- PinTypes.Any,
1143
- PinTypes.IO,
1144
- PinTypes.Input,
1145
- PinTypes.Output,
1146
- PinTypes.Power,
1147
- ];
1148
-
1149
- createImportFileHandler(directory: string, defaultLibsPath: string):
1150
- ((visitor: MainVisitor, importPath: string) =>
1151
- { hasError: boolean, hasParseError: boolean, pathExists: boolean }) {
1152
-
1153
- return (visitor: MainVisitor, importPath: string) => {
1154
- // Check if different files exist first
1155
- let importResult: {
1156
- hasError: boolean,
1157
- hasParseError: boolean,
1158
- pathExists: boolean,
1159
- };
1160
-
776
+ createImportFileHandler(directory, defaultLibsPath) {
777
+ return (visitor, importPath) => {
778
+ let importResult;
1161
779
  importResult = this.importLib(visitor, directory, importPath);
1162
-
1163
780
  if (!importResult.pathExists && importPath == 'lib') {
1164
- // Load default path
1165
781
  importResult = this.importLib(visitor, defaultLibsPath, importPath);
1166
782
  }
1167
-
1168
783
  return importResult;
1169
- }
784
+ };
1170
785
  }
1171
-
1172
- private importLib(visitor: MainVisitor, directory: string, filename: string): {hasError: boolean, hasParseError: boolean, pathExists: boolean} {
1173
- const tmpFilePath = join(directory, filename + ".cst");
786
+ importLib(visitor, directory, filename) {
787
+ const tmpFilePath = (0, path_1.join)(directory, filename + ".cst");
1174
788
  visitor.print('importing path:', tmpFilePath);
1175
789
  let pathExists = false;
1176
-
1177
- let fileData: string = null;
1178
-
790
+ let fileData = null;
1179
791
  try {
1180
- fileData = readFileSync(tmpFilePath, { encoding: 'utf8' });
792
+ fileData = (0, fs_1.readFileSync)(tmpFilePath, { encoding: 'utf8' });
1181
793
  pathExists = true;
1182
- } catch (err) {
794
+ }
795
+ catch (err) {
1183
796
  pathExists = false;
1184
797
  }
1185
-
1186
798
  try {
1187
- if (pathExists){
799
+ if (pathExists) {
1188
800
  visitor.print('done reading imported file data');
1189
-
1190
- const { hasError, hasParseError } =
1191
- parseFileWithVisitor(visitor, fileData);
1192
-
1193
- return { hasError, hasParseError, pathExists }
801
+ const { hasError, hasParseError } = (0, parser_js_1.parseFileWithVisitor)(visitor, fileData);
802
+ return { hasError, hasParseError, pathExists };
1194
803
  }
1195
- } catch (err) {
804
+ }
805
+ catch (err) {
1196
806
  visitor.print('Failed to import file: ', err.message);
1197
807
  }
1198
-
1199
808
  return {
1200
809
  hasError: true,
1201
810
  hasParseError: true,
1202
811
  pathExists,
1203
- }
812
+ };
1204
813
  }
1205
-
1206
- private parseCreateComponentPins(
1207
- pinData: number | Map<string, any>,
1208
- ): PinDefinition[] {
1209
- const pins: PinDefinition[] = [];
1210
-
814
+ parseCreateComponentPins(pinData) {
815
+ const pins = [];
1211
816
  if (typeof pinData === 'number') {
1212
817
  const lastPin = pinData;
1213
818
  for (let i = 0; i < lastPin; i++) {
1214
819
  const pinId = i + 1;
1215
- pins.push(
1216
- new PinDefinition(pinId, PinIdType.Int, pinId.toString()),
1217
- );
820
+ pins.push(new PinDefinition_js_1.PinDefinition(pinId, PinDefinition_js_1.PinIdType.Int, pinId.toString()));
1218
821
  }
1219
- } else if (pinData instanceof Map) {
822
+ }
823
+ else if (pinData instanceof Map) {
1220
824
  for (const [pinId, pinDef] of pinData) {
1221
- let pinIdType = PinIdType.Int;
1222
- let pinType = PinTypes.Any;
1223
- let pinName: string | null = null;
1224
- let altPinNames: string[] = [];
1225
-
825
+ let pinIdType = PinDefinition_js_1.PinIdType.Int;
826
+ let pinType = PinTypes_js_1.PinTypes.Any;
827
+ let pinName = null;
828
+ let altPinNames = [];
1226
829
  if (typeof pinId === 'string') {
1227
- pinIdType = PinIdType.Str;
830
+ pinIdType = PinDefinition_js_1.PinIdType.Str;
1228
831
  }
1229
-
1230
832
  if (Array.isArray(pinDef)) {
1231
833
  const firstValue = pinDef[0];
1232
-
1233
- // Check if firstValue matches a pin type
1234
834
  if (this.pinTypes.indexOf(firstValue) !== -1) {
1235
- // First value matches a pin type
1236
835
  pinType = firstValue;
1237
836
  pinName = pinDef[1];
1238
-
1239
837
  if (pinDef.length > 2) {
1240
838
  altPinNames = pinDef.slice(2);
1241
839
  }
1242
- } else {
840
+ }
841
+ else {
1243
842
  pinName = pinDef[0];
1244
843
  if (pinDef.length > 1) {
1245
844
  altPinNames = pinDef.slice(1);
1246
845
  }
1247
846
  }
1248
- } else {
847
+ }
848
+ else {
1249
849
  pinName = pinDef;
1250
850
  }
1251
-
1252
- pins.push(
1253
- new PinDefinition(
1254
- pinId,
1255
- pinIdType,
1256
- pinName,
1257
- pinType,
1258
- altPinNames,
1259
- ),
1260
- );
851
+ pins.push(new PinDefinition_js_1.PinDefinition(pinId, pinIdType, pinName, pinType, altPinNames));
1261
852
  }
1262
853
  }
1263
-
1264
854
  return pins;
1265
855
  }
1266
-
1267
- private parseCreateComponentParams(
1268
- params: Map<string, any>,
1269
- ): ParamDefinition[] {
856
+ parseCreateComponentParams(params) {
1270
857
  const result = [];
1271
858
  if (params) {
1272
859
  for (const [key, value] of params) {
1273
- result.push(new ParamDefinition(key, value));
860
+ result.push(new ParamDefinition_js_1.ParamDefinition(key, value));
1274
861
  }
1275
862
  }
1276
-
1277
863
  return result;
1278
864
  }
1279
-
1280
- private prepareStringValue(value: string): string {
865
+ prepareStringValue(value) {
1281
866
  return value.slice(1, value.length - 1);
1282
867
  }
1283
-
1284
- print(...params: any[]): void {
868
+ print(...params) {
1285
869
  const indentOutput = ''.padStart(this.indentLevel * 4, ' ');
1286
870
  const indentLevelText = this.indentLevel.toString().padStart(3, ' ');
1287
-
1288
871
  const args = ['[' + indentLevelText + ']', indentOutput, ...params];
1289
-
1290
872
  this.logger.add(args.join(' '));
1291
-
1292
- if (!this.silent){
873
+ if (!this.silent) {
1293
874
  console.log.apply(null, args);
1294
875
  }
1295
876
  }
1296
-
1297
- printNets(): void {
877
+ printNets() {
1298
878
  this.getExecutor().scope.printNets();
1299
879
  }
1300
-
1301
- dumpNets(): ComponentPinNet[] {
880
+ dumpNets() {
1302
881
  return this.getExecutor().scope.dumpNets();
1303
882
  }
1304
-
1305
- dumpUniqueNets(): Net[] {
883
+ dumpUniqueNets() {
1306
884
  const nets = this.getExecutor().scope.getNets();
1307
885
  return nets.reduce((accum, [, , net]) => {
1308
886
  accum.push(net);
1309
887
  return accum;
1310
- }, [] as Net[])
888
+ }, []);
1311
889
  }
1312
-
1313
- dumpVariables(): Map<string, any> {
890
+ dumpVariables() {
1314
891
  return this.getExecutor().scope.variables;
1315
892
  }
1316
-
1317
- dumpInstances(): Map<string, ClassComponent> {
893
+ dumpInstances() {
1318
894
  return this.getExecutor().scope.instances;
1319
895
  }
1320
-
1321
896
  dump2() {
1322
897
  const instances = this.getExecutor().scope.instances;
1323
898
  const items = [];
1324
-
1325
899
  for (const [instanceName, instance] of instances) {
1326
900
  if (instance.assignedRefDes === null) {
1327
901
  continue;
1328
902
  }
1329
-
1330
- const pinNets = this.resolveNets(
1331
- this.getExecutor().scope,
1332
- instance,
1333
- );
1334
-
903
+ const pinNets = this.resolveNets(this.getExecutor().scope, instance);
1335
904
  const componentItem = {
1336
905
  name: instanceName,
1337
906
  refdes: instance.assignedRefDes,
1338
907
  pins: {},
1339
908
  };
1340
-
1341
909
  pinNets.forEach((item) => {
1342
910
  componentItem.pins[item.pin.id] = item.netName;
1343
911
  });
1344
-
1345
912
  items.push(componentItem);
1346
913
  }
1347
-
1348
914
  return items;
1349
915
  }
1350
-
1351
- getNetList(): NetListItem[] {
1352
- const netlist: NetListItem[] = [];
1353
-
916
+ getNetList() {
917
+ const netlist = [];
1354
918
  const instances = this.getExecutor().scope.instances;
1355
919
  for (const [instanceName, instance] of instances) {
1356
- const pinNets = this.resolveNets(
1357
- this.getExecutor().scope,
1358
- instance,
1359
- );
1360
-
920
+ const pinNets = this.resolveNets(this.getExecutor().scope, instance);
1361
921
  const componentItem = {
1362
922
  instanceName,
1363
923
  instance,
@@ -1367,51 +927,40 @@ export class MainVisitor extends ParseTreeVisitor<any> {
1367
927
  componentItem.pins[item.pin.id] = {
1368
928
  netName: item.netName,
1369
929
  netBaseName: item.netBaseName
1370
- }
930
+ };
1371
931
  });
1372
-
1373
- netlist.push(componentItem)
932
+ netlist.push(componentItem);
1374
933
  }
1375
-
1376
934
  return netlist;
1377
935
  }
1378
-
1379
936
  getGraph() {
1380
937
  const executor = this.getExecutor();
1381
938
  const sequence = executor.scope.sequence;
1382
939
  const nets = executor.scope.getNets();
1383
-
1384
940
  return {
1385
941
  sequence,
1386
942
  nets,
1387
943
  components: Array.from(executor.scope.instances.values())
1388
944
  };
1389
945
  }
1390
-
1391
- annotateComponents(): void {
946
+ annotateComponents() {
1392
947
  this.print('===== annotate components =====');
1393
-
1394
948
  const annotater = new ComponentAnnotater();
1395
949
  const instances = this.getExecutor().scope.instances;
1396
-
1397
- const toAnnotate:ClassComponent[] = [];
1398
-
950
+ const toAnnotate = [];
1399
951
  for (const [, instance] of instances) {
1400
952
  if (instance.assignedRefDes === null) {
1401
- if (instance.typeProp === ComponentTypes.label ||
1402
- instance.typeProp === ComponentTypes.net ||
1403
- instance.typeProp === ComponentTypes.point) {
953
+ if (instance.typeProp === globals_js_1.ComponentTypes.label ||
954
+ instance.typeProp === globals_js_1.ComponentTypes.net ||
955
+ instance.typeProp === globals_js_1.ComponentTypes.point) {
1404
956
  continue;
1405
957
  }
1406
-
1407
- if (instance.typeProp === null){
958
+ if (instance.typeProp === null) {
1408
959
  this.print('Instance has no type:', instance.instanceName, ' assuming connector');
1409
960
  instance.typeProp = 'conn';
1410
961
  }
1411
-
1412
962
  if (instance.parameters.has('refdes')) {
1413
- const refdes = instance.parameters.get('refdes') as string;
1414
-
963
+ const refdes = instance.parameters.get('refdes');
1415
964
  if (refdes) {
1416
965
  instance.assignedRefDes = refdes;
1417
966
  annotater.trackRefDes(refdes);
@@ -1419,181 +968,106 @@ export class MainVisitor extends ParseTreeVisitor<any> {
1419
968
  continue;
1420
969
  }
1421
970
  }
1422
-
1423
971
  toAnnotate.push(instance);
1424
972
  }
1425
973
  }
1426
-
1427
974
  toAnnotate.forEach(instance => {
1428
975
  const newRefDes = annotater.getAnnotation(instance.typeProp);
1429
-
1430
976
  if (newRefDes !== null) {
1431
977
  instance.assignedRefDes = newRefDes;
1432
978
  this.print(newRefDes, '-', instance.instanceName);
1433
- } else {
979
+ }
980
+ else {
1434
981
  this.print('Failed to annotate:', instance.instanceName);
1435
982
  }
1436
983
  });
1437
-
1438
984
  this.print('===== annotate done =====');
1439
985
  this.print('');
1440
986
  }
1441
-
1442
- private resolveNets(
1443
- scope: ExecutionScope,
1444
- instance: ClassComponent,
1445
- ): { pin: PinDefinition; netName: string, netBaseName: string }[] {
1446
- // Returns the list of nets that the component pins are
1447
- // connected to.
1448
-
987
+ resolveNets(scope, instance) {
1449
988
  const result = [];
1450
-
1451
989
  for (const [pinId, pin] of instance.pins) {
1452
- let netName = NoNetText;
1453
- let netBaseName = NoNetText;
1454
-
990
+ let netName = globals_js_1.NoNetText;
991
+ let netBaseName = globals_js_1.NoNetText;
1455
992
  if (scope.hasNet(instance, pinId)) {
1456
993
  const netObject = scope.getNet(instance, pinId);
1457
994
  netName = netObject.namespace + netObject.name;
1458
995
  netBaseName = netObject.baseName;
1459
996
  }
1460
-
1461
997
  result.push({
1462
998
  pin: pin,
1463
999
  netName: netName,
1464
1000
  netBaseName,
1465
1001
  });
1466
1002
  }
1467
-
1468
1003
  return result;
1469
1004
  }
1470
-
1471
- private setComponentOrientation(component: ClassComponent, pin: number,
1472
- orientation: string): void {
1473
-
1474
- // This can be used to modify the orientation of the component.
1005
+ setComponentOrientation(component, pin, orientation) {
1475
1006
  if (this.acceptedDirections.indexOf(orientation) !== -1) {
1476
- // a valid direction
1477
1007
  component.setParam('_addDirection', orientation);
1478
1008
  component.setParam('_addPin', pin);
1479
- } else {
1009
+ }
1010
+ else {
1480
1011
  throw "Invalid modifier for orientation";
1481
1012
  }
1482
1013
  }
1483
-
1484
- private getPropertyExprList(items: Property_exprContext[]): Map<string, any>{
1485
- const properties = new Map<string, any>();
1486
-
1014
+ getPropertyExprList(items) {
1015
+ const properties = new Map();
1487
1016
  items.forEach((item) => {
1488
- const result: Map<string, any> = this.visit(item); // Map should be returned
1489
-
1017
+ const result = this.visit(item);
1490
1018
  for (const [key, value] of result) {
1491
1019
  properties.set(key, value);
1492
1020
  }
1493
1021
  });
1494
-
1495
1022
  return properties;
1496
1023
  }
1497
-
1498
- private runExpressions(executor: ExecutionContext,
1499
- expressions: ExpressionContext[] | Function_exprContext[]): ComplexType {
1500
-
1501
- let returnValue: ComplexType | null = null;
1502
-
1503
- // Execute the expressions within the context
1024
+ runExpressions(executor, expressions) {
1025
+ let returnValue = null;
1504
1026
  for (let i = 0; i < expressions.length; i++) {
1505
1027
  const expr = expressions[i];
1506
-
1507
- // The correct executor MUST be on the top/end of the stack!
1508
1028
  this.visit(expr);
1509
-
1510
- // If this flag is set, then do not parse anything further!
1511
1029
  if (executor.stopFurtherExpressions) {
1512
1030
  returnValue = executor.returnValue;
1513
1031
  break;
1514
1032
  }
1515
1033
  }
1516
-
1517
1034
  return returnValue;
1518
1035
  }
1519
-
1520
- private checkNetNamespaceIncludes(
1521
- targetNetName: string, targetNamespaceParts: string[], net: Net): boolean {
1522
-
1523
- // Returns true if the namespace of <net> is a fit for
1524
- // the target namespace supplied
1525
-
1526
- if (net.name === targetNetName) {
1527
- // split the net namespace into parts for comparison.
1528
- // For true to be returned, all parts in net must also be in
1529
- // targetNamespaceParts.
1530
- const netNamespaceParts = this.getNamespaceParts(net.namespace);
1531
- this.print('check namespace', targetNetName,
1532
- targetNamespaceParts, netNamespaceParts);
1533
-
1534
- let matches = 0;
1535
- for (let i = 0; i < netNamespaceParts.length; i++) {
1536
- if (netNamespaceParts[i] === targetNamespaceParts[i]) {
1537
- matches++;
1538
- }
1539
- }
1540
-
1541
- if (matches === netNamespaceParts.length) {
1542
- return true;
1543
- }
1544
- }
1545
-
1546
- return false;
1547
- }
1548
-
1549
- private getNamespaceParts(namespace: string): string[] {
1550
- return namespace.split(".").slice(0, -2);
1551
- }
1552
-
1553
- private setupPrintFunction(context: ExecutionContext): void {
1036
+ setupPrintFunction(context) {
1554
1037
  context.createFunction('print', (params) => {
1555
- // Only accept position params
1556
1038
  const items = params.map(([, , value]) => {
1557
- return value
1039
+ return value;
1558
1040
  });
1559
-
1560
1041
  if (this.printToConsole) {
1561
1042
  console.log('::', ...items);
1562
1043
  }
1563
1044
  this.printStream.push(...items);
1564
-
1565
1045
  return [this, null];
1566
1046
  });
1567
1047
  }
1568
-
1569
- private getNetNamespace(executorNetNamespace: string,
1570
- passedNetNamespace: string | null): string {
1571
-
1048
+ getNetNamespace(executorNetNamespace, passedNetNamespace) {
1572
1049
  let result = executorNetNamespace;
1573
-
1574
1050
  if (passedNetNamespace !== null && passedNetNamespace.length > 0) {
1575
- // Either user specified '/' or '/_' to indicate the global
1576
- // net namespace
1577
1051
  if (passedNetNamespace === '/' || passedNetNamespace === '_') {
1578
1052
  result = '';
1579
- } else if (passedNetNamespace[0] === '+') {
1053
+ }
1054
+ else if (passedNetNamespace[0] === '+') {
1580
1055
  if (executorNetNamespace === '/') {
1581
- result = passedNetNamespace.slice(1)
1582
- } else {
1056
+ result = passedNetNamespace.slice(1);
1057
+ }
1058
+ else {
1583
1059
  result = executorNetNamespace + passedNetNamespace.slice(2);
1584
1060
  }
1585
- } else {
1061
+ }
1062
+ else {
1586
1063
  result = passedNetNamespace;
1587
1064
  }
1588
-
1589
1065
  result = result + '/';
1590
1066
  }
1591
-
1592
1067
  return result;
1593
1068
  }
1594
1069
  }
1595
-
1596
-
1070
+ exports.MainVisitor = MainVisitor;
1597
1071
  const ComponentRefDesPrefixes = {
1598
1072
  'res': 'R',
1599
1073
  'cap': 'C',
@@ -1603,89 +1077,59 @@ const ComponentRefDesPrefixes = {
1603
1077
  'transistor': 'Q',
1604
1078
  'relay': 'K',
1605
1079
  'ic': 'U',
1606
-
1607
1080
  '?': '?',
1608
- }
1609
-
1081
+ };
1610
1082
  class ComponentAnnotater {
1611
-
1612
- counter = {};
1613
-
1614
- existingRefDes: string[] = [];
1615
-
1616
- constructor(){
1617
- for(const key in ComponentRefDesPrefixes){
1083
+ constructor() {
1084
+ this.counter = {};
1085
+ this.existingRefDes = [];
1086
+ for (const key in ComponentRefDesPrefixes) {
1618
1087
  this.counter[key] = 1;
1619
1088
  }
1620
-
1621
1089
  this.counter['?'] = 1;
1622
1090
  }
1623
-
1624
- getAnnotation(type: string): string | null {
1625
-
1626
- // If type is unknown, then allow it to define a new range
1091
+ getAnnotation(type) {
1627
1092
  if (this.counter[type] === undefined && type.length <= 2) {
1628
1093
  for (const [, value] of Object.entries(ComponentRefDesPrefixes)) {
1629
1094
  if (value === type) {
1630
1095
  throw "Refdes prefix is already in use!";
1631
1096
  }
1632
1097
  }
1633
-
1634
1098
  if (ComponentRefDesPrefixes[type] === undefined) {
1635
- // Define new type and start counting
1636
1099
  ComponentRefDesPrefixes[type] = type;
1637
1100
  this.counter[type] = 1;
1638
1101
  }
1639
1102
  }
1640
-
1641
1103
  let attempts = 100;
1642
- let proposedName: string;
1643
-
1104
+ let proposedName;
1644
1105
  while (attempts >= 0) {
1645
1106
  proposedName = ComponentRefDesPrefixes[type] + this.counter[type];
1646
1107
  this.counter[type]++;
1647
-
1648
1108
  if (this.existingRefDes.indexOf(proposedName) === -1) {
1649
1109
  break;
1650
1110
  }
1651
1111
  attempts--;
1652
1112
  }
1653
-
1654
1113
  if (attempts === 0) {
1655
1114
  throw "Annotation failed!";
1656
1115
  }
1657
-
1658
1116
  return proposedName;
1659
1117
  }
1660
-
1661
- trackRefDes(name: string): void {
1118
+ trackRefDes(name) {
1662
1119
  this.existingRefDes.push(name);
1663
1120
  }
1664
1121
  }
1665
-
1666
- export type NetListItem = {
1667
- instanceName: string,
1668
- instance: ClassComponent,
1669
- pins: { [key: string | number]: string },
1670
- }
1671
-
1672
- export class VisitorExecutionException {
1673
-
1674
- errorMessage: string;
1675
- context: ParserRuleContext;
1676
-
1677
- constructor(context: ParserRuleContext, errorMessage: string){
1122
+ class VisitorExecutionException {
1123
+ constructor(context, errorMessage) {
1678
1124
  this.errorMessage = errorMessage;
1679
1125
  this.context = context;
1680
1126
  }
1681
-
1682
- print(scriptData: string): void {
1127
+ print(scriptData) {
1683
1128
  const startPoint = this.context.start.start;
1684
1129
  const endPoint = this.context.stop.stop + 1;
1685
-
1686
- console.log('Error at line ' +
1687
- this.context.start.line + "," + this.context.start.column + ": "
1130
+ console.log('Error at line ' +
1131
+ this.context.start.line + "," + this.context.start.column + ": "
1688
1132
  + scriptData.slice(startPoint, endPoint) + " - " + this.errorMessage);
1689
-
1690
1133
  }
1691
- }
1134
+ }
1135
+ exports.VisitorExecutionException = VisitorExecutionException;