Browse Source

pastojs: started filer

git-svn-id: trunk@38049 -
Mattias Gaertner 7 years ago
parent
commit
adbb998377

+ 2 - 0
.gitattributes

@@ -6885,6 +6885,7 @@ packages/pastojs/src/fppjssrcmap.pp svneol=native#text/plain
 packages/pastojs/src/pas2js_defines.inc svneol=native#text/plain
 packages/pastojs/src/pas2jscompiler.pp svneol=native#text/plain
 packages/pastojs/src/pas2jsfilecache.pp svneol=native#text/plain
+packages/pastojs/src/pas2jsfiler.pp svneol=native#text/plain
 packages/pastojs/src/pas2jsfileutils.pp svneol=native#text/plain
 packages/pastojs/src/pas2jsfileutilsunix.inc svneol=native#text/plain
 packages/pastojs/src/pas2jsfileutilswin.inc svneol=native#text/plain
@@ -6892,6 +6893,7 @@ packages/pastojs/src/pas2jslibcompiler.pp svneol=native#text/plain
 packages/pastojs/src/pas2jslogger.pp svneol=native#text/plain
 packages/pastojs/src/pas2jspparser.pp svneol=native#text/plain
 packages/pastojs/tests/tcconverter.pp svneol=native#text/plain
+packages/pastojs/tests/tcfiler.pas svneol=native#text/plain
 packages/pastojs/tests/tcmodules.pas svneol=native#text/plain
 packages/pastojs/tests/tcoptimizations.pas svneol=native#text/plain
 packages/pastojs/tests/tcsrcmap.pas svneol=native#text/plain

+ 1 - 0
packages/pastojs/src/fppas2js.pp

@@ -282,6 +282,7 @@ ToDos:
   a:=[];
 - bug:
   v:=a[0]  gives Local variable "a" is assigned but never used
+- setlength(dynarray)  modeswitch to create a copy
 - range checks:
   - compile time: warnings to errors
   - proc args enum, custom enum, custom int

+ 14 - 1
packages/pastojs/src/pas2jsfilecache.pp

