circuitscript 0.2.0 → 0.3.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 +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/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/package.json +1 -1
package/dist/esm/BaseVisitor.js
CHANGED
|
@@ -6,7 +6,7 @@ import { Logger } from "./logger.js";
|
|
|
6
6
|
import { ClassComponent } from "./objects/ClassComponent.js";
|
|
7
7
|
import { NumberOperator, NumericValue, PercentageValue } from "./objects/ParamDefinition.js";
|
|
8
8
|
import { PinTypes } from "./objects/PinTypes.js";
|
|
9
|
-
import { Direction, AnyReference, UndeclaredReference,
|
|
9
|
+
import { Direction, AnyReference, UndeclaredReference, ImportedLibrary, ImportFunctionHandling as ImportFunctionHandling } from "./objects/types.js";
|
|
10
10
|
import { BaseNamespace, ComponentTypes, DoubleDelimiter1, GlobalDocumentName, ReferenceTypes, TrailerArrayIndex } from './globals.js';
|
|
11
11
|
import { isReference, unwrapValue as unwrapValue } from "./utils.js";
|
|
12
12
|
import { linkBuiltInMethods } from './builtinMethods.js';
|
|
@@ -145,17 +145,17 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
145
145
|
});
|
|
146
146
|
specificImports.push(...tmpSpecificImports);
|
|
147
147
|
}
|
|
148
|
-
const id = ctx.
|
|
148
|
+
const id = ctx._libraryName.text;
|
|
149
149
|
const importedFile = await this.handleImportFile(id, handling, true, ctx, specificImports);
|
|
150
150
|
const ctxImportAnnotation = ctx.import_annotation_expr();
|
|
151
151
|
if (ctxImportAnnotation) {
|
|
152
152
|
const textValue = ctxImportAnnotation.getText().replace('#=', '');
|
|
153
|
-
const {
|
|
153
|
+
const { importedLibrary } = importedFile;
|
|
154
154
|
if (textValue === 'annotate') {
|
|
155
|
-
|
|
155
|
+
importedLibrary.enableRefdesAnnotation = true;
|
|
156
156
|
}
|
|
157
157
|
else if (textValue === 'annotate-external') {
|
|
158
|
-
|
|
158
|
+
importedLibrary.enableRefdesAnnotationFile = true;
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
}
|
|
@@ -417,23 +417,23 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
417
417
|
}
|
|
418
418
|
const useNetNamespace = this.getNetNamespace(executor.netNamespace, passedNetNamespace);
|
|
419
419
|
try {
|
|
420
|
-
const
|
|
421
|
-
&& currentReference.rootValue instanceof
|
|
422
|
-
if (
|
|
423
|
-
this.log('create new
|
|
424
|
-
const
|
|
425
|
-
const
|
|
426
|
-
this.enterFile(
|
|
427
|
-
const newExecutor = this.handleEnterContext(this.getExecutor(), this.executionStack,
|
|
420
|
+
const isLibraryFunction = currentReference.rootValue
|
|
421
|
+
&& currentReference.rootValue instanceof ImportedLibrary;
|
|
422
|
+
if (isLibraryFunction) {
|
|
423
|
+
this.log('create new library context');
|
|
424
|
+
const importedLibrary = currentReference.rootValue;
|
|
425
|
+
const { context: importedLibraryContext } = importedLibrary;
|
|
426
|
+
this.enterFile(importedLibrary.libraryFilePath);
|
|
427
|
+
const newExecutor = this.handleEnterContext(this.getExecutor(), this.executionStack, importedLibraryContext.name, ctx, {
|
|
428
428
|
netNamespace: executor.netNamespace,
|
|
429
|
-
namespace:
|
|
429
|
+
namespace: importedLibrary.libraryNamespace
|
|
430
430
|
}, [], [], false);
|
|
431
|
-
this.log('copy
|
|
432
|
-
|
|
431
|
+
this.log('copy library context scope');
|
|
432
|
+
importedLibraryContext.scope.copyTo(newExecutor.scope);
|
|
433
433
|
}
|
|
434
434
|
const [, functionResult] = executor.callFunction(currentReference, parameters, this.executionStack, useNetNamespace);
|
|
435
|
-
if (
|
|
436
|
-
this.log('pop
|
|
435
|
+
if (isLibraryFunction) {
|
|
436
|
+
this.log('pop library context scope');
|
|
437
437
|
this.handlePopContext(this.getExecutor(), this.executionStack, "", false);
|
|
438
438
|
this.exitFile();
|
|
439
439
|
}
|
|
@@ -712,8 +712,8 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
712
712
|
return item.id === name;
|
|
713
713
|
});
|
|
714
714
|
if (importAlready) {
|
|
715
|
-
const
|
|
716
|
-
const alreadyImportedFlag =
|
|
715
|
+
const { importedLibrary: tmpImportedLibrary } = importAlready;
|
|
716
|
+
const alreadyImportedFlag = tmpImportedLibrary.importHandlingFlag;
|
|
717
717
|
const isMergedNamespace = alreadyImportedFlag === ImportFunctionHandling.AllMergeIntoNamespace
|
|
718
718
|
|| alreadyImportedFlag === ImportFunctionHandling.SpecificMergeIntoNamespace;
|
|
719
719
|
const invalidImportCondition1 = alreadyImportedFlag === ImportFunctionHandling.AllWithNamespace &&
|
|
@@ -727,11 +727,11 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
727
727
|
if (alreadyImportedFlag === ImportFunctionHandling.AllMergeIntoNamespace) {
|
|
728
728
|
}
|
|
729
729
|
else if (alreadyImportedFlag === ImportFunctionHandling.SpecificMergeIntoNamespace && importHandling === ImportFunctionHandling.AllMergeIntoNamespace) {
|
|
730
|
-
|
|
731
|
-
|
|
730
|
+
tmpImportedLibrary.specifiedImports = [];
|
|
731
|
+
tmpImportedLibrary.importHandlingFlag = ImportFunctionHandling.AllMergeIntoNamespace;
|
|
732
732
|
}
|
|
733
733
|
else if (alreadyImportedFlag === ImportFunctionHandling.SpecificMergeIntoNamespace && importHandling === ImportFunctionHandling.SpecificMergeIntoNamespace) {
|
|
734
|
-
|
|
734
|
+
tmpImportedLibrary.specifiedImports.push(...specificImports);
|
|
735
735
|
}
|
|
736
736
|
}
|
|
737
737
|
return importAlready;
|
|
@@ -752,7 +752,7 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
752
752
|
this.log('failed to read file');
|
|
753
753
|
pathExists = false;
|
|
754
754
|
}
|
|
755
|
-
let
|
|
755
|
+
let importedLibrary;
|
|
756
756
|
if (!pathExists) {
|
|
757
757
|
try {
|
|
758
758
|
const tmpFilePath2 = this.environment.getRelativeToDefaultLibs(name + ".cst");
|
|
@@ -773,26 +773,26 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
773
773
|
const executor = this.getExecutor();
|
|
774
774
|
const executionContextName = name;
|
|
775
775
|
const netNamespace = executor.netNamespace;
|
|
776
|
-
const
|
|
776
|
+
const libraryNamespace = `${BaseNamespace}${name}.`;
|
|
777
777
|
this.enterNewChildContext(executionStack, executor, executionContextName, {
|
|
778
778
|
netNamespace,
|
|
779
|
-
namespace:
|
|
779
|
+
namespace: libraryNamespace,
|
|
780
780
|
}, [], []);
|
|
781
781
|
const importResult = await this.onImportFile(this, filePathUsed, fileData, this.onErrorHandler);
|
|
782
782
|
hasError = importResult.hasError;
|
|
783
783
|
hasParseError = importResult.hasParseError;
|
|
784
784
|
const importContext = executionStack.pop();
|
|
785
785
|
this.log(`import handling flag: ${importHandling}`);
|
|
786
|
-
|
|
786
|
+
importedLibrary = new ImportedLibrary(name, libraryNamespace, filePathUsed, importResult.tree, importResult.tokens, importContext, importHandling, specificImports);
|
|
787
787
|
if (specificImports.length > 0) {
|
|
788
788
|
this.log('specific import: ' + specificImports.join(', '));
|
|
789
789
|
}
|
|
790
790
|
const scope = this.getScope();
|
|
791
|
-
scope.
|
|
792
|
-
|
|
793
|
-
scope.
|
|
791
|
+
scope.libraries.set(name, importedLibrary);
|
|
792
|
+
importedLibrary.context.scope.libraries.forEach((lib, key) => {
|
|
793
|
+
scope.libraries.set(key, lib);
|
|
794
794
|
});
|
|
795
|
-
await this.
|
|
795
|
+
await this.checkLibraryHasRefdesFile(filePathUsed);
|
|
796
796
|
}
|
|
797
797
|
}
|
|
798
798
|
catch (err) {
|
|
@@ -820,12 +820,12 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
820
820
|
hasError,
|
|
821
821
|
hasParseError,
|
|
822
822
|
pathExists,
|
|
823
|
-
|
|
823
|
+
importedLibrary: importedLibrary
|
|
824
824
|
};
|
|
825
825
|
this.importedFiles.push(newImportedFile);
|
|
826
826
|
return newImportedFile;
|
|
827
827
|
}
|
|
828
|
-
async
|
|
828
|
+
async checkLibraryHasRefdesFile(filePath) {
|
|
829
829
|
return;
|
|
830
830
|
}
|
|
831
831
|
getRefdesFileAnnotation(filePath, startLine, startColumn, stopLine, stopColumn) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { ComponentTypes } from "./globals.js";
|
|
1
2
|
import { NumericValue } from "./objects/ParamDefinition.js";
|
|
2
|
-
import { TypeProps } from "./objects/types.js";
|
|
3
3
|
export function flattenConditionNodes(conditionNodes, level = 0) {
|
|
4
4
|
const conditionBranches = [];
|
|
5
5
|
conditionNodes.forEach(node => {
|
|
@@ -95,7 +95,7 @@ export function partMatchesConditions(instance, partConditions) {
|
|
|
95
95
|
}
|
|
96
96
|
export function applyPartConditions(instances, paramKeys, partConditions) {
|
|
97
97
|
instances.forEach(item => {
|
|
98
|
-
if (item.typeProp !==
|
|
98
|
+
if (item.typeProp !== ComponentTypes.graphic) {
|
|
99
99
|
const matchedResult = partMatchesConditions(item, partConditions);
|
|
100
100
|
if (matchedResult !== undefined) {
|
|
101
101
|
paramKeys.forEach((paramKey, index) => {
|
|
@@ -3572,7 +3572,7 @@ export class CircuitScriptParser extends antlr.Parser {
|
|
|
3572
3572
|
this.state = 686;
|
|
3573
3573
|
this.match(CircuitScriptParser.Import);
|
|
3574
3574
|
this.state = 687;
|
|
3575
|
-
localContext.
|
|
3575
|
+
localContext._libraryName = this.match(CircuitScriptParser.ID);
|
|
3576
3576
|
this.state = 689;
|
|
3577
3577
|
this.errorHandler.sync(this);
|
|
3578
3578
|
switch (this.interpreter.adaptivePredict(this.tokenStream, 76, this.context)) {
|
|
@@ -3592,7 +3592,7 @@ export class CircuitScriptParser extends antlr.Parser {
|
|
|
3592
3592
|
this.state = 691;
|
|
3593
3593
|
this.match(CircuitScriptParser.From);
|
|
3594
3594
|
this.state = 692;
|
|
3595
|
-
localContext.
|
|
3595
|
+
localContext._libraryName = this.match(CircuitScriptParser.ID);
|
|
3596
3596
|
this.state = 693;
|
|
3597
3597
|
this.match(CircuitScriptParser.Import);
|
|
3598
3598
|
this.state = 694;
|
|
@@ -3616,7 +3616,7 @@ export class CircuitScriptParser extends antlr.Parser {
|
|
|
3616
3616
|
this.state = 698;
|
|
3617
3617
|
this.match(CircuitScriptParser.From);
|
|
3618
3618
|
this.state = 699;
|
|
3619
|
-
localContext.
|
|
3619
|
+
localContext._libraryName = this.match(CircuitScriptParser.ID);
|
|
3620
3620
|
this.state = 700;
|
|
3621
3621
|
this.match(CircuitScriptParser.Import);
|
|
3622
3622
|
this.state = 701;
|
|
@@ -6760,7 +6760,7 @@ export class Import_exprContext extends antlr.ParserRuleContext {
|
|
|
6760
6760
|
}
|
|
6761
6761
|
}
|
|
6762
6762
|
export class Import_specificContext extends Import_exprContext {
|
|
6763
|
-
|
|
6763
|
+
_libraryName;
|
|
6764
6764
|
_ID;
|
|
6765
6765
|
_funcNames = [];
|
|
6766
6766
|
constructor(ctx) {
|
|
@@ -6794,7 +6794,7 @@ export class Import_specificContext extends Import_exprContext {
|
|
|
6794
6794
|
}
|
|
6795
6795
|
}
|
|
6796
6796
|
export class Import_all_simpleContext extends Import_exprContext {
|
|
6797
|
-
|
|
6797
|
+
_libraryName;
|
|
6798
6798
|
constructor(ctx) {
|
|
6799
6799
|
super(ctx.parent, ctx.invokingState);
|
|
6800
6800
|
super.copyFrom(ctx);
|
|
@@ -6824,7 +6824,7 @@ export class Import_all_simpleContext extends Import_exprContext {
|
|
|
6824
6824
|
}
|
|
6825
6825
|
}
|
|
6826
6826
|
export class Import_simpleContext extends Import_exprContext {
|
|
6827
|
-
|
|
6827
|
+
_libraryName;
|
|
6828
6828
|
constructor(ctx) {
|
|
6829
6829
|
super(ctx.parent, ctx.invokingState);
|
|
6830
6830
|
super.copyFrom(ctx);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Big from "big.js";
|
|
2
2
|
import { numeric, NumericValue } from "./objects/ParamDefinition.js";
|
|
3
|
-
import { CFunctionEntry,
|
|
3
|
+
import { CFunctionEntry, ImportedLibrary } from "./objects/types.js";
|
|
4
4
|
import { unwrapValue, resolveToNumericValue, RuntimeExecutionError } from "./utils.js";
|
|
5
5
|
import { BaseNamespace } from "./globals.js";
|
|
6
6
|
const builtInMethods = [
|
|
@@ -149,8 +149,8 @@ function toString(obj) {
|
|
|
149
149
|
else if (obj instanceof CFunctionEntry) {
|
|
150
150
|
return obj.toString();
|
|
151
151
|
}
|
|
152
|
-
else if (obj instanceof
|
|
153
|
-
return `[
|
|
152
|
+
else if (obj instanceof ImportedLibrary) {
|
|
153
|
+
return `[library: ${obj.libraryName}]`;
|
|
154
154
|
}
|
|
155
155
|
else {
|
|
156
156
|
if (obj === undefined) {
|
package/dist/esm/execute.js
CHANGED
|
@@ -646,19 +646,18 @@ export class ExecutionContext {
|
|
|
646
646
|
});
|
|
647
647
|
}
|
|
648
648
|
else {
|
|
649
|
-
const
|
|
650
|
-
for (
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
const
|
|
656
|
-
|
|
657
|
-
if (module.context.hasFunction(functionPath)) {
|
|
649
|
+
const libraries = Array.from(context.scope.libraries.values());
|
|
650
|
+
for (const library of libraries) {
|
|
651
|
+
if (library.importHandlingFlag === ImportFunctionHandling.AllMergeIntoNamespace ||
|
|
652
|
+
(library.importHandlingFlag === ImportFunctionHandling.SpecificMergeIntoNamespace
|
|
653
|
+
&& library.specifiedImports.indexOf(idName) !== -1)) {
|
|
654
|
+
const { context: libraryContext } = library;
|
|
655
|
+
const functionPath = `${libraryContext.namespace}${idName}`;
|
|
656
|
+
if (library.context.hasFunction(functionPath)) {
|
|
658
657
|
return new DeclaredReference({
|
|
659
658
|
found: true,
|
|
660
|
-
rootValue:
|
|
661
|
-
value:
|
|
659
|
+
rootValue: library,
|
|
660
|
+
value: library.context.getFunction(functionPath),
|
|
662
661
|
type: ReferenceTypes.function,
|
|
663
662
|
name: idName,
|
|
664
663
|
trailerIndex: 1,
|
|
@@ -667,24 +666,24 @@ export class ExecutionContext {
|
|
|
667
666
|
}
|
|
668
667
|
}
|
|
669
668
|
}
|
|
670
|
-
let
|
|
671
|
-
if (context.scope.
|
|
672
|
-
const
|
|
673
|
-
if (
|
|
674
|
-
|
|
669
|
+
let isLibrary = false;
|
|
670
|
+
if (context.scope.libraries.has(idName)) {
|
|
671
|
+
const library = context.scope.libraries.get(idName);
|
|
672
|
+
if (library.importHandlingFlag === ImportFunctionHandling.AllWithNamespace) {
|
|
673
|
+
isLibrary = true;
|
|
675
674
|
}
|
|
676
675
|
}
|
|
677
676
|
let isVariable = context.scope.variables.has(idName);
|
|
678
677
|
let isComponentInstance = context.scope.instances.has(idName);
|
|
679
|
-
if (
|
|
680
|
-
const scopeList =
|
|
678
|
+
if (isLibrary || isVariable || isComponentInstance) {
|
|
679
|
+
const scopeList = isLibrary ? context.scope.libraries :
|
|
681
680
|
(isVariable ? context.scope.variables : context.scope.instances);
|
|
682
681
|
const useValue = scopeList.get(idName);
|
|
683
682
|
if (!isComponentInstance && (useValue instanceof ClassComponent)) {
|
|
684
683
|
isComponentInstance = true;
|
|
685
684
|
isVariable = false;
|
|
686
685
|
}
|
|
687
|
-
const referenceType =
|
|
686
|
+
const referenceType = isLibrary ? ReferenceTypes.library :
|
|
688
687
|
(isVariable ? ReferenceTypes.variable : ReferenceTypes.instance);
|
|
689
688
|
const tmpReference = this.resolveTrailers(referenceType, useValue, trailers);
|
|
690
689
|
return new DeclaredReference({
|
|
@@ -731,12 +730,12 @@ export class ExecutionContext {
|
|
|
731
730
|
}
|
|
732
731
|
break;
|
|
733
732
|
}
|
|
734
|
-
case ReferenceTypes.
|
|
733
|
+
case ReferenceTypes.library: {
|
|
735
734
|
const funcName = trailers[0];
|
|
736
|
-
const
|
|
737
|
-
const functionPath = `${
|
|
738
|
-
if (
|
|
739
|
-
const foundFunc =
|
|
735
|
+
const library = rootValue;
|
|
736
|
+
const functionPath = `${library.libraryNamespace}${funcName}`;
|
|
737
|
+
if (library.context.hasFunction(functionPath)) {
|
|
738
|
+
const foundFunc = library.context.getFunction(functionPath);
|
|
740
739
|
return new AnyReference({
|
|
741
740
|
found: true,
|
|
742
741
|
type: ReferenceTypes.function,
|
package/dist/esm/globals.js
CHANGED
|
@@ -87,6 +87,7 @@ export var ComponentTypes;
|
|
|
87
87
|
ComponentTypes["graphic"] = "graphic";
|
|
88
88
|
ComponentTypes["port"] = "port";
|
|
89
89
|
ComponentTypes["module"] = "module";
|
|
90
|
+
ComponentTypes["resistor"] = "res";
|
|
90
91
|
})(ComponentTypes || (ComponentTypes = {}));
|
|
91
92
|
export var ReferenceTypes;
|
|
92
93
|
(function (ReferenceTypes) {
|
|
@@ -95,7 +96,7 @@ export var ReferenceTypes;
|
|
|
95
96
|
ReferenceTypes["variable"] = "variable";
|
|
96
97
|
ReferenceTypes["instance"] = "instance";
|
|
97
98
|
ReferenceTypes["pinType"] = "pinType";
|
|
98
|
-
ReferenceTypes["
|
|
99
|
+
ReferenceTypes["library"] = "library";
|
|
99
100
|
ReferenceTypes["unknown"] = "unknown";
|
|
100
101
|
})(ReferenceTypes || (ReferenceTypes = {}));
|
|
101
102
|
export var BlockTypes;
|
package/dist/esm/graph.js
CHANGED
|
@@ -6,7 +6,7 @@ import { RenderFrame, RenderComponent, applyComponentParamsToSymbol, RenderWire
|
|
|
6
6
|
import { SequenceAction, FrameAction } from "./objects/ExecutionScope.js";
|
|
7
7
|
import { Frame, FixedFrameIds, FrameParamKeys } from "./objects/Frame.js";
|
|
8
8
|
import { numeric } from "./objects/ParamDefinition.js";
|
|
9
|
-
import { NetTypes
|
|
9
|
+
import { NetTypes } from "./objects/types.js";
|
|
10
10
|
import Matrix, { solve } from "ml-matrix";
|
|
11
11
|
import { getPinDefinition, PinId } from "./objects/PinDefinition.js";
|
|
12
12
|
export class NetGraph {
|
|
@@ -232,7 +232,7 @@ export class NetGraph {
|
|
|
232
232
|
const netsLength = netsIndexed.length;
|
|
233
233
|
const conductanceMatrix = Matrix.zeros(netsLength, netsLength);
|
|
234
234
|
components.forEach(item => {
|
|
235
|
-
if (item.typeProp ===
|
|
235
|
+
if (item.typeProp === ComponentTypes.resistor) {
|
|
236
236
|
const net1 = item.pinNets.get(1);
|
|
237
237
|
const net2 = item.pinNets.get(2);
|
|
238
238
|
const net1Index = netsIndexed.indexOf(net1);
|
package/dist/esm/helpers.js
CHANGED
|
@@ -149,7 +149,7 @@ export async function validateScript(filePath, scriptData, options) {
|
|
|
149
149
|
await visitorResolver.visitAsync(tree);
|
|
150
150
|
return visitorResolver;
|
|
151
151
|
}
|
|
152
|
-
async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens, componentLinks,
|
|
152
|
+
async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens, componentLinks, importedLibraries, environment) {
|
|
153
153
|
const { inputPath = null, updateSource = false, saveAnnotatedCopy = undefined, } = options;
|
|
154
154
|
if (inputPath && (updateSource || saveAnnotatedCopy !== undefined)) {
|
|
155
155
|
const annotatedFiles = [{
|
|
@@ -160,29 +160,29 @@ async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens,
|
|
|
160
160
|
filePath: inputPath,
|
|
161
161
|
outputType: RefdesOutputType.WithSource
|
|
162
162
|
}];
|
|
163
|
-
for (const
|
|
163
|
+
for (const library of importedLibraries) {
|
|
164
164
|
let outputType = RefdesOutputType.None;
|
|
165
|
-
if (
|
|
165
|
+
if (library.enableRefdesAnnotation) {
|
|
166
166
|
outputType = RefdesOutputType.WithSource;
|
|
167
167
|
}
|
|
168
|
-
else if (
|
|
168
|
+
else if (library.enableRefdesAnnotationFile) {
|
|
169
169
|
outputType = RefdesOutputType.CreateExternalFile;
|
|
170
170
|
}
|
|
171
171
|
if (outputType !== RefdesOutputType.None) {
|
|
172
|
-
const {
|
|
173
|
-
const
|
|
172
|
+
const { libraryFilePath, libraryName, tokens: libTokens, tree: libTree } = library;
|
|
173
|
+
const libraryScriptData = await environment.readFile(libraryFilePath, { encoding: 'utf8' });
|
|
174
174
|
annotatedFiles.push({
|
|
175
|
-
tokens:
|
|
176
|
-
tree:
|
|
177
|
-
filePath:
|
|
178
|
-
scriptData:
|
|
179
|
-
|
|
175
|
+
tokens: libTokens,
|
|
176
|
+
tree: libTree,
|
|
177
|
+
filePath: libraryFilePath,
|
|
178
|
+
scriptData: libraryScriptData,
|
|
179
|
+
libraryName,
|
|
180
180
|
outputType
|
|
181
181
|
});
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
184
|
for (const item of annotatedFiles) {
|
|
185
|
-
const { scriptData, tokens, tree, filePath,
|
|
185
|
+
const { scriptData, tokens, tree, filePath, libraryName, isMainFile = false } = item;
|
|
186
186
|
const tmpVisitor = new RefdesAnnotationVisitor(true, scriptData, tokens, componentLinks);
|
|
187
187
|
await tmpVisitor.visit(tree);
|
|
188
188
|
let usePath = filePath;
|
|
@@ -208,15 +208,15 @@ async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens,
|
|
|
208
208
|
const relativeFilePath = environment.relative(inputDir, filePath);
|
|
209
209
|
const jsonFile = {
|
|
210
210
|
format: 'v1',
|
|
211
|
-
|
|
211
|
+
library: libraryName,
|
|
212
212
|
file: relativeFilePath,
|
|
213
213
|
items: output,
|
|
214
214
|
};
|
|
215
215
|
environment.writeFileSync(usePath, JSON.stringify(jsonFile, null, 4));
|
|
216
216
|
}
|
|
217
217
|
let display = 'Refdes annotations';
|
|
218
|
-
if (
|
|
219
|
-
display += ` for
|
|
218
|
+
if (libraryName) {
|
|
219
|
+
display += ` for library ${libraryName}`;
|
|
220
220
|
}
|
|
221
221
|
console.log(`${display} saved to ${usePath}`);
|
|
222
222
|
}
|
|
@@ -300,9 +300,9 @@ export async function renderScriptCustom(scriptData, outputPath, options, parseH
|
|
|
300
300
|
throw new RenderError(`Error during component annotation: ${err}`, 'annotation');
|
|
301
301
|
}
|
|
302
302
|
const componentLinks = visitor.getComponentCtxLinks();
|
|
303
|
-
const
|
|
303
|
+
const importedLibraries = Array.from(visitor.getScope().libraries.values());
|
|
304
304
|
for (let i = 0; i < postAnnotationCallbacks.length; i++) {
|
|
305
|
-
await postAnnotationCallbacks[i](options, scriptData, tree, tokens, componentLinks,
|
|
305
|
+
await postAnnotationCallbacks[i](options, scriptData, tree, tokens, componentLinks, importedLibraries, environment);
|
|
306
306
|
}
|
|
307
307
|
if (dumpNets) {
|
|
308
308
|
const nets = visitor.dumpNets();
|
|
@@ -112,37 +112,26 @@ export var Direction;
|
|
|
112
112
|
Direction["Down"] = "down";
|
|
113
113
|
Direction["Up"] = "up";
|
|
114
114
|
})(Direction || (Direction = {}));
|
|
115
|
-
export var TypeProps;
|
|
116
|
-
(function (TypeProps) {
|
|
117
|
-
TypeProps["Net"] = "net";
|
|
118
|
-
TypeProps["Port"] = "port";
|
|
119
|
-
TypeProps["Graphic"] = "graphic";
|
|
120
|
-
TypeProps["Module"] = "module";
|
|
121
|
-
TypeProps["Resistor"] = "res";
|
|
122
|
-
TypeProps["Capacitor"] = "cap";
|
|
123
|
-
TypeProps["Inductor"] = "ind";
|
|
124
|
-
TypeProps["Diode"] = "diode";
|
|
125
|
-
})(TypeProps || (TypeProps = {}));
|
|
126
115
|
export var NetTypes;
|
|
127
116
|
(function (NetTypes) {
|
|
128
117
|
NetTypes["Any"] = "any";
|
|
129
118
|
NetTypes["Source"] = "source";
|
|
130
119
|
})(NetTypes || (NetTypes = {}));
|
|
131
|
-
export class
|
|
132
|
-
|
|
120
|
+
export class ImportedLibrary {
|
|
121
|
+
libraryName;
|
|
133
122
|
context;
|
|
134
123
|
importHandlingFlag;
|
|
135
124
|
specifiedImports;
|
|
136
|
-
|
|
137
|
-
|
|
125
|
+
libraryNamespace;
|
|
126
|
+
libraryFilePath;
|
|
138
127
|
enableRefdesAnnotation = false;
|
|
139
128
|
enableRefdesAnnotationFile = false;
|
|
140
129
|
tree;
|
|
141
130
|
tokens;
|
|
142
|
-
constructor(
|
|
143
|
-
this.
|
|
144
|
-
this.
|
|
145
|
-
this.
|
|
131
|
+
constructor(libraryName, libraryNamespace, libraryFilePath, tree, tokens, context, flag, specifiedImports) {
|
|
132
|
+
this.libraryName = libraryName;
|
|
133
|
+
this.libraryNamespace = libraryNamespace;
|
|
134
|
+
this.libraryFilePath = libraryFilePath;
|
|
146
135
|
this.tree = tree;
|
|
147
136
|
this.tokens = tokens;
|
|
148
137
|
this.context = context;
|
|
@@ -62,13 +62,13 @@ export class SymbolValidatorVisitor extends BaseVisitor {
|
|
|
62
62
|
});
|
|
63
63
|
specifiedImports.push(...tmpImports);
|
|
64
64
|
}
|
|
65
|
-
const id = ctx.
|
|
66
|
-
const { pathExists,
|
|
65
|
+
const id = ctx._libraryName.text;
|
|
66
|
+
const { pathExists, importedLibrary } = await this.handleImportFile(id, handling, true, ctx, specifiedImports);
|
|
67
67
|
if (!pathExists) {
|
|
68
|
-
this.symbolTable.addUndefined(this.getCurrentFile(), this.getExecutor(), id, ctx.
|
|
68
|
+
this.symbolTable.addUndefined(this.getCurrentFile(), this.getExecutor(), id, ctx._libraryName);
|
|
69
69
|
}
|
|
70
70
|
else {
|
|
71
|
-
this.
|
|
71
|
+
this.applyLibraryImports(importedLibrary);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
visitImport_simple = async (ctx) => {
|
|
@@ -80,15 +80,15 @@ export class SymbolValidatorVisitor extends BaseVisitor {
|
|
|
80
80
|
visitImport_specific = async (ctx) => {
|
|
81
81
|
await this.importCommon(ctx, ImportFunctionHandling.SpecificMergeIntoNamespace);
|
|
82
82
|
};
|
|
83
|
-
|
|
84
|
-
const { importHandlingFlag: importHandling, specifiedImports } =
|
|
83
|
+
applyLibraryImports(library) {
|
|
84
|
+
const { importHandlingFlag: importHandling, specifiedImports } = library;
|
|
85
85
|
const addedSymbols = [];
|
|
86
86
|
const executor = this.getExecutor();
|
|
87
87
|
const symbolTable = this.symbolTable.getSymbols();
|
|
88
88
|
symbolTable.forEach((value, key) => {
|
|
89
89
|
if (value.type === ParseSymbolType.Function) {
|
|
90
90
|
const definedSymbol = value;
|
|
91
|
-
if (definedSymbol.fileName ===
|
|
91
|
+
if (definedSymbol.fileName === library.libraryFilePath) {
|
|
92
92
|
const addSymbolToNamespace = importHandling === ImportFunctionHandling.AllMergeIntoNamespace
|
|
93
93
|
|| (importHandling === ImportFunctionHandling.SpecificMergeIntoNamespace
|
|
94
94
|
&& specifiedImports.indexOf(definedSymbol.id) !== -1);
|
package/dist/esm/visitor.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ClassComponent } from './objects/ClassComponent.js';
|
|
|
2
2
|
import { NumberOperator, numeric, NumericValue, ParamDefinition } from './objects/ParamDefinition.js';
|
|
3
3
|
import { PinDefinition, PinId, PinIdType } from './objects/PinDefinition.js';
|
|
4
4
|
import { PinTypes } from './objects/PinTypes.js';
|
|
5
|
-
import { AnyReference, DeclaredReference,
|
|
5
|
+
import { AnyReference, DeclaredReference, UndeclaredReference } from './objects/types.js';
|
|
6
6
|
import { BlockTypes, ComponentTypes, Delimiter1, FrameType, GlobalDocumentName, ModuleContainsKeyword, NoNetText, ParamKeys, RefdesFileSuffix, ReferenceTypes, SymbolPinSide, ValidPinSides, WireAutoDirection } from './globals.js';
|
|
7
7
|
import { unwrapValue } from "./utils.js";
|
|
8
8
|
import { PlaceHolderCommands, SymbolDrawingCommands } from './draw_symbols.js';
|
|
@@ -231,7 +231,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
231
231
|
const display = properties.get('display') ?? null;
|
|
232
232
|
const suffix = properties.get('suffix') ?? null;
|
|
233
233
|
let pins = [];
|
|
234
|
-
if (display !== null && arrange === null && typeProp !==
|
|
234
|
+
if (display !== null && arrange === null && typeProp !== ComponentTypes.graphic) {
|
|
235
235
|
const drawCommands = display.getCommands();
|
|
236
236
|
drawCommands.forEach(command => {
|
|
237
237
|
const [commandValue,] = command;
|
|
@@ -542,7 +542,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
542
542
|
return new PinDefinition(index + 1, PinIdType.Int, portName, PinTypes.Any);
|
|
543
543
|
});
|
|
544
544
|
const arrange = this.getArrangePropFromModulePorts(modulePorts, nameToPinId);
|
|
545
|
-
const unitProperties = this.extractComponentUnitProperties(properties,
|
|
545
|
+
const unitProperties = this.extractComponentUnitProperties(properties, ComponentTypes.module);
|
|
546
546
|
const firstUnitDef = unitProperties[0][1];
|
|
547
547
|
firstUnitDef.pins = tmpPorts;
|
|
548
548
|
firstUnitDef.arrange = arrange;
|
|
@@ -553,7 +553,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
553
553
|
};
|
|
554
554
|
const moduleInstanceName = this.getExecutor().getUniqueInstanceName();
|
|
555
555
|
const moduleComponent = this.getExecutor().createComponent(moduleInstanceName, tmpPorts, blankParams, props, true);
|
|
556
|
-
moduleComponent.typeProp =
|
|
556
|
+
moduleComponent.typeProp = ComponentTypes.module;
|
|
557
557
|
const ctxPropertyBlock = ctx.property_block_expr();
|
|
558
558
|
if (ctxPropertyBlock) {
|
|
559
559
|
const [firstBlock] = ctxPropertyBlock;
|
|
@@ -1375,7 +1375,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
1375
1375
|
children,
|
|
1376
1376
|
});
|
|
1377
1377
|
};
|
|
1378
|
-
async
|
|
1378
|
+
async checkLibraryHasRefdesFile(filePath) {
|
|
1379
1379
|
const dir = this.environment.dirname(filePath);
|
|
1380
1380
|
const ext = this.environment.extname(filePath);
|
|
1381
1381
|
const basename = this.environment.basename(filePath, ext);
|
|
@@ -1652,8 +1652,8 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
1652
1652
|
const fullNetNames = Array.from(uniqueNets).map(item => item.toString());
|
|
1653
1653
|
nets.forEach(([component, pin, net]) => {
|
|
1654
1654
|
if (net.priority === 0 && seenNets.indexOf(net) === -1
|
|
1655
|
-
&& component.typeProp !==
|
|
1656
|
-
&& component.typeProp !==
|
|
1655
|
+
&& component.typeProp !== ComponentTypes.module
|
|
1656
|
+
&& component.typeProp !== ComponentTypes.net) {
|
|
1657
1657
|
net.name = net.baseName =
|
|
1658
1658
|
`NET-(${component.assignedRefDes}-${pin.toString()})`;
|
|
1659
1659
|
if (fullNetNames.indexOf(net.toString()) !== -1) {
|
|
@@ -4,7 +4,7 @@ import { ExecutionContext } from "./execute.js";
|
|
|
4
4
|
import { Logger } from "./logger.js";
|
|
5
5
|
import { ClassComponent } from "./objects/ClassComponent.js";
|
|
6
6
|
import { Net } from "./objects/Net.js";
|
|
7
|
-
import { CallableParameter, ComplexType, Direction, FunctionDefinedParameter, AnyReference,
|
|
7
|
+
import { CallableParameter, ComplexType, Direction, FunctionDefinedParameter, AnyReference, ImportedLibrary, NewContextOptions, ImportFunctionHandling as ImportFunctionHandling } from "./objects/types.js";
|
|
8
8
|
import { CommonTokenStream, ParserRuleContext } from 'antlr4ng';
|
|
9
9
|
import { ExecutionWarning } from "./utils.js";
|
|
10
10
|
import { BaseError } from './utils.js';
|
|
@@ -26,7 +26,7 @@ export declare class BaseVisitor extends CircuitScriptVisitor<ComplexType | AnyR
|
|
|
26
26
|
pinTypesList: string[];
|
|
27
27
|
onErrorHandler: OnErrorHandler | null;
|
|
28
28
|
environment: NodeScriptEnvironment;
|
|
29
|
-
protected importedFiles:
|
|
29
|
+
protected importedFiles: ImportLibraryFile[];
|
|
30
30
|
protected warnings: ExecutionWarning[];
|
|
31
31
|
onImportFile: (visitor: BaseVisitor, filePath: string, fileData: string, onErrorHandler: OnErrorHandler) => Promise<ImportFileResult>;
|
|
32
32
|
refdesFileAnnotations: Map<string, string>;
|
|
@@ -73,8 +73,8 @@ export declare class BaseVisitor extends CircuitScriptVisitor<ComplexType | AnyR
|
|
|
73
73
|
protected linkComponentToCtx(ctx: ParserRuleContext, instance: ClassComponent, creationFlag?: boolean): void;
|
|
74
74
|
getComponentCtxLinks(): Map<ParserRuleContext, ClassComponent>;
|
|
75
75
|
visitResult(ctx: ParserRuleContext): any;
|
|
76
|
-
protected handleImportFile(name: string, importHandling: ImportFunctionHandling, throwErrors?: boolean, ctx?: ParserRuleContext | null, specificImports?: string[]): Promise<
|
|
77
|
-
|
|
76
|
+
protected handleImportFile(name: string, importHandling: ImportFunctionHandling, throwErrors?: boolean, ctx?: ParserRuleContext | null, specificImports?: string[]): Promise<ImportLibraryFile>;
|
|
77
|
+
checkLibraryHasRefdesFile(filePath: string): Promise<void>;
|
|
78
78
|
getRefdesFileAnnotation(filePath: string, startLine: number, startColumn: number, stopLine: number, stopColumn: number): string;
|
|
79
79
|
visitRoundedBracketsExpr: (ctx: RoundedBracketsExprContext) => void;
|
|
80
80
|
protected setupDefinedParameters(funcDefinedParameters: FunctionDefinedParameter[], passedInParameters: CallableParameter[], executor: ExecutionContext): void;
|
|
@@ -94,12 +94,12 @@ export declare class BaseVisitor extends CircuitScriptVisitor<ComplexType | AnyR
|
|
|
94
94
|
getCurrentFile(): string;
|
|
95
95
|
}
|
|
96
96
|
export type OnErrorHandler = (message: string, context: ParserRuleContext, e?: any) => void;
|
|
97
|
-
type
|
|
97
|
+
type ImportLibraryFile = {
|
|
98
98
|
id: string;
|
|
99
99
|
hasError: boolean;
|
|
100
100
|
hasParseError: boolean;
|
|
101
101
|
pathExists: boolean;
|
|
102
|
-
|
|
102
|
+
importedLibrary: ImportedLibrary;
|
|
103
103
|
};
|
|
104
104
|
export type ImportFileResult = {
|
|
105
105
|
hasError: boolean;
|