circuitscript 0.1.0 → 0.1.2
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 +314 -190
- package/dist/cjs/execute.js +113 -115
- package/dist/cjs/export.js +2 -4
- package/dist/cjs/geometry.js +52 -19
- package/dist/cjs/globals.js +12 -8
- package/dist/cjs/helpers.js +16 -3
- package/dist/cjs/layout.js +129 -125
- 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 +2 -1
- package/dist/cjs/objects/ParamDefinition.js +120 -4
- package/dist/cjs/objects/PinDefinition.js +1 -4
- package/dist/cjs/render.js +40 -110
- package/dist/cjs/sizing.js +33 -7
- package/dist/cjs/utils.js +68 -2
- package/dist/cjs/visitor.js +214 -254
- 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 +316 -193
- package/dist/esm/execute.mjs +115 -117
- package/dist/esm/export.mjs +2 -4
- package/dist/esm/geometry.mjs +52 -19
- package/dist/esm/globals.mjs +12 -8
- package/dist/esm/helpers.mjs +17 -4
- package/dist/esm/layout.mjs +131 -127
- 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 +2 -1
- package/dist/esm/objects/ParamDefinition.mjs +119 -3
- package/dist/esm/objects/PinDefinition.mjs +0 -2
- package/dist/esm/render.mjs +42 -112
- package/dist/esm/sizing.mjs +34 -8
- package/dist/esm/utils.mjs +64 -1
- package/dist/esm/visitor.mjs +216 -256
- package/dist/types/BaseVisitor.d.ts +1 -1
- package/dist/types/antlr/CircuitScriptParser.d.ts +2 -3
- package/dist/types/draw_symbols.d.ts +71 -45
- package/dist/types/execute.d.ts +15 -10
- package/dist/types/geometry.d.ts +31 -19
- package/dist/types/globals.d.ts +14 -10
- package/dist/types/helpers.d.ts +2 -1
- package/dist/types/layout.d.ts +21 -21
- package/dist/types/logger.d.ts +1 -1
- package/dist/types/objects/ClassComponent.d.ts +19 -16
- package/dist/types/objects/ExecutionScope.d.ts +2 -1
- package/dist/types/objects/Frame.d.ts +2 -2
- package/dist/types/objects/ParamDefinition.d.ts +31 -2
- package/dist/types/objects/PinDefinition.d.ts +0 -2
- package/dist/types/render.d.ts +2 -1
- package/dist/types/utils.d.ts +6 -1
- package/dist/types/visitor.d.ts +4 -5
- package/libs/lib.cst +15 -3
- package/package.json +7 -3
package/dist/esm/visitor.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ClassComponent } from './objects/ClassComponent.mjs';
|
|
2
|
-
import { NumericValue, ParamDefinition } from './objects/ParamDefinition.mjs';
|
|
2
|
+
import { NumberOperator, numeric, NumericValue, ParamDefinition } from './objects/ParamDefinition.mjs';
|
|
3
3
|
import { PinDefinition, PinIdType } from './objects/PinDefinition.mjs';
|
|
4
4
|
import { PinTypes } from './objects/PinTypes.mjs';
|
|
5
5
|
import { DeclaredReference, UndeclaredReference } from './objects/types.mjs';
|
|
6
|
-
import { BlockTypes, ComponentTypes, FrameType, GlobalDocumentName, ModuleContainsKeyword, NoNetText, ReferenceTypes, WireAutoDirection } from './globals.mjs';
|
|
6
|
+
import { BlockTypes, ComponentTypes, FrameType, GlobalDocumentName, ModuleContainsKeyword, NoNetText, ParamKeys, ReferenceTypes, SymbolPinSide, WireAutoDirection } from './globals.mjs';
|
|
7
7
|
import { PlaceHolderCommands, SymbolDrawingCommands } from './draw_symbols.mjs';
|
|
8
8
|
import { BaseVisitor } from './BaseVisitor.mjs';
|
|
9
9
|
import { getPortType } from './utils.mjs';
|
|
@@ -12,9 +12,7 @@ import { FrameParamKeys } from './objects/Frame.mjs';
|
|
|
12
12
|
export class ParserVisitor extends BaseVisitor {
|
|
13
13
|
visitKeyword_assignment_expr = (ctx) => {
|
|
14
14
|
const id = ctx.ID().getText();
|
|
15
|
-
const
|
|
16
|
-
this.visit(ctxDataExpr);
|
|
17
|
-
const value = this.getResult(ctxDataExpr);
|
|
15
|
+
const value = this.visitResult(ctx.data_expr());
|
|
18
16
|
this.setResult(ctx, [id, value]);
|
|
19
17
|
};
|
|
20
18
|
visitPin_select_expr = (ctx) => {
|
|
@@ -30,56 +28,48 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
30
28
|
this.setResult(ctx, value);
|
|
31
29
|
};
|
|
32
30
|
visitAdd_component_expr = (ctx) => {
|
|
33
|
-
const
|
|
34
|
-
this.visit(ctxDataWithAssignmentExpr);
|
|
35
|
-
const [component, pinValue] = this.getResult(ctxDataWithAssignmentExpr);
|
|
31
|
+
const [component, pinValue] = this.visitResult(ctx.data_expr_with_assignment());
|
|
36
32
|
this.getExecutor().addComponentExisting(component, pinValue);
|
|
37
33
|
};
|
|
38
34
|
visitAt_component_expr = (ctx) => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const ctxComponentSelectExpr = ctx.component_select_expr();
|
|
44
|
-
this.visit(ctxComponentSelectExpr);
|
|
45
|
-
const [component, pin] = this.getResult(ctxComponentSelectExpr);
|
|
46
|
-
this.getExecutor().atComponent(component, pin, {
|
|
47
|
-
addSequence: true
|
|
48
|
-
});
|
|
49
|
-
}
|
|
35
|
+
const [component, pin] = this.visitResult(ctx.component_select_expr());
|
|
36
|
+
this.getExecutor().atComponent(component, pin, {
|
|
37
|
+
addSequence: true
|
|
38
|
+
});
|
|
50
39
|
return this.getExecutor().getCurrentPoint();
|
|
51
40
|
};
|
|
52
41
|
visitTo_component_expr = (ctx) => {
|
|
53
|
-
|
|
54
|
-
this.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
ctx.component_select_expr().forEach(item => {
|
|
58
|
-
this.visit(item);
|
|
59
|
-
const [component, pin] = this.getResult(item);
|
|
60
|
-
this.getExecutor().toComponent(component, pin, {
|
|
61
|
-
addSequence: true
|
|
62
|
-
});
|
|
42
|
+
ctx.component_select_expr().forEach(item => {
|
|
43
|
+
const [component, pin] = this.visitResult(item);
|
|
44
|
+
this.getExecutor().toComponent(component, pin, {
|
|
45
|
+
addSequence: true
|
|
63
46
|
});
|
|
64
|
-
}
|
|
47
|
+
});
|
|
65
48
|
return this.getExecutor().getCurrentPoint();
|
|
66
49
|
};
|
|
67
50
|
visitComponent_select_expr = (ctx) => {
|
|
68
51
|
const ctxDataExprWithAssigment = ctx.data_expr_with_assignment();
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
52
|
+
let componentPin = null;
|
|
53
|
+
if (ctx.Point()) {
|
|
54
|
+
const [component, pin,] = this.getExecutor().getPointBlockLocation();
|
|
55
|
+
componentPin = [component, pin];
|
|
56
|
+
}
|
|
57
|
+
else if (ctxDataExprWithAssigment) {
|
|
58
|
+
componentPin = this.visitResult(ctxDataExprWithAssigment);
|
|
72
59
|
}
|
|
73
60
|
else {
|
|
74
61
|
const component = this.getExecutor().scope.currentComponent;
|
|
75
62
|
let pinId = null;
|
|
76
63
|
const ctxPinSelectExpr = ctx.pin_select_expr();
|
|
77
64
|
if (ctxPinSelectExpr) {
|
|
78
|
-
this.
|
|
79
|
-
|
|
65
|
+
pinId = this.visitResult(ctxPinSelectExpr);
|
|
66
|
+
}
|
|
67
|
+
if (pinId === null) {
|
|
68
|
+
this.throwWithContext(ctx, "Could not resolve pin");
|
|
80
69
|
}
|
|
81
|
-
|
|
70
|
+
componentPin = [component, pinId];
|
|
82
71
|
}
|
|
72
|
+
this.setResult(ctx, componentPin);
|
|
83
73
|
};
|
|
84
74
|
visitPath_blocks = (ctx) => {
|
|
85
75
|
const blocks = ctx.path_block_inner();
|
|
@@ -118,7 +108,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
118
108
|
visitCreate_component_expr = (ctx) => {
|
|
119
109
|
const properties = this.getPropertyExprList(ctx.property_expr());
|
|
120
110
|
const pins = this.parseCreateComponentPins(properties.get('pins'));
|
|
121
|
-
let instanceName = this.getExecutor().getUniqueInstanceName(
|
|
111
|
+
let instanceName = this.getExecutor().getUniqueInstanceName();
|
|
122
112
|
const propParams = properties.get('params');
|
|
123
113
|
const params = this.parseCreateComponentParams(propParams);
|
|
124
114
|
if (params.length > 0) {
|
|
@@ -140,12 +130,14 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
140
130
|
properties.get('copy') : false;
|
|
141
131
|
const width = properties.has('width') ?
|
|
142
132
|
properties.get('width') : null;
|
|
143
|
-
const
|
|
144
|
-
properties.get('
|
|
133
|
+
const height = properties.has('height') ?
|
|
134
|
+
properties.get('height') : null;
|
|
135
|
+
const angle = properties.has(ParamKeys.angle) ?
|
|
136
|
+
properties.get(ParamKeys.angle) : null;
|
|
145
137
|
const followWireOrientation = properties.has('followWireOrientation') ?
|
|
146
138
|
properties.get('followWireOrientation') : true;
|
|
147
139
|
const props = {
|
|
148
|
-
arrange, display, type, width, copy,
|
|
140
|
+
arrange, display, type, width, height, copy,
|
|
149
141
|
angle, followWireOrientation
|
|
150
142
|
};
|
|
151
143
|
const createdComponent = this.getExecutor().createComponent(instanceName, pins, params, props);
|
|
@@ -172,8 +164,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
172
164
|
const currentStack = this.executionStack.splice(0);
|
|
173
165
|
this.executionStack.push(...stack);
|
|
174
166
|
const graphicsExpressionsCtx = ctx.graphic_expressions_block();
|
|
175
|
-
this.
|
|
176
|
-
const commands = this.getResult(graphicsExpressionsCtx);
|
|
167
|
+
const commands = this.visitResult(graphicsExpressionsCtx);
|
|
177
168
|
this.executionStack.splice(0);
|
|
178
169
|
this.executionStack.push(...currentStack);
|
|
179
170
|
return commands;
|
|
@@ -183,8 +174,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
183
174
|
};
|
|
184
175
|
visitGraphic_expressions_block = (ctx) => {
|
|
185
176
|
const commands = ctx.graphic_expr().reduce((accum, item) => {
|
|
186
|
-
this.
|
|
187
|
-
const [commandName, parameters] = this.getResult(item);
|
|
177
|
+
const [commandName, parameters] = this.visitResult(item);
|
|
188
178
|
if (commandName === PlaceHolderCommands.for) {
|
|
189
179
|
accum = accum.concat(parameters);
|
|
190
180
|
}
|
|
@@ -217,18 +207,15 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
217
207
|
let parameters = [];
|
|
218
208
|
const ctxNestedProperties = ctx.nested_properties_inner();
|
|
219
209
|
if (ctxNestedProperties) {
|
|
220
|
-
this.
|
|
221
|
-
const nestedKeyValues = this.getResult(ctxNestedProperties);
|
|
210
|
+
const nestedKeyValues = this.visitResult(ctxNestedProperties);
|
|
222
211
|
nestedKeyValues.forEach((value, key) => {
|
|
223
212
|
parameters.push(['keyword', key, value]);
|
|
224
213
|
});
|
|
225
214
|
}
|
|
226
215
|
else {
|
|
227
|
-
|
|
228
|
-
this.visit(ctxParameters);
|
|
229
|
-
parameters = this.getResult(ctxParameters);
|
|
216
|
+
parameters = this.visitResult(ctx.parameters());
|
|
230
217
|
}
|
|
231
|
-
if (commandName ===
|
|
218
|
+
if (commandName === PlaceHolderCommands.label) {
|
|
232
219
|
parameters.forEach(item => {
|
|
233
220
|
if (item[0] == 'keyword' && item[1] === 'portType') {
|
|
234
221
|
if (item[2] === 'in') {
|
|
@@ -244,9 +231,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
244
231
|
};
|
|
245
232
|
visitGraphicForExpr = (ctx) => {
|
|
246
233
|
const forVariableNames = ctx.ID().map(item => item.getText());
|
|
247
|
-
const
|
|
248
|
-
this.visit(ctxDataExpr);
|
|
249
|
-
const listItems = this.getResult(ctxDataExpr);
|
|
234
|
+
const listItems = this.visitResult(ctx.data_expr());
|
|
250
235
|
let keepLooping = true;
|
|
251
236
|
let counter = 0;
|
|
252
237
|
let allCommands = [];
|
|
@@ -259,9 +244,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
259
244
|
useValueArray.forEach((value, index) => {
|
|
260
245
|
this.getExecutor().scope.variables.set(forVariableNames[index], value);
|
|
261
246
|
});
|
|
262
|
-
const
|
|
263
|
-
this.visit(graphicsExpressionsCtx);
|
|
264
|
-
const commands = this.getResult(graphicsExpressionsCtx);
|
|
247
|
+
const commands = this.visitResult(ctx.graphic_expressions_block());
|
|
265
248
|
allCommands = allCommands.concat(commands);
|
|
266
249
|
counter += 1;
|
|
267
250
|
}
|
|
@@ -273,8 +256,10 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
273
256
|
};
|
|
274
257
|
visitCreate_module_expr = (ctx) => {
|
|
275
258
|
const properties = this.getPropertyExprList(ctx.property_expr());
|
|
276
|
-
const
|
|
277
|
-
const
|
|
259
|
+
const modulePorts = this.parseCreateModulePorts(properties.get('ports'));
|
|
260
|
+
const { [SymbolPinSide.Left]: leftPorts, [SymbolPinSide.Right]: rightPorts, [SymbolPinSide.Top]: topPorts, [SymbolPinSide.Bottom]: bottomPorts } = modulePorts;
|
|
261
|
+
const allPorts = [...leftPorts, ...rightPorts,
|
|
262
|
+
...topPorts, ...bottomPorts].filter(item => {
|
|
278
263
|
return !(Array.isArray(item));
|
|
279
264
|
});
|
|
280
265
|
const nameToPinId = new Map();
|
|
@@ -282,64 +267,42 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
282
267
|
nameToPinId.set(portName, index + 1);
|
|
283
268
|
return new PinDefinition(index + 1, PinIdType.Int, portName, PinTypes.Any);
|
|
284
269
|
});
|
|
285
|
-
const
|
|
286
|
-
if (Array.isArray(item)) {
|
|
287
|
-
return item;
|
|
288
|
-
}
|
|
289
|
-
else {
|
|
290
|
-
return nameToPinId.get(item);
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
const arrangeRightItems = rightPorts.map(item => {
|
|
294
|
-
if (Array.isArray(item)) {
|
|
295
|
-
return item;
|
|
296
|
-
}
|
|
297
|
-
else {
|
|
298
|
-
return nameToPinId.get(item);
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
const arrange = new Map();
|
|
302
|
-
if (arrangeLeftItems.length > 0) {
|
|
303
|
-
arrange.set('left', arrangeLeftItems);
|
|
304
|
-
}
|
|
305
|
-
if (arrangeRightItems.length > 0) {
|
|
306
|
-
arrange.set('right', arrangeRightItems);
|
|
307
|
-
}
|
|
270
|
+
const arrange = this.getArrangePropFromModulePorts(modulePorts, nameToPinId);
|
|
308
271
|
const width = properties.has('width') ?
|
|
309
272
|
properties.get('width') : null;
|
|
273
|
+
const height = properties.has('height') ?
|
|
274
|
+
properties.get('height') : null;
|
|
310
275
|
const blankParams = [];
|
|
311
276
|
const props = {
|
|
312
|
-
arrange, width
|
|
277
|
+
arrange, width, height,
|
|
278
|
+
copy: false,
|
|
279
|
+
followWireOrientation: true,
|
|
313
280
|
};
|
|
314
|
-
const moduleInstanceName = this.getExecutor().getUniqueInstanceName(
|
|
315
|
-
const
|
|
316
|
-
|
|
281
|
+
const moduleInstanceName = this.getExecutor().getUniqueInstanceName();
|
|
282
|
+
const moduleComponent = this.getExecutor().createComponent(moduleInstanceName, tmpPorts, blankParams, props, true);
|
|
283
|
+
moduleComponent.typeProp = ComponentTypes.module;
|
|
317
284
|
const ctxPropertyBlock = ctx.property_block_expr();
|
|
318
285
|
if (ctxPropertyBlock) {
|
|
319
286
|
const [firstBlock] = ctxPropertyBlock;
|
|
320
|
-
this.
|
|
321
|
-
const [keyName, expressionsBlock] = this.getResult(firstBlock);
|
|
287
|
+
const [keyName, expressionsBlock] = this.visitResult(firstBlock);
|
|
322
288
|
if (keyName === ModuleContainsKeyword) {
|
|
323
|
-
|
|
324
|
-
this.expandModuleContains(
|
|
289
|
+
moduleComponent.moduleContainsExpressions = expressionsBlock;
|
|
290
|
+
this.expandModuleContains(moduleComponent, this.getExecutor().netNamespace);
|
|
325
291
|
}
|
|
326
292
|
}
|
|
327
|
-
|
|
293
|
+
if (moduleComponent.moduleContainsExpressions === undefined) {
|
|
294
|
+
throw 'Module has no `contains` block defined!';
|
|
295
|
+
}
|
|
296
|
+
this.setResult(ctx, moduleComponent);
|
|
328
297
|
};
|
|
329
298
|
visitProperty_block_expr = (ctx) => {
|
|
330
|
-
const
|
|
331
|
-
this.visit(tmpCtx);
|
|
332
|
-
const keyName = this.getResult(tmpCtx);
|
|
299
|
+
const keyName = this.visitResult(ctx.property_key_expr());
|
|
333
300
|
const expressionsBlock = ctx.expressions_block();
|
|
334
301
|
this.setResult(ctx, [keyName, expressionsBlock]);
|
|
335
302
|
};
|
|
336
303
|
visitProperty_expr = (ctx) => {
|
|
337
|
-
const
|
|
338
|
-
const
|
|
339
|
-
this.visit(ctxPropertyKeyExpr);
|
|
340
|
-
this.visit(ctxPropertyValueExpr);
|
|
341
|
-
const keyName = this.getResult(ctxPropertyKeyExpr);
|
|
342
|
-
const value = this.getResult(ctxPropertyValueExpr);
|
|
304
|
+
const keyName = this.visitResult(ctx.property_key_expr());
|
|
305
|
+
const value = this.visitResult(ctx.property_value_expr());
|
|
343
306
|
if (value instanceof UndeclaredReference && (value.reference.parentValue === undefined
|
|
344
307
|
&& value.reference.value === undefined)) {
|
|
345
308
|
throw value.throwMessage();
|
|
@@ -351,14 +314,11 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
351
314
|
visitSingle_line_property = (ctx) => {
|
|
352
315
|
let value;
|
|
353
316
|
if (ctx.data_expr().length === 1) {
|
|
354
|
-
|
|
355
|
-
this.visit(ctxFirst);
|
|
356
|
-
value = this.getResult(ctxFirst);
|
|
317
|
+
value = this.visitResult(ctx.data_expr(0));
|
|
357
318
|
}
|
|
358
319
|
else {
|
|
359
320
|
value = ctx.data_expr().map(item => {
|
|
360
|
-
this.
|
|
361
|
-
return this.getResult(item);
|
|
321
|
+
return this.visitResult(item);
|
|
362
322
|
});
|
|
363
323
|
}
|
|
364
324
|
this.setResult(ctx, value);
|
|
@@ -366,8 +326,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
366
326
|
visitNested_properties_inner = (ctx) => {
|
|
367
327
|
const result = new Map();
|
|
368
328
|
ctx.property_expr().forEach((item) => {
|
|
369
|
-
this.
|
|
370
|
-
const property = this.getResult(item);
|
|
329
|
+
const property = this.visitResult(item);
|
|
371
330
|
for (const [key, value] of property) {
|
|
372
331
|
result.set(key, value);
|
|
373
332
|
}
|
|
@@ -375,9 +334,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
375
334
|
this.setResult(ctx, result);
|
|
376
335
|
};
|
|
377
336
|
visitNested_properties = (ctx) => {
|
|
378
|
-
|
|
379
|
-
this.visit(ctxNested);
|
|
380
|
-
this.setResult(ctx, this.getResult(ctxNested));
|
|
337
|
+
this.setResult(ctx, this.visitResult(ctx.nested_properties_inner()));
|
|
381
338
|
};
|
|
382
339
|
visitProperty_key_expr = (ctx) => {
|
|
383
340
|
const ctxID = ctx.ID();
|
|
@@ -401,16 +358,14 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
401
358
|
const ctxDataExpr = ctx.data_expr();
|
|
402
359
|
const ctxAssignmentExpr = ctx.assignment_expr();
|
|
403
360
|
if (ctxDataExpr) {
|
|
404
|
-
this.
|
|
405
|
-
component = this.getResult(ctxDataExpr);
|
|
361
|
+
component = this.visitResult(ctxDataExpr);
|
|
406
362
|
componentCtx = ctxDataExpr;
|
|
407
363
|
if (component === null || component === undefined) {
|
|
408
364
|
this.throwWithContext(ctxDataExpr, "Could not find component: " + ctxDataExpr.getText());
|
|
409
365
|
}
|
|
410
366
|
}
|
|
411
367
|
else if (ctxAssignmentExpr) {
|
|
412
|
-
this.
|
|
413
|
-
component = this.getResult(ctxAssignmentExpr);
|
|
368
|
+
component = this.visitResult(ctxAssignmentExpr);
|
|
414
369
|
componentCtx = ctxAssignmentExpr;
|
|
415
370
|
}
|
|
416
371
|
if (component instanceof ClassComponent
|
|
@@ -434,27 +389,25 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
434
389
|
const ctxID2 = modifier.ID(1);
|
|
435
390
|
let result = null;
|
|
436
391
|
if (ctxValueExpr) {
|
|
437
|
-
this.
|
|
438
|
-
result = this.getResult(ctxValueExpr);
|
|
392
|
+
result = this.visitResult(ctxValueExpr);
|
|
439
393
|
}
|
|
440
394
|
else if (ctxID2) {
|
|
441
395
|
result = ctxID2.getText();
|
|
442
396
|
}
|
|
443
397
|
let shouldIgnoreWireOrientation = false;
|
|
444
|
-
if (modifierText ===
|
|
398
|
+
if (modifierText === ParamKeys.flip) {
|
|
445
399
|
const flipValue = result;
|
|
446
400
|
if (flipValue.indexOf('x') !== -1) {
|
|
447
|
-
component.setParam(
|
|
401
|
+
component.setParam(ParamKeys.flipX, 1);
|
|
448
402
|
shouldIgnoreWireOrientation = true;
|
|
449
403
|
}
|
|
450
404
|
if (flipValue.indexOf('y') !== -1) {
|
|
451
|
-
component.setParam(
|
|
405
|
+
component.setParam(ParamKeys.flipY, 1);
|
|
452
406
|
shouldIgnoreWireOrientation = true;
|
|
453
407
|
}
|
|
454
408
|
}
|
|
455
|
-
else if (modifierText ===
|
|
456
|
-
|
|
457
|
-
component.setParam('angle', angleValue);
|
|
409
|
+
else if (modifierText === ParamKeys.angle) {
|
|
410
|
+
component.setParam(ParamKeys.angle, result);
|
|
458
411
|
shouldIgnoreWireOrientation = true;
|
|
459
412
|
}
|
|
460
413
|
else if (modifierText === 'anchor') {
|
|
@@ -468,8 +421,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
468
421
|
let pinValue = null;
|
|
469
422
|
const ctxPinSelectExpr = ctx.pin_select_expr();
|
|
470
423
|
if (ctxPinSelectExpr) {
|
|
471
|
-
this.
|
|
472
|
-
pinValue = this.getResult(ctxPinSelectExpr);
|
|
424
|
+
pinValue = this.visitResult(ctxPinSelectExpr);
|
|
473
425
|
}
|
|
474
426
|
else {
|
|
475
427
|
if (component instanceof ClassComponent) {
|
|
@@ -486,11 +438,12 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
486
438
|
this.getExecutor().log('expanding module `contains`');
|
|
487
439
|
const executionStack = this.executionStack;
|
|
488
440
|
const resolveNet = this.createNetResolver(executionStack);
|
|
489
|
-
const
|
|
441
|
+
const executor = this.getExecutor();
|
|
442
|
+
const executionContextName = executor.namespace + "_"
|
|
490
443
|
+ component.instanceName
|
|
491
444
|
+ '_' + component.moduleCounter;
|
|
492
445
|
const tmpNamespace = this.getNetNamespace(netNamespace, "+/" + component.instanceName + "_" + component.moduleCounter);
|
|
493
|
-
const newExecutor = this.enterNewChildContext(executionStack,
|
|
446
|
+
const newExecutor = this.enterNewChildContext(executionStack, executor, executionContextName, { netNamespace: tmpNamespace }, [], []);
|
|
494
447
|
component.moduleCounter += 1;
|
|
495
448
|
newExecutor.resolveNet = resolveNet;
|
|
496
449
|
this.visit(component.moduleContainsExpressions);
|
|
@@ -508,9 +461,9 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
508
461
|
});
|
|
509
462
|
const pinIdToPortMap = new Map();
|
|
510
463
|
moduleComponent.modulePinIdToPortMap = pinIdToPortMap;
|
|
511
|
-
for (const [
|
|
512
|
-
if (component._copyID !== null && component.typeProp ===
|
|
513
|
-
const portName = component.parameters.get(
|
|
464
|
+
for (const [, component] of executionContext.scope.instances) {
|
|
465
|
+
if (component._copyID !== null && component.typeProp === ComponentTypes.port) {
|
|
466
|
+
const portName = component.parameters.get(ParamKeys.net_name);
|
|
514
467
|
const modulePinId = modulePinMapping.get(portName);
|
|
515
468
|
pinIdToPortMap.set(modulePinId, component);
|
|
516
469
|
const portType = getPortType(component);
|
|
@@ -520,7 +473,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
520
473
|
}
|
|
521
474
|
}
|
|
522
475
|
placeModuleContains(moduleComponent) {
|
|
523
|
-
if (moduleComponent.typeProp ===
|
|
476
|
+
if (moduleComponent.typeProp === ComponentTypes.module
|
|
524
477
|
&& moduleComponent.moduleContainsExpressions) {
|
|
525
478
|
this.log('place module `contains`');
|
|
526
479
|
this.getExecutor().mergeScope(moduleComponent.moduleExecutionContext.scope, moduleComponent.moduleExecutionContextName);
|
|
@@ -532,24 +485,23 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
532
485
|
}
|
|
533
486
|
}
|
|
534
487
|
visitUnaryOperatorExpr = (ctx) => {
|
|
535
|
-
this.
|
|
536
|
-
let value = this.getResult(ctx.data_expr());
|
|
488
|
+
let value = this.visitResult(ctx.data_expr());
|
|
537
489
|
const unaryOp = ctx.unary_operator();
|
|
538
490
|
if (unaryOp) {
|
|
539
491
|
if (unaryOp.Not()) {
|
|
540
492
|
if (typeof value === "boolean") {
|
|
541
493
|
value = !value;
|
|
542
494
|
}
|
|
543
|
-
else if (
|
|
544
|
-
value = (value === 0) ?
|
|
495
|
+
else if (value instanceof NumericValue) {
|
|
496
|
+
value = (value.toNumber() === 0) ? true : false;
|
|
545
497
|
}
|
|
546
498
|
else {
|
|
547
499
|
throw "Failed to do Not operator";
|
|
548
500
|
}
|
|
549
501
|
}
|
|
550
502
|
else if (unaryOp.Minus()) {
|
|
551
|
-
if (
|
|
552
|
-
value =
|
|
503
|
+
if (value instanceof NumericValue) {
|
|
504
|
+
value = value.neg();
|
|
553
505
|
}
|
|
554
506
|
else {
|
|
555
507
|
throw "Failed to do Negation operator";
|
|
@@ -564,16 +516,13 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
564
516
|
const ctxCreateGraphicExpr = ctx.create_graphic_expr();
|
|
565
517
|
const ctxCreateModuleExpr = ctx.create_module_expr();
|
|
566
518
|
if (ctxCreateComponentExpr) {
|
|
567
|
-
this.
|
|
568
|
-
value = this.getResult(ctxCreateComponentExpr);
|
|
519
|
+
value = this.visitResult(ctxCreateComponentExpr);
|
|
569
520
|
}
|
|
570
521
|
else if (ctxCreateGraphicExpr) {
|
|
571
|
-
this.
|
|
572
|
-
value = this.getResult(ctxCreateGraphicExpr);
|
|
522
|
+
value = this.visitResult(ctxCreateGraphicExpr);
|
|
573
523
|
}
|
|
574
524
|
else if (ctxCreateModuleExpr) {
|
|
575
|
-
this.
|
|
576
|
-
value = this.getResult(ctxCreateModuleExpr);
|
|
525
|
+
value = this.visitResult(ctxCreateModuleExpr);
|
|
577
526
|
}
|
|
578
527
|
else {
|
|
579
528
|
throw "Invalid data expression";
|
|
@@ -583,10 +532,14 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
583
532
|
visitBinaryOperatorExpr = (ctx) => {
|
|
584
533
|
const ctx0 = ctx.data_expr(0);
|
|
585
534
|
const ctx1 = ctx.data_expr(1);
|
|
586
|
-
this.
|
|
587
|
-
this.
|
|
588
|
-
|
|
589
|
-
|
|
535
|
+
let value1 = this.visitResult(ctx0);
|
|
536
|
+
let value2 = this.visitResult(ctx1);
|
|
537
|
+
if (value1 instanceof NumericValue) {
|
|
538
|
+
value1 = value1.toNumber();
|
|
539
|
+
}
|
|
540
|
+
if (value2 instanceof NumericValue) {
|
|
541
|
+
value2 = value2.toNumber();
|
|
542
|
+
}
|
|
590
543
|
const binaryOperatorType = ctx.binary_operator();
|
|
591
544
|
let result = null;
|
|
592
545
|
if (binaryOperatorType.Equals()) {
|
|
@@ -612,60 +565,87 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
612
565
|
visitLogicalOperatorExpr = (ctx) => {
|
|
613
566
|
const ctx0 = ctx.data_expr(0);
|
|
614
567
|
const ctx1 = ctx.data_expr(1);
|
|
615
|
-
this.
|
|
616
|
-
|
|
568
|
+
let value1 = this.visitResult(ctx0);
|
|
569
|
+
if (value1 instanceof NumericValue) {
|
|
570
|
+
value1 = value1.toNumber();
|
|
571
|
+
}
|
|
617
572
|
let value2 = false;
|
|
618
573
|
let skipNext = false;
|
|
619
|
-
|
|
574
|
+
const isLogicalOr = ctx.LogicalOr();
|
|
575
|
+
if (isLogicalOr && value1) {
|
|
620
576
|
skipNext = true;
|
|
621
577
|
}
|
|
622
578
|
if (!skipNext) {
|
|
623
|
-
this.
|
|
624
|
-
value2
|
|
579
|
+
value2 = this.visitResult(ctx1);
|
|
580
|
+
if (value2 instanceof NumericValue) {
|
|
581
|
+
value2 = value2.toNumber();
|
|
582
|
+
}
|
|
625
583
|
}
|
|
626
584
|
let result = null;
|
|
627
585
|
if (ctx.LogicalAnd()) {
|
|
628
586
|
result = value1 && value2;
|
|
629
587
|
}
|
|
630
|
-
else if (
|
|
588
|
+
else if (isLogicalOr) {
|
|
631
589
|
result = value1 || value2;
|
|
632
590
|
}
|
|
591
|
+
if (typeof result === "number") {
|
|
592
|
+
result = numeric(result);
|
|
593
|
+
}
|
|
633
594
|
this.setResult(ctx, result);
|
|
634
595
|
};
|
|
635
596
|
visitMultiplyExpr = (ctx) => {
|
|
636
597
|
const value1 = this.resolveDataExpr(ctx.data_expr(0));
|
|
637
598
|
const value2 = this.resolveDataExpr(ctx.data_expr(1));
|
|
599
|
+
const operator = new NumberOperator();
|
|
600
|
+
const tmpValue1 = operator.prepare(value1);
|
|
601
|
+
const tmpValue2 = operator.prepare(value2);
|
|
638
602
|
let result = null;
|
|
639
603
|
if (ctx.Multiply()) {
|
|
640
|
-
result =
|
|
604
|
+
result = operator.multiply(tmpValue1, tmpValue2);
|
|
641
605
|
}
|
|
642
606
|
else if (ctx.Divide()) {
|
|
643
|
-
result =
|
|
607
|
+
result = operator.divide(tmpValue1, tmpValue2);
|
|
644
608
|
}
|
|
645
609
|
else if (ctx.Modulus()) {
|
|
646
|
-
result =
|
|
610
|
+
result = operator.modulus(tmpValue1, tmpValue2);
|
|
647
611
|
}
|
|
648
612
|
this.setResult(ctx, result);
|
|
649
613
|
};
|
|
650
614
|
visitAdditionExpr = (ctx) => {
|
|
651
615
|
const value1 = this.resolveDataExpr(ctx.data_expr(0));
|
|
652
616
|
const value2 = this.resolveDataExpr(ctx.data_expr(1));
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
617
|
+
if (ctx.Addition() && (typeof value1 === 'string' || typeof value2 === 'string')) {
|
|
618
|
+
let tmpValue1 = value1;
|
|
619
|
+
if (value1 instanceof NumericValue) {
|
|
620
|
+
tmpValue1 = value1.toDisplayString();
|
|
621
|
+
}
|
|
622
|
+
let tmpValue2 = value2;
|
|
623
|
+
if (value2 instanceof NumericValue) {
|
|
624
|
+
tmpValue2 = value2.toDisplayString();
|
|
625
|
+
}
|
|
626
|
+
const result = tmpValue1 + tmpValue2;
|
|
627
|
+
this.setResult(ctx, result);
|
|
656
628
|
}
|
|
657
|
-
else
|
|
658
|
-
|
|
629
|
+
else {
|
|
630
|
+
const operator = new NumberOperator();
|
|
631
|
+
const tmpValue1 = operator.prepare(value1);
|
|
632
|
+
const tmpValue2 = operator.prepare(value2);
|
|
633
|
+
let result = null;
|
|
634
|
+
if (ctx.Addition()) {
|
|
635
|
+
result = operator.addition(tmpValue1, tmpValue2);
|
|
636
|
+
}
|
|
637
|
+
else if (ctx.Minus()) {
|
|
638
|
+
result = operator.subtraction(tmpValue1, tmpValue2);
|
|
639
|
+
}
|
|
640
|
+
this.setResult(ctx, result);
|
|
659
641
|
}
|
|
660
|
-
this.setResult(ctx, result);
|
|
661
642
|
};
|
|
662
643
|
visitFunction_def_expr = (ctx) => {
|
|
663
644
|
const functionName = ctx.ID().getText();
|
|
664
645
|
let funcDefinedParameters = [];
|
|
665
646
|
const ctxFunctionArgsExpr = ctx.function_args_expr();
|
|
666
647
|
if (ctxFunctionArgsExpr) {
|
|
667
|
-
this.
|
|
668
|
-
funcDefinedParameters = this.getResult(ctxFunctionArgsExpr);
|
|
648
|
+
funcDefinedParameters = this.visitResult(ctxFunctionArgsExpr);
|
|
669
649
|
}
|
|
670
650
|
const executionStack = this.executionStack;
|
|
671
651
|
const functionCounter = { counter: 0 };
|
|
@@ -696,12 +676,9 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
696
676
|
this.setResult(ctx, result);
|
|
697
677
|
};
|
|
698
678
|
visitAt_block_pin_expr = (ctx) => {
|
|
699
|
-
const
|
|
700
|
-
this.visit(ctxPinSelectExpr2);
|
|
701
|
-
const atPin = this.getResult(ctxPinSelectExpr2);
|
|
679
|
+
const atPin = this.visitResult(ctx.pin_select_expr2());
|
|
702
680
|
const executor = this.getExecutor();
|
|
703
|
-
const currentComponent = executor.
|
|
704
|
-
const currentPin = executor.scope.currentPin;
|
|
681
|
+
const [currentComponent, currentPin] = executor.getCurrentPoint();
|
|
705
682
|
executor.atComponent(currentComponent, atPin, {
|
|
706
683
|
addSequence: true
|
|
707
684
|
});
|
|
@@ -763,8 +740,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
763
740
|
useValue = Number(ctxIntegerValue);
|
|
764
741
|
}
|
|
765
742
|
else if (ctxDataExpr) {
|
|
766
|
-
this.
|
|
767
|
-
useValue = this.getResult(ctxDataExpr);
|
|
743
|
+
useValue = this.visitResult(ctxDataExpr);
|
|
768
744
|
}
|
|
769
745
|
if (useValue !== null) {
|
|
770
746
|
this.setResult(ctx, [direction, new UnitDimension(useValue)]);
|
|
@@ -776,8 +752,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
776
752
|
visitWire_expr = (ctx) => {
|
|
777
753
|
const wireAtomExpr = ctx.wire_atom_expr();
|
|
778
754
|
const segments = wireAtomExpr.map(wireSegment => {
|
|
779
|
-
this.
|
|
780
|
-
return this.getResult(wireSegment);
|
|
755
|
+
return this.visitResult(wireSegment);
|
|
781
756
|
});
|
|
782
757
|
this.getExecutor().addWire(segments);
|
|
783
758
|
};
|
|
@@ -786,18 +761,12 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
786
761
|
return this.getExecutor().addPoint(ID.getText());
|
|
787
762
|
};
|
|
788
763
|
visitProperty_set_expr = (ctx) => {
|
|
789
|
-
const
|
|
790
|
-
this.
|
|
791
|
-
const result = this.getResult(ctxDataExpr);
|
|
792
|
-
const ctxAtomExpr = ctx.atom_expr();
|
|
793
|
-
this.visit(ctxAtomExpr);
|
|
794
|
-
const resolvedProperty = this.getResult(ctxAtomExpr);
|
|
764
|
+
const result = this.visitResult(ctx.data_expr());
|
|
765
|
+
const resolvedProperty = this.visitResult(ctx.atom_expr());
|
|
795
766
|
this.getExecutor().setProperty(resolvedProperty, result);
|
|
796
767
|
};
|
|
797
768
|
visitDouble_dot_property_set_expr = (ctx) => {
|
|
798
|
-
const
|
|
799
|
-
this.visit(ctxDataExpr);
|
|
800
|
-
const result = this.getResult(ctxDataExpr);
|
|
769
|
+
const result = this.visitResult(ctx.data_expr());
|
|
801
770
|
const propertyName = ctx.ID().getText();
|
|
802
771
|
this.getExecutor().setProperty('..' + propertyName, result);
|
|
803
772
|
};
|
|
@@ -819,8 +788,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
819
788
|
const hasPlus = ctx.Addition();
|
|
820
789
|
const ctxDataExpr = ctx.data_expr();
|
|
821
790
|
if (ctxDataExpr) {
|
|
822
|
-
this.
|
|
823
|
-
dataValue = this.getResult(ctxDataExpr);
|
|
791
|
+
dataValue = this.visitResult(ctxDataExpr);
|
|
824
792
|
if (dataValue instanceof UndeclaredReference) {
|
|
825
793
|
netNamespace = "/" + dataValue.reference.name;
|
|
826
794
|
}
|
|
@@ -837,9 +805,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
837
805
|
this.setResult(ctx, (hasPlus ? "+" : "") + netNamespace);
|
|
838
806
|
};
|
|
839
807
|
visitIf_expr = (ctx) => {
|
|
840
|
-
const
|
|
841
|
-
this.visit(ctxDataExpr);
|
|
842
|
-
const result = this.getResult(ctxDataExpr);
|
|
808
|
+
const result = this.visitResult(ctx.data_expr());
|
|
843
809
|
let resultValue = result;
|
|
844
810
|
if (result instanceof UndeclaredReference) {
|
|
845
811
|
resultValue = false;
|
|
@@ -851,9 +817,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
851
817
|
const ctxInnerIfExprs = ctx.if_inner_expr();
|
|
852
818
|
let innerIfWasTrue = false;
|
|
853
819
|
for (let i = 0; i < ctxInnerIfExprs.length; i++) {
|
|
854
|
-
const
|
|
855
|
-
this.visit(tmpCtx);
|
|
856
|
-
const innerResult = this.getResult(tmpCtx);
|
|
820
|
+
const innerResult = this.visitResult(ctxInnerIfExprs[i]);
|
|
857
821
|
if (innerResult) {
|
|
858
822
|
innerIfWasTrue = true;
|
|
859
823
|
break;
|
|
@@ -868,9 +832,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
868
832
|
}
|
|
869
833
|
};
|
|
870
834
|
visitIf_inner_expr = (ctx) => {
|
|
871
|
-
const
|
|
872
|
-
this.visit(ctxDataExpr);
|
|
873
|
-
const result = this.getResult(ctxDataExpr);
|
|
835
|
+
const result = this.visitResult(ctx.data_expr());
|
|
874
836
|
if (result) {
|
|
875
837
|
this.visit(ctx.expressions_block());
|
|
876
838
|
}
|
|
@@ -882,8 +844,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
882
844
|
this.log('enter while loop');
|
|
883
845
|
this.getExecutor().addBreakContext(ctx);
|
|
884
846
|
while (keepLooping) {
|
|
885
|
-
this.
|
|
886
|
-
const result = this.getResult(dataExpr);
|
|
847
|
+
const result = this.visitResult(dataExpr);
|
|
887
848
|
if (result) {
|
|
888
849
|
this.visit(ctx.expressions_block());
|
|
889
850
|
keepLooping = true;
|
|
@@ -908,10 +869,9 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
908
869
|
this.log('exit while loop');
|
|
909
870
|
};
|
|
910
871
|
visitFor_expr = (ctx) => {
|
|
872
|
+
this.log('in for loop');
|
|
911
873
|
const forVariableNames = ctx.ID().map(item => item.getText());
|
|
912
|
-
const
|
|
913
|
-
this.visit(ctxDataExpr);
|
|
914
|
-
const listItems = this.getResult(ctxDataExpr);
|
|
874
|
+
const listItems = this.visitResult(ctx.data_expr());
|
|
915
875
|
this.getExecutor().addBreakContext(ctx);
|
|
916
876
|
let keepLooping = true;
|
|
917
877
|
let counter = 0;
|
|
@@ -928,6 +888,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
928
888
|
keepLooping = true;
|
|
929
889
|
const currentResult = this.getResult(ctx) ?? {};
|
|
930
890
|
const { breakSignal = false, continueSignal = false } = currentResult;
|
|
891
|
+
this.log('condition result: ', breakSignal, continueSignal);
|
|
931
892
|
if (breakSignal && !continueSignal) {
|
|
932
893
|
keepLooping = false;
|
|
933
894
|
}
|
|
@@ -947,8 +908,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
947
908
|
this.getExecutor().popBreakContext();
|
|
948
909
|
};
|
|
949
910
|
resolveDataExpr(data_expr) {
|
|
950
|
-
this.
|
|
951
|
-
const value = this.getResult(data_expr);
|
|
911
|
+
const value = this.visitResult(data_expr);
|
|
952
912
|
if (value instanceof UndeclaredReference) {
|
|
953
913
|
this.throwWithContext(data_expr, value.throwMessage());
|
|
954
914
|
}
|
|
@@ -975,8 +935,8 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
975
935
|
];
|
|
976
936
|
parseCreateComponentPins(pinData) {
|
|
977
937
|
const pins = [];
|
|
978
|
-
if (
|
|
979
|
-
const lastPin = pinData;
|
|
938
|
+
if (pinData instanceof NumericValue) {
|
|
939
|
+
const lastPin = pinData.toNumber();
|
|
980
940
|
for (let i = 0; i < lastPin; i++) {
|
|
981
941
|
const pinId = i + 1;
|
|
982
942
|
pins.push(new PinDefinition(pinId, PinIdType.Int, pinId.toString()));
|
|
@@ -1012,30 +972,49 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
1012
972
|
else {
|
|
1013
973
|
pinName = pinDef;
|
|
1014
974
|
}
|
|
975
|
+
this.log('pins', pinId, pinIdType, pinName, pinType, altPinNames);
|
|
1015
976
|
pins.push(new PinDefinition(pinId, pinIdType, pinName, pinType, altPinNames));
|
|
1016
977
|
}
|
|
1017
978
|
}
|
|
1018
979
|
return pins;
|
|
1019
980
|
}
|
|
1020
981
|
parseCreateModulePorts(portsDefinition) {
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
982
|
+
return {
|
|
983
|
+
left: this.getPortItems(portsDefinition, SymbolPinSide.Left),
|
|
984
|
+
right: this.getPortItems(portsDefinition, SymbolPinSide.Right),
|
|
985
|
+
top: this.getPortItems(portsDefinition, SymbolPinSide.Top),
|
|
986
|
+
bottom: this.getPortItems(portsDefinition, SymbolPinSide.Bottom),
|
|
987
|
+
};
|
|
988
|
+
}
|
|
989
|
+
getArrangePropFromModulePorts(modulePorts, nameToPinId) {
|
|
990
|
+
const keys = [SymbolPinSide.Left, SymbolPinSide.Right, SymbolPinSide.Top, SymbolPinSide.Bottom];
|
|
991
|
+
const arrangeProp = new Map();
|
|
992
|
+
keys.forEach(key => {
|
|
993
|
+
if (modulePorts[key]) {
|
|
994
|
+
const items = modulePorts[key].map(item => {
|
|
995
|
+
if (Array.isArray(item)) {
|
|
996
|
+
return item;
|
|
997
|
+
}
|
|
998
|
+
else {
|
|
999
|
+
return numeric(nameToPinId.get(item));
|
|
1000
|
+
}
|
|
1001
|
+
});
|
|
1002
|
+
if (items.length > 0) {
|
|
1003
|
+
arrangeProp.set(key, items);
|
|
1004
|
+
}
|
|
1027
1005
|
}
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1006
|
+
});
|
|
1007
|
+
return arrangeProp;
|
|
1008
|
+
}
|
|
1009
|
+
getPortItems(portsDefinition, key) {
|
|
1010
|
+
let tmpItems = [];
|
|
1011
|
+
if (portsDefinition.has(key)) {
|
|
1012
|
+
tmpItems = portsDefinition.get(key);
|
|
1013
|
+
if (!Array.isArray(tmpItems)) {
|
|
1014
|
+
tmpItems = [tmpItems];
|
|
1033
1015
|
}
|
|
1034
1016
|
}
|
|
1035
|
-
return
|
|
1036
|
-
left: leftItems,
|
|
1037
|
-
right: rightItems
|
|
1038
|
-
};
|
|
1017
|
+
return tmpItems;
|
|
1039
1018
|
}
|
|
1040
1019
|
parseCreateComponentParams(params) {
|
|
1041
1020
|
const result = [];
|
|
@@ -1114,8 +1093,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
1114
1093
|
const nets = executor.scope.getNets();
|
|
1115
1094
|
return {
|
|
1116
1095
|
sequence,
|
|
1117
|
-
nets
|
|
1118
|
-
components: Array.from(executor.scope.instances.values())
|
|
1096
|
+
nets
|
|
1119
1097
|
};
|
|
1120
1098
|
}
|
|
1121
1099
|
annotateComponents() {
|
|
@@ -1124,16 +1102,11 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
1124
1102
|
const instances = this.getExecutor().scope.instances;
|
|
1125
1103
|
const toAnnotate = [];
|
|
1126
1104
|
for (const [, instance] of instances) {
|
|
1105
|
+
if (instance.typeProp === ComponentTypes.net
|
|
1106
|
+
|| instance.typeProp == ComponentTypes.graphic) {
|
|
1107
|
+
continue;
|
|
1108
|
+
}
|
|
1127
1109
|
if (instance.assignedRefDes === null) {
|
|
1128
|
-
if (instance.typeProp === ComponentTypes.label ||
|
|
1129
|
-
instance.typeProp === ComponentTypes.net ||
|
|
1130
|
-
instance.typeProp === ComponentTypes.point) {
|
|
1131
|
-
continue;
|
|
1132
|
-
}
|
|
1133
|
-
if (instance.typeProp === null) {
|
|
1134
|
-
this.log('Instance has no type:', instance.instanceName, ' assuming connector');
|
|
1135
|
-
instance.typeProp = 'conn';
|
|
1136
|
-
}
|
|
1137
1110
|
if (instance.parameters.has('refdes')) {
|
|
1138
1111
|
const refdes = instance.parameters.get('refdes');
|
|
1139
1112
|
if (refdes) {
|
|
@@ -1147,7 +1120,10 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
1147
1120
|
}
|
|
1148
1121
|
}
|
|
1149
1122
|
toAnnotate.forEach(instance => {
|
|
1150
|
-
const
|
|
1123
|
+
const useTypeProp = instance.typeProp ?? 'conn';
|
|
1124
|
+
instance.typeProp === null
|
|
1125
|
+
&& this.log('Instance has no type:', instance.instanceName, ' assuming connector');
|
|
1126
|
+
const newRefDes = annotater.getAnnotation(useTypeProp);
|
|
1151
1127
|
if (newRefDes !== null) {
|
|
1152
1128
|
instance.assignedRefDes = newRefDes;
|
|
1153
1129
|
this.log(newRefDes, '-', instance.instanceName);
|
|
@@ -1170,9 +1146,9 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
1170
1146
|
});
|
|
1171
1147
|
const totalSheets = sheets.length;
|
|
1172
1148
|
sheets.forEach((item, index) => {
|
|
1173
|
-
item.parameters.set(FrameParamKeys.SheetType, frameComponent)
|
|
1174
|
-
|
|
1175
|
-
|
|
1149
|
+
item.parameters.set(FrameParamKeys.SheetType, frameComponent)
|
|
1150
|
+
.set(FrameParamKeys.SheetNumber, index + 1)
|
|
1151
|
+
.set(FrameParamKeys.SheetTotal, totalSheets);
|
|
1176
1152
|
});
|
|
1177
1153
|
}
|
|
1178
1154
|
return {
|
|
@@ -1197,25 +1173,10 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
1197
1173
|
}
|
|
1198
1174
|
return result;
|
|
1199
1175
|
}
|
|
1200
|
-
setComponentOrientation(component, pin, orientation) {
|
|
1201
|
-
if (this.acceptedDirections.indexOf(orientation) !== -1) {
|
|
1202
|
-
component.setParam('_addDirection', orientation);
|
|
1203
|
-
component.setParam('_addPin', pin);
|
|
1204
|
-
}
|
|
1205
|
-
else {
|
|
1206
|
-
throw "Invalid modifier for orientation";
|
|
1207
|
-
}
|
|
1208
|
-
}
|
|
1209
|
-
setComponentFlip(component, flipValue) {
|
|
1210
|
-
if (this.acceptedFlip.indexOf(flipValue) !== -1) {
|
|
1211
|
-
component.setParam(flipValue, 1);
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
1176
|
getPropertyExprList(items) {
|
|
1215
1177
|
const properties = new Map();
|
|
1216
1178
|
items.forEach((item) => {
|
|
1217
|
-
this.
|
|
1218
|
-
const result = this.getResult(item);
|
|
1179
|
+
const result = this.visitResult(item);
|
|
1219
1180
|
for (const [key, value] of result) {
|
|
1220
1181
|
properties.set(key, value);
|
|
1221
1182
|
}
|
|
@@ -1224,14 +1185,14 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
1224
1185
|
}
|
|
1225
1186
|
}
|
|
1226
1187
|
const ComponentRefDesPrefixes = {
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1188
|
+
res: 'R',
|
|
1189
|
+
cap: 'C',
|
|
1190
|
+
ind: 'L',
|
|
1191
|
+
diode: 'D',
|
|
1192
|
+
conn: 'J',
|
|
1193
|
+
transistor: 'Q',
|
|
1194
|
+
relay: 'K',
|
|
1195
|
+
ic: 'U',
|
|
1235
1196
|
'?': '?',
|
|
1236
1197
|
};
|
|
1237
1198
|
class ComponentAnnotater {
|
|
@@ -1241,7 +1202,6 @@ class ComponentAnnotater {
|
|
|
1241
1202
|
for (const key in ComponentRefDesPrefixes) {
|
|
1242
1203
|
this.counter[key] = 1;
|
|
1243
1204
|
}
|
|
1244
|
-
this.counter['?'] = 1;
|
|
1245
1205
|
}
|
|
1246
1206
|
getAnnotation(type) {
|
|
1247
1207
|
if (this.counter[type] === undefined && type.length <= 2) {
|
|
@@ -1259,7 +1219,7 @@ class ComponentAnnotater {
|
|
|
1259
1219
|
return null;
|
|
1260
1220
|
}
|
|
1261
1221
|
let attempts = 100;
|
|
1262
|
-
let proposedName;
|
|
1222
|
+
let proposedName = "";
|
|
1263
1223
|
while (attempts >= 0) {
|
|
1264
1224
|
proposedName = ComponentRefDesPrefixes[type] + this.counter[type];
|
|
1265
1225
|
this.counter[type]++;
|