circuitscript 0.3.1 → 0.4.0
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 +394 -262
- package/dist/cjs/LexerDiagnosticListener.js +375 -0
- package/dist/cjs/{ComponentAnnotater.js → annotate/ComponentAnnotater.js} +29 -15
- package/dist/cjs/annotate/DefaultPostAnnotationCallback.js +126 -0
- package/dist/cjs/{RefdesAnnotationVisitor.js → annotate/RefdesAnnotationVisitor.js} +10 -84
- package/dist/cjs/annotate/utils.js +70 -0
- package/dist/cjs/antlr/CircuitScriptLexer.js +279 -286
- package/dist/cjs/antlr/CircuitScriptParser.js +1954 -3535
- package/dist/cjs/antlr/CircuitScriptParserVisitor.js +7 -0
- package/dist/cjs/cache/deserializer.js +34 -0
- package/dist/cjs/cache/hash.js +8 -0
- package/dist/cjs/cache/serializer.js +122 -0
- package/dist/cjs/cache/storage.js +45 -0
- package/dist/cjs/cache/types.js +4 -0
- package/dist/cjs/{environment.js → environment/environment.js} +18 -6
- package/dist/cjs/environment/esm-environment.js +21 -0
- package/dist/cjs/environment/helpers.js +8 -0
- package/dist/cjs/execute.js +49 -15
- package/dist/cjs/globals.js +9 -1
- package/dist/cjs/helpers.js +3 -467
- package/dist/cjs/importResolver.js +102 -0
- package/dist/cjs/index.js +7 -6
- package/dist/cjs/lexer.js +48 -12
- package/dist/cjs/main.js +14 -4
- package/dist/cjs/objects/ClassComponent.js +1 -1
- package/dist/cjs/objects/ExecutionScope.js +0 -1
- package/dist/cjs/objects/types.js +17 -1
- package/dist/cjs/parser.js +18 -4
- package/dist/cjs/pipeline.js +284 -0
- package/dist/cjs/regenerate-tests.js +4 -3
- package/dist/cjs/render/KiCadNetListOutputHandler.js +30 -0
- package/dist/cjs/render/PaperSizes.js +46 -0
- package/dist/cjs/{draw_symbols.js → render/draw_symbols.js} +58 -36
- package/dist/cjs/{export.js → render/export.js} +2 -2
- package/dist/cjs/{geometry.js → render/geometry.js} +5 -5
- package/dist/cjs/{graph.js → render/graph.js} +7 -7
- package/dist/cjs/{layout.js → render/layout.js} +8 -8
- package/dist/cjs/{render.js → render/render.js} +9 -8
- package/dist/cjs/rules-check/no-connect-on-connected-pin.js +1 -1
- package/dist/cjs/rules-check/unconnected-pins.js +1 -1
- package/dist/cjs/{SemanticTokenVisitor.js → semantic-tokens/SemanticTokenVisitor.js} +12 -14
- package/dist/cjs/semantic-tokens/getSemanticTokens.js +55 -0
- package/dist/cjs/sizing.js +2 -2
- package/dist/cjs/utils.js +2 -2
- package/dist/cjs/validate/SymbolValidatorResolveVisitor.js +6 -0
- package/dist/cjs/validate/SymbolValidatorVisitor.js +34 -39
- package/dist/cjs/validate/validateScript.js +54 -0
- package/dist/cjs/validate.js +5 -4
- package/dist/cjs/visitor.js +158 -212
- package/dist/esm/BaseVisitor.js +396 -264
- package/dist/esm/LexerDiagnosticListener.js +371 -0
- package/dist/esm/{ComponentAnnotater.js → annotate/ComponentAnnotater.js} +29 -15
- package/dist/esm/annotate/DefaultPostAnnotationCallback.js +122 -0
- package/dist/esm/{RefdesAnnotationVisitor.js → annotate/RefdesAnnotationVisitor.js} +10 -84
- package/dist/esm/annotate/utils.js +66 -0
- package/dist/esm/antlr/CircuitScriptLexer.js +279 -286
- package/dist/esm/antlr/CircuitScriptParser.js +1962 -3522
- package/dist/esm/antlr/{CircuitScriptVisitor.js → CircuitScriptParserVisitor.js} +14 -35
- package/dist/esm/cache/deserializer.js +30 -0
- package/dist/esm/cache/hash.js +4 -0
- package/dist/esm/cache/serializer.js +118 -0
- package/dist/esm/cache/storage.js +39 -0
- package/dist/esm/cache/types.js +1 -0
- package/dist/esm/{environment.js → environment/environment.js} +18 -6
- package/dist/esm/environment/esm-environment.js +17 -0
- package/dist/esm/environment/helpers.js +4 -0
- package/dist/esm/execute.js +49 -15
- package/dist/esm/globals.js +8 -0
- package/dist/esm/helpers.js +5 -456
- package/dist/esm/importResolver.js +96 -0
- package/dist/esm/index.js +7 -6
- package/dist/esm/lexer.js +51 -12
- package/dist/esm/main.js +13 -3
- package/dist/esm/objects/ClassComponent.js +1 -1
- package/dist/esm/objects/ExecutionScope.js +0 -1
- package/dist/esm/objects/types.js +21 -1
- package/dist/esm/parser.js +19 -5
- package/dist/esm/pipeline.js +276 -0
- package/dist/esm/regenerate-tests.js +3 -2
- package/dist/esm/render/KiCadNetListOutputHandler.js +20 -0
- package/dist/esm/render/PaperSizes.js +41 -0
- package/dist/esm/{draw_symbols.js → render/draw_symbols.js} +58 -36
- package/dist/esm/{export.js → render/export.js} +2 -2
- package/dist/esm/{geometry.js → render/geometry.js} +5 -5
- package/dist/esm/{graph.js → render/graph.js} +7 -7
- package/dist/esm/{layout.js → render/layout.js} +8 -8
- package/dist/esm/{render.js → render/render.js} +8 -7
- package/dist/esm/rules-check/no-connect-on-connected-pin.js +1 -1
- package/dist/esm/rules-check/unconnected-pins.js +1 -1
- package/dist/esm/{SemanticTokenVisitor.js → semantic-tokens/SemanticTokenVisitor.js} +12 -14
- package/dist/esm/semantic-tokens/getSemanticTokens.js +51 -0
- package/dist/esm/sizing.js +2 -2
- package/dist/esm/utils.js +2 -2
- package/dist/esm/validate/SymbolValidatorResolveVisitor.js +3 -0
- package/dist/esm/validate/SymbolValidatorVisitor.js +36 -41
- package/dist/esm/validate/validateScript.js +50 -0
- package/dist/esm/validate.js +4 -3
- package/dist/esm/visitor.js +160 -214
- package/dist/libs/std.cst +15 -19
- package/dist/types/BaseVisitor.d.ts +25 -18
- package/dist/types/BomGeneration.d.ts +1 -1
- package/dist/types/LexerDiagnosticListener.d.ts +85 -0
- package/dist/types/{ComponentAnnotater.d.ts → annotate/ComponentAnnotater.d.ts} +1 -1
- package/dist/types/annotate/DefaultPostAnnotationCallback.d.ts +7 -0
- package/dist/types/{RefdesAnnotationVisitor.d.ts → annotate/RefdesAnnotationVisitor.d.ts} +7 -9
- package/dist/types/annotate/utils.d.ts +6 -0
- package/dist/types/antlr/CircuitScriptLexer.d.ts +71 -70
- package/dist/types/antlr/CircuitScriptParser.d.ts +357 -515
- package/dist/types/antlr/{CircuitScriptVisitor.d.ts → CircuitScriptParserVisitor.d.ts} +27 -69
- package/dist/types/cache/deserializer.d.ts +5 -0
- package/dist/types/cache/hash.d.ts +1 -0
- package/dist/types/cache/serializer.d.ts +3 -0
- package/dist/types/cache/storage.d.ts +4 -0
- package/dist/types/cache/types.d.ts +20 -0
- package/dist/types/{environment.d.ts → environment/environment.d.ts} +5 -4
- package/dist/types/environment/esm-environment.d.ts +4 -0
- package/dist/types/environment/helpers.d.ts +2 -0
- package/dist/types/execute.d.ts +3 -2
- package/dist/types/globals.d.ts +1 -0
- package/dist/types/helpers.d.ts +31 -36
- package/dist/types/importResolver.d.ts +4 -0
- package/dist/types/index.d.ts +7 -6
- package/dist/types/lexer.d.ts +9 -5
- package/dist/types/objects/ClassComponent.d.ts +1 -1
- package/dist/types/objects/ExecutionScope.d.ts +1 -4
- package/dist/types/objects/types.d.ts +16 -2
- package/dist/types/parser.d.ts +9 -2
- package/dist/types/pipeline.d.ts +9 -0
- package/dist/types/render/KiCadNetListOutputHandler.d.ts +10 -0
- package/dist/types/render/PaperSizes.d.ts +12 -0
- package/dist/types/{draw_symbols.d.ts → render/draw_symbols.d.ts} +4 -4
- package/dist/types/{export.d.ts → render/export.d.ts} +1 -1
- package/dist/types/{geometry.d.ts → render/geometry.d.ts} +2 -2
- package/dist/types/{graph.d.ts → render/graph.d.ts} +6 -6
- package/dist/types/{layout.d.ts → render/layout.d.ts} +10 -10
- package/dist/types/{render.d.ts → render/render.d.ts} +1 -1
- package/dist/types/{SemanticTokenVisitor.d.ts → semantic-tokens/SemanticTokenVisitor.d.ts} +6 -6
- package/dist/types/semantic-tokens/getSemanticTokens.d.ts +6 -0
- package/dist/types/sizing.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -1
- package/dist/types/validate/SymbolValidatorResolveVisitor.d.ts +3 -0
- package/dist/types/validate/SymbolValidatorVisitor.d.ts +8 -8
- package/dist/types/validate/validateScript.d.ts +3 -0
- package/dist/types/visitor.d.ts +8 -14
- package/libs/std.cst +15 -19
- package/package.json +3 -6
- package/dist/cjs/antlr/CircuitScriptVisitor.js +0 -7
package/dist/cjs/visitor.js
CHANGED
|
@@ -8,23 +8,18 @@ const PinTypes_js_1 = require("./objects/PinTypes.js");
|
|
|
8
8
|
const types_js_1 = require("./objects/types.js");
|
|
9
9
|
const globals_js_1 = require("./globals.js");
|
|
10
10
|
const utils_js_1 = require("./utils.js");
|
|
11
|
-
const draw_symbols_js_1 = require("./draw_symbols.js");
|
|
11
|
+
const draw_symbols_js_1 = require("./render/draw_symbols.js");
|
|
12
12
|
const BaseVisitor_js_1 = require("./BaseVisitor.js");
|
|
13
13
|
const utils_js_2 = require("./utils.js");
|
|
14
14
|
const helpers_js_1 = require("./helpers.js");
|
|
15
15
|
const Frame_js_1 = require("./objects/Frame.js");
|
|
16
|
-
const ComponentAnnotater_js_1 = require("./ComponentAnnotater.js");
|
|
16
|
+
const ComponentAnnotater_js_1 = require("./annotate/ComponentAnnotater.js");
|
|
17
17
|
const ComponentMatchConditions_js_1 = require("./ComponentMatchConditions.js");
|
|
18
18
|
class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
19
19
|
constructor(silent = false, onErrorHandler = null, environment) {
|
|
20
20
|
super(silent, onErrorHandler, environment);
|
|
21
21
|
this.componentCreationIndex = 0;
|
|
22
22
|
this.creationCtx = new Map();
|
|
23
|
-
this.visitKeyword_assignment_expr = (ctx) => {
|
|
24
|
-
const id = ctx.ID().getText();
|
|
25
|
-
const value = this.visitResult(ctx.data_expr());
|
|
26
|
-
this.setResult(ctx, [id, value]);
|
|
27
|
-
};
|
|
28
23
|
this.visitPin_select_expr = (ctx) => {
|
|
29
24
|
let pinId = null;
|
|
30
25
|
const ctxData = ctx.data_expr();
|
|
@@ -159,22 +154,19 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
159
154
|
if (ctx.path_block() === null) {
|
|
160
155
|
this.getExecutor().closeOpenPathBlocks();
|
|
161
156
|
}
|
|
162
|
-
|
|
163
|
-
const ctxNotPathBlock = ctx.graph_linear_expression();
|
|
164
|
-
if (ctxPathBlock) {
|
|
165
|
-
this.visit(ctxPathBlock);
|
|
166
|
-
}
|
|
167
|
-
if (ctxNotPathBlock) {
|
|
168
|
-
this.visit(ctxNotPathBlock);
|
|
169
|
-
}
|
|
157
|
+
this.visitChildren(ctx);
|
|
170
158
|
if (ctx.start && ctx.stop) {
|
|
171
159
|
const startToken = ctx.start;
|
|
172
160
|
const stopToken = ctx.stop;
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
161
|
+
if (this.filePathStack.length > 0) {
|
|
162
|
+
const useFilePath = this.getCurrentFile();
|
|
163
|
+
const annotationKey = this.getRefdesFileAnnotationKey(useFilePath, startToken.line, startToken.column, stopToken.line, stopToken.column);
|
|
164
|
+
if (this.refdesFileAnnotations.has(annotationKey)) {
|
|
165
|
+
this.log(`refdes annotation key matched: ${annotationKey}`);
|
|
166
|
+
let refdesValue = this.refdesFileAnnotations.get(annotationKey);
|
|
167
|
+
refdesValue = refdesValue.split(',')[0];
|
|
168
|
+
this.setCurrentComponentRefdes(refdesValue, true);
|
|
169
|
+
}
|
|
178
170
|
}
|
|
179
171
|
}
|
|
180
172
|
};
|
|
@@ -182,12 +174,10 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
182
174
|
const scope = this.getScope();
|
|
183
175
|
scope.setOnPropertyHandler(this.createComponentPropertyValidator());
|
|
184
176
|
scope.enterContext(ctx);
|
|
185
|
-
ctx.
|
|
186
|
-
|
|
187
|
-
});
|
|
177
|
+
const ctxPropertiesBlock = ctx.properties_block();
|
|
178
|
+
const properties = this.visitResult(ctxPropertiesBlock);
|
|
188
179
|
scope.exitContext();
|
|
189
180
|
scope.popOnPropertyHandler();
|
|
190
|
-
const properties = this.getPropertyExprList(ctx.property_expr());
|
|
191
181
|
let instanceName = this.getExecutor().getUniqueInstanceName();
|
|
192
182
|
const propParams = properties.get('params');
|
|
193
183
|
const params = this.parseCreateComponentParams(propParams);
|
|
@@ -288,9 +278,9 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
288
278
|
throw "Invalid command!";
|
|
289
279
|
}
|
|
290
280
|
let parameters = [];
|
|
291
|
-
const
|
|
292
|
-
if (
|
|
293
|
-
const nestedKeyValues = this.visitResult(
|
|
281
|
+
const ctxPropertiesBlock = ctx.properties_block();
|
|
282
|
+
if (ctxPropertiesBlock) {
|
|
283
|
+
const nestedKeyValues = this.visitResult(ctxPropertiesBlock);
|
|
294
284
|
nestedKeyValues.forEach((value, key) => {
|
|
295
285
|
parameters.push(['keyword', key, (0, utils_js_1.unwrapValue)(value)]);
|
|
296
286
|
});
|
|
@@ -385,10 +375,6 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
385
375
|
this.visitProperty_expr = (ctx) => {
|
|
386
376
|
const ctxKey = ctx.property_key_expr();
|
|
387
377
|
const ctxValue = ctx.property_value_expr();
|
|
388
|
-
const extraValue = ctx._extra;
|
|
389
|
-
if (extraValue) {
|
|
390
|
-
console.log('extra', extraValue.text);
|
|
391
|
-
}
|
|
392
378
|
const scope = this.getScope();
|
|
393
379
|
this.getScope().enterContext(ctxKey);
|
|
394
380
|
this.getScope().enterContext(ctxValue);
|
|
@@ -423,18 +409,25 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
423
409
|
this.getScope().exitContext();
|
|
424
410
|
this.setResult(ctx, value);
|
|
425
411
|
};
|
|
426
|
-
this.
|
|
412
|
+
this.visitProperties_block = (ctx) => {
|
|
427
413
|
const result = new Map();
|
|
428
|
-
|
|
414
|
+
const keyCounter = new Map();
|
|
415
|
+
ctx.property_expr().forEach(item => {
|
|
429
416
|
const property = this.visitResult(item);
|
|
430
417
|
for (const [key, value] of property) {
|
|
431
|
-
|
|
418
|
+
let useKey = key;
|
|
419
|
+
const counterValue = keyCounter.get(key) ?? 0;
|
|
420
|
+
keyCounter.set(key, counterValue + 1);
|
|
421
|
+
if (counterValue > 0) {
|
|
422
|
+
useKey = key + ':' + counterValue;
|
|
423
|
+
}
|
|
424
|
+
result.set(useKey, value);
|
|
432
425
|
}
|
|
433
426
|
});
|
|
434
427
|
this.setResult(ctx, result);
|
|
435
428
|
};
|
|
436
429
|
this.visitNested_properties = (ctx) => {
|
|
437
|
-
this.
|
|
430
|
+
this.passResult(ctx, ctx.children[0]);
|
|
438
431
|
};
|
|
439
432
|
this.visitProperty_key_expr = (ctx) => {
|
|
440
433
|
const ctxID = ctx.ID();
|
|
@@ -458,22 +451,25 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
458
451
|
const ctxDataExpr = ctx.data_expr();
|
|
459
452
|
const ctxAssignmentExpr = ctx.assignment_expr();
|
|
460
453
|
if (ctxDataExpr) {
|
|
461
|
-
dataResult = this.visitResult(ctxDataExpr);
|
|
462
454
|
componentCtx = ctxDataExpr;
|
|
455
|
+
this.setResult(ctxDataExpr, { keepReference: true });
|
|
456
|
+
const reference = this.visitResult(ctxDataExpr);
|
|
457
|
+
if (reference.found) {
|
|
458
|
+
dataResult = (0, utils_js_1.unwrapValue)(reference);
|
|
459
|
+
}
|
|
460
|
+
else {
|
|
461
|
+
const { trailers = [], rootValue = null } = reference;
|
|
462
|
+
if (rootValue instanceof ClassComponent_js_1.ClassComponent && trailers.length > 0
|
|
463
|
+
&& trailers[0] === globals_js_1.ModuleContainsKeyword) {
|
|
464
|
+
dataResult = rootValue;
|
|
465
|
+
this.placeModuleContains(dataResult);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
463
468
|
}
|
|
464
469
|
else if (ctxAssignmentExpr) {
|
|
465
470
|
dataResult = this.visitResult(ctxAssignmentExpr);
|
|
466
471
|
componentCtx = ctxAssignmentExpr;
|
|
467
472
|
}
|
|
468
|
-
if (dataResult instanceof types_js_1.AnyReference) {
|
|
469
|
-
const { trailers = [], rootValue = null } = dataResult;
|
|
470
|
-
if (rootValue instanceof ClassComponent_js_1.ClassComponent
|
|
471
|
-
&& trailers.length > 0
|
|
472
|
-
&& trailers[0] === globals_js_1.ModuleContainsKeyword) {
|
|
473
|
-
dataResult = rootValue;
|
|
474
|
-
this.placeModuleContains(dataResult);
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
473
|
dataResult = (0, utils_js_1.unwrapValue)(dataResult);
|
|
478
474
|
if (dataResult === null || dataResult === undefined) {
|
|
479
475
|
this.throwWithContext(componentCtx, "Could not find component: " + componentCtx.getText());
|
|
@@ -487,18 +483,12 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
487
483
|
const modifiers = ctx.component_modifier_expr();
|
|
488
484
|
modifiers.forEach(modifier => {
|
|
489
485
|
const modifierText = modifier.ID(0).getText();
|
|
490
|
-
const
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
if (ctxValueExpr) {
|
|
494
|
-
result = this.visitResult(ctxValueExpr);
|
|
495
|
-
}
|
|
496
|
-
else if (ctxID2) {
|
|
497
|
-
result = ctxID2.getText();
|
|
498
|
-
}
|
|
486
|
+
const ctxDataExpr = modifier.data_expr();
|
|
487
|
+
this.setResult(ctxDataExpr, { keepReference: true });
|
|
488
|
+
const result = this.visitResult(ctxDataExpr);
|
|
499
489
|
let shouldIgnoreWireOrientation = false;
|
|
500
490
|
if (modifierText === globals_js_1.ParamKeys.flip) {
|
|
501
|
-
const flipValue = result;
|
|
491
|
+
const flipValue = result.name;
|
|
502
492
|
if (flipValue.indexOf('x') !== -1) {
|
|
503
493
|
defaultUnit.setParam(globals_js_1.ParamKeys.flipX, (0, ParamDefinition_js_1.numeric)(1));
|
|
504
494
|
shouldIgnoreWireOrientation = true;
|
|
@@ -513,7 +503,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
513
503
|
shouldIgnoreWireOrientation = true;
|
|
514
504
|
}
|
|
515
505
|
else if (modifierText === 'anchor') {
|
|
516
|
-
dataResult.setParam('anchor', result);
|
|
506
|
+
dataResult.setParam('anchor', result.name);
|
|
517
507
|
}
|
|
518
508
|
if (shouldIgnoreWireOrientation) {
|
|
519
509
|
defaultUnit.useWireOrientationAngle = false;
|
|
@@ -538,31 +528,28 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
538
528
|
};
|
|
539
529
|
this.visitUnaryOperatorExpr = (ctx) => {
|
|
540
530
|
let value = this.visitResult(ctx.data_expr());
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
if (typeof value === "boolean") {
|
|
545
|
-
value = !value;
|
|
546
|
-
}
|
|
547
|
-
else if (value instanceof ParamDefinition_js_1.NumericValue) {
|
|
548
|
-
value = (value.toNumber() === 0) ? true : false;
|
|
549
|
-
}
|
|
550
|
-
else {
|
|
551
|
-
throw "Failed to do Not operator";
|
|
552
|
-
}
|
|
531
|
+
if (ctx.Not()) {
|
|
532
|
+
if (typeof value === "boolean") {
|
|
533
|
+
value = !value;
|
|
553
534
|
}
|
|
554
|
-
else if (
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
535
|
+
else if (value instanceof ParamDefinition_js_1.NumericValue) {
|
|
536
|
+
value = (value.toNumber() === 0) ? true : false;
|
|
537
|
+
}
|
|
538
|
+
else {
|
|
539
|
+
throw "Failed to do Not operator";
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
else if (ctx.Minus()) {
|
|
543
|
+
if (value instanceof ParamDefinition_js_1.NumericValue) {
|
|
544
|
+
value = value.neg();
|
|
545
|
+
}
|
|
546
|
+
else {
|
|
547
|
+
throw "Failed to do Negation operator";
|
|
561
548
|
}
|
|
562
549
|
}
|
|
563
550
|
this.setResult(ctx, value);
|
|
564
551
|
};
|
|
565
|
-
this.
|
|
552
|
+
this.visitCreate_expr = (ctx) => {
|
|
566
553
|
let value;
|
|
567
554
|
const ctxCreateComponentExpr = ctx.create_component_expr();
|
|
568
555
|
const ctxCreateGraphicExpr = ctx.create_graphic_expr();
|
|
@@ -581,6 +568,10 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
581
568
|
}
|
|
582
569
|
this.setResult(ctx, value);
|
|
583
570
|
};
|
|
571
|
+
this.visitCreateExpr = (ctx) => {
|
|
572
|
+
const result = this.visitResult(ctx.create_expr());
|
|
573
|
+
this.setResult(ctx, result);
|
|
574
|
+
};
|
|
584
575
|
this.visitBinaryOperatorExpr = (ctx) => {
|
|
585
576
|
const ctx0 = ctx.data_expr(0);
|
|
586
577
|
const ctx1 = ctx.data_expr(1);
|
|
@@ -592,24 +583,23 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
592
583
|
if (value2 instanceof ParamDefinition_js_1.NumericValue) {
|
|
593
584
|
value2 = value2.toNumber();
|
|
594
585
|
}
|
|
595
|
-
const binaryOperatorType = ctx.binary_operator();
|
|
596
586
|
let result = null;
|
|
597
|
-
if (
|
|
587
|
+
if (ctx.Equals()) {
|
|
598
588
|
result = value1 == value2;
|
|
599
589
|
}
|
|
600
|
-
else if (
|
|
590
|
+
else if (ctx.NotEquals()) {
|
|
601
591
|
result = value1 != value2;
|
|
602
592
|
}
|
|
603
|
-
else if (
|
|
593
|
+
else if (ctx.GreaterThan()) {
|
|
604
594
|
result = value1 > value2;
|
|
605
595
|
}
|
|
606
|
-
else if (
|
|
596
|
+
else if (ctx.GreatOrEqualThan()) {
|
|
607
597
|
result = value1 >= value2;
|
|
608
598
|
}
|
|
609
|
-
else if (
|
|
599
|
+
else if (ctx.LessThan()) {
|
|
610
600
|
result = value1 < value2;
|
|
611
601
|
}
|
|
612
|
-
else if (
|
|
602
|
+
else if (ctx.LessOrEqualThan()) {
|
|
613
603
|
result = value1 <= value2;
|
|
614
604
|
}
|
|
615
605
|
this.setResult(ctx, result);
|
|
@@ -703,8 +693,8 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
703
693
|
}
|
|
704
694
|
const executionStack = this.executionStack;
|
|
705
695
|
const functionCounter = { counter: 0 };
|
|
706
|
-
const resolveNet = this.createNetResolver(
|
|
707
|
-
const resolveComponentPinNet = this.createComponentPinNetResolver(
|
|
696
|
+
const resolveNet = this.createNetResolver(executionStack);
|
|
697
|
+
const resolveComponentPinNet = this.createComponentPinNetResolver(executionStack);
|
|
708
698
|
const __runFunc = (passedInParameters, options) => {
|
|
709
699
|
const executor = this.getExecutor();
|
|
710
700
|
const functionCounterIndex = functionCounter['counter'];
|
|
@@ -719,41 +709,23 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
719
709
|
};
|
|
720
710
|
this.getExecutor().createFunction(this.getExecutor().namespace, functionName, __runFunc, ctx, uniqueFunctionID);
|
|
721
711
|
};
|
|
722
|
-
this.visitPin_select_expr2 = (ctx) => {
|
|
723
|
-
const ctxStringValue = ctx.STRING_VALUE();
|
|
724
|
-
const ctxIntegerValue = ctx.INTEGER_VALUE();
|
|
725
|
-
let pinIdValue;
|
|
726
|
-
let pinId = null;
|
|
727
|
-
if (ctxStringValue) {
|
|
728
|
-
pinIdValue = this.prepareStringValue(ctxStringValue.getText());
|
|
729
|
-
}
|
|
730
|
-
else if (ctxIntegerValue) {
|
|
731
|
-
pinIdValue = Number(ctxIntegerValue.getText());
|
|
732
|
-
}
|
|
733
|
-
if (pinIdValue !== undefined) {
|
|
734
|
-
pinId = new PinDefinition_js_1.PinId(pinIdValue);
|
|
735
|
-
}
|
|
736
|
-
else {
|
|
737
|
-
throw new utils_js_2.RuntimeExecutionError("Invalid select pin", ctx);
|
|
738
|
-
}
|
|
739
|
-
this.setResult(ctx, pinId);
|
|
740
|
-
};
|
|
741
712
|
this.visitAt_block_pin_expr = (ctx) => {
|
|
742
713
|
const executor = this.getExecutor();
|
|
743
714
|
const [currentComponent, currentPin] = executor.getCurrentPoint();
|
|
744
715
|
executor.closeOpenPathBlocks();
|
|
745
|
-
const
|
|
716
|
+
const propKey = this.visitResult(ctx.property_key_expr());
|
|
717
|
+
const atPin = new PinDefinition_js_1.PinId(propKey);
|
|
746
718
|
executor.atComponent(currentComponent, atPin, {
|
|
747
719
|
addSequence: true
|
|
748
720
|
});
|
|
749
721
|
executor.log('at block pin expressions');
|
|
750
|
-
const
|
|
751
|
-
const
|
|
752
|
-
if (
|
|
753
|
-
this.visit(
|
|
722
|
+
const ctxExpression = ctx.expression();
|
|
723
|
+
const ctxExpressionsBlock = ctx.expressions_block();
|
|
724
|
+
if (ctxExpression) {
|
|
725
|
+
this.visit(ctxExpression);
|
|
754
726
|
}
|
|
755
|
-
else if (
|
|
756
|
-
this.visit(
|
|
727
|
+
else if (ctxExpressionsBlock) {
|
|
728
|
+
this.visit(ctxExpressionsBlock);
|
|
757
729
|
}
|
|
758
730
|
executor.log('end at block pin expressions');
|
|
759
731
|
executor.atComponent(currentComponent, currentPin);
|
|
@@ -782,63 +754,33 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
782
754
|
executor.scope.setCurrent(currentComponent, currentPin);
|
|
783
755
|
executor.log('leaving at block');
|
|
784
756
|
};
|
|
785
|
-
this.
|
|
786
|
-
const
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
}
|
|
793
|
-
};
|
|
794
|
-
this.visitAt_block_pin_expression_complex = (ctx) => {
|
|
795
|
-
this.visit(ctx.expressions_block());
|
|
796
|
-
};
|
|
797
|
-
this.visitWire_expr_direction_only = (ctx) => {
|
|
798
|
-
const value = ctx.ID().getText();
|
|
799
|
-
if (value === globals_js_1.WireAutoDirection.Auto || value === globals_js_1.WireAutoDirection.Auto_) {
|
|
800
|
-
this.setResult(ctx, [value]);
|
|
801
|
-
}
|
|
802
|
-
else {
|
|
803
|
-
throw 'Invalid direction for wire';
|
|
804
|
-
}
|
|
805
|
-
};
|
|
806
|
-
this.visitWire_expr_direction_value = (ctx) => {
|
|
807
|
-
const direction = ctx.ID().getText();
|
|
808
|
-
if (this.acceptedDirections.indexOf(direction) !== -1) {
|
|
809
|
-
let useValue = null;
|
|
810
|
-
const ctxIntegerValue = ctx.INTEGER_VALUE();
|
|
811
|
-
const ctxDataExpr = ctx.data_expr();
|
|
812
|
-
if (ctxIntegerValue) {
|
|
813
|
-
useValue = Number(ctxIntegerValue);
|
|
757
|
+
this.visitWire_expr = (ctx) => {
|
|
758
|
+
const segments = [];
|
|
759
|
+
ctx.ID().forEach((ctxId, index) => {
|
|
760
|
+
const value = ctxId.getText();
|
|
761
|
+
const ctxDataExpr = ctx.data_expr(index);
|
|
762
|
+
if ((value === globals_js_1.WireAutoDirection.Auto || value === globals_js_1.WireAutoDirection.Auto_) && ctxDataExpr === null) {
|
|
763
|
+
segments.push([value]);
|
|
814
764
|
}
|
|
815
|
-
else if (ctxDataExpr) {
|
|
765
|
+
else if (this.acceptedDirections.indexOf(value) !== -1 && ctxDataExpr) {
|
|
766
|
+
let useValue = null;
|
|
816
767
|
useValue = this.visitResult(ctxDataExpr);
|
|
817
768
|
if (useValue instanceof ParamDefinition_js_1.NumericValue) {
|
|
818
769
|
useValue = useValue.toNumber();
|
|
819
770
|
}
|
|
771
|
+
segments.push([value, new helpers_js_1.UnitDimension(useValue)]);
|
|
820
772
|
}
|
|
821
|
-
if (useValue !== null) {
|
|
822
|
-
this.setResult(ctx, [direction, new helpers_js_1.UnitDimension(useValue)]);
|
|
823
|
-
return;
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
throw "Invalid direction or value for wire";
|
|
827
|
-
};
|
|
828
|
-
this.visitWire_expr = (ctx) => {
|
|
829
|
-
const wireAtomExpr = ctx.wire_atom_expr();
|
|
830
|
-
const segments = wireAtomExpr.map(wireSegment => {
|
|
831
|
-
return this.visitResult(wireSegment);
|
|
832
773
|
});
|
|
833
774
|
const newWire = this.getExecutor().addWire(segments);
|
|
834
775
|
this.creationCtx.set(newWire, ctx);
|
|
835
776
|
};
|
|
836
777
|
this.visitPoint_expr = (ctx) => {
|
|
837
|
-
const
|
|
838
|
-
|
|
778
|
+
const ctxDataExpr = ctx.data_expr();
|
|
779
|
+
this.setResult(ctxDataExpr, { keepReference: true });
|
|
780
|
+
const result = this.visitResult(ctxDataExpr);
|
|
839
781
|
let pointValue;
|
|
840
|
-
if (
|
|
841
|
-
const resultValue =
|
|
782
|
+
if (result.found) {
|
|
783
|
+
const resultValue = (0, utils_js_1.unwrapValue)(result);
|
|
842
784
|
if (typeof resultValue === 'string') {
|
|
843
785
|
pointValue = resultValue;
|
|
844
786
|
}
|
|
@@ -846,16 +788,11 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
846
788
|
throw new utils_js_2.RuntimeExecutionError('Invalid value for point');
|
|
847
789
|
}
|
|
848
790
|
}
|
|
849
|
-
else
|
|
850
|
-
pointValue =
|
|
791
|
+
else {
|
|
792
|
+
pointValue = result.name;
|
|
851
793
|
}
|
|
852
794
|
return this.getExecutor().addPoint(pointValue);
|
|
853
795
|
};
|
|
854
|
-
this.visitProperty_set_expr = (ctx) => {
|
|
855
|
-
const result = this.visitResult(ctx.data_expr());
|
|
856
|
-
const resolvedProperty = this.visitResult(ctx.atom_expr());
|
|
857
|
-
this.getExecutor().setProperty(resolvedProperty, result);
|
|
858
|
-
};
|
|
859
796
|
this.visitDouble_dot_property_set_expr = (ctx) => {
|
|
860
797
|
const result = this.visitResult(ctx.data_expr());
|
|
861
798
|
const propertyName = ctx.ID().getText();
|
|
@@ -874,14 +811,15 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
874
811
|
this.getExecutor().exitFrame(frameId);
|
|
875
812
|
};
|
|
876
813
|
this.visitNet_namespace_expr = (ctx) => {
|
|
877
|
-
let dataValue
|
|
814
|
+
let dataValue;
|
|
878
815
|
let netNamespace = null;
|
|
879
816
|
const hasPlus = ctx.Addition();
|
|
880
817
|
const ctxDataExpr = ctx.data_expr();
|
|
881
818
|
if (ctxDataExpr) {
|
|
819
|
+
this.setResult(ctxDataExpr, { keepReference: true });
|
|
882
820
|
dataValue = this.visitResult(ctxDataExpr);
|
|
883
|
-
if (dataValue
|
|
884
|
-
netNamespace = "/" + dataValue.
|
|
821
|
+
if (!dataValue.found) {
|
|
822
|
+
netNamespace = "/" + dataValue.name;
|
|
885
823
|
}
|
|
886
824
|
else if (typeof dataValue === "string") {
|
|
887
825
|
netNamespace = "/" + dataValue;
|
|
@@ -1008,7 +946,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1008
946
|
executor.popBreakContext();
|
|
1009
947
|
};
|
|
1010
948
|
this.visitAnnotation_comment_expr = (ctx) => {
|
|
1011
|
-
const refdesID = ctx.
|
|
949
|
+
const refdesID = ctx.getText().replace('#=', '').trim();
|
|
1012
950
|
this.setCurrentComponentRefdes(refdesID);
|
|
1013
951
|
};
|
|
1014
952
|
this.visitPart_set_expr = (ctx) => {
|
|
@@ -1022,26 +960,21 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1022
960
|
(0, ComponentMatchConditions_js_1.applyPartConditions)(instances, paramKeys, partConditions);
|
|
1023
961
|
};
|
|
1024
962
|
this.visitPart_match_block = (ctx) => {
|
|
1025
|
-
const results = ctx.part_sub_expr().
|
|
1026
|
-
|
|
1027
|
-
|
|
963
|
+
const results = ctx.part_sub_expr().reduce((accum, ctxExpr) => {
|
|
964
|
+
const result = this.visitResult(ctxExpr);
|
|
965
|
+
if (result !== undefined) {
|
|
966
|
+
accum.push(result);
|
|
967
|
+
}
|
|
968
|
+
return accum;
|
|
969
|
+
}, []);
|
|
1028
970
|
this.setResult(ctx, results);
|
|
1029
971
|
};
|
|
1030
972
|
this.visitPart_sub_expr = (ctx) => {
|
|
1031
|
-
|
|
1032
|
-
const
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
if (ctxForm1) {
|
|
1036
|
-
result = this.visitResult(ctxForm1);
|
|
1037
|
-
}
|
|
1038
|
-
else if (ctxForm2) {
|
|
1039
|
-
result = this.visitResult(ctxForm2);
|
|
1040
|
-
}
|
|
1041
|
-
else if (ctxForm3) {
|
|
1042
|
-
result = this.visitResult(ctxForm3);
|
|
973
|
+
this.visitChildren(ctx);
|
|
974
|
+
const result = this.getResult(ctx.children[0]);
|
|
975
|
+
if (result !== undefined) {
|
|
976
|
+
this.setResult(ctx, result);
|
|
1043
977
|
}
|
|
1044
|
-
this.setResult(ctx, result);
|
|
1045
978
|
};
|
|
1046
979
|
this.visitPart_set_key = (ctx) => {
|
|
1047
980
|
const ctxID = ctx.ID();
|
|
@@ -1073,10 +1006,17 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1073
1006
|
};
|
|
1074
1007
|
this.visitPart_value_expr = (ctx) => {
|
|
1075
1008
|
const key = this.visitResult(ctx.part_set_key());
|
|
1076
|
-
const
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1009
|
+
const ctxPartMatchBlock = ctx.part_match_block();
|
|
1010
|
+
if (ctxPartMatchBlock) {
|
|
1011
|
+
const children = this.visitResult(ctxPartMatchBlock);
|
|
1012
|
+
this.setResult(ctx, { key, children });
|
|
1013
|
+
}
|
|
1014
|
+
else {
|
|
1015
|
+
const values = ctx.data_expr().map(ctxData => {
|
|
1016
|
+
return this.visitResult(ctxData);
|
|
1017
|
+
});
|
|
1018
|
+
this.setResult(ctx, { key, endValue: values });
|
|
1019
|
+
}
|
|
1080
1020
|
};
|
|
1081
1021
|
this.visitPart_condition_expr = (ctx) => {
|
|
1082
1022
|
const allKeys = ctx._key_id.map(ctx => {
|
|
@@ -1116,14 +1056,6 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1116
1056
|
});
|
|
1117
1057
|
this.setResult(ctx, tmpKeyValues);
|
|
1118
1058
|
};
|
|
1119
|
-
this.visitPart_condition_key_only_expr = (ctx) => {
|
|
1120
|
-
const key = this.visitResult(ctx.part_set_key());
|
|
1121
|
-
const children = this.visitResult(ctx.part_match_block());
|
|
1122
|
-
this.setResult(ctx, {
|
|
1123
|
-
key,
|
|
1124
|
-
children,
|
|
1125
|
-
});
|
|
1126
|
-
};
|
|
1127
1059
|
this.pinTypes = [
|
|
1128
1060
|
PinTypes_js_1.PinTypes.Any,
|
|
1129
1061
|
PinTypes_js_1.PinTypes.IO,
|
|
@@ -1385,25 +1317,39 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1385
1317
|
currentComponent.forceSaveRefdesAnnotation = forceSave;
|
|
1386
1318
|
}
|
|
1387
1319
|
}
|
|
1388
|
-
|
|
1389
|
-
const
|
|
1390
|
-
const
|
|
1391
|
-
const
|
|
1392
|
-
|
|
1393
|
-
|
|
1320
|
+
getPathRefdesFile(filePath) {
|
|
1321
|
+
const mainDir = this.environment.dirname(filePath);
|
|
1322
|
+
const mainExt = this.environment.extname(filePath);
|
|
1323
|
+
const mainBasename = this.environment.basename(filePath, mainExt);
|
|
1324
|
+
return this.environment.join(mainDir, `${mainBasename}${globals_js_1.RefdesFileSuffix}`);
|
|
1325
|
+
}
|
|
1326
|
+
checkLibraryInRefdesFile(filePath) {
|
|
1327
|
+
if (this.filePathStack.length === 0) {
|
|
1328
|
+
return;
|
|
1329
|
+
}
|
|
1330
|
+
const [baseFile] = this.filePathStack;
|
|
1331
|
+
const mainDir = this.environment.dirname(baseFile);
|
|
1332
|
+
const refdesFilePath = this.getPathRefdesFile(baseFile);
|
|
1333
|
+
const exists = this.loadedFiles.has(refdesFilePath);
|
|
1394
1334
|
if (exists) {
|
|
1395
|
-
this.log(`
|
|
1396
|
-
const fileData =
|
|
1335
|
+
this.log(`Main schematic has refdes file: ${refdesFilePath}`);
|
|
1336
|
+
const fileData = this.loadedFiles.get(refdesFilePath);
|
|
1397
1337
|
const jsonData = JSON.parse(fileData);
|
|
1398
|
-
const
|
|
1399
|
-
const
|
|
1400
|
-
const
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1338
|
+
const relativeLibraryPath = this.environment.relative(mainDir, filePath);
|
|
1339
|
+
const { libraries = [] } = jsonData;
|
|
1340
|
+
for (const library of libraries) {
|
|
1341
|
+
const { path: libraryPath, items } = library;
|
|
1342
|
+
if (libraryPath === relativeLibraryPath) {
|
|
1343
|
+
this.log(`Found refdes annotations for library at: ${libraryPath}`);
|
|
1344
|
+
const useFilePath = this.environment.join(mainDir, libraryPath);
|
|
1345
|
+
for (const refdes in items) {
|
|
1346
|
+
const val = items[refdes];
|
|
1347
|
+
const parts = val.split(':');
|
|
1348
|
+
const key = this.getRefdesFileAnnotationKey(useFilePath, Number(parts[0]), Number(parts[1]), Number(parts[2]), Number(parts[3]));
|
|
1349
|
+
this.refdesFileAnnotations.set(key, refdes);
|
|
1350
|
+
}
|
|
1351
|
+
break;
|
|
1352
|
+
}
|
|
1407
1353
|
}
|
|
1408
1354
|
}
|
|
1409
1355
|
}
|