circuitscript 0.1.31 → 0.1.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/BaseVisitor.js +37 -3
- package/dist/cjs/RefdesAnnotationVisitor.js +27 -10
- package/dist/cjs/antlr/CircuitScriptParser.js +990 -831
- package/dist/cjs/draw_symbols.js +38 -34
- package/dist/cjs/environment.js +24 -4
- package/dist/cjs/execute.js +107 -68
- package/dist/cjs/globals.js +4 -2
- package/dist/cjs/graph.js +14 -12
- package/dist/cjs/helpers.js +85 -16
- package/dist/cjs/layout.js +50 -25
- package/dist/cjs/main.js +16 -18
- package/dist/cjs/objects/ClassComponent.js +199 -30
- package/dist/cjs/objects/types.js +5 -1
- package/dist/cjs/regenerate-tests.js +3 -3
- package/dist/cjs/render.js +5 -3
- package/dist/cjs/rules-check/no-connect-on-connected-pin.js +9 -8
- package/dist/cjs/rules-check/rules.js +7 -2
- package/dist/cjs/rules-check/unconnected-pins.js +10 -8
- package/dist/cjs/utils.js +2 -1
- package/dist/cjs/validate/SymbolValidatorVisitor.js +0 -10
- package/dist/cjs/visitor.js +284 -191
- package/dist/esm/BaseVisitor.js +37 -3
- package/dist/esm/RefdesAnnotationVisitor.js +27 -10
- package/dist/esm/antlr/CircuitScriptParser.js +989 -830
- package/dist/esm/antlr/CircuitScriptVisitor.js +1 -0
- package/dist/esm/draw_symbols.js +38 -34
- package/dist/esm/environment.js +21 -1
- package/dist/esm/execute.js +108 -69
- package/dist/esm/globals.js +2 -0
- package/dist/esm/graph.js +14 -12
- package/dist/esm/helpers.js +86 -17
- package/dist/esm/layout.js +51 -26
- package/dist/esm/main.js +16 -18
- package/dist/esm/objects/ClassComponent.js +201 -30
- package/dist/esm/objects/types.js +7 -1
- package/dist/esm/regenerate-tests.js +3 -3
- package/dist/esm/render.js +5 -3
- package/dist/esm/rules-check/no-connect-on-connected-pin.js +9 -8
- package/dist/esm/rules-check/rules.js +7 -2
- package/dist/esm/rules-check/unconnected-pins.js +10 -8
- package/dist/esm/utils.js +2 -1
- package/dist/esm/validate/SymbolValidatorVisitor.js +0 -10
- package/dist/esm/visitor.js +185 -92
- package/dist/types/BaseVisitor.d.ts +15 -5
- package/dist/types/RefdesAnnotationVisitor.d.ts +2 -0
- package/dist/types/antlr/CircuitScriptParser.d.ts +32 -14
- package/dist/types/antlr/CircuitScriptVisitor.d.ts +2 -0
- package/dist/types/environment.d.ts +7 -1
- package/dist/types/execute.d.ts +4 -1
- package/dist/types/globals.d.ts +2 -0
- package/dist/types/graph.d.ts +2 -2
- package/dist/types/helpers.d.ts +2 -1
- package/dist/types/layout.d.ts +5 -4
- package/dist/types/objects/ClassComponent.d.ts +34 -9
- package/dist/types/objects/types.d.ts +19 -3
- package/dist/types/validate/SymbolValidatorVisitor.d.ts +0 -4
- package/dist/types/visitor.d.ts +7 -1
- package/package.json +1 -1
package/dist/esm/BaseVisitor.js
CHANGED
|
@@ -16,6 +16,7 @@ import { PinId } from './objects/PinDefinition.js';
|
|
|
16
16
|
export class BaseVisitor extends CircuitScriptVisitor {
|
|
17
17
|
startingContext;
|
|
18
18
|
executionStack;
|
|
19
|
+
filePathStack = [];
|
|
19
20
|
silent = false;
|
|
20
21
|
logger;
|
|
21
22
|
printStream = [];
|
|
@@ -39,6 +40,7 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
39
40
|
onImportFile = async (visitor, filePath, fileData, onErrorHandler) => {
|
|
40
41
|
throw "Import file not implemented";
|
|
41
42
|
};
|
|
43
|
+
refdesFileAnnotations = new Map();
|
|
42
44
|
constructor(silent = false, onErrorHandler = null, environment) {
|
|
43
45
|
super();
|
|
44
46
|
this.silent = silent;
|
|
@@ -144,7 +146,18 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
144
146
|
specificImports.push(...tmpSpecificImports);
|
|
145
147
|
}
|
|
146
148
|
const id = ctx._moduleName.text;
|
|
147
|
-
await this.handleImportFile(id, handling, true, ctx, specificImports);
|
|
149
|
+
const importedFile = await this.handleImportFile(id, handling, true, ctx, specificImports);
|
|
150
|
+
const ctxImportAnnotation = ctx.import_annotation_expr();
|
|
151
|
+
if (ctxImportAnnotation) {
|
|
152
|
+
const textValue = ctxImportAnnotation.getText().replace('#=', '');
|
|
153
|
+
const { importedModule } = importedFile;
|
|
154
|
+
if (textValue === 'annotate') {
|
|
155
|
+
importedModule.enableRefdesAnnotation = true;
|
|
156
|
+
}
|
|
157
|
+
else if (textValue === 'annotate-external') {
|
|
158
|
+
importedModule.enableRefdesAnnotationFile = true;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
148
161
|
}
|
|
149
162
|
visitImport_simple = async (ctx) => {
|
|
150
163
|
await this.importCommon(ctx, ImportFunctionHandling.AllWithNamespace);
|
|
@@ -410,6 +423,7 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
410
423
|
this.log('create new module context');
|
|
411
424
|
const importedModule = currentReference.rootValue;
|
|
412
425
|
const importedModuleContext = importedModule.context;
|
|
426
|
+
this.enterFile(importedModule.moduleFilePath);
|
|
413
427
|
const newExecutor = this.handleEnterContext(this.getExecutor(), this.executionStack, importedModuleContext.name, ctx, {
|
|
414
428
|
netNamespace: executor.netNamespace,
|
|
415
429
|
namespace: importedModule.moduleNamespace
|
|
@@ -421,6 +435,7 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
421
435
|
if (isModuleFunction) {
|
|
422
436
|
this.log('pop module context scope');
|
|
423
437
|
this.handlePopContext(this.getExecutor(), this.executionStack, "", false);
|
|
438
|
+
this.exitFile();
|
|
424
439
|
}
|
|
425
440
|
if (isReference(functionResult)) {
|
|
426
441
|
currentReference = functionResult;
|
|
@@ -679,7 +694,8 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
679
694
|
instance.ctxReferences.push({
|
|
680
695
|
ctx,
|
|
681
696
|
indexedStack,
|
|
682
|
-
creationFlag
|
|
697
|
+
creationFlag,
|
|
698
|
+
filePath: this.getCurrentFile(),
|
|
683
699
|
});
|
|
684
700
|
this.componentCtxLinks.set(ctx, instance);
|
|
685
701
|
}
|
|
@@ -767,7 +783,7 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
767
783
|
hasParseError = importResult.hasParseError;
|
|
768
784
|
const importContext = executionStack.pop();
|
|
769
785
|
this.log(`import handling flag: ${importHandling}`);
|
|
770
|
-
importedModule = new ImportedModule(name, moduleNamespace, filePathUsed, importContext, importHandling, specificImports);
|
|
786
|
+
importedModule = new ImportedModule(name, moduleNamespace, filePathUsed, importResult.tree, importResult.tokens, importContext, importHandling, specificImports);
|
|
771
787
|
if (specificImports.length > 0) {
|
|
772
788
|
this.log('specific import: ' + specificImports.join(', '));
|
|
773
789
|
}
|
|
@@ -776,6 +792,7 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
776
792
|
importedModule.context.scope.modules.forEach((module, key) => {
|
|
777
793
|
scope.modules.set(key, module);
|
|
778
794
|
});
|
|
795
|
+
await this.checkModuleHasRefdesFile(filePathUsed);
|
|
779
796
|
}
|
|
780
797
|
}
|
|
781
798
|
catch (err) {
|
|
@@ -808,6 +825,12 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
808
825
|
this.importedFiles.push(newImportedFile);
|
|
809
826
|
return newImportedFile;
|
|
810
827
|
}
|
|
828
|
+
async checkModuleHasRefdesFile(filePath) {
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
getRefdesFileAnnotation(filePath, startLine, startColumn, stopLine, stopColumn) {
|
|
832
|
+
return `${filePath}:${startLine}:${startColumn}:${stopLine}:${stopColumn}`;
|
|
833
|
+
}
|
|
811
834
|
visitRoundedBracketsExpr = (ctx) => {
|
|
812
835
|
const ctxDataExpr = ctx.data_expr();
|
|
813
836
|
this.visit(ctxDataExpr);
|
|
@@ -941,4 +964,15 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
941
964
|
return (val instanceof NumericValue);
|
|
942
965
|
}, 'numeric value');
|
|
943
966
|
}
|
|
967
|
+
enterFile(filePath) {
|
|
968
|
+
this.log(`enter file: ${filePath}`);
|
|
969
|
+
this.filePathStack.push(filePath);
|
|
970
|
+
}
|
|
971
|
+
exitFile() {
|
|
972
|
+
this.log(`exit file: ${this.getCurrentFile()}`);
|
|
973
|
+
this.filePathStack.pop();
|
|
974
|
+
}
|
|
975
|
+
getCurrentFile() {
|
|
976
|
+
return this.filePathStack[this.filePathStack.length - 1];
|
|
977
|
+
}
|
|
944
978
|
}
|
|
@@ -22,8 +22,7 @@ export class RefdesAnnotationVisitor extends BaseVisitor {
|
|
|
22
22
|
return this.sourceText.substring(startIndex, stopIndex + 1);
|
|
23
23
|
}
|
|
24
24
|
visitScript = async (ctx) => {
|
|
25
|
-
|
|
26
|
-
this.setResult(ctx, result);
|
|
25
|
+
this.runExpressions(this.getExecutor(), ctx.expression());
|
|
27
26
|
this.getExecutor().closeOpenPathBlocks();
|
|
28
27
|
this.resultText = this.generateModifiedText();
|
|
29
28
|
};
|
|
@@ -55,8 +54,10 @@ export class RefdesAnnotationVisitor extends BaseVisitor {
|
|
|
55
54
|
});
|
|
56
55
|
if (allRefdes.length > 0) {
|
|
57
56
|
const originalText = this.getOriginalText(ctx);
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
this.modifications.set(ctx, {
|
|
58
|
+
originalText,
|
|
59
|
+
refdes: allRefdes,
|
|
60
|
+
});
|
|
60
61
|
}
|
|
61
62
|
};
|
|
62
63
|
visitFunction_def_expr = (ctx) => {
|
|
@@ -77,10 +78,10 @@ export class RefdesAnnotationVisitor extends BaseVisitor {
|
|
|
77
78
|
const instance = this.componentCtxLinks.get(ctx);
|
|
78
79
|
const alreadyHaveRefdesAnnotation = instance.assignedRefDes !== null ?
|
|
79
80
|
(this.addedRefdesAnnotations.indexOf(instance.assignedRefDes) !== -1) : false;
|
|
80
|
-
|
|
81
|
+
const { forceSaveRefdesAnnotation: forceSaveRefdes } = instance;
|
|
82
|
+
if (!alreadyHaveRefdesAnnotation && (forceSaveRefdes || (!instance.hasParam('refdes')
|
|
81
83
|
&& instance.placeHolderRefDes === null
|
|
82
|
-
&& instance.assignedRefDes
|
|
83
|
-
&& !alreadyHaveRefdesAnnotation) {
|
|
84
|
+
&& instance.assignedRefDes))) {
|
|
84
85
|
let useRefDes = instance.assignedRefDes;
|
|
85
86
|
let isPlaceholderRefdes = false;
|
|
86
87
|
const { ctxReferences } = instance;
|
|
@@ -106,13 +107,25 @@ export class RefdesAnnotationVisitor extends BaseVisitor {
|
|
|
106
107
|
const refdes = this.generateRefdesAnnotationComment(ctx);
|
|
107
108
|
if (refdes !== null) {
|
|
108
109
|
const originalText = this.getOriginalText(ctx);
|
|
109
|
-
|
|
110
|
-
|
|
110
|
+
this.modifications.set(ctx, {
|
|
111
|
+
originalText,
|
|
112
|
+
refdes: [refdes]
|
|
113
|
+
});
|
|
111
114
|
}
|
|
112
115
|
}
|
|
113
116
|
getOutput() {
|
|
114
117
|
return this.resultText;
|
|
115
118
|
}
|
|
119
|
+
getOutputForExternalRefdesFile() {
|
|
120
|
+
const result = [];
|
|
121
|
+
this.modifications.forEach((modification, ctx) => {
|
|
122
|
+
const { line: startLine, column: startColumn } = ctx.start;
|
|
123
|
+
const { line: stopLine, column: stopColumn } = ctx.stop;
|
|
124
|
+
const joinedRefdes = modification.refdes.join(',');
|
|
125
|
+
result.push(`${startLine}:${startColumn}:${stopLine}:${stopColumn}:${joinedRefdes}`);
|
|
126
|
+
});
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
116
129
|
generateModifiedText() {
|
|
117
130
|
const output = [];
|
|
118
131
|
const allTokens = this.tokenStream.getTokens();
|
|
@@ -140,7 +153,7 @@ export class RefdesAnnotationVisitor extends BaseVisitor {
|
|
|
140
153
|
output.push(this.sourceText.substring(lastSourcePos, token.start));
|
|
141
154
|
}
|
|
142
155
|
if (this.modifications.has(ctx)) {
|
|
143
|
-
output.push(this.modifications.get(ctx));
|
|
156
|
+
output.push(this.generateReplacementText(this.modifications.get(ctx)));
|
|
144
157
|
this.markTokensAsProcessed(ctx, processedTokens);
|
|
145
158
|
if (ctx.stop) {
|
|
146
159
|
lastSourcePos = ctx.stop.stop + 1;
|
|
@@ -193,4 +206,8 @@ export class RefdesAnnotationVisitor extends BaseVisitor {
|
|
|
193
206
|
console.log(...message);
|
|
194
207
|
}
|
|
195
208
|
}
|
|
209
|
+
generateReplacementText(modification) {
|
|
210
|
+
const joinedRefdes = modification.refdes.join(', ');
|
|
211
|
+
return `${modification.originalText} #= ${joinedRefdes}`;
|
|
212
|
+
}
|
|
196
213
|
}
|