mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-08-21 05:29:08 +02:00
pastojs: nicer filer error messages
This commit is contained in:
parent
0c50b6a698
commit
a3346a1c63
@ -607,6 +607,7 @@ type
|
|||||||
public
|
public
|
||||||
Owner: TObject;
|
Owner: TObject;
|
||||||
end;
|
end;
|
||||||
|
EPas2JsFilerErrorClass = class of EPas2JsFilerError;
|
||||||
EPas2JsWriteError = class(EPas2JsFilerError);
|
EPas2JsWriteError = class(EPas2JsFilerError);
|
||||||
EPas2JsReadError = class(EPas2JsFilerError);
|
EPas2JsReadError = class(EPas2JsFilerError);
|
||||||
|
|
||||||
@ -663,6 +664,7 @@ type
|
|||||||
|
|
||||||
TPCUFiler = class
|
TPCUFiler = class
|
||||||
private
|
private
|
||||||
|
FErrorClass: EPas2JsFilerErrorClass;
|
||||||
FFileVersion: longint;
|
FFileVersion: longint;
|
||||||
FGUID: TGUID;
|
FGUID: TGUID;
|
||||||
FInitialFlags: TPCUInitialFlags;
|
FInitialFlags: TPCUInitialFlags;
|
||||||
@ -674,7 +676,7 @@ type
|
|||||||
function GetSourceFiles(Index: integer): TPCUSourceFile;
|
function GetSourceFiles(Index: integer): TPCUSourceFile;
|
||||||
protected
|
protected
|
||||||
FElementRefs: TAVLTree; // tree of TPCUFilerElementRef sorted for Element
|
FElementRefs: TAVLTree; // tree of TPCUFilerElementRef sorted for Element
|
||||||
procedure RaiseMsg(Id: int64; const Msg: string = ''); virtual; abstract; overload;
|
procedure RaiseMsg(Id: int64; const Msg: string = ''); virtual; overload;
|
||||||
procedure RaiseMsg(Id: int64; El: TPasElement; const Msg: string = ''); overload;
|
procedure RaiseMsg(Id: int64; El: TPasElement; const Msg: string = ''); overload;
|
||||||
function GetDefaultMemberVisibility(El: TPasElement): TPasMemberVisibility; virtual;
|
function GetDefaultMemberVisibility(El: TPasElement): TPasMemberVisibility; virtual;
|
||||||
function GetDefaultPasScopeVisibilityContext(Scope: TPasScope): TPasElement; virtual;
|
function GetDefaultPasScopeVisibilityContext(Scope: TPasScope): TPasElement; virtual;
|
||||||
@ -701,6 +703,7 @@ type
|
|||||||
property SourceFiles[Index: integer]: TPCUSourceFile read GetSourceFiles;
|
property SourceFiles[Index: integer]: TPCUSourceFile read GetSourceFiles;
|
||||||
property ElementRefs: TAVLTree read FElementRefs;
|
property ElementRefs: TAVLTree read FElementRefs;
|
||||||
property GUID: TGUID read FGUID write FGUID;
|
property GUID: TGUID read FGUID write FGUID;
|
||||||
|
property ErrorClass: EPas2JsFilerErrorClass read FErrorClass write FErrorClass;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TPCUCustomWriter }
|
{ TPCUCustomWriter }
|
||||||
@ -709,6 +712,7 @@ type
|
|||||||
private
|
private
|
||||||
FOnIsElementUsed: TPas2JSIsElementUsedEvent;
|
FOnIsElementUsed: TPas2JSIsElementUsedEvent;
|
||||||
public
|
public
|
||||||
|
constructor Create; override;
|
||||||
procedure WritePCU(aResolver: TPas2JSResolver; aConverter: TPasToJSConverter;
|
procedure WritePCU(aResolver: TPas2JSResolver; aConverter: TPasToJSConverter;
|
||||||
InitFlags: TPCUInitialFlags; aStream: TStream; Compressed: boolean); virtual; abstract;
|
InitFlags: TPCUInitialFlags; aStream: TStream; Compressed: boolean); virtual; abstract;
|
||||||
property OnIsElementUsed: TPas2JSIsElementUsedEvent read FOnIsElementUsed write FOnIsElementUsed;
|
property OnIsElementUsed: TPas2JSIsElementUsedEvent read FOnIsElementUsed write FOnIsElementUsed;
|
||||||
@ -719,12 +723,15 @@ type
|
|||||||
|
|
||||||
TPCUCustomReader = class(TPCUFiler)
|
TPCUCustomReader = class(TPCUFiler)
|
||||||
private
|
private
|
||||||
|
FPCUFilename: string;
|
||||||
FSourceFilename: string;
|
FSourceFilename: string;
|
||||||
public
|
public
|
||||||
|
constructor Create; override;
|
||||||
procedure ReadPCU(aResolver: TPas2JSResolver; aStream: TStream); virtual; abstract;
|
procedure ReadPCU(aResolver: TPas2JSResolver; aStream: TStream); virtual; abstract;
|
||||||
function ReadContinue: boolean; virtual; abstract; // true=finished
|
function ReadContinue: boolean; virtual; abstract; // true=finished
|
||||||
function ReadCanContinue: boolean; virtual; // true=not finished and no pending used interface
|
function ReadCanContinue: boolean; virtual; // true=not finished and no pending used interface
|
||||||
property SourceFilename: string read FSourceFilename write FSourceFilename; // default value for TPasElement.SourceFilename
|
property SourceFilename: string read FSourceFilename write FSourceFilename; // default value for TPasElement.SourceFilename
|
||||||
|
property PCUFilename: string read FPCUFilename write FPCUFilename; // for nicer error messages
|
||||||
end;
|
end;
|
||||||
TPCUReaderClass = class of TPCUCustomReader;
|
TPCUReaderClass = class of TPCUCustomReader;
|
||||||
|
|
||||||
@ -766,7 +773,6 @@ type
|
|||||||
FBuiltInSymbolsArr: TJSONArray;
|
FBuiltInSymbolsArr: TJSONArray;
|
||||||
protected
|
protected
|
||||||
FFirstNewExt, FLastNewExt: TPCUFilerElementRef; // not yet stored external references
|
FFirstNewExt, FLastNewExt: TPCUFilerElementRef; // not yet stored external references
|
||||||
procedure RaiseMsg(Id: int64; const Msg: string = ''); override; overload;
|
|
||||||
procedure ResolvePendingElRefs(Ref: TPCUFilerElementRef);
|
procedure ResolvePendingElRefs(Ref: TPCUFilerElementRef);
|
||||||
function CheckElScope(El: TPasElement; NotNilId: int64; ScopeClass: TPasScopeClass): TPasScope; virtual;
|
function CheckElScope(El: TPasElement; NotNilId: int64; ScopeClass: TPasScopeClass): TPasScope; virtual;
|
||||||
procedure AddArrayFlag(Obj: TJSONObject; var Arr: TJSONArray;
|
procedure AddArrayFlag(Obj: TJSONObject; var Arr: TJSONArray;
|
||||||
@ -1237,6 +1243,7 @@ type
|
|||||||
procedure ReadPCU(aResolver: TPas2JSResolver; aStream: TStream); override; // sets property JSON, reads header and returns
|
procedure ReadPCU(aResolver: TPas2JSResolver; aStream: TStream); override; // sets property JSON, reads header and returns
|
||||||
procedure ReadJSONHeader(aResolver: TPas2JSResolver; Obj: TJSONObject); virtual;
|
procedure ReadJSONHeader(aResolver: TPas2JSResolver; Obj: TJSONObject); virtual;
|
||||||
function ReadContinue: boolean; override; // true=finished
|
function ReadContinue: boolean; override; // true=finished
|
||||||
|
function GetPCUExt: string; virtual; // without dot
|
||||||
property FileVersion: longint read FFileVersion;
|
property FileVersion: longint read FFileVersion;
|
||||||
property JSON: TJSONObject read FJSON;
|
property JSON: TJSONObject read FJSON;
|
||||||
end;
|
end;
|
||||||
@ -1854,6 +1861,14 @@ begin
|
|||||||
AddLine(Line);
|
AddLine(Line);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TPCUCustomWriter }
|
||||||
|
|
||||||
|
constructor TPCUCustomWriter.Create;
|
||||||
|
begin
|
||||||
|
inherited Create;
|
||||||
|
FErrorClass:=EPas2JsWriteError;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TPCUReaderPendingSpecialized }
|
{ TPCUReaderPendingSpecialized }
|
||||||
|
|
||||||
destructor TPCUReaderPendingSpecialized.Destroy;
|
destructor TPCUReaderPendingSpecialized.Destroy;
|
||||||
@ -1874,6 +1889,12 @@ end;
|
|||||||
|
|
||||||
{ TPCUCustomReader }
|
{ TPCUCustomReader }
|
||||||
|
|
||||||
|
constructor TPCUCustomReader.Create;
|
||||||
|
begin
|
||||||
|
inherited Create;
|
||||||
|
FErrorClass:=EPas2JsReadError;
|
||||||
|
end;
|
||||||
|
|
||||||
function TPCUCustomReader.ReadCanContinue: boolean;
|
function TPCUCustomReader.ReadCanContinue: boolean;
|
||||||
var
|
var
|
||||||
Module: TPasModule;
|
Module: TPasModule;
|
||||||
@ -1927,6 +1948,18 @@ begin
|
|||||||
Result:=TPCUSourceFile(FSourceFiles[Index]);
|
Result:=TPCUSourceFile(FSourceFiles[Index]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TPCUFiler.RaiseMsg(Id: int64; const Msg: string);
|
||||||
|
var
|
||||||
|
E: EPas2JsFilerError;
|
||||||
|
begin
|
||||||
|
E:=ErrorClass.Create('['+IntToStr(Id)+'] '+Msg);
|
||||||
|
E.Owner:=Self;
|
||||||
|
{$IFDEF VerbosePCUFiler}
|
||||||
|
writeln(ClassName+'/TPCUFiler.RaiseMsg ',E.Message);
|
||||||
|
{$ENDIF}
|
||||||
|
raise E;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TPCUFiler.RaiseMsg(Id: int64; El: TPasElement; const Msg: string);
|
procedure TPCUFiler.RaiseMsg(Id: int64; El: TPasElement; const Msg: string);
|
||||||
var
|
var
|
||||||
Path, s: String;
|
Path, s: String;
|
||||||
@ -2212,18 +2245,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TPCUWriter.RaiseMsg(Id: int64; const Msg: string);
|
|
||||||
var
|
|
||||||
E: EPas2JsWriteError;
|
|
||||||
begin
|
|
||||||
E:=EPas2JsWriteError.Create('['+IntToStr(Id)+'] '+Msg);
|
|
||||||
E.Owner:=Self;
|
|
||||||
{$IFDEF VerbosePCUFiler}
|
|
||||||
writeln('TPCUWriter.RaiseMsg ',E.Message);
|
|
||||||
{$ENDIF}
|
|
||||||
raise E;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TPCUWriter.CheckElScope(El: TPasElement; NotNilId: int64;
|
function TPCUWriter.CheckElScope(El: TPasElement; NotNilId: int64;
|
||||||
ScopeClass: TPasScopeClass): TPasScope;
|
ScopeClass: TPasScopeClass): TPasScope;
|
||||||
var
|
var
|
||||||
@ -5777,12 +5798,16 @@ end;
|
|||||||
|
|
||||||
procedure TPCUReader.RaiseMsg(Id: int64; const Msg: string);
|
procedure TPCUReader.RaiseMsg(Id: int64; const Msg: string);
|
||||||
var
|
var
|
||||||
E: EPas2JsReadError;
|
E: EPas2JsFilerError;
|
||||||
|
s: String;
|
||||||
begin
|
begin
|
||||||
E:=EPas2JsReadError.Create('['+IntToStr(Id)+'] '+Msg);
|
s:='['+IntToStr(Id)+'] '+Msg;
|
||||||
|
if PCUFilename<>'' then
|
||||||
|
s:=s+' file: '+PCUFilename;
|
||||||
|
E:=ErrorClass.Create(s);
|
||||||
E.Owner:=Self;
|
E.Owner:=Self;
|
||||||
{$IFDEF VerbosePCUFiler}
|
{$IFDEF VerbosePCUFiler}
|
||||||
writeln('TPCUReader.RaiseMsg ',E.Message);
|
writeln(ClassName+'/TPCUReader.RaiseMsg ',E.Message);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
raise E;
|
raise E;
|
||||||
end;
|
end;
|
||||||
@ -6313,9 +6338,9 @@ begin
|
|||||||
writeln('TPCUReader.ReadHeaderVersion ',FFileVersion);
|
writeln('TPCUReader.ReadHeaderVersion ',FFileVersion);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
if FFileVersion<1 then
|
if FFileVersion<1 then
|
||||||
RaiseMsg(20180130201801,'invalid PCU file version');
|
RaiseMsg(20180130201801,'invalid file version');
|
||||||
if FFileVersion>PCUVersion then
|
if FFileVersion>PCUVersion then
|
||||||
RaiseMsg(20180130201822,'pcu file was created by a newer compiler.');
|
RaiseMsg(20180130201822,'file was created by a newer compiler.');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TPCUReader.ReadGUID(Obj: TJSONObject);
|
procedure TPCUReader.ReadGUID(Obj: TJSONObject);
|
||||||
@ -10130,6 +10155,15 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TPCUReader.GetPCUExt: string;
|
||||||
|
begin
|
||||||
|
Result:=ExtractFileExt(PCUFilename);
|
||||||
|
if Result='' then
|
||||||
|
Result:='pcu'
|
||||||
|
else
|
||||||
|
System.Delete(Result,1,1); // remove leading dot
|
||||||
|
end;
|
||||||
|
|
||||||
{ TPas2JSPrecompileFormats }
|
{ TPas2JSPrecompileFormats }
|
||||||
|
|
||||||
function TPas2JSPrecompileFormats.GetItems(Index: integer
|
function TPas2JSPrecompileFormats.GetItems(Index: integer
|
||||||
|
@ -187,6 +187,7 @@ begin
|
|||||||
RaiseInternalError(20180312142954,'');
|
RaiseInternalError(20180312142954,'');
|
||||||
FPCUReader:=FPCUFormat.ReaderClass.Create;
|
FPCUReader:=FPCUFormat.ReaderClass.Create;
|
||||||
FPCUReader.SourceFilename:=ExtractFileName(MyFile.PCUFilename);
|
FPCUReader.SourceFilename:=ExtractFileName(MyFile.PCUFilename);
|
||||||
|
FPCUReader.PCUFilename:=MyFile.PCUFilename;
|
||||||
|
|
||||||
if MyFile.ShowDebug then
|
if MyFile.ShowDebug then
|
||||||
MyFile.Log.LogMsg(nParsingFile,[QuoteStr(MyFile.PCUFilename)]);
|
MyFile.Log.LogMsg(nParsingFile,[QuoteStr(MyFile.PCUFilename)]);
|
||||||
|
Loading…
Reference in New Issue
Block a user