@@ -1,4 +1,17 @@
-{ Author: Mattias Gaertner  2017  [email protected]
+{
+    This file is part of the Free Component Library (FCL)
+    Copyright (c) 2018  Mattias Gaertner  [email protected]
+
+    Pascal to Javascript converter class.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************
 
   Abstract:
     TPas2jsFileResolver extends TFileResolver and searches source files.

+ 50 - 0
packages/pastojs/src/pas2jsfiler.pp

@@ -0,0 +1,50 @@
+{
+    This file is part of the Free Component Library (FCL)
+    Copyright (c) 2018  Mattias Gaertner  [email protected]
+
+    Pascal to Javascript converter class.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************
+
+Abstract:
+  Write and read a precompiled module.
+
+  Store whole unit, except all
+  procedure declarations, proc bodies, finalization/initialization sections are
+  replaced by
+    -precompiled code
+    -lists of references
+    -local consts
+  The useanalyzer needs the references - TPas2jsUseAnalyzer.
+
+  Due to uses cycles, ability to stop read interface
+  ReadContinueImplementation
+}
+unit Pas2JsFiler;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+  Classes, SysUtils, FPPas2Js, PasResolver, PasTree;
+
+type
+  TPasToJsFiler = class
+  public
+    constructor Create; virtual;
+    destructor Destroy; override;
+    procedure WriteModule(aResolver: TPasResolver);
+  end;
+
+implementation
+
+end.
+

+ 14 - 1
packages/pastojs/src/pas2jsfileutils.pp

@@ -1,4 +1,17 @@
-{ Author: Mattias Gaertner  2017  [email protected]
+{
+    This file is part of the Free Component Library (FCL)
+    Copyright (c) 2018  Mattias Gaertner  [email protected]
+
+    Pascal to Javascript converter class.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************
 
   Abstract:
     Low level file path handling.

+ 15 - 0
packages/pastojs/src/pas2jsfileutilsunix.inc

@@ -1,4 +1,19 @@
 {%MainUnit pas2jsfileutils.pas}
+{
+    This file is part of the Free Component Library (FCL)
+    Copyright (c) 2018  Mattias Gaertner  [email protected]
+
+    Pascal to Javascript converter class.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************
+}
 
 function FilenameIsAbsolute(const aFilename: string): boolean;
 begin

+ 14 - 0
packages/pastojs/src/pas2jsfileutilswin.inc

@@ -1,5 +1,19 @@
 {%MainUnit pas2jsfileutils.pas}
+{
+    This file is part of the Free Component Library (FCL)
+    Copyright (c) 2018  Mattias Gaertner  [email protected]
 
+    Pascal to Javascript converter class.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************
+}
 {$IF DEFINED(UTF8_RTL) AND NOT DEFINED(WINCE)}
   {$DEFINE ArgsWAsUTF8}
 {$ENDIF}

+ 15 - 0
packages/pastojs/src/pas2jslibcompiler.pp

@@ -1,3 +1,18 @@
+{
+    This file is part of the Free Component Library (FCL)
+    Copyright (c) 2018  Michael Van Canneyt
+
+    Pascal to Javascript converter class.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************
+}
 unit pas2jslibcompiler;
 
 {$mode objfpc}

+ 14 - 1
packages/pastojs/src/pas2jslogger.pp

@@ -1,4 +1,17 @@
-{ Author: Mattias Gaertner  2017  [email protected]
+{
+    This file is part of the Free Component Library (FCL)
+    Copyright (c) 2018  Mattias Gaertner  [email protected]
+
+    Pascal to Javascript converter class.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************
 
   Abstract:
     Logging to stdout or file.

+ 14 - 1
packages/pastojs/src/pas2jspparser.pp

@@ -1,4 +1,17 @@
-{ Author: Mattias Gaertner  2017  [email protected]
+{
+    This file is part of the Free Component Library (FCL)
+    Copyright (c) 2018  Mattias Gaertner  [email protected]
+
+    Pascal to Javascript converter class.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************
 
   Abstract:
     Extends the FCL Pascal parser for the language subset of pas2js.

+ 85 - 0
packages/pastojs/tests/tcfiler.pas

@@ -0,0 +1,85 @@
+{
+    This file is part of the Free Component Library (FCL)
+    Copyright (c) 2014 by Michael Van Canneyt
+
+    Unit tests for Pascal-to-Javascript precompile class.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************
+
+ Examples:
+   ./testpas2js --suite=TTestPrecompile.TestPC_EmptyUnit
+}
+unit tcfiler;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+  Classes, SysUtils, fpcunit, testregistry,
+  PasTree, PScanner, PasResolver,
+  FPPas2Js,
+  tcmodules;
+
+type
+
+  { TCustomTestPrecompile }
+
+  TCustomTestPrecompile = Class(TCustomTestModule)
+  protected
+    procedure SetUp; override;
+    procedure TearDown; override;
+    procedure WriteUnit; virtual;
+  public
+  end;
+
+  { TTestPrecompile }
+
+  TTestPrecompile = class(TCustomTestPrecompile)
+  published
+    procedure TestPC_EmptyUnit;
+  end;
+
+implementation
+
+{ TCustomTestPrecompile }
+
+procedure TCustomTestPrecompile.SetUp;
+begin
+  inherited SetUp;
+
+end;
+
+procedure TCustomTestPrecompile.TearDown;
+begin
+
+  inherited TearDown;
+end;
+
+procedure TCustomTestPrecompile.WriteUnit;
+begin
+
+end;
+
+{ TTestPrecompile }
+
+procedure TTestPrecompile.TestPC_EmptyUnit;
+begin
+  StartUnit(false);
+  Add('interface');
+  Add('implementation');
+  ConvertUnit;
+  WriteUnit;
+end;
+
+Initialization
+  RegisterTests([TTestPrecompile]);
+end.
+

+ 9 - 1
packages/pastojs/tests/testpas2js.lpi

@@ -32,7 +32,7 @@
         <PackageName Value="FCL"/>
       </Item2>
     </RequiredPackages>
-    <Units Count="7">
+    <Units Count="9">
       <Unit0>
         <Filename Value="testpas2js.pp"/>
         <IsPartOfProject Value="True"/>
@@ -63,6 +63,14 @@
         <IsPartOfProject Value="True"/>
         <UnitName Value="FPPJsSrcMap"/>
       </Unit6>
+      <Unit7>
+        <Filename Value="tcfiler.pas"/>
+        <IsPartOfProject Value="True"/>
+      </Unit7>
+      <Unit8>
+        <Filename Value="../src/pas2jsfiler.pas"/>
+        <IsPartOfProject Value="True"/>
+      </Unit8>
     </Units>
   </ProjectOptions>
   <CompilerOptions>

+ 2 - 1
packages/pastojs/tests/testpas2js.pp

@@ -17,7 +17,8 @@ program testpas2js;
 {$mode objfpc}{$H+}
 
 uses
-  Classes, consoletestrunner, tcconverter, tcmodules, tcoptimizations, tcsrcmap;
+  Classes, consoletestrunner, tcconverter, tcmodules, tcoptimizations, tcsrcmap,
+  tcfiler, pas2jsfiler;
 
 type