|
@@ -33,7 +33,7 @@ uses
|
|
Classes, SysUtils,
|
|
Classes, SysUtils,
|
|
fpjson,
|
|
fpjson,
|
|
PScanner, PasResolver, PasUseAnalyzer,
|
|
PScanner, PasResolver, PasUseAnalyzer,
|
|
- Pas2jsLogger, Pas2jsFileUtils, Pas2JSFS;
|
|
|
|
|
|
+ Pas2jsLogger, Pas2jsFileUtils, Pas2JSFS, Pas2JSUtils;
|
|
|
|
|
|
|
|
|
|
type
|
|
type
|
|
@@ -107,7 +107,7 @@ type
|
|
property Sorted: boolean read FSorted write SetSorted; // descending, sort first case insensitive, then sensitive
|
|
property Sorted: boolean read FSorted write SetSorted; // descending, sort first case insensitive, then sensitive
|
|
end;
|
|
end;
|
|
|
|
|
|
- TReadDirectoryEvent = function(Dir: TPas2jsCachedDirectory): boolean of object;// true = skip default function
|
|
|
|
|
|
+ TPas2jsReadDirectoryEvent = function(Dir: TPas2jsCachedDirectory): boolean of object;// true = skip default function
|
|
|
|
|
|
{ TPas2jsCachedDirectories }
|
|
{ TPas2jsCachedDirectories }
|
|
|
|
|
|
@@ -117,7 +117,7 @@ type
|
|
FDirectories: TPasAnalyzerKeySet;// set of TPas2jsCachedDirectory, key is Directory
|
|
FDirectories: TPasAnalyzerKeySet;// set of TPas2jsCachedDirectory, key is Directory
|
|
FWorkingDirectory: string;
|
|
FWorkingDirectory: string;
|
|
private
|
|
private
|
|
- FOnReadDirectory: TReadDirectoryEvent;
|
|
|
|
|
|
+ FOnReadDirectory: TPas2jsReadDirectoryEvent;
|
|
type
|
|
type
|
|
TFileInfo = record
|
|
TFileInfo = record
|
|
Filename: string;
|
|
Filename: string;
|
|
@@ -148,7 +148,7 @@ type
|
|
CreateIfNotExists: boolean = true;
|
|
CreateIfNotExists: boolean = true;
|
|
DoReference: boolean = true): TPas2jsCachedDirectory;
|
|
DoReference: boolean = true): TPas2jsCachedDirectory;
|
|
property WorkingDirectory: string read FWorkingDirectory write SetWorkingDirectory; // used for relative filenames, contains trailing path delimiter
|
|
property WorkingDirectory: string read FWorkingDirectory write SetWorkingDirectory; // used for relative filenames, contains trailing path delimiter
|
|
- property OnReadDirectory: TReadDirectoryEvent read FOnReadDirectory write FOnReadDirectory;
|
|
|
|
|
|
+ property OnReadDirectory: TPas2jsReadDirectoryEvent read FOnReadDirectory write FOnReadDirectory;
|
|
end;
|
|
end;
|
|
|
|
|
|
type
|
|
type
|
|
@@ -205,7 +205,13 @@ type
|
|
function CreateLineReader(RaiseOnError: boolean): TSourceLineReader; override;
|
|
function CreateLineReader(RaiseOnError: boolean): TSourceLineReader; override;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+ TPas2jsFileSrcAttr = packed record
|
|
|
|
+ AllowSrcMap: boolean;
|
|
|
|
+ end;
|
|
|
|
+ PPas2jsFileSrcAttr = ^TPas2jsFileSrcAttr;
|
|
|
|
+
|
|
TPas2jsReadFileEvent = function(aFilename: string; var aSource: string): boolean of object;
|
|
TPas2jsReadFileEvent = function(aFilename: string; var aSource: string): boolean of object;
|
|
|
|
+ TPas2jsGetFileSrcAttrEvent = procedure(aFilename: string; var Attr: TPas2jsFileSrcAttr) of object;
|
|
TPas2jsWriteFileEvent = procedure(aFilename: string; Source: string) of object;
|
|
TPas2jsWriteFileEvent = procedure(aFilename: string; Source: string) of object;
|
|
|
|
|
|
TPas2jsSearchPathKind = (
|
|
TPas2jsSearchPathKind = (
|
|
@@ -225,6 +231,7 @@ type
|
|
FIncludePaths: TStringList;
|
|
FIncludePaths: TStringList;
|
|
FIncludePathsFromCmdLine: integer;
|
|
FIncludePathsFromCmdLine: integer;
|
|
FLog: TPas2jsLogger;
|
|
FLog: TPas2jsLogger;
|
|
|
|
+ FOnGetFileSrcAttr: TPas2jsGetFileSrcAttrEvent;
|
|
FOnReadFile: TPas2jsReadFileEvent;
|
|
FOnReadFile: TPas2jsReadFileEvent;
|
|
FOnWriteFile: TPas2jsWriteFileEvent;
|
|
FOnWriteFile: TPas2jsWriteFileEvent;
|
|
FResetStamp: TChangeStamp;
|
|
FResetStamp: TChangeStamp;
|
|
@@ -234,16 +241,16 @@ type
|
|
FPCUPaths: TStringList;
|
|
FPCUPaths: TStringList;
|
|
function FileExistsILogged(var Filename: string): integer;
|
|
function FileExistsILogged(var Filename: string): integer;
|
|
function FileExistsLogged(const Filename: string): boolean;
|
|
function FileExistsLogged(const Filename: string): boolean;
|
|
- function GetOnReadDirectory: TReadDirectoryEvent;
|
|
|
|
|
|
+ function GetOnReadDirectory: TPas2jsReadDirectoryEvent;
|
|
procedure RegisterMessages;
|
|
procedure RegisterMessages;
|
|
procedure SetBaseDirectory(AValue: string);
|
|
procedure SetBaseDirectory(AValue: string);
|
|
function AddSearchPaths(const Paths: string; Kind: TPas2jsSearchPathKind;
|
|
function AddSearchPaths(const Paths: string; Kind: TPas2jsSearchPathKind;
|
|
FromCmdLine: boolean; var List: TStringList; var CmdLineCount: integer): string;
|
|
FromCmdLine: boolean; var List: TStringList; var CmdLineCount: integer): string;
|
|
- procedure SetOnReadDirectory(AValue: TReadDirectoryEvent);
|
|
|
|
|
|
+ procedure SetOnReadDirectory(AValue: TPas2jsReadDirectoryEvent);
|
|
protected
|
|
protected
|
|
function FindSourceFileName(const aFilename: string): String; override;
|
|
function FindSourceFileName(const aFilename: string): String; override;
|
|
function GetHasPCUSupport: Boolean; virtual;
|
|
function GetHasPCUSupport: Boolean; virtual;
|
|
- function ReadFile(Filename: string; var Source: string): boolean; virtual;
|
|
|
|
|
|
+ function ReadFile(Filename: string; var Source: string; var Attr: TPas2jsFileSrcAttr): boolean; virtual;
|
|
procedure FindMatchingFiles(Mask: string; MaxCount: integer; Files: TStrings);// find files, matching * and ?
|
|
procedure FindMatchingFiles(Mask: string; MaxCount: integer; Files: TStrings);// find files, matching * and ?
|
|
public
|
|
public
|
|
constructor Create(aLog: TPas2jsLogger); overload;
|
|
constructor Create(aLog: TPas2jsLogger); overload;
|
|
@@ -296,8 +303,9 @@ type
|
|
property ResetStamp: TChangeStamp read FResetStamp;
|
|
property ResetStamp: TChangeStamp read FResetStamp;
|
|
property UnitPaths: TStringList read FUnitPaths;
|
|
property UnitPaths: TStringList read FUnitPaths;
|
|
property UnitPathsFromCmdLine: integer read FUnitPathsFromCmdLine;
|
|
property UnitPathsFromCmdLine: integer read FUnitPathsFromCmdLine;
|
|
- property OnReadDirectory: TReadDirectoryEvent read GetOnReadDirectory write SetOnReadDirectory;
|
|
|
|
|
|
+ property OnReadDirectory: TPas2jsReadDirectoryEvent read GetOnReadDirectory write SetOnReadDirectory;
|
|
property OnReadFile: TPas2jsReadFileEvent read FOnReadFile write FOnReadFile;
|
|
property OnReadFile: TPas2jsReadFileEvent read FOnReadFile write FOnReadFile;
|
|
|
|
+ property OnGetFileSrcAttr: TPas2jsGetFileSrcAttrEvent read FOnGetFileSrcAttr write FOnGetFileSrcAttr;
|
|
property OnWriteFile: TPas2jsWriteFileEvent read FOnWriteFile write FOnWriteFile;
|
|
property OnWriteFile: TPas2jsWriteFileEvent read FOnWriteFile write FOnWriteFile;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -1120,6 +1128,7 @@ function TPas2jsCachedFile.Load(RaiseOnError: boolean; Binary: boolean
|
|
var
|
|
var
|
|
NewSource: string;
|
|
NewSource: string;
|
|
b: Boolean;
|
|
b: Boolean;
|
|
|
|
+ SrcAttr: TPas2jsFileSrcAttr;
|
|
begin
|
|
begin
|
|
{$IFDEF VerboseFileCache}
|
|
{$IFDEF VerboseFileCache}
|
|
writeln('TPas2jsCachedFile.Load START "',Filename,'" Loaded=',Loaded);
|
|
writeln('TPas2jsCachedFile.Load START "',Filename,'" Loaded=',Loaded);
|
|
@@ -1157,11 +1166,13 @@ begin
|
|
exit;
|
|
exit;
|
|
end;
|
|
end;
|
|
NewSource:='';
|
|
NewSource:='';
|
|
|
|
+ SrcAttr:=Default(TPas2jsFileSrcAttr);
|
|
|
|
+ SrcAttr.AllowSrcMap:=not Binary;
|
|
if RaiseOnError then
|
|
if RaiseOnError then
|
|
- b:=Cache.ReadFile(Filename,NewSource)
|
|
|
|
|
|
+ b:=Cache.ReadFile(Filename,NewSource,SrcAttr)
|
|
else
|
|
else
|
|
try
|
|
try
|
|
- b:=Cache.ReadFile(Filename,NewSource);
|
|
|
|
|
|
+ b:=Cache.ReadFile(Filename,NewSource,SrcAttr);
|
|
except
|
|
except
|
|
end;
|
|
end;
|
|
if not b then begin
|
|
if not b then begin
|
|
@@ -1187,6 +1198,7 @@ begin
|
|
FLoaded:=true;
|
|
FLoaded:=true;
|
|
FCacheStamp:=Cache.ResetStamp;
|
|
FCacheStamp:=Cache.ResetStamp;
|
|
FLoadedFileAge:=Cache.DirectoryCache.FileAge(Filename);
|
|
FLoadedFileAge:=Cache.DirectoryCache.FileAge(Filename);
|
|
|
|
+ AllowSrcMap:=SrcAttr.AllowSrcMap;
|
|
{$IFDEF VerboseFileCache}
|
|
{$IFDEF VerboseFileCache}
|
|
writeln('TPas2jsCachedFile.Load END ',Filename,' FFileEncoding=',FFileEncoding);
|
|
writeln('TPas2jsCachedFile.Load END ',Filename,' FFileEncoding=',FFileEncoding);
|
|
{$ENDIF}
|
|
{$ENDIF}
|
|
@@ -1344,13 +1356,13 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TPas2jsFilesCache.SetOnReadDirectory(AValue: TReadDirectoryEvent);
|
|
|
|
|
|
+procedure TPas2jsFilesCache.SetOnReadDirectory(AValue: TPas2jsReadDirectoryEvent);
|
|
begin
|
|
begin
|
|
DirectoryCache.OnReadDirectory:=AValue;
|
|
DirectoryCache.OnReadDirectory:=AValue;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TPas2jsFilesCache.ReadFile(Filename: string; var Source: string
|
|
|
|
- ): boolean;
|
|
|
|
|
|
+function TPas2jsFilesCache.ReadFile(Filename: string; var Source: string;
|
|
|
|
+ var Attr: TPas2jsFileSrcAttr): boolean;
|
|
{$IFDEF Pas2js}
|
|
{$IFDEF Pas2js}
|
|
{$ELSE}
|
|
{$ELSE}
|
|
var
|
|
var
|
|
@@ -1361,28 +1373,31 @@ begin
|
|
try
|
|
try
|
|
if Assigned(OnReadFile) then
|
|
if Assigned(OnReadFile) then
|
|
Result:=OnReadFile(Filename,Source);
|
|
Result:=OnReadFile(Filename,Source);
|
|
- if Result then
|
|
|
|
- Exit;
|
|
|
|
- {$IFDEF Pas2js}
|
|
|
|
- try
|
|
|
|
- Source:=NJS_FS.readFileSync(Filename,new(['encoding','utf8']));
|
|
|
|
- except
|
|
|
|
- raise EReadError.Create(String(JSExceptValue));
|
|
|
|
- end;
|
|
|
|
- Result:=true;
|
|
|
|
- {$ELSE}
|
|
|
|
- ms:=TMemoryStream.Create;
|
|
|
|
- try
|
|
|
|
- ms.LoadFromFile(Filename);
|
|
|
|
- SetLength(Source,ms.Size);
|
|
|
|
- ms.Position:=0;
|
|
|
|
- if Source<>'' then
|
|
|
|
- ms.Read(Source[1],length(Source));
|
|
|
|
|
|
+ if not Result then
|
|
|
|
+ begin
|
|
|
|
+ {$IFDEF Pas2js}
|
|
|
|
+ try
|
|
|
|
+ Source:=NJS_FS.readFileSync(Filename,new(['encoding','utf8']));
|
|
|
|
+ except
|
|
|
|
+ raise EReadError.Create(String(JSExceptValue));
|
|
|
|
+ end;
|
|
Result:=true;
|
|
Result:=true;
|
|
- finally
|
|
|
|
- ms.Free;
|
|
|
|
- end;
|
|
|
|
- {$ENDIF}
|
|
|
|
|
|
+ {$ELSE}
|
|
|
|
+ ms:=TMemoryStream.Create;
|
|
|
|
+ try
|
|
|
|
+ ms.LoadFromFile(Filename);
|
|
|
|
+ SetLength(Source,ms.Size);
|
|
|
|
+ ms.Position:=0;
|
|
|
|
+ if Source<>'' then
|
|
|
|
+ ms.Read(Source[1],length(Source));
|
|
|
|
+ Result:=true;
|
|
|
|
+ finally
|
|
|
|
+ ms.Free;
|
|
|
|
+ end;
|
|
|
|
+ {$ENDIF}
|
|
|
|
+ end;
|
|
|
|
+ if Assigned(OnGetFileSrcAttr) then
|
|
|
|
+ OnGetFileSrcAttr(Filename,Attr);
|
|
except
|
|
except
|
|
on E: Exception do begin
|
|
on E: Exception do begin
|
|
EPas2jsFileCache.Create('Error reading file "'+Filename+'": '+E.Message);
|
|
EPas2jsFileCache.Create('Error reading file "'+Filename+'": '+E.Message);
|
|
@@ -2142,7 +2157,7 @@ begin
|
|
Log.LogMsgIgnoreFilter(nSearchingFileNotFound,[FormatPath(Filename)]);
|
|
Log.LogMsgIgnoreFilter(nSearchingFileNotFound,[FormatPath(Filename)]);
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TPas2jsFilesCache.GetOnReadDirectory: TReadDirectoryEvent;
|
|
|
|
|
|
+function TPas2jsFilesCache.GetOnReadDirectory: TPas2jsReadDirectoryEvent;
|
|
begin
|
|
begin
|
|
Result:=DirectoryCache.OnReadDirectory;
|
|
Result:=DirectoryCache.OnReadDirectory;
|
|
end;
|
|
end;
|