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/cjs/BaseVisitor.js
CHANGED
|
@@ -19,6 +19,7 @@ const PinDefinition_js_1 = require("./objects/PinDefinition.js");
|
|
|
19
19
|
class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
20
20
|
constructor(silent = false, onErrorHandler = null, environment) {
|
|
21
21
|
super();
|
|
22
|
+
this.filePathStack = [];
|
|
22
23
|
this.silent = false;
|
|
23
24
|
this.printStream = [];
|
|
24
25
|
this.printToConsole = true;
|
|
@@ -40,6 +41,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
40
41
|
this.onImportFile = async (visitor, filePath, fileData, onErrorHandler) => {
|
|
41
42
|
throw "Import file not implemented";
|
|
42
43
|
};
|
|
44
|
+
this.refdesFileAnnotations = new Map();
|
|
43
45
|
this.visitScript = async (ctx) => {
|
|
44
46
|
this.log('===', 'start', '===');
|
|
45
47
|
this.allowParseImports = true;
|
|
@@ -527,7 +529,18 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
527
529
|
specificImports.push(...tmpSpecificImports);
|
|
528
530
|
}
|
|
529
531
|
const id = ctx._moduleName.text;
|
|
530
|
-
await this.handleImportFile(id, handling, true, ctx, specificImports);
|
|
532
|
+
const importedFile = await this.handleImportFile(id, handling, true, ctx, specificImports);
|
|
533
|
+
const ctxImportAnnotation = ctx.import_annotation_expr();
|
|
534
|
+
if (ctxImportAnnotation) {
|
|
535
|
+
const textValue = ctxImportAnnotation.getText().replace('#=', '');
|
|
536
|
+
const { importedModule } = importedFile;
|
|
537
|
+
if (textValue === 'annotate') {
|
|
538
|
+
importedModule.enableRefdesAnnotation = true;
|
|
539
|
+
}
|
|
540
|
+
else if (textValue === 'annotate-external') {
|
|
541
|
+
importedModule.enableRefdesAnnotationFile = true;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
531
544
|
}
|
|
532
545
|
getReference(ctx) {
|
|
533
546
|
const atomStr = ctx.getText();
|
|
@@ -578,6 +591,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
578
591
|
this.log('create new module context');
|
|
579
592
|
const importedModule = currentReference.rootValue;
|
|
580
593
|
const importedModuleContext = importedModule.context;
|
|
594
|
+
this.enterFile(importedModule.moduleFilePath);
|
|
581
595
|
const newExecutor = this.handleEnterContext(this.getExecutor(), this.executionStack, importedModuleContext.name, ctx, {
|
|
582
596
|
netNamespace: executor.netNamespace,
|
|
583
597
|
namespace: importedModule.moduleNamespace
|
|
@@ -589,6 +603,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
589
603
|
if (isModuleFunction) {
|
|
590
604
|
this.log('pop module context scope');
|
|
591
605
|
this.handlePopContext(this.getExecutor(), this.executionStack, "", false);
|
|
606
|
+
this.exitFile();
|
|
592
607
|
}
|
|
593
608
|
if ((0, utils_js_1.isReference)(functionResult)) {
|
|
594
609
|
currentReference = functionResult;
|
|
@@ -684,7 +699,8 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
684
699
|
instance.ctxReferences.push({
|
|
685
700
|
ctx,
|
|
686
701
|
indexedStack,
|
|
687
|
-
creationFlag
|
|
702
|
+
creationFlag,
|
|
703
|
+
filePath: this.getCurrentFile(),
|
|
688
704
|
});
|
|
689
705
|
this.componentCtxLinks.set(ctx, instance);
|
|
690
706
|
}
|
|
@@ -772,7 +788,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
772
788
|
hasParseError = importResult.hasParseError;
|
|
773
789
|
const importContext = executionStack.pop();
|
|
774
790
|
this.log(`import handling flag: ${importHandling}`);
|
|
775
|
-
importedModule = new types_js_1.ImportedModule(name, moduleNamespace, filePathUsed, importContext, importHandling, specificImports);
|
|
791
|
+
importedModule = new types_js_1.ImportedModule(name, moduleNamespace, filePathUsed, importResult.tree, importResult.tokens, importContext, importHandling, specificImports);
|
|
776
792
|
if (specificImports.length > 0) {
|
|
777
793
|
this.log('specific import: ' + specificImports.join(', '));
|
|
778
794
|
}
|
|
@@ -781,6 +797,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
781
797
|
importedModule.context.scope.modules.forEach((module, key) => {
|
|
782
798
|
scope.modules.set(key, module);
|
|
783
799
|
});
|
|
800
|
+
await this.checkModuleHasRefdesFile(filePathUsed);
|
|
784
801
|
}
|
|
785
802
|
}
|
|
786
803
|
catch (err) {
|
|
@@ -813,6 +830,12 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
813
830
|
this.importedFiles.push(newImportedFile);
|
|
814
831
|
return newImportedFile;
|
|
815
832
|
}
|
|
833
|
+
async checkModuleHasRefdesFile(filePath) {
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
836
|
+
getRefdesFileAnnotation(filePath, startLine, startColumn, stopLine, stopColumn) {
|
|
837
|
+
return `${filePath}:${startLine}:${startColumn}:${stopLine}:${stopColumn}`;
|
|
838
|
+
}
|
|
816
839
|
setupDefinedParameters(funcDefinedParameters, passedInParameters, executor) {
|
|
817
840
|
for (let i = 0; i < funcDefinedParameters.length; i++) {
|
|
818
841
|
const tmpFuncArg = funcDefinedParameters[i];
|
|
@@ -940,5 +963,16 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
940
963
|
return (val instanceof ParamDefinition_js_1.NumericValue);
|
|
941
964
|
}, 'numeric value');
|
|
942
965
|
}
|
|
966
|
+
enterFile(filePath) {
|
|
967
|
+
this.log(`enter file: ${filePath}`);
|
|
968
|
+
this.filePathStack.push(filePath);
|
|
969
|
+
}
|
|
970
|
+
exitFile() {
|
|
971
|
+
this.log(`exit file: ${this.getCurrentFile()}`);
|
|
972
|
+
this.filePathStack.pop();
|
|
973
|
+
}
|
|
974
|
+
getCurrentFile() {
|
|
975
|
+
return this.filePathStack[this.filePathStack.length - 1];
|
|
976
|
+
}
|
|
943
977
|
}
|
|
944
978
|
exports.BaseVisitor = BaseVisitor;
|
|
@@ -10,8 +10,7 @@ class RefdesAnnotationVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
10
10
|
this.resultText = '';
|
|
11
11
|
this.debug = false;
|
|
12
12
|
this.visitScript = async (ctx) => {
|
|
13
|
-
|
|
14
|
-
this.setResult(ctx, result);
|
|
13
|
+
this.runExpressions(this.getExecutor(), ctx.expression());
|
|
15
14
|
this.getExecutor().closeOpenPathBlocks();
|
|
16
15
|
this.resultText = this.generateModifiedText();
|
|
17
16
|
};
|
|
@@ -43,8 +42,10 @@ class RefdesAnnotationVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
43
42
|
});
|
|
44
43
|
if (allRefdes.length > 0) {
|
|
45
44
|
const originalText = this.getOriginalText(ctx);
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
this.modifications.set(ctx, {
|
|
46
|
+
originalText,
|
|
47
|
+
refdes: allRefdes,
|
|
48
|
+
});
|
|
48
49
|
}
|
|
49
50
|
};
|
|
50
51
|
this.visitFunction_def_expr = (ctx) => {
|
|
@@ -77,10 +78,10 @@ class RefdesAnnotationVisitor extends BaseVisitor_js_1.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 @@ class RefdesAnnotationVisitor extends BaseVisitor_js_1.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 @@ class RefdesAnnotationVisitor extends BaseVisitor_js_1.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,5 +206,9 @@ class RefdesAnnotationVisitor extends BaseVisitor_js_1.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
|
}
|
|
197
214
|
exports.RefdesAnnotationVisitor = RefdesAnnotationVisitor;
|