circuitscript 0.1.29 → 0.1.32

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.
Files changed (71) hide show
  1. package/dist/cjs/BaseVisitor.js +185 -22
  2. package/dist/cjs/RefdesAnnotationVisitor.js +27 -10
  3. package/dist/cjs/antlr/CircuitScriptLexer.js +241 -236
  4. package/dist/cjs/antlr/CircuitScriptParser.js +1197 -901
  5. package/dist/cjs/builtinMethods.js +6 -2
  6. package/dist/cjs/draw_symbols.js +38 -34
  7. package/dist/cjs/environment.js +28 -4
  8. package/dist/cjs/execute.js +195 -125
  9. package/dist/cjs/globals.js +6 -1
  10. package/dist/cjs/graph.js +14 -12
  11. package/dist/cjs/helpers.js +90 -17
  12. package/dist/cjs/layout.js +50 -25
  13. package/dist/cjs/main.js +16 -14
  14. package/dist/cjs/objects/ClassComponent.js +199 -30
  15. package/dist/cjs/objects/ExecutionScope.js +9 -0
  16. package/dist/cjs/objects/types.js +25 -2
  17. package/dist/cjs/parser.js +6 -2
  18. package/dist/cjs/regenerate-tests.js +3 -3
  19. package/dist/cjs/render.js +5 -3
  20. package/dist/cjs/rules-check/no-connect-on-connected-pin.js +9 -8
  21. package/dist/cjs/rules-check/rules.js +7 -2
  22. package/dist/cjs/rules-check/unconnected-pins.js +10 -8
  23. package/dist/cjs/utils.js +2 -1
  24. package/dist/cjs/validate/SymbolTable.js +7 -1
  25. package/dist/cjs/validate/SymbolValidatorVisitor.js +54 -17
  26. package/dist/cjs/visitor.js +299 -238
  27. package/dist/esm/BaseVisitor.js +187 -24
  28. package/dist/esm/RefdesAnnotationVisitor.js +27 -10
  29. package/dist/esm/antlr/CircuitScriptLexer.js +241 -236
  30. package/dist/esm/antlr/CircuitScriptParser.js +1196 -899
  31. package/dist/esm/antlr/CircuitScriptVisitor.js +4 -1
  32. package/dist/esm/builtinMethods.js +7 -3
  33. package/dist/esm/draw_symbols.js +38 -34
  34. package/dist/esm/environment.js +25 -1
  35. package/dist/esm/execute.js +197 -127
  36. package/dist/esm/globals.js +4 -0
  37. package/dist/esm/graph.js +14 -12
  38. package/dist/esm/helpers.js +91 -18
  39. package/dist/esm/layout.js +51 -26
  40. package/dist/esm/main.js +16 -14
  41. package/dist/esm/objects/ClassComponent.js +201 -30
  42. package/dist/esm/objects/ExecutionScope.js +9 -0
  43. package/dist/esm/objects/types.js +33 -1
  44. package/dist/esm/parser.js +6 -2
  45. package/dist/esm/regenerate-tests.js +3 -3
  46. package/dist/esm/render.js +5 -3
  47. package/dist/esm/rules-check/no-connect-on-connected-pin.js +9 -8
  48. package/dist/esm/rules-check/rules.js +7 -2
  49. package/dist/esm/rules-check/unconnected-pins.js +10 -8
  50. package/dist/esm/utils.js +2 -1
  51. package/dist/esm/validate/SymbolTable.js +5 -0
  52. package/dist/esm/validate/SymbolValidatorVisitor.js +53 -16
  53. package/dist/esm/visitor.js +201 -137
  54. package/dist/types/BaseVisitor.d.ts +27 -10
  55. package/dist/types/RefdesAnnotationVisitor.d.ts +2 -0
  56. package/dist/types/antlr/CircuitScriptLexer.d.ts +43 -42
  57. package/dist/types/antlr/CircuitScriptParser.d.ts +102 -58
  58. package/dist/types/antlr/CircuitScriptVisitor.d.ts +8 -2
  59. package/dist/types/environment.d.ts +8 -1
  60. package/dist/types/execute.d.ts +6 -3
  61. package/dist/types/globals.d.ts +4 -0
  62. package/dist/types/graph.d.ts +2 -2
  63. package/dist/types/helpers.d.ts +2 -1
  64. package/dist/types/layout.d.ts +5 -4
  65. package/dist/types/objects/ClassComponent.d.ts +34 -9
  66. package/dist/types/objects/ExecutionScope.d.ts +3 -1
  67. package/dist/types/objects/types.d.ts +40 -3
  68. package/dist/types/validate/SymbolTable.d.ts +1 -0
  69. package/dist/types/validate/SymbolValidatorVisitor.d.ts +6 -6
  70. package/dist/types/visitor.d.ts +10 -2
  71. package/package.json +4 -1
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BaseVisitor = void 0;
4
4
  const big_js_1 = require("big.js");
