mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-10 20:56:14 +02:00
CompilerOptions: formatting, refactoring and cleanup of compiler messages code
git-svn-id: trunk@39059 -
This commit is contained in:
parent
70da0a47bf
commit
08bdcbcf3f
@ -395,9 +395,9 @@ type
|
||||
function FindHash(AIndex: integer):TCompilerMessageConfig ;
|
||||
|
||||
function GetMsgConfigByIndex(AIndex: Integer): TCompilerMessageConfig;
|
||||
function GetMsgConfig(i: Integer): TCompilerMessageConfig; virtual;
|
||||
procedure SetMsgState(i: Integer; const AValue: TCompilerMessageState); virtual;
|
||||
function GetMsgState(i: Integer): TCompilerMessageState; virtual;
|
||||
function GetMsgConfig(i: Integer): TCompilerMessageConfig;
|
||||
procedure SetMsgState(i: Integer; const AValue: TCompilerMessageState);
|
||||
function GetMsgState(i: Integer): TCompilerMessageState;
|
||||
|
||||
procedure GetStateArray(var b: array of TCompilerMessageState); // array must be large enough
|
||||
procedure SetStateArray(const b: array of TCompilerMessageState); // to store b[MaxMsgIndex], or function fail
|
||||
@ -405,26 +405,27 @@ type
|
||||
function GetCount: Integer;
|
||||
function GetErrorNames(errtype: TFPCErrorType): string;
|
||||
|
||||
property ChangeStamp: int64 read FChangeStamp;
|
||||
procedure IncreaseChangeStamp;
|
||||
property ChangeStamp: int64 read FChangeStamp;
|
||||
property OnChanged: TNotifyEvent read FOnChanged write FOnChanged;
|
||||
public
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
procedure Clear; virtual;
|
||||
procedure Clear;
|
||||
|
||||
procedure Assign(Src: TCompilerMessagesList); virtual;
|
||||
procedure Assign(Src: TCompilerMessagesList);
|
||||
|
||||
procedure BeginUpdate; virtual;
|
||||
procedure EndUpdate; virtual;
|
||||
procedure BeginUpdate;
|
||||
procedure EndUpdate;
|
||||
|
||||
function LoadMsgFile(const FileName: string): Boolean; virtual;
|
||||
function LoadMsgFile(const FileName: string): Boolean;
|
||||
|
||||
function Add(AMsgIndex: Integer; AMsgType: TFPCErrorType; const AMsgText: string; DefIgnored: Boolean = false; AState: TCompilerMessageState = msDefault): TCompilerMessageConfig; virtual;
|
||||
function Add(AMsgIndex: Integer; AMsgType: TFPCErrorType; const AMsgText: string;
|
||||
DefIgnored: Boolean = false; AState: TCompilerMessageState = msDefault): TCompilerMessageConfig;
|
||||
|
||||
procedure SetDefault(KeepState: Boolean=true); virtual;
|
||||
function GetParams(MsgIndex: Integer; var prms: array of string; out PrmCount: Integer): Integer; virtual;
|
||||
function Equals(Obj: TObject): boolean; {$ifndef ver2_4_0}override;{$endif}
|
||||
procedure SetDefault(KeepState: Boolean=true);
|
||||
function GetParams(MsgIndex: Integer; var prms: array of string; out PrmCount: Integer): Integer;
|
||||
function Equals(Obj: TObject): boolean; override;
|
||||
|
||||
property Msg[i: Integer]: TCompilerMessageConfig read GetMsgConfig;
|
||||
property MsgByIndex[AIndex: Integer]: TCompilerMessageConfig read GetMsgConfigByIndex;
|
||||
@ -1519,7 +1520,7 @@ begin
|
||||
Win32GraphicApp := aXMLConfig.GetValue(p+'Options/Win32/GraphicApplication/Value', false);
|
||||
ExecutableType := CompilationExecutableTypeNameToType(
|
||||
aXMLConfig.GetValue(p+'Options/ExecutableType/Value',''));
|
||||
//DebugLn('TBaseCompilerOptions.LoadTheCompilerOptions ',CompilationExecutableTypeNames[ExecutableType]);
|
||||
//DebugLn('TBaseCompilerOptions.LoadFromXMLConfig ',CompilationExecutableTypeNames[ExecutableType]);
|
||||
|
||||
{ Messages }
|
||||
p:=Path+'Other/';
|
||||
@ -1564,11 +1565,11 @@ begin
|
||||
with aXMLConfig do begin
|
||||
// ErrorNames should be stored, because the Message file is not read (or parsed)
|
||||
// on project opening. So errors needs to be initialized properly from the CompilerOptions.xml
|
||||
CompilerMessages.fErrorNames[etHint]:=GetValue(p+'CompilerMessages/ErrorNames/Hint', FPCErrorTypeNames[etHint]);
|
||||
CompilerMessages.fErrorNames[etNote]:=GetValue(p+'CompilerMessages/ErrorNames/Note', FPCErrorTypeNames[etNote]);
|
||||
CompilerMessages.fErrorNames[etWarning]:=GetValue(p+'CompilerMessages/ErrorNames/Warning', FPCErrorTypeNames[etWarning]);
|
||||
CompilerMessages.fErrorNames[etError]:=GetValue(p+'CompilerMessages/ErrorNames/Error', FPCErrorTypeNames[etError]);
|
||||
CompilerMessages.fErrorNames[etFatal]:=GetValue(p+'CompilerMessages/ErrorNames/Fatal', FPCErrorTypeNames[etFatal]);
|
||||
fCompilerMessages.fErrorNames[etHint]:=GetValue(p+'fCompilerMessages/ErrorNames/Hint', FPCErrorTypeNames[etHint]);
|
||||
fCompilerMessages.fErrorNames[etNote]:=GetValue(p+'fCompilerMessages/ErrorNames/Note', FPCErrorTypeNames[etNote]);
|
||||
fCompilerMessages.fErrorNames[etWarning]:=GetValue(p+'fCompilerMessages/ErrorNames/Warning', FPCErrorTypeNames[etWarning]);
|
||||
fCompilerMessages.fErrorNames[etError]:=GetValue(p+'fCompilerMessages/ErrorNames/Error', FPCErrorTypeNames[etError]);
|
||||
fCompilerMessages.fErrorNames[etFatal]:=GetValue(p+'fCompilerMessages/ErrorNames/Fatal', FPCErrorTypeNames[etFatal]);
|
||||
end;
|
||||
|
||||
|
||||
@ -4390,7 +4391,8 @@ procedure TCompilerMessagesList.ClearHash;
|
||||
var
|
||||
i : integer;
|
||||
begin
|
||||
for i := 0 to length(fHash) - 1 do SetLength(fHash[i], 0);
|
||||
for i := 0 to length(fHash) - 1 do
|
||||
SetLength(fHash[i], 0);
|
||||
end;
|
||||
|
||||
procedure TCompilerMessagesList.AddHash(Msg: TCompilerMessageConfig);
|
||||
@ -4421,11 +4423,9 @@ begin
|
||||
idx := AIndex div 1000;
|
||||
sub := AIndex mod 1000;
|
||||
Result := nil;
|
||||
if (idx >= 0) and (idx < length(fHash)) then begin
|
||||
if (idx >= 0) and (idx < length(fHash)) then
|
||||
if (sub >= 0) and (sub < length(fHash[idx])) then
|
||||
Result := fHash[idx][sub];
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
function TCompilerMessagesList.GetMsgConfigByIndex(AIndex: Integer): TCompilerMessageConfig;
|
||||
@ -4744,57 +4744,6 @@ begin
|
||||
Result := msgconf;
|
||||
end;
|
||||
|
||||
function GetNextNumber(const s: string; var index: Integer; var Num : Integer): Boolean;
|
||||
var
|
||||
i : integer;
|
||||
err:Integer;
|
||||
begin
|
||||
i := index;
|
||||
while (i <= length(s)) and (s[i] in ['0'..'9']) do inc (i);
|
||||
Result := i - index > 0;
|
||||
if Result then begin
|
||||
Val(Copy(s, Index, i - Index), Num, err);
|
||||
if err=0 then ;
|
||||
index := i;
|
||||
end;
|
||||
end;
|
||||
|
||||
function ReplaceParamsArray(const ACompilerMsg: string;
|
||||
const ReplaceParams: array of string): string;
|
||||
var
|
||||
j : Integer;
|
||||
i : Integer;
|
||||
nm : Integer;
|
||||
p : Integer;
|
||||
begin
|
||||
if length(ReplaceParams)=0 then begin
|
||||
Result:=ACompilerMsg;
|
||||
Exit;
|
||||
end;
|
||||
i := 1;
|
||||
p := 1;
|
||||
Result := '';
|
||||
while i <= length(ACompilerMsg) do begin
|
||||
if ACompilerMsg[i] = '$' then begin
|
||||
j := i + 1;
|
||||
nm := 0;
|
||||
if GetNextNumber(ACompilerMsg, j, nm) then begin
|
||||
Result := Result + Copy(ACompilerMsg, p, i - p);
|
||||
if nm <= length(ReplaceParams) then
|
||||
Result := Result + ReplaceParams[nm-1]
|
||||
else
|
||||
Result:=Result+'$'+IntToStr(nm);
|
||||
p := j;
|
||||
i := p;
|
||||
end else
|
||||
inc(i);
|
||||
end else
|
||||
inc(i);
|
||||
end;
|
||||
if p < length(ACompilerMsg) then
|
||||
Result := Result + Copy(ACompilerMsg, p, length(ACompilerMsg) - p + 1);
|
||||
end;
|
||||
|
||||
procedure TCompilerMessagesList.SetDefault(KeepState: Boolean);
|
||||
var
|
||||
b : array of TCompilerMessageState;
|
||||
@ -4948,8 +4897,10 @@ function TCompilerMessagesList.GetParams(MsgIndex: Integer;
|
||||
i : integer;
|
||||
begin
|
||||
PrmCount := length(src);
|
||||
if PrmCount > length(prms) then Result := length(Prms)
|
||||
else Result := PrmCount;
|
||||
if PrmCount > length(prms) then
|
||||
Result := length(Prms)
|
||||
else
|
||||
Result := PrmCount;
|
||||
for i := 0 to PrmCount - 1 do
|
||||
Prms[i] := Src[i];
|
||||
end;
|
||||
@ -5015,8 +4966,57 @@ begin
|
||||
end;
|
||||
|
||||
function TCompilerMessageConfig.GetUserText(const ReplaceParams: array of string): string;
|
||||
|
||||
function GetNextNumber(var index: Integer; var Num : Integer): Boolean;
|
||||
var
|
||||
i : integer;
|
||||
err:Integer;
|
||||
begin
|
||||
i := index;
|
||||
while (i <= length(MsgText)) and (MsgText[i] in ['0'..'9']) do inc (i);
|
||||
Result := i - index > 0;
|
||||
if Result then begin
|
||||
Val(Copy(MsgText, Index, i - Index), Num, err);
|
||||
if err=0 then ;
|
||||
index := i;
|
||||
end;
|
||||
end;
|
||||
|
||||
var
|
||||
j : Integer;
|
||||
i : Integer;
|
||||
nm : Integer;
|
||||
p : Integer;
|
||||
begin
|
||||
Result := ReplaceParamsArray(MsgText, ReplaceParams);
|
||||
DebugLn(['TCompilerMessageConfig.GetUserText: MsgIndex=', MsgIndex, ', ReplaceParamCnt=', Length(ReplaceParams)]);
|
||||
if length(ReplaceParams)=0 then begin
|
||||
Result:=MsgText;
|
||||
Exit;
|
||||
end;
|
||||
i := 1;
|
||||
p := 1;
|
||||
Result := '';
|
||||
while i <= length(MsgText) do begin
|
||||
if MsgText[i] = '$' then begin
|
||||
j := i + 1;
|
||||
nm := 0;
|
||||
if GetNextNumber(j, nm) then begin
|
||||
Result := Result + Copy(MsgText, p, i - p);
|
||||
if nm <= length(ReplaceParams) then begin
|
||||
Result := Result + ReplaceParams[nm-1];
|
||||
DebugLn(['TCompilerMessageConfig.GetUserText: param ', nm-1, ' =', ReplaceParams[nm-1]]);
|
||||
end
|
||||
else
|
||||
Result:=Result+'$'+IntToStr(nm);
|
||||
p := j;
|
||||
i := p;
|
||||
end else
|
||||
inc(i);
|
||||
end else
|
||||
inc(i);
|
||||
end;
|
||||
if p < length(MsgText) then
|
||||
Result := Result + Copy(MsgText, p, length(MsgText) - p + 1);
|
||||
end;
|
||||
|
||||
function TCompilerMessageConfig.GetUserText: string;
|
||||
@ -5024,6 +5024,7 @@ var
|
||||
prm : array of string;
|
||||
cnt : Integer;
|
||||
begin
|
||||
raise Exception.Create('TCompilerMessageConfig.GetUserText is called after all!');
|
||||
if Assigned(fOwner) then begin
|
||||
SetLength(prm, MaxMsgParams);
|
||||
fOwner.GetParams(MsgIndex, prm, cnt);
|
||||
|
Loading…
Reference in New Issue
Block a user