pas2jswebcompiler.pp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. unit pas2jswebcompiler;
  2. {$mode objfpc}
  3. interface
  4. uses
  5. Classes, SysUtils, pas2jsfs, pasuseanalyzer, pas2jscompiler, FPPJsSrcMap, webfilecache;
  6. Type
  7. { TPas2JSWebcompiler }
  8. TPas2JSWebcompiler = Class(TPas2JSCompiler)
  9. private
  10. function GetWebFS: TPas2JSWebFS;
  11. Protected
  12. function DoWriteJSFile(const DestFilename: String; aWriter: TPas2JSMapper): Boolean; override;
  13. function CreateSetOfCompilerFiles(keyType: TKeyCompareType): TPasAnalyzerKeySet; override;
  14. function CreateFS : TPas2JSFS; override;
  15. Public
  16. Property WebFS : TPas2JSWebFS read GetWebFS;
  17. end;
  18. implementation
  19. uses js;
  20. function Pas2jsCompilerFile_FilenameToKeyName(Item: Pointer): String;
  21. var
  22. aFile: TPas2jsCompilerFile absolute Item;
  23. begin
  24. Result:=LowerCase(aFile.PasFilename);
  25. end;
  26. function PtrUnitnameToKeyName(Item: Pointer): String;
  27. var
  28. aUnitName: string absolute Item;
  29. begin
  30. Result:=LowerCase(aUnitName);
  31. end;
  32. function Pas2jsCompilerFile_UnitnameToKeyName(Item: Pointer): String;
  33. var
  34. aFile: TPas2jsCompilerFile absolute Item;
  35. begin
  36. Result:=LowerCase(aFile.PasUnitName);
  37. end;
  38. function PtrFilenameToKeyName(FilenameAsPtr: Pointer): string;
  39. var
  40. Filename: String absolute FilenameAsPtr;
  41. begin
  42. Result:=LowerCase(Filename);
  43. end;
  44. { TPas2JSWebcompiler }
  45. function TPas2JSWebcompiler.GetWebFS: TPas2JSWebFS;
  46. begin
  47. Result:=TPas2JSWebFS(FS)
  48. end;
  49. function TPas2JSWebcompiler.DoWriteJSFile(const DestFilename: String; aWriter: TPas2JSMapper): Boolean;
  50. Var
  51. S : String;
  52. begin
  53. // Writeln('aWriter',AWriter.BufferLength,', array size ',Length(AWriter.Buffer));
  54. S:=TJSArray(AWriter.Buffer).Join('');
  55. // Writeln('TPas2JSWebcompiler.DoWriteJSFile(',DestFileName,') (',Length(S),' chars): ',S);
  56. WebFS.SetFileContent(DestFileName,S);
  57. Result:=True;
  58. end;
  59. function TPas2JSWebcompiler.CreateSetOfCompilerFiles(keyType: TKeyCompareType): TPasAnalyzerKeySet;
  60. begin
  61. Case keyType of
  62. kcFileName:
  63. Result:=TPasAnalyzerKeySet.Create(@Pas2jsCompilerFile_FilenameToKeyName,@PtrFilenameToKeyName);
  64. kcUnitName:
  65. Result:=TPasAnalyzerKeySet.Create(@Pas2jsCompilerFile_UnitnameToKeyName,@PtrUnitnameToKeyName);
  66. else
  67. Raise EPas2jsFS.CreateFmt('Internal Unknown key type: %d',[Ord(KeyType)]);
  68. end;
  69. end;
  70. function TPas2JSWebcompiler.CreateFS: TPas2JSFS;
  71. begin
  72. Result:=TPas2JSWebFS.Create;
  73. end;
  74. end.