circuitscript 0.2.0 → 0.3.1
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 +32 -32
- package/dist/cjs/ComponentMatchConditions.js +2 -2
- package/dist/cjs/antlr/CircuitScriptParser.js +3 -3
- package/dist/cjs/builtinMethods.js +2 -2
- package/dist/cjs/execute.js +23 -24
- package/dist/cjs/globals.js +2 -1
- package/dist/cjs/graph.js +1 -1
- package/dist/cjs/helpers.js +17 -17
- package/dist/cjs/objects/ExecutionScope.js +1 -1
- package/dist/cjs/objects/types.js +7 -18
- package/dist/cjs/validate/SymbolValidatorVisitor.js +7 -7
- package/dist/cjs/visitor.js +6 -6
- package/dist/esm/BaseVisitor.js +33 -33
- package/dist/esm/ComponentMatchConditions.js +2 -2
- package/dist/esm/antlr/CircuitScriptParser.js +6 -6
- package/dist/esm/builtinMethods.js +3 -3
- package/dist/esm/execute.js +23 -24
- package/dist/esm/globals.js +2 -1
- package/dist/esm/graph.js +2 -2
- package/dist/esm/helpers.js +17 -17
- package/dist/esm/objects/ExecutionScope.js +1 -1
- package/dist/esm/objects/types.js +8 -19
- package/dist/esm/validate/SymbolValidatorVisitor.js +7 -7
- package/dist/esm/visitor.js +7 -7
- package/dist/libs/std.cst +2 -1
- package/dist/types/BaseVisitor.d.ts +6 -6
- package/dist/types/antlr/CircuitScriptParser.d.ts +3 -3
- package/dist/types/globals.d.ts +3 -2
- package/dist/types/helpers.d.ts +2 -2
- package/dist/types/objects/ExecutionScope.d.ts +2 -2
- package/dist/types/objects/types.d.ts +5 -15
- package/dist/types/validate/SymbolValidatorVisitor.d.ts +1 -1
- package/dist/types/visitor.d.ts +1 -1
- package/libs/std.cst +2 -1
- package/package.json +1 -1
package/dist/cjs/BaseVisitor.js
CHANGED
|
@@ -528,17 +528,17 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
528
528
|
});
|
|
529
529
|
specificImports.push(...tmpSpecificImports);
|
|
530
530
|
}
|
|
531
|
-
const id = ctx.
|
|
531
|
+
const id = ctx._libraryName.text;
|
|
532
532
|
const importedFile = await this.handleImportFile(id, handling, true, ctx, specificImports);
|
|
533
533
|
const ctxImportAnnotation = ctx.import_annotation_expr();
|
|
534
534
|
if (ctxImportAnnotation) {
|
|
535
535
|
const textValue = ctxImportAnnotation.getText().replace('#=', '');
|
|
536
|
-
const {
|
|
536
|
+
const { importedLibrary } = importedFile;
|
|
537
537
|
if (textValue === 'annotate') {
|
|
538
|
-
|
|
538
|
+
importedLibrary.enableRefdesAnnotation = true;
|
|
539
539
|
}
|
|
540
540
|
else if (textValue === 'annotate-external') {
|
|
541
|
-
|
|
541
|
+
importedLibrary.enableRefdesAnnotationFile = true;
|
|
542
542
|
}
|
|
543
543
|
}
|
|
544
544
|
}
|
|
@@ -585,23 +585,23 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
585
585
|
}
|
|
586
586
|
const useNetNamespace = this.getNetNamespace(executor.netNamespace, passedNetNamespace);
|
|
587
587
|
try {
|
|
588
|
-
const
|
|
589
|
-
&& currentReference.rootValue instanceof types_js_1.
|
|
590
|
-
if (
|
|
591
|
-
this.log('create new
|
|
592
|
-
const
|
|
593
|
-
const
|
|
594
|
-
this.enterFile(
|
|
595
|
-
const newExecutor = this.handleEnterContext(this.getExecutor(), this.executionStack,
|
|
588
|
+
const isLibraryFunction = currentReference.rootValue
|
|
589
|
+
&& currentReference.rootValue instanceof types_js_1.ImportedLibrary;
|
|
590
|
+
if (isLibraryFunction) {
|
|
591
|
+
this.log('create new library context');
|
|
592
|
+
const importedLibrary = currentReference.rootValue;
|
|
593
|
+
const { context: importedLibraryContext } = importedLibrary;
|
|
594
|
+
this.enterFile(importedLibrary.libraryFilePath);
|
|
595
|
+
const newExecutor = this.handleEnterContext(this.getExecutor(), this.executionStack, importedLibraryContext.name, ctx, {
|
|
596
596
|
netNamespace: executor.netNamespace,
|
|
597
|
-
namespace:
|
|
597
|
+
namespace: importedLibrary.libraryNamespace
|
|
598
598
|
}, [], [], false);
|
|
599
|
-
this.log('copy
|
|
600
|
-
|
|
599
|
+
this.log('copy library context scope');
|
|
600
|
+
importedLibraryContext.scope.copyTo(newExecutor.scope);
|
|
601
601
|
}
|
|
602
602
|
const [, functionResult] = executor.callFunction(currentReference, parameters, this.executionStack, useNetNamespace);
|
|
603
|
-
if (
|
|
604
|
-
this.log('pop
|
|
603
|
+
if (isLibraryFunction) {
|
|
604
|
+
this.log('pop library context scope');
|
|
605
605
|
this.handlePopContext(this.getExecutor(), this.executionStack, "", false);
|
|
606
606
|
this.exitFile();
|
|
607
607
|
}
|
|
@@ -717,8 +717,8 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
717
717
|
return item.id === name;
|
|
718
718
|
});
|
|
719
719
|
if (importAlready) {
|
|
720
|
-
const
|
|
721
|
-
const alreadyImportedFlag =
|
|
720
|
+
const { importedLibrary: tmpImportedLibrary } = importAlready;
|
|
721
|
+
const alreadyImportedFlag = tmpImportedLibrary.importHandlingFlag;
|
|
722
722
|
const isMergedNamespace = alreadyImportedFlag === types_js_1.ImportFunctionHandling.AllMergeIntoNamespace
|
|
723
723
|
|| alreadyImportedFlag === types_js_1.ImportFunctionHandling.SpecificMergeIntoNamespace;
|
|
724
724
|
const invalidImportCondition1 = alreadyImportedFlag === types_js_1.ImportFunctionHandling.AllWithNamespace &&
|
|
@@ -732,11 +732,11 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
732
732
|
if (alreadyImportedFlag === types_js_1.ImportFunctionHandling.AllMergeIntoNamespace) {
|
|
733
733
|
}
|
|
734
734
|
else if (alreadyImportedFlag === types_js_1.ImportFunctionHandling.SpecificMergeIntoNamespace && importHandling === types_js_1.ImportFunctionHandling.AllMergeIntoNamespace) {
|
|
735
|
-
|
|
736
|
-
|
|
735
|
+
tmpImportedLibrary.specifiedImports = [];
|
|
736
|
+
tmpImportedLibrary.importHandlingFlag = types_js_1.ImportFunctionHandling.AllMergeIntoNamespace;
|
|
737
737
|
}
|
|
738
738
|
else if (alreadyImportedFlag === types_js_1.ImportFunctionHandling.SpecificMergeIntoNamespace && importHandling === types_js_1.ImportFunctionHandling.SpecificMergeIntoNamespace) {
|
|
739
|
-
|
|
739
|
+
tmpImportedLibrary.specifiedImports.push(...specificImports);
|
|
740
740
|
}
|
|
741
741
|
}
|
|
742
742
|
return importAlready;
|
|
@@ -757,7 +757,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
757
757
|
this.log('failed to read file');
|
|
758
758
|
pathExists = false;
|
|
759
759
|
}
|
|
760
|
-
let
|
|
760
|
+
let importedLibrary;
|
|
761
761
|
if (!pathExists) {
|
|
762
762
|
try {
|
|
763
763
|
const tmpFilePath2 = this.environment.getRelativeToDefaultLibs(name + ".cst");
|
|
@@ -778,26 +778,26 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
778
778
|
const executor = this.getExecutor();
|
|
779
779
|
const executionContextName = name;
|
|
780
780
|
const netNamespace = executor.netNamespace;
|
|
781
|
-
const
|
|
781
|
+
const libraryNamespace = `${globals_js_1.BaseNamespace}${name}.`;
|
|
782
782
|
this.enterNewChildContext(executionStack, executor, executionContextName, {
|
|
783
783
|
netNamespace,
|
|
784
|
-
namespace:
|
|
784
|
+
namespace: libraryNamespace,
|
|
785
785
|
}, [], []);
|
|
786
786
|
const importResult = await this.onImportFile(this, filePathUsed, fileData, this.onErrorHandler);
|
|
787
787
|
hasError = importResult.hasError;
|
|
788
788
|
hasParseError = importResult.hasParseError;
|
|
789
789
|
const importContext = executionStack.pop();
|
|
790
790
|
this.log(`import handling flag: ${importHandling}`);
|
|
791
|
-
|
|
791
|
+
importedLibrary = new types_js_1.ImportedLibrary(name, libraryNamespace, filePathUsed, importResult.tree, importResult.tokens, importContext, importHandling, specificImports);
|
|
792
792
|
if (specificImports.length > 0) {
|
|
793
793
|
this.log('specific import: ' + specificImports.join(', '));
|
|
794
794
|
}
|
|
795
795
|
const scope = this.getScope();
|
|
796
|
-
scope.
|
|
797
|
-
|
|
798
|
-
scope.
|
|
796
|
+
scope.libraries.set(name, importedLibrary);
|
|
797
|
+
importedLibrary.context.scope.libraries.forEach((lib, key) => {
|
|
798
|
+
scope.libraries.set(key, lib);
|
|
799
799
|
});
|
|
800
|
-
await this.
|
|
800
|
+
await this.checkLibraryHasRefdesFile(filePathUsed);
|
|
801
801
|
}
|
|
802
802
|
}
|
|
803
803
|
catch (err) {
|
|
@@ -825,12 +825,12 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
825
825
|
hasError,
|
|
826
826
|
hasParseError,
|
|
827
827
|
pathExists,
|
|
828
|
-
|
|
828
|
+
importedLibrary: importedLibrary
|
|
829
829
|
};
|
|
830
830
|
this.importedFiles.push(newImportedFile);
|
|
831
831
|
return newImportedFile;
|
|
832
832
|
}
|
|
833
|
-
async
|
|
833
|
+
async checkLibraryHasRefdesFile(filePath) {
|
|
834
834
|
return;
|
|
835
835
|
}
|
|
836
836
|
getRefdesFileAnnotation(filePath, startLine, startColumn, stopLine, stopColumn) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.applyPartConditions = exports.partMatchesConditions = exports.extractPartConditions = exports.flattenConditionNodes = void 0;
|
|
4
|
+
const globals_js_1 = require("./globals.js");
|
|
4
5
|
const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
|
|
5
|
-
const types_js_1 = require("./objects/types.js");
|
|
6
6
|
function flattenConditionNodes(conditionNodes, level = 0) {
|
|
7
7
|
const conditionBranches = [];
|
|
8
8
|
conditionNodes.forEach(node => {
|
|
@@ -101,7 +101,7 @@ function partMatchesConditions(instance, partConditions) {
|
|
|
101
101
|
exports.partMatchesConditions = partMatchesConditions;
|
|
102
102
|
function applyPartConditions(instances, paramKeys, partConditions) {
|
|
103
103
|
instances.forEach(item => {
|
|
104
|
-
if (item.typeProp !==
|
|
104
|
+
if (item.typeProp !== globals_js_1.ComponentTypes.graphic) {
|
|
105
105
|
const matchedResult = partMatchesConditions(item, partConditions);
|
|
106
106
|
if (matchedResult !== undefined) {
|
|
107
107
|
paramKeys.forEach((paramKey, index) => {
|
|
@@ -3406,7 +3406,7 @@ class CircuitScriptParser extends antlr.Parser {
|
|
|
3406
3406
|
this.state = 686;
|
|
3407
3407
|
this.match(CircuitScriptParser.Import);
|
|
3408
3408
|
this.state = 687;
|
|
3409
|
-
localContext.
|
|
3409
|
+
localContext._libraryName = this.match(CircuitScriptParser.ID);
|
|
3410
3410
|
this.state = 689;
|
|
3411
3411
|
this.errorHandler.sync(this);
|
|
3412
3412
|
switch (this.interpreter.adaptivePredict(this.tokenStream, 76, this.context)) {
|
|
@@ -3426,7 +3426,7 @@ class CircuitScriptParser extends antlr.Parser {
|
|
|
3426
3426
|
this.state = 691;
|
|
3427
3427
|
this.match(CircuitScriptParser.From);
|
|
3428
3428
|
this.state = 692;
|
|
3429
|
-
localContext.
|
|
3429
|
+
localContext._libraryName = this.match(CircuitScriptParser.ID);
|
|
3430
3430
|
this.state = 693;
|
|
3431
3431
|
this.match(CircuitScriptParser.Import);
|
|
3432
3432
|
this.state = 694;
|
|
@@ -3450,7 +3450,7 @@ class CircuitScriptParser extends antlr.Parser {
|
|
|
3450
3450
|
this.state = 698;
|
|
3451
3451
|
this.match(CircuitScriptParser.From);
|
|
3452
3452
|
this.state = 699;
|
|
3453
|
-
localContext.
|
|
3453
|
+
localContext._libraryName = this.match(CircuitScriptParser.ID);
|
|
3454
3454
|
this.state = 700;
|
|
3455
3455
|
this.match(CircuitScriptParser.Import);
|
|
3456
3456
|
this.state = 701;
|
|
@@ -156,8 +156,8 @@ function toString(obj) {
|
|
|
156
156
|
else if (obj instanceof types_js_1.CFunctionEntry) {
|
|
157
157
|
return obj.toString();
|
|
158
158
|
}
|
|
159
|
-
else if (obj instanceof types_js_1.
|
|
160
|
-
return `[
|
|
159
|
+
else if (obj instanceof types_js_1.ImportedLibrary) {
|
|
160
|
+
return `[library: ${obj.libraryName}]`;
|
|
161
161
|
}
|
|
162
162
|
else {
|
|
163
163
|
if (obj === undefined) {
|
package/dist/cjs/execute.js
CHANGED
|
@@ -641,19 +641,18 @@ class ExecutionContext {
|
|
|
641
641
|
});
|
|
642
642
|
}
|
|
643
643
|
else {
|
|
644
|
-
const
|
|
645
|
-
for (
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
const
|
|
651
|
-
|
|
652
|
-
if (module.context.hasFunction(functionPath)) {
|
|
644
|
+
const libraries = Array.from(context.scope.libraries.values());
|
|
645
|
+
for (const library of libraries) {
|
|
646
|
+
if (library.importHandlingFlag === types_js_1.ImportFunctionHandling.AllMergeIntoNamespace ||
|
|
647
|
+
(library.importHandlingFlag === types_js_1.ImportFunctionHandling.SpecificMergeIntoNamespace
|
|
648
|
+
&& library.specifiedImports.indexOf(idName) !== -1)) {
|
|
649
|
+
const { context: libraryContext } = library;
|
|
650
|
+
const functionPath = `${libraryContext.namespace}${idName}`;
|
|
651
|
+
if (library.context.hasFunction(functionPath)) {
|
|
653
652
|
return new types_js_1.DeclaredReference({
|
|
654
653
|
found: true,
|
|
655
|
-
rootValue:
|
|
656
|
-
value:
|
|
654
|
+
rootValue: library,
|
|
655
|
+
value: library.context.getFunction(functionPath),
|
|
657
656
|
type: globals_js_1.ReferenceTypes.function,
|
|
658
657
|
name: idName,
|
|
659
658
|
trailerIndex: 1,
|
|
@@ -662,24 +661,24 @@ class ExecutionContext {
|
|
|
662
661
|
}
|
|
663
662
|
}
|
|
664
663
|
}
|
|
665
|
-
let
|
|
666
|
-
if (context.scope.
|
|
667
|
-
const
|
|
668
|
-
if (
|
|
669
|
-
|
|
664
|
+
let isLibrary = false;
|
|
665
|
+
if (context.scope.libraries.has(idName)) {
|
|
666
|
+
const library = context.scope.libraries.get(idName);
|
|
667
|
+
if (library.importHandlingFlag === types_js_1.ImportFunctionHandling.AllWithNamespace) {
|
|
668
|
+
isLibrary = true;
|
|
670
669
|
}
|
|
671
670
|
}
|
|
672
671
|
let isVariable = context.scope.variables.has(idName);
|
|
673
672
|
let isComponentInstance = context.scope.instances.has(idName);
|
|
674
|
-
if (
|
|
675
|
-
const scopeList =
|
|
673
|
+
if (isLibrary || isVariable || isComponentInstance) {
|
|
674
|
+
const scopeList = isLibrary ? context.scope.libraries :
|
|
676
675
|
(isVariable ? context.scope.variables : context.scope.instances);
|
|
677
676
|
const useValue = scopeList.get(idName);
|
|
678
677
|
if (!isComponentInstance && (useValue instanceof ClassComponent_js_1.ClassComponent)) {
|
|
679
678
|
isComponentInstance = true;
|
|
680
679
|
isVariable = false;
|
|
681
680
|
}
|
|
682
|
-
const referenceType =
|
|
681
|
+
const referenceType = isLibrary ? globals_js_1.ReferenceTypes.library :
|
|
683
682
|
(isVariable ? globals_js_1.ReferenceTypes.variable : globals_js_1.ReferenceTypes.instance);
|
|
684
683
|
const tmpReference = this.resolveTrailers(referenceType, useValue, trailers);
|
|
685
684
|
return new types_js_1.DeclaredReference({
|
|
@@ -726,12 +725,12 @@ class ExecutionContext {
|
|
|
726
725
|
}
|
|
727
726
|
break;
|
|
728
727
|
}
|
|
729
|
-
case globals_js_1.ReferenceTypes.
|
|
728
|
+
case globals_js_1.ReferenceTypes.library: {
|
|
730
729
|
const funcName = trailers[0];
|
|
731
|
-
const
|
|
732
|
-
const functionPath = `${
|
|
733
|
-
if (
|
|
734
|
-
const foundFunc =
|
|
730
|
+
const library = rootValue;
|
|
731
|
+
const functionPath = `${library.libraryNamespace}${funcName}`;
|
|
732
|
+
if (library.context.hasFunction(functionPath)) {
|
|
733
|
+
const foundFunc = library.context.getFunction(functionPath);
|
|
735
734
|
return new types_js_1.AnyReference({
|
|
736
735
|
found: true,
|
|
737
736
|
type: globals_js_1.ReferenceTypes.function,
|
package/dist/cjs/globals.js
CHANGED
|
@@ -91,6 +91,7 @@ var ComponentTypes;
|
|
|
91
91
|
ComponentTypes["graphic"] = "graphic";
|
|
92
92
|
ComponentTypes["port"] = "port";
|
|
93
93
|
ComponentTypes["module"] = "module";
|
|
94
|
+
ComponentTypes["resistor"] = "res";
|
|
94
95
|
})(ComponentTypes || (exports.ComponentTypes = ComponentTypes = {}));
|
|
95
96
|
var ReferenceTypes;
|
|
96
97
|
(function (ReferenceTypes) {
|
|
@@ -99,7 +100,7 @@ var ReferenceTypes;
|
|
|
99
100
|
ReferenceTypes["variable"] = "variable";
|
|
100
101
|
ReferenceTypes["instance"] = "instance";
|
|
101
102
|
ReferenceTypes["pinType"] = "pinType";
|
|
102
|
-
ReferenceTypes["
|
|
103
|
+
ReferenceTypes["library"] = "library";
|
|
103
104
|
ReferenceTypes["unknown"] = "unknown";
|
|
104
105
|
})(ReferenceTypes || (exports.ReferenceTypes = ReferenceTypes = {}));
|
|
105
106
|
var BlockTypes;
|
package/dist/cjs/graph.js
CHANGED
|
@@ -257,7 +257,7 @@ class NetGraph {
|
|
|
257
257
|
const netsLength = netsIndexed.length;
|
|
258
258
|
const conductanceMatrix = ml_matrix_1.default.zeros(netsLength, netsLength);
|
|
259
259
|
components.forEach(item => {
|
|
260
|
-
if (item.typeProp ===
|
|
260
|
+
if (item.typeProp === globals_js_1.ComponentTypes.resistor) {
|
|
261
261
|
const net1 = item.pinNets.get(1);
|
|
262
262
|
const net2 = item.pinNets.get(2);
|
|
263
263
|
const net1Index = netsIndexed.indexOf(net1);
|
package/dist/cjs/helpers.js
CHANGED
|
@@ -159,7 +159,7 @@ async function validateScript(filePath, scriptData, options) {
|
|
|
159
159
|
return visitorResolver;
|
|
160
160
|
}
|
|
161
161
|
exports.validateScript = validateScript;
|
|
162
|
-
async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens, componentLinks,
|
|
162
|
+
async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens, componentLinks, importedLibraries, environment) {
|
|
163
163
|
const { inputPath = null, updateSource = false, saveAnnotatedCopy = undefined, } = options;
|
|
164
164
|
if (inputPath && (updateSource || saveAnnotatedCopy !== undefined)) {
|
|
165
165
|
const annotatedFiles = [{
|
|
@@ -170,29 +170,29 @@ async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens,
|
|
|
170
170
|
filePath: inputPath,
|
|
171
171
|
outputType: RefdesOutputType.WithSource
|
|
172
172
|
}];
|
|
173
|
-
for (const
|
|
173
|
+
for (const library of importedLibraries) {
|
|
174
174
|
let outputType = RefdesOutputType.None;
|
|
175
|
-
if (
|
|
175
|
+
if (library.enableRefdesAnnotation) {
|
|
176
176
|
outputType = RefdesOutputType.WithSource;
|
|
177
177
|
}
|
|
178
|
-
else if (
|
|
178
|
+
else if (library.enableRefdesAnnotationFile) {
|
|
179
179
|
outputType = RefdesOutputType.CreateExternalFile;
|
|
180
180
|
}
|
|
181
181
|
if (outputType !== RefdesOutputType.None) {
|
|
182
|
-
const {
|
|
183
|
-
const
|
|
182
|
+
const { libraryFilePath, libraryName, tokens: libTokens, tree: libTree } = library;
|
|
183
|
+
const libraryScriptData = await environment.readFile(libraryFilePath, { encoding: 'utf8' });
|
|
184
184
|
annotatedFiles.push({
|
|
185
|
-
tokens:
|
|
186
|
-
tree:
|
|
187
|
-
filePath:
|
|
188
|
-
scriptData:
|
|
189
|
-
|
|
185
|
+
tokens: libTokens,
|
|
186
|
+
tree: libTree,
|
|
187
|
+
filePath: libraryFilePath,
|
|
188
|
+
scriptData: libraryScriptData,
|
|
189
|
+
libraryName,
|
|
190
190
|
outputType
|
|
191
191
|
});
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
for (const item of annotatedFiles) {
|
|
195
|
-
const { scriptData, tokens, tree, filePath,
|
|
195
|
+
const { scriptData, tokens, tree, filePath, libraryName, isMainFile = false } = item;
|
|
196
196
|
const tmpVisitor = new RefdesAnnotationVisitor_js_1.RefdesAnnotationVisitor(true, scriptData, tokens, componentLinks);
|
|
197
197
|
await tmpVisitor.visit(tree);
|
|
198
198
|
let usePath = filePath;
|
|
@@ -218,15 +218,15 @@ async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens,
|
|
|
218
218
|
const relativeFilePath = environment.relative(inputDir, filePath);
|
|
219
219
|
const jsonFile = {
|
|
220
220
|
format: 'v1',
|
|
221
|
-
|
|
221
|
+
library: libraryName,
|
|
222
222
|
file: relativeFilePath,
|
|
223
223
|
items: output,
|
|
224
224
|
};
|
|
225
225
|
environment.writeFileSync(usePath, JSON.stringify(jsonFile, null, 4));
|
|
226
226
|
}
|
|
227
227
|
let display = 'Refdes annotations';
|
|
228
|
-
if (
|
|
229
|
-
display += ` for
|
|
228
|
+
if (libraryName) {
|
|
229
|
+
display += ` for library ${libraryName}`;
|
|
230
230
|
}
|
|
231
231
|
console.log(`${display} saved to ${usePath}`);
|
|
232
232
|
}
|
|
@@ -311,9 +311,9 @@ async function renderScriptCustom(scriptData, outputPath, options, parseHandlers
|
|
|
311
311
|
throw new utils_js_1.RenderError(`Error during component annotation: ${err}`, 'annotation');
|
|
312
312
|
}
|
|
313
313
|
const componentLinks = visitor.getComponentCtxLinks();
|
|
314
|
-
const
|
|
314
|
+
const importedLibraries = Array.from(visitor.getScope().libraries.values());
|
|
315
315
|
for (let i = 0; i < postAnnotationCallbacks.length; i++) {
|
|
316
|
-
await postAnnotationCallbacks[i](options, scriptData, tree, tokens, componentLinks,
|
|
316
|
+
await postAnnotationCallbacks[i](options, scriptData, tree, tokens, componentLinks, importedLibraries, environment);
|
|
317
317
|
}
|
|
318
318
|
if (dumpNets) {
|
|
319
319
|
const nets = visitor.dumpNets();
|
|
@@ -12,7 +12,7 @@ class ExecutionScope {
|
|
|
12
12
|
this.functionCounter = new Map();
|
|
13
13
|
this.variables = new Map();
|
|
14
14
|
this.symbols = new Map();
|
|
15
|
-
this.
|
|
15
|
+
this.libraries = new Map();
|
|
16
16
|
this.blockStack = new Map();
|
|
17
17
|
this.contextStack = [];
|
|
18
18
|
this.onPropertyHandler = [];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ImportFunctionHandling = exports.
|
|
3
|
+
exports.ImportFunctionHandling = exports.ImportedLibrary = exports.NetTypes = exports.Direction = exports.ParseSymbolType = exports.DeclaredReference = exports.UndeclaredReference = exports.AnyReference = exports.CFunctionEntry = void 0;
|
|
4
4
|
const globals_js_1 = require("../globals.js");
|
|
5
5
|
const utils_js_1 = require("../utils.js");
|
|
6
6
|
class CFunctionEntry {
|
|
@@ -111,29 +111,18 @@ var Direction;
|
|
|
111
111
|
Direction["Down"] = "down";
|
|
112
112
|
Direction["Up"] = "up";
|
|
113
113
|
})(Direction || (exports.Direction = Direction = {}));
|
|
114
|
-
var TypeProps;
|
|
115
|
-
(function (TypeProps) {
|
|
116
|
-
TypeProps["Net"] = "net";
|
|
117
|
-
TypeProps["Port"] = "port";
|
|
118
|
-
TypeProps["Graphic"] = "graphic";
|
|
119
|
-
TypeProps["Module"] = "module";
|
|
120
|
-
TypeProps["Resistor"] = "res";
|
|
121
|
-
TypeProps["Capacitor"] = "cap";
|
|
122
|
-
TypeProps["Inductor"] = "ind";
|
|
123
|
-
TypeProps["Diode"] = "diode";
|
|
124
|
-
})(TypeProps || (exports.TypeProps = TypeProps = {}));
|
|
125
114
|
var NetTypes;
|
|
126
115
|
(function (NetTypes) {
|
|
127
116
|
NetTypes["Any"] = "any";
|
|
128
117
|
NetTypes["Source"] = "source";
|
|
129
118
|
})(NetTypes || (exports.NetTypes = NetTypes = {}));
|
|
130
|
-
class
|
|
131
|
-
constructor(
|
|
119
|
+
class ImportedLibrary {
|
|
120
|
+
constructor(libraryName, libraryNamespace, libraryFilePath, tree, tokens, context, flag, specifiedImports) {
|
|
132
121
|
this.enableRefdesAnnotation = false;
|
|
133
122
|
this.enableRefdesAnnotationFile = false;
|
|
134
|
-
this.
|
|
135
|
-
this.
|
|
136
|
-
this.
|
|
123
|
+
this.libraryName = libraryName;
|
|
124
|
+
this.libraryNamespace = libraryNamespace;
|
|
125
|
+
this.libraryFilePath = libraryFilePath;
|
|
137
126
|
this.tree = tree;
|
|
138
127
|
this.tokens = tokens;
|
|
139
128
|
this.context = context;
|
|
@@ -141,7 +130,7 @@ class ImportedModule {
|
|
|
141
130
|
this.specifiedImports = specifiedImports;
|
|
142
131
|
}
|
|
143
132
|
}
|
|
144
|
-
exports.
|
|
133
|
+
exports.ImportedLibrary = ImportedLibrary;
|
|
145
134
|
var ImportFunctionHandling;
|
|
146
135
|
(function (ImportFunctionHandling) {
|
|
147
136
|
ImportFunctionHandling["AllWithNamespace"] = "all-with-namespace";
|
|
@@ -167,24 +167,24 @@ class SymbolValidatorVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
167
167
|
});
|
|
168
168
|
specifiedImports.push(...tmpImports);
|
|
169
169
|
}
|
|
170
|
-
const id = ctx.
|
|
171
|
-
const { pathExists,
|
|
170
|
+
const id = ctx._libraryName.text;
|
|
171
|
+
const { pathExists, importedLibrary } = await this.handleImportFile(id, handling, true, ctx, specifiedImports);
|
|
172
172
|
if (!pathExists) {
|
|
173
|
-
this.symbolTable.addUndefined(this.getCurrentFile(), this.getExecutor(), id, ctx.
|
|
173
|
+
this.symbolTable.addUndefined(this.getCurrentFile(), this.getExecutor(), id, ctx._libraryName);
|
|
174
174
|
}
|
|
175
175
|
else {
|
|
176
|
-
this.
|
|
176
|
+
this.applyLibraryImports(importedLibrary);
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
|
-
|
|
180
|
-
const { importHandlingFlag: importHandling, specifiedImports } =
|
|
179
|
+
applyLibraryImports(library) {
|
|
180
|
+
const { importHandlingFlag: importHandling, specifiedImports } = library;
|
|
181
181
|
const addedSymbols = [];
|
|
182
182
|
const executor = this.getExecutor();
|
|
183
183
|
const symbolTable = this.symbolTable.getSymbols();
|
|
184
184
|
symbolTable.forEach((value, key) => {
|
|
185
185
|
if (value.type === types_js_1.ParseSymbolType.Function) {
|
|
186
186
|
const definedSymbol = value;
|
|
187
|
-
if (definedSymbol.fileName ===
|
|
187
|
+
if (definedSymbol.fileName === library.libraryFilePath) {
|
|
188
188
|
const addSymbolToNamespace = importHandling === types_js_1.ImportFunctionHandling.AllMergeIntoNamespace
|
|
189
189
|
|| (importHandling === types_js_1.ImportFunctionHandling.SpecificMergeIntoNamespace
|
|
190
190
|
&& specifiedImports.indexOf(definedSymbol.id) !== -1);
|
package/dist/cjs/visitor.js
CHANGED
|
@@ -351,7 +351,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
351
351
|
return new PinDefinition_js_1.PinDefinition(index + 1, PinDefinition_js_1.PinIdType.Int, portName, PinTypes_js_1.PinTypes.Any);
|
|
352
352
|
});
|
|
353
353
|
const arrange = this.getArrangePropFromModulePorts(modulePorts, nameToPinId);
|
|
354
|
-
const unitProperties = this.extractComponentUnitProperties(properties,
|
|
354
|
+
const unitProperties = this.extractComponentUnitProperties(properties, globals_js_1.ComponentTypes.module);
|
|
355
355
|
const firstUnitDef = unitProperties[0][1];
|
|
356
356
|
firstUnitDef.pins = tmpPorts;
|
|
357
357
|
firstUnitDef.arrange = arrange;
|
|
@@ -362,7 +362,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
362
362
|
};
|
|
363
363
|
const moduleInstanceName = this.getExecutor().getUniqueInstanceName();
|
|
364
364
|
const moduleComponent = this.getExecutor().createComponent(moduleInstanceName, tmpPorts, blankParams, props, true);
|
|
365
|
-
moduleComponent.typeProp =
|
|
365
|
+
moduleComponent.typeProp = globals_js_1.ComponentTypes.module;
|
|
366
366
|
const ctxPropertyBlock = ctx.property_block_expr();
|
|
367
367
|
if (ctxPropertyBlock) {
|
|
368
368
|
const [firstBlock] = ctxPropertyBlock;
|
|
@@ -1148,7 +1148,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1148
1148
|
const display = properties.get('display') ?? null;
|
|
1149
1149
|
const suffix = properties.get('suffix') ?? null;
|
|
1150
1150
|
let pins = [];
|
|
1151
|
-
if (display !== null && arrange === null && typeProp !==
|
|
1151
|
+
if (display !== null && arrange === null && typeProp !== globals_js_1.ComponentTypes.graphic) {
|
|
1152
1152
|
const drawCommands = display.getCommands();
|
|
1153
1153
|
drawCommands.forEach(command => {
|
|
1154
1154
|
const [commandValue,] = command;
|
|
@@ -1385,7 +1385,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1385
1385
|
currentComponent.forceSaveRefdesAnnotation = forceSave;
|
|
1386
1386
|
}
|
|
1387
1387
|
}
|
|
1388
|
-
async
|
|
1388
|
+
async checkLibraryHasRefdesFile(filePath) {
|
|
1389
1389
|
const dir = this.environment.dirname(filePath);
|
|
1390
1390
|
const ext = this.environment.extname(filePath);
|
|
1391
1391
|
const basename = this.environment.basename(filePath, ext);
|
|
@@ -1655,8 +1655,8 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1655
1655
|
const fullNetNames = Array.from(uniqueNets).map(item => item.toString());
|
|
1656
1656
|
nets.forEach(([component, pin, net]) => {
|
|
1657
1657
|
if (net.priority === 0 && seenNets.indexOf(net) === -1
|
|
1658
|
-
&& component.typeProp !==
|
|
1659
|
-
&& component.typeProp !==
|
|
1658
|
+
&& component.typeProp !== globals_js_1.ComponentTypes.module
|
|
1659
|
+
&& component.typeProp !== globals_js_1.ComponentTypes.net) {
|
|
1660
1660
|
net.name = net.baseName =
|
|
1661
1661
|
`NET-(${component.assignedRefDes}-${pin.toString()})`;
|
|
1662
1662
|
if (fullNetNames.indexOf(net.toString()) !== -1) {
|