5
+ const CircuitScriptParser_js_1 = require("./antlr/CircuitScriptParser.js");
5
6
  const CircuitScriptVisitor_js_1 = require("./antlr/CircuitScriptVisitor.js");
6
7
  const execute_js_1 = require("./execute.js");
7
8
  const logger_js_1 = require("./logger.js");
@@ -18,10 +19,11 @@ const PinDefinition_js_1 = require("./objects/PinDefinition.js");
18
19
  class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
19
20
  constructor(silent = false, onErrorHandler = null, environment) {
20
21
  super();
21
- this.indentLevel = 0;
22
+ this.filePathStack = [];
22
23
  this.silent = false;
23
24
  this.printStream = [];
24
25
  this.printToConsole = true;
26
+ this.allowParseImports = false;
25
27
  this.acceptedDirections = [types_js_1.Direction.Up, types_js_1.Direction.Down,
26
28
  types_js_1.Direction.Right, types_js_1.Direction.Left];
27
29
  this.resultData = new Map;
@@ -39,19 +41,28 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
39
41
  this.onImportFile = async (visitor, filePath, fileData, onErrorHandler) => {
40
42
  throw "Import file not implemented";
41
43
  };
44
+ this.refdesFileAnnotations = new Map();
42
45
  this.visitScript = async (ctx) => {
43
46
  this.log('===', 'start', '===');
44
- const imports = ctx.import_expr();
45
- for (let i = 0; i < imports.length; i++) {
46
- const ctxImport = imports[i];
47
- const ID = ctxImport.ID().toString();
48
- await this.handleImportFile(ID, true, ctxImport);
47
+ this.allowParseImports = true;
48
+ for (const ctxImport of ctx.import_expr()) {
49
+ await this.visit(ctxImport);
49
50
  }
51
+ this.allowParseImports = false;
50
52
  const result = this.runExpressions(this.getExecutor(), ctx.expression());
51
53
  this.setResult(ctx, result);
52
54
  this.getExecutor().closeOpenPathBlocks();
53
55
  this.log('===', 'end', '===');
54
56
  };
57
+ this.visitImport_simple = async (ctx) => {
58
+ await this.importCommon(ctx, types_js_1.ImportFunctionHandling.AllWithNamespace);
59
+ };
60
+ this.visitImport_all_simple = async (ctx) => {
61
+ await this.importCommon(ctx, types_js_1.ImportFunctionHandling.AllMergeIntoNamespace);
62
+ };
63
+ this.visitImport_specific = async (ctx) => {
64
+ await this.importCommon(ctx, types_js_1.ImportFunctionHandling.SpecificMergeIntoNamespace);
65
+ };
55
66
  this.visitAssignment_expr = (ctx) => {
56
67
  const ctxAtom = ctx.atom_expr();
57
68
  const ctxFuncCallRef = ctx.function_call_expr();
@@ -431,12 +442,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
431
442
  this.logger = new logger_js_1.Logger();
432
443
  this.onErrorHandler = onErrorHandler;
433
444
  this.environment = environment;
434
- this.log('-- Environment --');
435
- this.log('Module directory: ' + environment.getModuleDirectory());
436
- this.log('Default libs path: ' + environment.getDefaultLibsPath());
437
- this.log('Current file: ' + environment.getCurrentFile());
438
- this.log('-----------------');
439
- this.startingContext = new execute_js_1.ExecutionContext(globals_js_1.DoubleDelimiter1, `${globals_js_1.DoubleDelimiter1}.`, '/', 0, 0, silent, this.logger, this.warnings, null);
445
+ this.startingContext = new execute_js_1.ExecutionContext(globals_js_1.DoubleDelimiter1, globals_js_1.BaseNamespace, '/', 0, 0, silent, this.logger, this.warnings, null);
440
446
  const scope = this.startingContext.scope;
441
447
  scope.sequence.push([
442
448
  ExecutionScope_js_1.SequenceAction.At, scope.componentRoot, scope.currentPin
@@ -498,8 +504,9 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
498
504
  };
499
505
  }
500
506
  log(...params) {
501
- const indentOutput = ''.padStart(this.indentLevel * 4, ' ');
502
- const indentLevelText = this.indentLevel.toString().padStart(3, ' ');
507
+ const indentLevel = this.getScope().scopeLevel;
508
+ const indentOutput = ''.padStart(indentLevel * 4, ' ');
509
+ const indentLevelText = indentLevel.toString().padStart(3, ' ');
503
510
  const args = ['[' + indentLevelText + ']', indentOutput, ...params];
504
511
  this.logger.add(args.join(' '));
505
512
  if (!this.silent) {
@@ -513,6 +520,28 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
513
520
  const result = await ctx.accept(this);
514
521
  return result;
515
522
  }
523
+ async importCommon(ctx, handling) {
524
+ const specificImports = [];
525
+ if (ctx instanceof CircuitScriptParser_js_1.Import_specificContext) {
526
+ const tmpSpecificImports = ctx._funcNames.map(item => {
527
+ return item.text;
528
+ });
529
+ specificImports.push(...tmpSpecificImports);
530
+ }
531
+ const id = ctx._moduleName.text;
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
+ }
544
+ }
516
545
  getReference(ctx) {
517
546
  const atomStr = ctx.getText();
518
547
  if (atomStr.indexOf('(') !== -1 || atomStr.indexOf(')') !== -1) {
@@ -538,7 +567,8 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
538
567
  let currentReference = executor.resolveVariable(this.executionStack, atomId);
539
568
  if (ctx.trailer_expr().length > 0) {
540
569
  if (!currentReference.found) {
541
- this.throwWithContext(ctx, "Unknown function name: " + atomId);
570
+ this.log(`could not resolve function: ${atomId}`);
571
+ this.throwWithContext(ctx, "could not resolve function: " + atomId);
542
572
  }
543
573
  currentReference.trailers = [];
544
574
  ctx.trailer_expr().forEach(item => {
@@ -555,7 +585,26 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
555
585
  }
556
586
  const useNetNamespace = this.getNetNamespace(executor.netNamespace, passedNetNamespace);
557
587
  try {
558
- const [, functionResult] = executor.callFunction(currentReference.name, parameters, this.executionStack, useNetNamespace);
588
+ const isModuleFunction = currentReference.rootValue
589
+ && currentReference.rootValue instanceof types_js_1.ImportedModule;
590
+ if (isModuleFunction) {
591
+ this.log('create new module context');
592
+ const importedModule = currentReference.rootValue;
593
+ const importedModuleContext = importedModule.context;
594
+ this.enterFile(importedModule.moduleFilePath);
595
+ const newExecutor = this.handleEnterContext(this.getExecutor(), this.executionStack, importedModuleContext.name, ctx, {
596
+ netNamespace: executor.netNamespace,
597
+ namespace: importedModule.moduleNamespace
598
+ }, [], [], false);
599
+ this.log('copy module context scope');
600
+ importedModuleContext.scope.copyTo(newExecutor.scope);
601
+ }
602
+ const [, functionResult] = executor.callFunction(currentReference, parameters, this.executionStack, useNetNamespace);
603
+ if (isModuleFunction) {
604
+ this.log('pop module context scope');
605
+ this.handlePopContext(this.getExecutor(), this.executionStack, "", false);
606
+ this.exitFile();
607
+ }
559
608
  if ((0, utils_js_1.isReference)(functionResult)) {
560
609
  currentReference = functionResult;
561
610
  }
@@ -582,6 +631,54 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
582
631
  }
583
632
  this.setResult(ctx, currentReference);
584
633
  }
634
+ handleEnterContext(executor, executionStack, contextName, ctx, options, funcDefinedParameters, passedInParameters, isBreakContext = true) {
635
+ if (isBreakContext) {
636
+ const parentBreakContext = executor.getParentBreakContext();
637
+ executor.addBreakContext(ctx);
638
+ let useIndex = -1;
639
+ if (parentBreakContext === null) {
640
+ useIndex = options.functionCallIndex;
641
+ }
642
+ else {
643
+ const parentEntry = executor.indexedStack.get(parentBreakContext);
644
+ const { funcCallIndex } = parentEntry;
645
+ if (!funcCallIndex.has(ctx)) {
646
+ funcCallIndex.set(ctx, 0);
647
+ useIndex = 0;
648
+ }
649
+ else {
650
+ useIndex = funcCallIndex.get(ctx) + 1;
651
+ funcCallIndex.set(ctx, useIndex);
652
+ }
653
+ }
654
+ executor.setBreakContextIndex(useIndex);
655
+ }
656
+ return this.enterNewChildContext(executionStack, executor, contextName, options, funcDefinedParameters, passedInParameters);
657
+ }
658
+ handlePopContext(executor, executionStack, namespaceExtension, isBreakContext = true) {
659
+ const poppedContext = executionStack.pop();
660
+ const nextLastExecution = executionStack[executionStack.length - 1];
661
+ const mergedComponents = nextLastExecution.mergeScope(poppedContext.scope, namespaceExtension);
662
+ if (isBreakContext) {
663
+ const scope = this.getScope();
664
+ const indexedStack = [];
665
+ if (scope.breakStack.length > 0) {
666
+ const executor = this.getExecutor();
667
+ scope.breakStack.forEach(stackCtx => {
668
+ const entry = executor.indexedStack.get(stackCtx);
669
+ const { index } = entry;
670
+ indexedStack.push([stackCtx, index]);
671
+ });
672
+ mergedComponents.forEach(component => {
673
+ component.ctxReferences.forEach(ref => {
674
+ ref.indexedStack = [...indexedStack, ...ref.indexedStack];
675
+ });
676
+ });
677
+ }
678
+ executor.popBreakContext();
679
+ }
680
+ return poppedContext;
681
+ }
585
682
  setResult(ctx, value) {
586
683
  this.resultData.set(ctx, value);
587
684
  }
@@ -602,7 +699,8 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
602
699
  instance.ctxReferences.push({
603
700
  ctx,
604
701
  indexedStack,
605
- creationFlag
702
+ creationFlag,
703
+ filePath: this.getCurrentFile(),
606
704
  });
607
705
  this.componentCtxLinks.set(ctx, instance);
608
706
  }
@@ -613,12 +711,34 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
613
711
  this.visit(ctx);
614
712
  return this.getResult(ctx);
615
713
  }
616
- async handleImportFile(name, throwErrors = true, ctx = null) {
714
+ async handleImportFile(name, importHandling, throwErrors = true, ctx = null, specificImports = []) {
617
715
  name = name.trim();
618
716
  const importAlready = this.importedFiles.find(item => {
619
717
  return item.id === name;
620
718
  });
621
719
  if (importAlready) {
720
+ const tmpImportedModule = importAlready.importedModule;
721
+ const alreadyImportedFlag = tmpImportedModule.importHandlingFlag;
722
+ const isMergedNamespace = alreadyImportedFlag === types_js_1.ImportFunctionHandling.AllMergeIntoNamespace
723
+ || alreadyImportedFlag === types_js_1.ImportFunctionHandling.SpecificMergeIntoNamespace;
724
+ const invalidImportCondition1 = alreadyImportedFlag === types_js_1.ImportFunctionHandling.AllWithNamespace &&
725
+ importHandling !== types_js_1.ImportFunctionHandling.AllWithNamespace;
726
+ const invalidImportCondition2 = alreadyImportedFlag !== types_js_1.ImportFunctionHandling.AllWithNamespace &&
727
+ importHandling === types_js_1.ImportFunctionHandling.AllWithNamespace;
728
+ if (invalidImportCondition1 || invalidImportCondition2) {
729
+ throw new utils_js_2.RuntimeExecutionError(`Namespace import and wildcard/specific imports cannot be mixed: ${name}`, ctx);
730
+ }
731
+ if (isMergedNamespace) {
732
+ if (alreadyImportedFlag === types_js_1.ImportFunctionHandling.AllMergeIntoNamespace) {
733
+ }
734
+ else if (alreadyImportedFlag === types_js_1.ImportFunctionHandling.SpecificMergeIntoNamespace && importHandling === types_js_1.ImportFunctionHandling.AllMergeIntoNamespace) {
735
+ tmpImportedModule.specifiedImports = [];
736
+ tmpImportedModule.importHandlingFlag = types_js_1.ImportFunctionHandling.AllMergeIntoNamespace;
737
+ }
738
+ else if (alreadyImportedFlag === types_js_1.ImportFunctionHandling.SpecificMergeIntoNamespace && importHandling === types_js_1.ImportFunctionHandling.SpecificMergeIntoNamespace) {
739
+ tmpImportedModule.specifiedImports.push(...specificImports);
740
+ }
741
+ }
622
742
  return importAlready;
623
743
  }
624
744
  let hasError = false;
@@ -637,6 +757,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
637
757
  this.log('failed to read file');
638
758
  pathExists = false;
639
759
  }
760
+ let importedModule;
640
761
  if (!pathExists) {
641
762
  try {
642
763
  const tmpFilePath2 = this.environment.getRelativeToDefaultLibs(name + ".cst");
@@ -651,16 +772,37 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
651
772
  }
652
773
  }
653
774
  try {
654
- if (pathExists) {
775
+ if (pathExists && filePathUsed) {
655
776
  this.log('done reading imported file data');
777
+ const executionStack = this.executionStack;
778
+ const executor = this.getExecutor();
779
+ const executionContextName = name;
780
+ const netNamespace = executor.netNamespace;
781
+ const moduleNamespace = `${globals_js_1.BaseNamespace}${name}.`;
782
+ this.enterNewChildContext(executionStack, executor, executionContextName, {
783
+ netNamespace,
784
+ namespace: moduleNamespace,
785
+ }, [], []);
656
786
  const importResult = await this.onImportFile(this, filePathUsed, fileData, this.onErrorHandler);
657
787
  hasError = importResult.hasError;
658
788
  hasParseError = importResult.hasParseError;
789
+ const importContext = executionStack.pop();
790
+ this.log(`import handling flag: ${importHandling}`);
791
+ importedModule = new types_js_1.ImportedModule(name, moduleNamespace, filePathUsed, importResult.tree, importResult.tokens, importContext, importHandling, specificImports);
792
+ if (specificImports.length > 0) {
793
+ this.log('specific import: ' + specificImports.join(', '));
794
+ }
795
+ const scope = this.getScope();
796
+ scope.modules.set(name, importedModule);
797
+ importedModule.context.scope.modules.forEach((module, key) => {
798
+ scope.modules.set(key, module);
799
+ });
800
+ await this.checkModuleHasRefdesFile(filePathUsed);
659
801
  }
660
802
  }
661
803
  catch (err) {
662
804
  if (ctx != null) {
663
- throw new utils_js_2.RuntimeExecutionError("An error occurred while importing file", ctx);
805
+ throw err;
664
806
  }
665
807
  else {
666
808
  this.log('An error occurred while importing file:', err.message);
@@ -683,10 +825,17 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
683
825
  hasError,
684
826
  hasParseError,
685
827
  pathExists,
828
+ importedModule: importedModule
686
829
  };
687
830
  this.importedFiles.push(newImportedFile);
688
831
  return newImportedFile;
689
832
  }
833
+ async checkModuleHasRefdesFile(filePath) {
834
+ return;
835
+ }
836
+ getRefdesFileAnnotation(filePath, startLine, startColumn, stopLine, stopColumn) {
837
+ return `${filePath}:${startLine}:${startColumn}:${stopLine}:${stopColumn}`;
838
+ }
690
839
  setupDefinedParameters(funcDefinedParameters, passedInParameters, executor) {
691
840
  for (let i = 0; i < funcDefinedParameters.length; i++) {
692
841
  const tmpFuncArg = funcDefinedParameters[i];
@@ -770,14 +919,17 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
770
919
  return object.getParam(paramName);
771
920
  }
772
921
  enterNewChildContext(executionStack, parentContext, executionContextName, options, funcDefinedParameters, passedInParameters) {
773
- const { netNamespace = "" } = options;
922
+ const { netNamespace = "", namespace = null, } = options;
774
923
  const currentExecutionContext = executionStack[executionStack.length - 1];
775
924
  const executionLevel = currentExecutionContext.executionLevel;
776
- const executionContextNamespace = currentExecutionContext.namespace
925
+ const executionContextNamespace = namespace ?? currentExecutionContext.namespace
777
926
  + executionContextName + ".";
778
927
  const newExecutor = new execute_js_1.ExecutionContext(executionContextName, executionContextNamespace, netNamespace, executionLevel + 1, this.getExecutor().scope.scopeLevel + 1, currentExecutionContext.silent, currentExecutionContext.logger, currentExecutionContext.warnings, parentContext);
779
928
  executionStack.push(newExecutor);
780
929
  this.setupDefinedParameters(funcDefinedParameters, passedInParameters, newExecutor);
930
+ newExecutor.resolveNet = this.createNetResolver(executionStack);
931
+ newExecutor.resolveComponentPinNet =
932
+ this.createComponentPinNetResolver(executionStack);
781
933
  return newExecutor;
782
934
  }
783
935
  prepareStringValue(value) {
@@ -811,5 +963,16 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
811
963
  return (val instanceof ParamDefinition_js_1.NumericValue);
812
964
  }, 'numeric value');
813
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
+ }
814
977
  }
815
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
- const result = this.runExpressions(this.getExecutor(), ctx.expression());
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
- const annotation = ' #= ' + allRefdes.join(',');
47
- this.modifications.set(ctx, originalText + annotation);
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
- if (!instance.hasParam('refdes')
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
- const annotation = ' #= ' + refdes;
110
- this.modifications.set(ctx, originalText + annotation);
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;