circuitscript 0.1.0 → 0.1.3
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.
- package/dist/cjs/BaseVisitor.js +13 -8
- package/dist/cjs/antlr/CircuitScriptLexer.js +80 -80
- package/dist/cjs/antlr/CircuitScriptParser.js +599 -657
- package/dist/cjs/builtinMethods.js +27 -8
- package/dist/cjs/draw_symbols.js +320 -197
- package/dist/cjs/execute.js +114 -116
- package/dist/cjs/export.js +2 -4
- package/dist/cjs/geometry.js +52 -19
- package/dist/cjs/globals.js +17 -12
- package/dist/cjs/helpers.js +16 -3
- package/dist/cjs/layout.js +473 -354
- package/dist/cjs/logger.js +8 -1
- package/dist/cjs/objects/ClassComponent.js +22 -22
- package/dist/cjs/objects/ExecutionScope.js +10 -4
- package/dist/cjs/objects/Frame.js +11 -2
- package/dist/cjs/objects/ParamDefinition.js +123 -4
- package/dist/cjs/objects/PinDefinition.js +1 -4
- package/dist/cjs/render.js +76 -138
- package/dist/cjs/sizing.js +33 -7
- package/dist/cjs/utils.js +86 -2
- package/dist/cjs/visitor.js +224 -255
- package/dist/esm/BaseVisitor.mjs +15 -10
- package/dist/esm/antlr/CircuitScriptLexer.mjs +80 -80
- package/dist/esm/antlr/CircuitScriptParser.mjs +599 -657
- package/dist/esm/builtinMethods.mjs +24 -8
- package/dist/esm/draw_symbols.mjs +322 -200
- package/dist/esm/execute.mjs +116 -118
- package/dist/esm/export.mjs +2 -4
- package/dist/esm/geometry.mjs +52 -19
- package/dist/esm/globals.mjs +17 -12
- package/dist/esm/helpers.mjs +17 -4
- package/dist/esm/layout.mjs +479 -360
- package/dist/esm/logger.mjs +8 -1
- package/dist/esm/objects/ClassComponent.mjs +21 -26
- package/dist/esm/objects/ExecutionScope.mjs +10 -4
- package/dist/esm/objects/Frame.mjs +10 -1
- package/dist/esm/objects/ParamDefinition.mjs +122 -3
- package/dist/esm/objects/PinDefinition.mjs +0 -2
- package/dist/esm/render.mjs +79 -141
- package/dist/esm/sizing.mjs +34 -8
- package/dist/esm/utils.mjs +80 -1
- package/dist/esm/visitor.mjs +226 -257
- package/dist/types/BaseVisitor.d.ts +1 -1
- package/dist/types/antlr/CircuitScriptParser.d.ts +2 -3
- package/dist/types/draw_symbols.d.ts +72 -45
- package/dist/types/execute.d.ts +15 -10
- package/dist/types/geometry.d.ts +31 -19
- package/dist/types/globals.d.ts +15 -11
- package/dist/types/helpers.d.ts +2 -1
- package/dist/types/layout.d.ts +35 -54
- package/dist/types/logger.d.ts +1 -1
- package/dist/types/objects/ClassComponent.d.ts +19 -16
- package/dist/types/objects/ExecutionScope.d.ts +3 -2
- package/dist/types/objects/Frame.d.ts +9 -2
- package/dist/types/objects/ParamDefinition.d.ts +32 -2
- package/dist/types/objects/PinDefinition.d.ts +0 -2
- package/dist/types/render.d.ts +2 -1
- package/dist/types/utils.d.ts +14 -1
- package/dist/types/visitor.d.ts +4 -5
- package/libs/lib.cst +25 -8
- package/package.json +7 -3
package/dist/cjs/visitor.js
CHANGED
|
@@ -17,9 +17,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
17
17
|
super(...arguments);
|
|
18
18
|
this.visitKeyword_assignment_expr = (ctx) => {
|
|
19
19
|
const id = ctx.ID().getText();
|
|
20
|
-
const
|
|
21
|
-
this.visit(ctxDataExpr);
|
|
22
|
-
const value = this.getResult(ctxDataExpr);
|
|
20
|
+
const value = this.visitResult(ctx.data_expr());
|
|
23
21
|
this.setResult(ctx, [id, value]);
|
|
24
22
|
};
|
|
25
23
|
this.visitPin_select_expr = (ctx) => {
|
|
@@ -35,56 +33,48 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
35
33
|
this.setResult(ctx, value);
|
|
36
34
|
};
|
|
37
35
|
this.visitAdd_component_expr = (ctx) => {
|
|
38
|
-
const
|
|
39
|
-
this.visit(ctxDataWithAssignmentExpr);
|
|
40
|
-
const [component, pinValue] = this.getResult(ctxDataWithAssignmentExpr);
|
|
36
|
+
const [component, pinValue] = this.visitResult(ctx.data_expr_with_assignment());
|
|
41
37
|
this.getExecutor().addComponentExisting(component, pinValue);
|
|
42
38
|
};
|
|
43
39
|
this.visitAt_component_expr = (ctx) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const ctxComponentSelectExpr = ctx.component_select_expr();
|
|
49
|
-
this.visit(ctxComponentSelectExpr);
|
|
50
|
-
const [component, pin] = this.getResult(ctxComponentSelectExpr);
|
|
51
|
-
this.getExecutor().atComponent(component, pin, {
|
|
52
|
-
addSequence: true
|
|
53
|
-
});
|
|
54
|
-
}
|
|
40
|
+
const [component, pin] = this.visitResult(ctx.component_select_expr());
|
|
41
|
+
this.getExecutor().atComponent(component, pin, {
|
|
42
|
+
addSequence: true
|
|
43
|
+
});
|
|
55
44
|
return this.getExecutor().getCurrentPoint();
|
|
56
45
|
};
|
|
57
46
|
this.visitTo_component_expr = (ctx) => {
|
|
58
|
-
|
|
59
|
-
this.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
ctx.component_select_expr().forEach(item => {
|
|
63
|
-
this.visit(item);
|
|
64
|
-
const [component, pin] = this.getResult(item);
|
|
65
|
-
this.getExecutor().toComponent(component, pin, {
|
|
66
|
-
addSequence: true
|
|
67
|
-
});
|
|
47
|
+
ctx.component_select_expr().forEach(item => {
|
|
48
|
+
const [component, pin] = this.visitResult(item);
|
|
49
|
+
this.getExecutor().toComponent(component, pin, {
|
|
50
|
+
addSequence: true
|
|
68
51
|
});
|
|
69
|
-
}
|
|
52
|
+
});
|
|
70
53
|
return this.getExecutor().getCurrentPoint();
|
|
71
54
|
};
|
|
72
55
|
this.visitComponent_select_expr = (ctx) => {
|
|
73
56
|
const ctxDataExprWithAssigment = ctx.data_expr_with_assignment();
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
57
|
+
let componentPin = null;
|
|
58
|
+
if (ctx.Point()) {
|
|
59
|
+
const [component, pin,] = this.getExecutor().getPointBlockLocation();
|
|
60
|
+
componentPin = [component, pin];
|
|
61
|
+
}
|
|
62
|
+
else if (ctxDataExprWithAssigment) {
|
|
63
|
+
componentPin = this.visitResult(ctxDataExprWithAssigment);
|
|
77
64
|
}
|
|
78
65
|
else {
|
|
79
66
|
const component = this.getExecutor().scope.currentComponent;
|
|
80
67
|
let pinId = null;
|
|
81
68
|
const ctxPinSelectExpr = ctx.pin_select_expr();
|
|
82
69
|
if (ctxPinSelectExpr) {
|
|
83
|
-
this.
|
|
84
|
-
|
|
70
|
+
pinId = this.visitResult(ctxPinSelectExpr);
|
|
71
|
+
}
|
|
72
|
+
if (pinId === null) {
|
|
73
|
+
this.throwWithContext(ctx, "Could not resolve pin");
|
|
85
74
|
}
|
|
86
|
-
|
|
75
|
+
componentPin = [component, pinId];
|
|
87
76
|
}
|
|
77
|
+
this.setResult(ctx, componentPin);
|
|
88
78
|
};
|
|
89
79
|
this.visitPath_blocks = (ctx) => {
|
|
90
80
|
const blocks = ctx.path_block_inner();
|
|
@@ -123,7 +113,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
123
113
|
this.visitCreate_component_expr = (ctx) => {
|
|
124
114
|
const properties = this.getPropertyExprList(ctx.property_expr());
|
|
125
115
|
const pins = this.parseCreateComponentPins(properties.get('pins'));
|
|
126
|
-
let instanceName = this.getExecutor().getUniqueInstanceName(
|
|
116
|
+
let instanceName = this.getExecutor().getUniqueInstanceName();
|
|
127
117
|
const propParams = properties.get('params');
|
|
128
118
|
const params = this.parseCreateComponentParams(propParams);
|
|
129
119
|
if (params.length > 0) {
|
|
@@ -145,12 +135,14 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
145
135
|
properties.get('copy') : false;
|
|
146
136
|
const width = properties.has('width') ?
|
|
147
137
|
properties.get('width') : null;
|
|
148
|
-
const
|
|
149
|
-
properties.get('
|
|
138
|
+
const height = properties.has('height') ?
|
|
139
|
+
properties.get('height') : null;
|
|
140
|
+
const angle = properties.has(globals_js_1.ParamKeys.angle) ?
|
|
141
|
+
properties.get(globals_js_1.ParamKeys.angle) : null;
|
|
150
142
|
const followWireOrientation = properties.has('followWireOrientation') ?
|
|
151
143
|
properties.get('followWireOrientation') : true;
|
|
152
144
|
const props = {
|
|
153
|
-
arrange, display, type, width, copy,
|
|
145
|
+
arrange, display, type, width, height, copy,
|
|
154
146
|
angle, followWireOrientation
|
|
155
147
|
};
|
|
156
148
|
const createdComponent = this.getExecutor().createComponent(instanceName, pins, params, props);
|
|
@@ -177,8 +169,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
177
169
|
const currentStack = this.executionStack.splice(0);
|
|
178
170
|
this.executionStack.push(...stack);
|
|
179
171
|
const graphicsExpressionsCtx = ctx.graphic_expressions_block();
|
|
180
|
-
this.
|
|
181
|
-
const commands = this.getResult(graphicsExpressionsCtx);
|
|
172
|
+
const commands = this.visitResult(graphicsExpressionsCtx);
|
|
182
173
|
this.executionStack.splice(0);
|
|
183
174
|
this.executionStack.push(...currentStack);
|
|
184
175
|
return commands;
|
|
@@ -188,8 +179,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
188
179
|
};
|
|
189
180
|
this.visitGraphic_expressions_block = (ctx) => {
|
|
190
181
|
const commands = ctx.graphic_expr().reduce((accum, item) => {
|
|
191
|
-
this.
|
|
192
|
-
const [commandName, parameters] = this.getResult(item);
|
|
182
|
+
const [commandName, parameters] = this.visitResult(item);
|
|
193
183
|
if (commandName === draw_symbols_js_1.PlaceHolderCommands.for) {
|
|
194
184
|
accum = accum.concat(parameters);
|
|
195
185
|
}
|
|
@@ -204,7 +194,16 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
204
194
|
}
|
|
205
195
|
return accum;
|
|
206
196
|
}, []);
|
|
207
|
-
|
|
197
|
+
let useCommandName = commandName;
|
|
198
|
+
let usePositionParams = positionParams;
|
|
199
|
+
if (commandName === draw_symbols_js_1.PlaceHolderCommands.crect) {
|
|
200
|
+
useCommandName = draw_symbols_js_1.PlaceHolderCommands.rect;
|
|
201
|
+
const [centerX, centerY, width, height] = positionParams;
|
|
202
|
+
const newX = centerX.sub(width.half());
|
|
203
|
+
const newY = centerY.sub(height.half());
|
|
204
|
+
usePositionParams = [newX, newY, width, height];
|
|
205
|
+
}
|
|
206
|
+
accum.push([useCommandName, usePositionParams, keywordParams, item]);
|
|
208
207
|
}
|
|
209
208
|
return accum;
|
|
210
209
|
}, []);
|
|
@@ -222,18 +221,15 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
222
221
|
let parameters = [];
|
|
223
222
|
const ctxNestedProperties = ctx.nested_properties_inner();
|
|
224
223
|
if (ctxNestedProperties) {
|
|
225
|
-
this.
|
|
226
|
-
const nestedKeyValues = this.getResult(ctxNestedProperties);
|
|
224
|
+
const nestedKeyValues = this.visitResult(ctxNestedProperties);
|
|
227
225
|
nestedKeyValues.forEach((value, key) => {
|
|
228
226
|
parameters.push(['keyword', key, value]);
|
|
229
227
|
});
|
|
230
228
|
}
|
|
231
229
|
else {
|
|
232
|
-
|
|
233
|
-
this.visit(ctxParameters);
|
|
234
|
-
parameters = this.getResult(ctxParameters);
|
|
230
|
+
parameters = this.visitResult(ctx.parameters());
|
|
235
231
|
}
|
|
236
|
-
if (commandName ===
|
|
232
|
+
if (commandName === draw_symbols_js_1.PlaceHolderCommands.label) {
|
|
237
233
|
parameters.forEach(item => {
|
|
238
234
|
if (item[0] == 'keyword' && item[1] === 'portType') {
|
|
239
235
|
if (item[2] === 'in') {
|
|
@@ -249,9 +245,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
249
245
|
};
|
|
250
246
|
this.visitGraphicForExpr = (ctx) => {
|
|
251
247
|
const forVariableNames = ctx.ID().map(item => item.getText());
|
|
252
|
-
const
|
|
253
|
-
this.visit(ctxDataExpr);
|
|
254
|
-
const listItems = this.getResult(ctxDataExpr);
|
|
248
|
+
const listItems = this.visitResult(ctx.data_expr());
|
|
255
249
|
let keepLooping = true;
|
|
256
250
|
let counter = 0;
|
|
257
251
|
let allCommands = [];
|
|
@@ -264,9 +258,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
264
258
|
useValueArray.forEach((value, index) => {
|
|
265
259
|
this.getExecutor().scope.variables.set(forVariableNames[index], value);
|
|
266
260
|
});
|
|
267
|
-
const
|
|
268
|
-
this.visit(graphicsExpressionsCtx);
|
|
269
|
-
const commands = this.getResult(graphicsExpressionsCtx);
|
|
261
|
+
const commands = this.visitResult(ctx.graphic_expressions_block());
|
|
270
262
|
allCommands = allCommands.concat(commands);
|
|
271
263
|
counter += 1;
|
|
272
264
|
}
|
|
@@ -278,8 +270,10 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
278
270
|
};
|
|
279
271
|
this.visitCreate_module_expr = (ctx) => {
|
|
280
272
|
const properties = this.getPropertyExprList(ctx.property_expr());
|
|
281
|
-
const
|
|
282
|
-
const
|
|
273
|
+
const modulePorts = this.parseCreateModulePorts(properties.get('ports'));
|
|
274
|
+
const { [globals_js_1.SymbolPinSide.Left]: leftPorts, [globals_js_1.SymbolPinSide.Right]: rightPorts, [globals_js_1.SymbolPinSide.Top]: topPorts, [globals_js_1.SymbolPinSide.Bottom]: bottomPorts } = modulePorts;
|
|
275
|
+
const allPorts = [...leftPorts, ...rightPorts,
|
|
276
|
+
...topPorts, ...bottomPorts].filter(item => {
|
|
283
277
|
return !(Array.isArray(item));
|
|
284
278
|
});
|
|
285
279
|
const nameToPinId = new Map();
|
|
@@ -287,64 +281,42 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
287
281
|
nameToPinId.set(portName, index + 1);
|
|
288
282
|
return new PinDefinition_js_1.PinDefinition(index + 1, PinDefinition_js_1.PinIdType.Int, portName, PinTypes_js_1.PinTypes.Any);
|
|
289
283
|
});
|
|
290
|
-
const
|
|
291
|
-
if (Array.isArray(item)) {
|
|
292
|
-
return item;
|
|
293
|
-
}
|
|
294
|
-
else {
|
|
295
|
-
return nameToPinId.get(item);
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
const arrangeRightItems = rightPorts.map(item => {
|
|
299
|
-
if (Array.isArray(item)) {
|
|
300
|
-
return item;
|
|
301
|
-
}
|
|
302
|
-
else {
|
|
303
|
-
return nameToPinId.get(item);
|
|
304
|
-
}
|
|
305
|
-
});
|
|
306
|
-
const arrange = new Map();
|
|
307
|
-
if (arrangeLeftItems.length > 0) {
|
|
308
|
-
arrange.set('left', arrangeLeftItems);
|
|
309
|
-
}
|
|
310
|
-
if (arrangeRightItems.length > 0) {
|
|
311
|
-
arrange.set('right', arrangeRightItems);
|
|
312
|
-
}
|
|
284
|
+
const arrange = this.getArrangePropFromModulePorts(modulePorts, nameToPinId);
|
|
313
285
|
const width = properties.has('width') ?
|
|
314
286
|
properties.get('width') : null;
|
|
287
|
+
const height = properties.has('height') ?
|
|
288
|
+
properties.get('height') : null;
|
|
315
289
|
const blankParams = [];
|
|
316
290
|
const props = {
|
|
317
|
-
arrange, width
|
|
291
|
+
arrange, width, height,
|
|
292
|
+
copy: false,
|
|
293
|
+
followWireOrientation: true,
|
|
318
294
|
};
|
|
319
|
-
const moduleInstanceName = this.getExecutor().getUniqueInstanceName(
|
|
320
|
-
const
|
|
321
|
-
|
|
295
|
+
const moduleInstanceName = this.getExecutor().getUniqueInstanceName();
|
|
296
|
+
const moduleComponent = this.getExecutor().createComponent(moduleInstanceName, tmpPorts, blankParams, props, true);
|
|
297
|
+
moduleComponent.typeProp = globals_js_1.ComponentTypes.module;
|
|
322
298
|
const ctxPropertyBlock = ctx.property_block_expr();
|
|
323
299
|
if (ctxPropertyBlock) {
|
|
324
300
|
const [firstBlock] = ctxPropertyBlock;
|
|
325
|
-
this.
|
|
326
|
-
const [keyName, expressionsBlock] = this.getResult(firstBlock);
|
|
301
|
+
const [keyName, expressionsBlock] = this.visitResult(firstBlock);
|
|
327
302
|
if (keyName === globals_js_1.ModuleContainsKeyword) {
|
|
328
|
-
|
|
329
|
-
this.expandModuleContains(
|
|
303
|
+
moduleComponent.moduleContainsExpressions = expressionsBlock;
|
|
304
|
+
this.expandModuleContains(moduleComponent, this.getExecutor().netNamespace);
|
|
330
305
|
}
|
|
331
306
|
}
|
|
332
|
-
|
|
307
|
+
if (moduleComponent.moduleContainsExpressions === undefined) {
|
|
308
|
+
throw 'Module has no `contains` block defined!';
|
|
309
|
+
}
|
|
310
|
+
this.setResult(ctx, moduleComponent);
|
|
333
311
|
};
|
|
334
312
|
this.visitProperty_block_expr = (ctx) => {
|
|
335
|
-
const
|
|
336
|
-
this.visit(tmpCtx);
|
|
337
|
-
const keyName = this.getResult(tmpCtx);
|
|
313
|
+
const keyName = this.visitResult(ctx.property_key_expr());
|
|
338
314
|
const expressionsBlock = ctx.expressions_block();
|
|
339
315
|
this.setResult(ctx, [keyName, expressionsBlock]);
|
|
340
316
|
};
|
|
341
317
|
this.visitProperty_expr = (ctx) => {
|
|
342
|
-
const
|
|
343
|
-
const
|
|
344
|
-
this.visit(ctxPropertyKeyExpr);
|
|
345
|
-
this.visit(ctxPropertyValueExpr);
|
|
346
|
-
const keyName = this.getResult(ctxPropertyKeyExpr);
|
|
347
|
-
const value = this.getResult(ctxPropertyValueExpr);
|
|
318
|
+
const keyName = this.visitResult(ctx.property_key_expr());
|
|
319
|
+
const value = this.visitResult(ctx.property_value_expr());
|
|
348
320
|
if (value instanceof types_js_1.UndeclaredReference && (value.reference.parentValue === undefined
|
|
349
321
|
&& value.reference.value === undefined)) {
|
|
350
322
|
throw value.throwMessage();
|
|
@@ -356,14 +328,11 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
356
328
|
this.visitSingle_line_property = (ctx) => {
|
|
357
329
|
let value;
|
|
358
330
|
if (ctx.data_expr().length === 1) {
|
|
359
|
-
|
|
360
|
-
this.visit(ctxFirst);
|
|
361
|
-
value = this.getResult(ctxFirst);
|
|
331
|
+
value = this.visitResult(ctx.data_expr(0));
|
|
362
332
|
}
|
|
363
333
|
else {
|
|
364
334
|
value = ctx.data_expr().map(item => {
|
|
365
|
-
this.
|
|
366
|
-
return this.getResult(item);
|
|
335
|
+
return this.visitResult(item);
|
|
367
336
|
});
|
|
368
337
|
}
|
|
369
338
|
this.setResult(ctx, value);
|
|
@@ -371,8 +340,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
371
340
|
this.visitNested_properties_inner = (ctx) => {
|
|
372
341
|
const result = new Map();
|
|
373
342
|
ctx.property_expr().forEach((item) => {
|
|
374
|
-
this.
|
|
375
|
-
const property = this.getResult(item);
|
|
343
|
+
const property = this.visitResult(item);
|
|
376
344
|
for (const [key, value] of property) {
|
|
377
345
|
result.set(key, value);
|
|
378
346
|
}
|
|
@@ -380,9 +348,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
380
348
|
this.setResult(ctx, result);
|
|
381
349
|
};
|
|
382
350
|
this.visitNested_properties = (ctx) => {
|
|
383
|
-
|
|
384
|
-
this.visit(ctxNested);
|
|
385
|
-
this.setResult(ctx, this.getResult(ctxNested));
|
|
351
|
+
this.setResult(ctx, this.visitResult(ctx.nested_properties_inner()));
|
|
386
352
|
};
|
|
387
353
|
this.visitProperty_key_expr = (ctx) => {
|
|
388
354
|
const ctxID = ctx.ID();
|
|
@@ -406,16 +372,14 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
406
372
|
const ctxDataExpr = ctx.data_expr();
|
|
407
373
|
const ctxAssignmentExpr = ctx.assignment_expr();
|
|
408
374
|
if (ctxDataExpr) {
|
|
409
|
-
this.
|
|
410
|
-
component = this.getResult(ctxDataExpr);
|
|
375
|
+
component = this.visitResult(ctxDataExpr);
|
|
411
376
|
componentCtx = ctxDataExpr;
|
|
412
377
|
if (component === null || component === undefined) {
|
|
413
378
|
this.throwWithContext(ctxDataExpr, "Could not find component: " + ctxDataExpr.getText());
|
|
414
379
|
}
|
|
415
380
|
}
|
|
416
381
|
else if (ctxAssignmentExpr) {
|
|
417
|
-
this.
|
|
418
|
-
component = this.getResult(ctxAssignmentExpr);
|
|
382
|
+
component = this.visitResult(ctxAssignmentExpr);
|
|
419
383
|
componentCtx = ctxAssignmentExpr;
|
|
420
384
|
}
|
|
421
385
|
if (component instanceof ClassComponent_js_1.ClassComponent
|
|
@@ -439,27 +403,25 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
439
403
|
const ctxID2 = modifier.ID(1);
|
|
440
404
|
let result = null;
|
|
441
405
|
if (ctxValueExpr) {
|
|
442
|
-
this.
|
|
443
|
-
result = this.getResult(ctxValueExpr);
|
|
406
|
+
result = this.visitResult(ctxValueExpr);
|
|
444
407
|
}
|
|
445
408
|
else if (ctxID2) {
|
|
446
409
|
result = ctxID2.getText();
|
|
447
410
|
}
|
|
448
411
|
let shouldIgnoreWireOrientation = false;
|
|
449
|
-
if (modifierText ===
|
|
412
|
+
if (modifierText === globals_js_1.ParamKeys.flip) {
|
|
450
413
|
const flipValue = result;
|
|
451
414
|
if (flipValue.indexOf('x') !== -1) {
|
|
452
|
-
component.setParam(
|
|
415
|
+
component.setParam(globals_js_1.ParamKeys.flipX, 1);
|
|
453
416
|
shouldIgnoreWireOrientation = true;
|
|
454
417
|
}
|
|
455
418
|
if (flipValue.indexOf('y') !== -1) {
|
|
456
|
-
component.setParam(
|
|
419
|
+
component.setParam(globals_js_1.ParamKeys.flipY, 1);
|
|
457
420
|
shouldIgnoreWireOrientation = true;
|
|
458
421
|
}
|
|
459
422
|
}
|
|
460
|
-
else if (modifierText ===
|
|
461
|
-
|
|
462
|
-
component.setParam('angle', angleValue);
|
|
423
|
+
else if (modifierText === globals_js_1.ParamKeys.angle) {
|
|
424
|
+
component.setParam(globals_js_1.ParamKeys.angle, result);
|
|
463
425
|
shouldIgnoreWireOrientation = true;
|
|
464
426
|
}
|
|
465
427
|
else if (modifierText === 'anchor') {
|
|
@@ -473,8 +435,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
473
435
|
let pinValue = null;
|
|
474
436
|
const ctxPinSelectExpr = ctx.pin_select_expr();
|
|
475
437
|
if (ctxPinSelectExpr) {
|
|
476
|
-
this.
|
|
477
|
-
pinValue = this.getResult(ctxPinSelectExpr);
|
|
438
|
+
pinValue = this.visitResult(ctxPinSelectExpr);
|
|
478
439
|
}
|
|
479
440
|
else {
|
|
480
441
|
if (component instanceof ClassComponent_js_1.ClassComponent) {
|
|
@@ -488,24 +449,23 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
488
449
|
this.setResult(ctx, [component, pinValue]);
|
|
489
450
|
};
|
|
490
451
|
this.visitUnaryOperatorExpr = (ctx) => {
|
|
491
|
-
this.
|
|
492
|
-
let value = this.getResult(ctx.data_expr());
|
|
452
|
+
let value = this.visitResult(ctx.data_expr());
|
|
493
453
|
const unaryOp = ctx.unary_operator();
|
|
494
454
|
if (unaryOp) {
|
|
495
455
|
if (unaryOp.Not()) {
|
|
496
456
|
if (typeof value === "boolean") {
|
|
497
457
|
value = !value;
|
|
498
458
|
}
|
|
499
|
-
else if (
|
|
500
|
-
value = (value === 0) ?
|
|
459
|
+
else if (value instanceof ParamDefinition_js_1.NumericValue) {
|
|
460
|
+
value = (value.toNumber() === 0) ? true : false;
|
|
501
461
|
}
|
|
502
462
|
else {
|
|
503
463
|
throw "Failed to do Not operator";
|
|
504
464
|
}
|
|
505
465
|
}
|
|
506
466
|
else if (unaryOp.Minus()) {
|
|
507
|
-
if (
|
|
508
|
-
value =
|
|
467
|
+
if (value instanceof ParamDefinition_js_1.NumericValue) {
|
|
468
|
+
value = value.neg();
|
|
509
469
|
}
|
|
510
470
|
else {
|
|
511
471
|
throw "Failed to do Negation operator";
|
|
@@ -520,16 +480,13 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
520
480
|
const ctxCreateGraphicExpr = ctx.create_graphic_expr();
|
|
521
481
|
const ctxCreateModuleExpr = ctx.create_module_expr();
|
|
522
482
|
if (ctxCreateComponentExpr) {
|
|
523
|
-
this.
|
|
524
|
-
value = this.getResult(ctxCreateComponentExpr);
|
|
483
|
+
value = this.visitResult(ctxCreateComponentExpr);
|
|
525
484
|
}
|
|
526
485
|
else if (ctxCreateGraphicExpr) {
|
|
527
|
-
this.
|
|
528
|
-
value = this.getResult(ctxCreateGraphicExpr);
|
|
486
|
+
value = this.visitResult(ctxCreateGraphicExpr);
|
|
529
487
|
}
|
|
530
488
|
else if (ctxCreateModuleExpr) {
|
|
531
|
-
this.
|
|
532
|
-
value = this.getResult(ctxCreateModuleExpr);
|
|
489
|
+
value = this.visitResult(ctxCreateModuleExpr);
|
|
533
490
|
}
|
|
534
491
|
else {
|
|
535
492
|
throw "Invalid data expression";
|
|
@@ -539,10 +496,14 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
539
496
|
this.visitBinaryOperatorExpr = (ctx) => {
|
|
540
497
|
const ctx0 = ctx.data_expr(0);
|
|
541
498
|
const ctx1 = ctx.data_expr(1);
|
|
542
|
-
this.
|
|
543
|
-
this.
|
|
544
|
-
|
|
545
|
-
|
|
499
|
+
let value1 = this.visitResult(ctx0);
|
|
500
|
+
let value2 = this.visitResult(ctx1);
|
|
501
|
+
if (value1 instanceof ParamDefinition_js_1.NumericValue) {
|
|
502
|
+
value1 = value1.toNumber();
|
|
503
|
+
}
|
|
504
|
+
if (value2 instanceof ParamDefinition_js_1.NumericValue) {
|
|
505
|
+
value2 = value2.toNumber();
|
|
506
|
+
}
|
|
546
507
|
const binaryOperatorType = ctx.binary_operator();
|
|
547
508
|
let result = null;
|
|
548
509
|
if (binaryOperatorType.Equals()) {
|
|
@@ -568,60 +529,87 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
568
529
|
this.visitLogicalOperatorExpr = (ctx) => {
|
|
569
530
|
const ctx0 = ctx.data_expr(0);
|
|
570
531
|
const ctx1 = ctx.data_expr(1);
|
|
571
|
-
this.
|
|
572
|
-
|
|
532
|
+
let value1 = this.visitResult(ctx0);
|
|
533
|
+
if (value1 instanceof ParamDefinition_js_1.NumericValue) {
|
|
534
|
+
value1 = value1.toNumber();
|
|
535
|
+
}
|
|
573
536
|
let value2 = false;
|
|
574
537
|
let skipNext = false;
|
|
575
|
-
|
|
538
|
+
const isLogicalOr = ctx.LogicalOr();
|
|
539
|
+
if (isLogicalOr && value1) {
|
|
576
540
|
skipNext = true;
|
|
577
541
|
}
|
|
578
542
|
if (!skipNext) {
|
|
579
|
-
this.
|
|
580
|
-
value2
|
|
543
|
+
value2 = this.visitResult(ctx1);
|
|
544
|
+
if (value2 instanceof ParamDefinition_js_1.NumericValue) {
|
|
545
|
+
value2 = value2.toNumber();
|
|
546
|
+
}
|
|
581
547
|
}
|
|
582
548
|
let result = null;
|
|
583
549
|
if (ctx.LogicalAnd()) {
|
|
584
550
|
result = value1 && value2;
|
|
585
551
|
}
|
|
586
|
-
else if (
|
|
552
|
+
else if (isLogicalOr) {
|
|
587
553
|
result = value1 || value2;
|
|
588
554
|
}
|
|
555
|
+
if (typeof result === "number") {
|
|
556
|
+
result = (0, ParamDefinition_js_1.numeric)(result);
|
|
557
|
+
}
|
|
589
558
|
this.setResult(ctx, result);
|
|
590
559
|
};
|
|
591
560
|
this.visitMultiplyExpr = (ctx) => {
|
|
592
561
|
const value1 = this.resolveDataExpr(ctx.data_expr(0));
|
|
593
562
|
const value2 = this.resolveDataExpr(ctx.data_expr(1));
|
|
563
|
+
const operator = new ParamDefinition_js_1.NumberOperator();
|
|
564
|
+
const tmpValue1 = operator.prepare(value1);
|
|
565
|
+
const tmpValue2 = operator.prepare(value2);
|
|
594
566
|
let result = null;
|
|
595
567
|
if (ctx.Multiply()) {
|
|
596
|
-
result =
|
|
568
|
+
result = operator.multiply(tmpValue1, tmpValue2);
|
|
597
569
|
}
|
|
598
570
|
else if (ctx.Divide()) {
|
|
599
|
-
result =
|
|
571
|
+
result = operator.divide(tmpValue1, tmpValue2);
|
|
600
572
|
}
|
|
601
573
|
else if (ctx.Modulus()) {
|
|
602
|
-
result =
|
|
574
|
+
result = operator.modulus(tmpValue1, tmpValue2);
|
|
603
575
|
}
|
|
604
576
|
this.setResult(ctx, result);
|
|
605
577
|
};
|
|
606
578
|
this.visitAdditionExpr = (ctx) => {
|
|
607
579
|
const value1 = this.resolveDataExpr(ctx.data_expr(0));
|
|
608
580
|
const value2 = this.resolveDataExpr(ctx.data_expr(1));
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
581
|
+
if (ctx.Addition() && (typeof value1 === 'string' || typeof value2 === 'string')) {
|
|
582
|
+
let tmpValue1 = value1;
|
|
583
|
+
if (value1 instanceof ParamDefinition_js_1.NumericValue) {
|
|
584
|
+
tmpValue1 = value1.toDisplayString();
|
|
585
|
+
}
|
|
586
|
+
let tmpValue2 = value2;
|
|
587
|
+
if (value2 instanceof ParamDefinition_js_1.NumericValue) {
|
|
588
|
+
tmpValue2 = value2.toDisplayString();
|
|
589
|
+
}
|
|
590
|
+
const result = tmpValue1 + tmpValue2;
|
|
591
|
+
this.setResult(ctx, result);
|
|
612
592
|
}
|
|
613
|
-
else
|
|
614
|
-
|
|
593
|
+
else {
|
|
594
|
+
const operator = new ParamDefinition_js_1.NumberOperator();
|
|
595
|
+
const tmpValue1 = operator.prepare(value1);
|
|
596
|
+
const tmpValue2 = operator.prepare(value2);
|
|
597
|
+
let result = null;
|
|
598
|
+
if (ctx.Addition()) {
|
|
599
|
+
result = operator.addition(tmpValue1, tmpValue2);
|
|
600
|
+
}
|
|
601
|
+
else if (ctx.Minus()) {
|
|
602
|
+
result = operator.subtraction(tmpValue1, tmpValue2);
|
|
603
|
+
}
|
|
604
|
+
this.setResult(ctx, result);
|
|
615
605
|
}
|
|
616
|
-
this.setResult(ctx, result);
|
|
617
606
|
};
|
|
618
607
|
this.visitFunction_def_expr = (ctx) => {
|
|
619
608
|
const functionName = ctx.ID().getText();
|
|
620
609
|
let funcDefinedParameters = [];
|
|
621
610
|
const ctxFunctionArgsExpr = ctx.function_args_expr();
|
|
622
611
|
if (ctxFunctionArgsExpr) {
|
|
623
|
-
this.
|
|
624
|
-
funcDefinedParameters = this.getResult(ctxFunctionArgsExpr);
|
|
612
|
+
funcDefinedParameters = this.visitResult(ctxFunctionArgsExpr);
|
|
625
613
|
}
|
|
626
614
|
const executionStack = this.executionStack;
|
|
627
615
|
const functionCounter = { counter: 0 };
|
|
@@ -652,12 +640,9 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
652
640
|
this.setResult(ctx, result);
|
|
653
641
|
};
|
|
654
642
|
this.visitAt_block_pin_expr = (ctx) => {
|
|
655
|
-
const
|
|
656
|
-
this.visit(ctxPinSelectExpr2);
|
|
657
|
-
const atPin = this.getResult(ctxPinSelectExpr2);
|
|
643
|
+
const atPin = this.visitResult(ctx.pin_select_expr2());
|
|
658
644
|
const executor = this.getExecutor();
|
|
659
|
-
const currentComponent = executor.
|
|
660
|
-
const currentPin = executor.scope.currentPin;
|
|
645
|
+
const [currentComponent, currentPin] = executor.getCurrentPoint();
|
|
661
646
|
executor.atComponent(currentComponent, atPin, {
|
|
662
647
|
addSequence: true
|
|
663
648
|
});
|
|
@@ -719,8 +704,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
719
704
|
useValue = Number(ctxIntegerValue);
|
|
720
705
|
}
|
|
721
706
|
else if (ctxDataExpr) {
|
|
722
|
-
this.
|
|
723
|
-
useValue = this.getResult(ctxDataExpr);
|
|
707
|
+
useValue = this.visitResult(ctxDataExpr);
|
|
724
708
|
}
|
|
725
709
|
if (useValue !== null) {
|
|
726
710
|
this.setResult(ctx, [direction, new helpers_js_1.UnitDimension(useValue)]);
|
|
@@ -732,8 +716,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
732
716
|
this.visitWire_expr = (ctx) => {
|
|
733
717
|
const wireAtomExpr = ctx.wire_atom_expr();
|
|
734
718
|
const segments = wireAtomExpr.map(wireSegment => {
|
|
735
|
-
this.
|
|
736
|
-
return this.getResult(wireSegment);
|
|
719
|
+
return this.visitResult(wireSegment);
|
|
737
720
|
});
|
|
738
721
|
this.getExecutor().addWire(segments);
|
|
739
722
|
};
|
|
@@ -742,18 +725,12 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
742
725
|
return this.getExecutor().addPoint(ID.getText());
|
|
743
726
|
};
|
|
744
727
|
this.visitProperty_set_expr = (ctx) => {
|
|
745
|
-
const
|
|
746
|
-
this.
|
|
747
|
-
const result = this.getResult(ctxDataExpr);
|
|
748
|
-
const ctxAtomExpr = ctx.atom_expr();
|
|
749
|
-
this.visit(ctxAtomExpr);
|
|
750
|
-
const resolvedProperty = this.getResult(ctxAtomExpr);
|
|
728
|
+
const result = this.visitResult(ctx.data_expr());
|
|
729
|
+
const resolvedProperty = this.visitResult(ctx.atom_expr());
|
|
751
730
|
this.getExecutor().setProperty(resolvedProperty, result);
|
|
752
731
|
};
|
|
753
732
|
this.visitDouble_dot_property_set_expr = (ctx) => {
|
|
754
|
-
const
|
|
755
|
-
this.visit(ctxDataExpr);
|
|
756
|
-
const result = this.getResult(ctxDataExpr);
|
|
733
|
+
const result = this.visitResult(ctx.data_expr());
|
|
757
734
|
const propertyName = ctx.ID().getText();
|
|
758
735
|
this.getExecutor().setProperty('..' + propertyName, result);
|
|
759
736
|
};
|
|
@@ -775,8 +752,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
775
752
|
const hasPlus = ctx.Addition();
|
|
776
753
|
const ctxDataExpr = ctx.data_expr();
|
|
777
754
|
if (ctxDataExpr) {
|
|
778
|
-
this.
|
|
779
|
-
dataValue = this.getResult(ctxDataExpr);
|
|
755
|
+
dataValue = this.visitResult(ctxDataExpr);
|
|
780
756
|
if (dataValue instanceof types_js_1.UndeclaredReference) {
|
|
781
757
|
netNamespace = "/" + dataValue.reference.name;
|
|
782
758
|
}
|
|
@@ -793,9 +769,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
793
769
|
this.setResult(ctx, (hasPlus ? "+" : "") + netNamespace);
|
|
794
770
|
};
|
|
795
771
|
this.visitIf_expr = (ctx) => {
|
|
796
|
-
const
|
|
797
|
-
this.visit(ctxDataExpr);
|
|
798
|
-
const result = this.getResult(ctxDataExpr);
|
|
772
|
+
const result = this.visitResult(ctx.data_expr());
|
|
799
773
|
let resultValue = result;
|
|
800
774
|
if (result instanceof types_js_1.UndeclaredReference) {
|
|
801
775
|
resultValue = false;
|
|
@@ -807,9 +781,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
807
781
|
const ctxInnerIfExprs = ctx.if_inner_expr();
|
|
808
782
|
let innerIfWasTrue = false;
|
|
809
783
|
for (let i = 0; i < ctxInnerIfExprs.length; i++) {
|
|
810
|
-
const
|
|
811
|
-
this.visit(tmpCtx);
|
|
812
|
-
const innerResult = this.getResult(tmpCtx);
|
|
784
|
+
const innerResult = this.visitResult(ctxInnerIfExprs[i]);
|
|
813
785
|
if (innerResult) {
|
|
814
786
|
innerIfWasTrue = true;
|
|
815
787
|
break;
|
|
@@ -824,9 +796,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
824
796
|
}
|
|
825
797
|
};
|
|
826
798
|
this.visitIf_inner_expr = (ctx) => {
|
|
827
|
-
const
|
|
828
|
-
this.visit(ctxDataExpr);
|
|
829
|
-
const result = this.getResult(ctxDataExpr);
|
|
799
|
+
const result = this.visitResult(ctx.data_expr());
|
|
830
800
|
if (result) {
|
|
831
801
|
this.visit(ctx.expressions_block());
|
|
832
802
|
}
|
|
@@ -838,8 +808,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
838
808
|
this.log('enter while loop');
|
|
839
809
|
this.getExecutor().addBreakContext(ctx);
|
|
840
810
|
while (keepLooping) {
|
|
841
|
-
this.
|
|
842
|
-
const result = this.getResult(dataExpr);
|
|
811
|
+
const result = this.visitResult(dataExpr);
|
|
843
812
|
if (result) {
|
|
844
813
|
this.visit(ctx.expressions_block());
|
|
845
814
|
keepLooping = true;
|
|
@@ -864,10 +833,9 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
864
833
|
this.log('exit while loop');
|
|
865
834
|
};
|
|
866
835
|
this.visitFor_expr = (ctx) => {
|
|
836
|
+
this.log('in for loop');
|
|
867
837
|
const forVariableNames = ctx.ID().map(item => item.getText());
|
|
868
|
-
const
|
|
869
|
-
this.visit(ctxDataExpr);
|
|
870
|
-
const listItems = this.getResult(ctxDataExpr);
|
|
838
|
+
const listItems = this.visitResult(ctx.data_expr());
|
|
871
839
|
this.getExecutor().addBreakContext(ctx);
|
|
872
840
|
let keepLooping = true;
|
|
873
841
|
let counter = 0;
|
|
@@ -884,6 +852,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
884
852
|
keepLooping = true;
|
|
885
853
|
const currentResult = this.getResult(ctx) ?? {};
|
|
886
854
|
const { breakSignal = false, continueSignal = false } = currentResult;
|
|
855
|
+
this.log('condition result: ', breakSignal, continueSignal);
|
|
887
856
|
if (breakSignal && !continueSignal) {
|
|
888
857
|
keepLooping = false;
|
|
889
858
|
}
|
|
@@ -914,11 +883,12 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
914
883
|
this.getExecutor().log('expanding module `contains`');
|
|
915
884
|
const executionStack = this.executionStack;
|
|
916
885
|
const resolveNet = this.createNetResolver(executionStack);
|
|
917
|
-
const
|
|
886
|
+
const executor = this.getExecutor();
|
|
887
|
+
const executionContextName = executor.namespace + "_"
|
|
918
888
|
+ component.instanceName
|
|
919
889
|
+ '_' + component.moduleCounter;
|
|
920
890
|
const tmpNamespace = this.getNetNamespace(netNamespace, "+/" + component.instanceName + "_" + component.moduleCounter);
|
|
921
|
-
const newExecutor = this.enterNewChildContext(executionStack,
|
|
891
|
+
const newExecutor = this.enterNewChildContext(executionStack, executor, executionContextName, { netNamespace: tmpNamespace }, [], []);
|
|
922
892
|
component.moduleCounter += 1;
|
|
923
893
|
newExecutor.resolveNet = resolveNet;
|
|
924
894
|
this.visit(component.moduleContainsExpressions);
|
|
@@ -936,9 +906,9 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
936
906
|
});
|
|
937
907
|
const pinIdToPortMap = new Map();
|
|
938
908
|
moduleComponent.modulePinIdToPortMap = pinIdToPortMap;
|
|
939
|
-
for (const [
|
|
940
|
-
if (component._copyID !== null && component.typeProp ===
|
|
941
|
-
const portName = component.parameters.get(
|
|
909
|
+
for (const [, component] of executionContext.scope.instances) {
|
|
910
|
+
if (component._copyID !== null && component.typeProp === globals_js_1.ComponentTypes.port) {
|
|
911
|
+
const portName = component.parameters.get(globals_js_1.ParamKeys.net_name);
|
|
942
912
|
const modulePinId = modulePinMapping.get(portName);
|
|
943
913
|
pinIdToPortMap.set(modulePinId, component);
|
|
944
914
|
const portType = (0, utils_js_1.getPortType)(component);
|
|
@@ -948,7 +918,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
948
918
|
}
|
|
949
919
|
}
|
|
950
920
|
placeModuleContains(moduleComponent) {
|
|
951
|
-
if (moduleComponent.typeProp ===
|
|
921
|
+
if (moduleComponent.typeProp === globals_js_1.ComponentTypes.module
|
|
952
922
|
&& moduleComponent.moduleContainsExpressions) {
|
|
953
923
|
this.log('place module `contains`');
|
|
954
924
|
this.getExecutor().mergeScope(moduleComponent.moduleExecutionContext.scope, moduleComponent.moduleExecutionContextName);
|
|
@@ -960,8 +930,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
960
930
|
}
|
|
961
931
|
}
|
|
962
932
|
resolveDataExpr(data_expr) {
|
|
963
|
-
this.
|
|
964
|
-
const value = this.getResult(data_expr);
|
|
933
|
+
const value = this.visitResult(data_expr);
|
|
965
934
|
if (value instanceof types_js_1.UndeclaredReference) {
|
|
966
935
|
this.throwWithContext(data_expr, value.throwMessage());
|
|
967
936
|
}
|
|
@@ -981,8 +950,8 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
981
950
|
}
|
|
982
951
|
parseCreateComponentPins(pinData) {
|
|
983
952
|
const pins = [];
|
|
984
|
-
if (
|
|
985
|
-
const lastPin = pinData;
|
|
953
|
+
if (pinData instanceof ParamDefinition_js_1.NumericValue) {
|
|
954
|
+
const lastPin = pinData.toNumber();
|
|
986
955
|
for (let i = 0; i < lastPin; i++) {
|
|
987
956
|
const pinId = i + 1;
|
|
988
957
|
pins.push(new PinDefinition_js_1.PinDefinition(pinId, PinDefinition_js_1.PinIdType.Int, pinId.toString()));
|
|
@@ -1018,30 +987,49 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1018
987
|
else {
|
|
1019
988
|
pinName = pinDef;
|
|
1020
989
|
}
|
|
990
|
+
this.log('pins', pinId, pinIdType, pinName, pinType, altPinNames);
|
|
1021
991
|
pins.push(new PinDefinition_js_1.PinDefinition(pinId, pinIdType, pinName, pinType, altPinNames));
|
|
1022
992
|
}
|
|
1023
993
|
}
|
|
1024
994
|
return pins;
|
|
1025
995
|
}
|
|
1026
996
|
parseCreateModulePorts(portsDefinition) {
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
997
|
+
return {
|
|
998
|
+
left: this.getPortItems(portsDefinition, globals_js_1.SymbolPinSide.Left),
|
|
999
|
+
right: this.getPortItems(portsDefinition, globals_js_1.SymbolPinSide.Right),
|
|
1000
|
+
top: this.getPortItems(portsDefinition, globals_js_1.SymbolPinSide.Top),
|
|
1001
|
+
bottom: this.getPortItems(portsDefinition, globals_js_1.SymbolPinSide.Bottom),
|
|
1002
|
+
};
|
|
1003
|
+
}
|
|
1004
|
+
getArrangePropFromModulePorts(modulePorts, nameToPinId) {
|
|
1005
|
+
const keys = [globals_js_1.SymbolPinSide.Left, globals_js_1.SymbolPinSide.Right, globals_js_1.SymbolPinSide.Top, globals_js_1.SymbolPinSide.Bottom];
|
|
1006
|
+
const arrangeProp = new Map();
|
|
1007
|
+
keys.forEach(key => {
|
|
1008
|
+
if (modulePorts[key]) {
|
|
1009
|
+
const items = modulePorts[key].map(item => {
|
|
1010
|
+
if (Array.isArray(item)) {
|
|
1011
|
+
return item;
|
|
1012
|
+
}
|
|
1013
|
+
else {
|
|
1014
|
+
return (0, ParamDefinition_js_1.numeric)(nameToPinId.get(item));
|
|
1015
|
+
}
|
|
1016
|
+
});
|
|
1017
|
+
if (items.length > 0) {
|
|
1018
|
+
arrangeProp.set(key, items);
|
|
1019
|
+
}
|
|
1033
1020
|
}
|
|
1034
|
-
}
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1021
|
+
});
|
|
1022
|
+
return arrangeProp;
|
|
1023
|
+
}
|
|
1024
|
+
getPortItems(portsDefinition, key) {
|
|
1025
|
+
let tmpItems = [];
|
|
1026
|
+
if (portsDefinition.has(key)) {
|
|
1027
|
+
tmpItems = portsDefinition.get(key);
|
|
1028
|
+
if (!Array.isArray(tmpItems)) {
|
|
1029
|
+
tmpItems = [tmpItems];
|
|
1039
1030
|
}
|
|
1040
1031
|
}
|
|
1041
|
-
return
|
|
1042
|
-
left: leftItems,
|
|
1043
|
-
right: rightItems
|
|
1044
|
-
};
|
|
1032
|
+
return tmpItems;
|
|
1045
1033
|
}
|
|
1046
1034
|
parseCreateComponentParams(params) {
|
|
1047
1035
|
const result = [];
|
|
@@ -1120,8 +1108,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1120
1108
|
const nets = executor.scope.getNets();
|
|
1121
1109
|
return {
|
|
1122
1110
|
sequence,
|
|
1123
|
-
nets
|
|
1124
|
-
components: Array.from(executor.scope.instances.values())
|
|
1111
|
+
nets
|
|
1125
1112
|
};
|
|
1126
1113
|
}
|
|
1127
1114
|
annotateComponents() {
|
|
@@ -1130,16 +1117,11 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1130
1117
|
const instances = this.getExecutor().scope.instances;
|
|
1131
1118
|
const toAnnotate = [];
|
|
1132
1119
|
for (const [, instance] of instances) {
|
|
1120
|
+
if (instance.typeProp === globals_js_1.ComponentTypes.net
|
|
1121
|
+
|| instance.typeProp == globals_js_1.ComponentTypes.graphic) {
|
|
1122
|
+
continue;
|
|
1123
|
+
}
|
|
1133
1124
|
if (instance.assignedRefDes === null) {
|
|
1134
|
-
if (instance.typeProp === globals_js_1.ComponentTypes.label ||
|
|
1135
|
-
instance.typeProp === globals_js_1.ComponentTypes.net ||
|
|
1136
|
-
instance.typeProp === globals_js_1.ComponentTypes.point) {
|
|
1137
|
-
continue;
|
|
1138
|
-
}
|
|
1139
|
-
if (instance.typeProp === null) {
|
|
1140
|
-
this.log('Instance has no type:', instance.instanceName, ' assuming connector');
|
|
1141
|
-
instance.typeProp = 'conn';
|
|
1142
|
-
}
|
|
1143
1125
|
if (instance.parameters.has('refdes')) {
|
|
1144
1126
|
const refdes = instance.parameters.get('refdes');
|
|
1145
1127
|
if (refdes) {
|
|
@@ -1153,7 +1135,10 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1153
1135
|
}
|
|
1154
1136
|
}
|
|
1155
1137
|
toAnnotate.forEach(instance => {
|
|
1156
|
-
const
|
|
1138
|
+
const useTypeProp = instance.typeProp ?? 'conn';
|
|
1139
|
+
instance.typeProp === null
|
|
1140
|
+
&& this.log('Instance has no type:', instance.instanceName, ' assuming connector');
|
|
1141
|
+
const newRefDes = annotater.getAnnotation(useTypeProp);
|
|
1157
1142
|
if (newRefDes !== null) {
|
|
1158
1143
|
instance.assignedRefDes = newRefDes;
|
|
1159
1144
|
this.log(newRefDes, '-', instance.instanceName);
|
|
@@ -1176,9 +1161,9 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1176
1161
|
});
|
|
1177
1162
|
const totalSheets = sheets.length;
|
|
1178
1163
|
sheets.forEach((item, index) => {
|
|
1179
|
-
item.parameters.set(Frame_js_1.FrameParamKeys.SheetType, frameComponent)
|
|
1180
|
-
|
|
1181
|
-
|
|
1164
|
+
item.parameters.set(Frame_js_1.FrameParamKeys.SheetType, frameComponent)
|
|
1165
|
+
.set(Frame_js_1.FrameParamKeys.SheetNumber, index + 1)
|
|
1166
|
+
.set(Frame_js_1.FrameParamKeys.SheetTotal, totalSheets);
|
|
1182
1167
|
});
|
|
1183
1168
|
}
|
|
1184
1169
|
return {
|
|
@@ -1203,25 +1188,10 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1203
1188
|
}
|
|
1204
1189
|
return result;
|
|
1205
1190
|
}
|
|
1206
|
-
setComponentOrientation(component, pin, orientation) {
|
|
1207
|
-
if (this.acceptedDirections.indexOf(orientation) !== -1) {
|
|
1208
|
-
component.setParam('_addDirection', orientation);
|
|
1209
|
-
component.setParam('_addPin', pin);
|
|
1210
|
-
}
|
|
1211
|
-
else {
|
|
1212
|
-
throw "Invalid modifier for orientation";
|
|
1213
|
-
}
|
|
1214
|
-
}
|
|
1215
|
-
setComponentFlip(component, flipValue) {
|
|
1216
|
-
if (this.acceptedFlip.indexOf(flipValue) !== -1) {
|
|
1217
|
-
component.setParam(flipValue, 1);
|
|
1218
|
-
}
|
|
1219
|
-
}
|
|
1220
1191
|
getPropertyExprList(items) {
|
|
1221
1192
|
const properties = new Map();
|
|
1222
1193
|
items.forEach((item) => {
|
|
1223
|
-
this.
|
|
1224
|
-
const result = this.getResult(item);
|
|
1194
|
+
const result = this.visitResult(item);
|
|
1225
1195
|
for (const [key, value] of result) {
|
|
1226
1196
|
properties.set(key, value);
|
|
1227
1197
|
}
|
|
@@ -1231,14 +1201,14 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1231
1201
|
}
|
|
1232
1202
|
exports.ParserVisitor = ParserVisitor;
|
|
1233
1203
|
const ComponentRefDesPrefixes = {
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1204
|
+
res: 'R',
|
|
1205
|
+
cap: 'C',
|
|
1206
|
+
ind: 'L',
|
|
1207
|
+
diode: 'D',
|
|
1208
|
+
conn: 'J',
|
|
1209
|
+
transistor: 'Q',
|
|
1210
|
+
relay: 'K',
|
|
1211
|
+
ic: 'U',
|
|
1242
1212
|
'?': '?',
|
|
1243
1213
|
};
|
|
1244
1214
|
class ComponentAnnotater {
|
|
@@ -1248,7 +1218,6 @@ class ComponentAnnotater {
|
|
|
1248
1218
|
for (const key in ComponentRefDesPrefixes) {
|
|
1249
1219
|
this.counter[key] = 1;
|
|
1250
1220
|
}
|
|
1251
|
-
this.counter['?'] = 1;
|
|
1252
1221
|
}
|
|
1253
1222
|
getAnnotation(type) {
|
|
1254
1223
|
if (this.counter[type] === undefined && type.length <= 2) {
|
|
@@ -1266,7 +1235,7 @@ class ComponentAnnotater {
|
|
|
1266
1235
|
return null;
|
|
1267
1236
|
}
|
|
1268
1237
|
let attempts = 100;
|
|
1269
|
-
let proposedName;
|
|
1238
|
+
let proposedName = "";
|
|
1270
1239
|
while (attempts >= 0) {
|
|
1271
1240
|
proposedName = ComponentRefDesPrefixes[type] + this.counter[type];
|
|
1272
1241
|
this.counter[type]++;
|