IDE, codetools: fixed parsing compiler time stamps

git-svn-id: trunk@10554 -
This commit is contained in:
mattias 2007-02-01 09:55:30 +00:00
parent bf735e87cf
commit 346794aaae
3 changed files with 101 additions and 116 deletions

View File

@ -2774,8 +2774,7 @@ function TDefinePool.CreateFPCTemplate(
// To get reliable values the compiler itself is asked for
var
LastDefTempl: TDefineTemplate;
ShortUpTestFile: string;
procedure AddTemplate(NewDefTempl: TDefineTemplate);
begin
if NewDefTempl=nil then exit;
@ -2825,90 +2824,60 @@ var
procedure ProcessOutputLine(var Line: string);
var
SymbolName, SymbolValue, UpLine, NewPath: string;
i, len, curpos, remain: integer;
i, len, curpos: integer;
begin
len := length(Line);
if len <= 6 then Exit; // shortest match
CurPos := 1;
remain:=len;
// strip timestamp
// strip timestamp e.g. [0.306]
if Line[CurPos] = '[' then begin
repeat
inc(CurPos);
if CurPos > len then Exit;
until line[CurPos] = ']';
Inc(CurPos, 2); //skip space also
remain := len - CurPos + 1;
if remain <= 6 then Exit; // shortest match
if len - CurPos < 6 then Exit; // shortest match
end;
UpLine:=UpperCaseStr(Line);
// check for filename
i := length(ShortUpTestFile);
if (remain > i) and (StrLComp(@ShortUpTestFile[1], @UpLine[CurPos], i) = 0) then begin
Inc(Curpos, i);
if Line[CurPos] <> '(' then Exit; // no linenumbers ??
// strip linenumbers
repeat
inc(CurPos);
if CurPos > len then Exit;
until Line[CurPos] = ')';
repeat
inc(CurPos);
if CurPos > len then Exit;
until Line[CurPos] <> ' ';
Dec(CurPos);
remain := len - CurPos + 1;
if remain <= 6 then Exit; // shortest match
end;
case UpLine[CurPos] of
'M': begin
if StrLComp(@UpLine[CurPos], 'MACRO ', 6) <> 0 then Exit; // no macro
Inc(CurPos, 6);
Dec(remain, 6);
if (remain > 9) and (StrLComp(@UpLine[CurPos], 'DEFINED: ', 9) = 0) then begin
Inc(CurPos, 9);
Dec(remain, 9);
SymbolName:=copy(UpLine, CurPos, remain);
DefineSymbol(SymbolName,'');
Exit;
end;
if (remain > 11) and (StrLComp(@UpLine[CurPos], 'UNDEFINED: ', 11) = 0) then begin
Inc(CurPos, 11);
Dec(remain, 11);
SymbolName:=copy(UpLine,CurPos,remain);
UndefineSymbol(SymbolName);
Exit;
end;
// MACRO something...
i := CurPos;
while (i <= len) and (Line[i]<>' ') do inc(i);
SymbolName:=copy(UpLine,CurPos,i-CurPos);
CurPos := i + 1; // skip space
remain := len - CurPos + 1;
if remain < 7 then Exit;
'M':
if StrLComp(@UpLine[CurPos], 'MACRO ', 6) = 0 then begin
// no macro
Inc(CurPos, 6);
if StrLComp(@UpLine[CurPos], 'SET TO ', 7) = 0 then begin
Inc(CurPos, 7);
Dec(remain, 7);
SymbolValue:=copy(Line, CurPos, remain);
DefineSymbol(SymbolName, SymbolValue);
if (StrLComp(@UpLine[CurPos], 'DEFINED: ', 9) = 0) then begin
Inc(CurPos, 9);
SymbolName:=copy(UpLine, CurPos, len);
DefineSymbol(SymbolName,'');
Exit;
end;
if (StrLComp(@UpLine[CurPos], 'UNDEFINED: ', 11) = 0) then begin
Inc(CurPos, 11);
SymbolName:=copy(UpLine,CurPos,len);
UndefineSymbol(SymbolName);
Exit;
end;
// MACRO something...
i := CurPos;
while (i <= len) and (Line[i]<>' ') do inc(i);
SymbolName:=copy(UpLine,CurPos,i-CurPos);
CurPos := i + 1; // skip space
if StrLComp(@UpLine[CurPos], 'SET TO ', 7) = 0 then begin
Inc(CurPos, 7);
SymbolValue:=copy(Line, CurPos, len);
DefineSymbol(SymbolName, SymbolValue);
end;
end;
end;
'U': begin
if (remain > 17) and (StrLComp(@UpLine[CurPos], 'USING UNIT PATH: ', 17) = 0) then begin
'U':
if (StrLComp(@UpLine[CurPos], 'USING UNIT PATH: ', 17) = 0) then begin
Inc(CurPos, 17);
Dec(remain, 17);
NewPath:=copy(Line,CurPos,Remain);
NewPath:=copy(Line,CurPos,len);
if not FilenameIsAbsolute(NewPath) then
NewPath:=ExpandFileName(NewPath);
{$IFDEF VerboseFPCSrcScan}
@ -2916,7 +2885,6 @@ var
{$ENDIF}
UnitSearchPath:=UnitSearchPath+NewPath+';';
end;
end;
end;
end;
@ -2945,14 +2913,13 @@ begin
SetLength(Buf,1024);
Step:='Init';
try
CmdLine:=CompilerPath+' -va -vs- ';
CmdLine:=CompilerPath+' -va ';
if FileExistsCached(EnglishErrorMsgFilename) then
CmdLine:=CmdLine+'-Fr'+EnglishErrorMsgFilename+' ';
if CompilerOptions<>'' then
CmdLine:=CmdLine+CompilerOptions+' ';
CmdLine:=CmdLine+TestPascalFile;
//DebugLn('TDefinePool.CreateFPCTemplate CmdLine="',CmdLine,'"');
ShortUpTestFile := UpperCaseStr(ExtractFileName(TestPascalFile));
TheProcess := TProcess.Create(nil);
TheProcess.CommandLine := CmdLine;

View File

@ -34,7 +34,7 @@
<Unit1>
<Filename Value="scanexamples/simpleunit1.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="SimpleUnit1"/>
<UnitName Value="S"/>
</Unit1>
</Units>
</ProjectOptions>

View File

@ -415,22 +415,29 @@ var i, j, FilenameEndPos: integer;
MessageStartPos: Integer;
LineNumberEndPos: LongInt;
AbsFilename: String;
function CompStr(const SubStr, s: string; Position: integer): boolean;
begin
Result:=(SubStr<>'') and (length(s)>=(Position+length(SubStr)-1))
and (strlcomp(PChar(Pointer(@s[Position])),
PChar(Pointer(SubStr)),length(SubStr))=0);
end;
function CheckForCompilingState: boolean;
function CheckForCompilingState(p: integer): boolean;
var
AFilename: string;
begin
Result:=false;
if ('Compiling '=copy(s,1,length('Compiling '))) then begin
if CompStr('Compiling ',s,p) then begin
// for example 'Compiling ./subdir/unit1.pas'
fLastMessageType:=omtFPC;
fLastErrorType:=etNone;
// add path to history
if fCompilingHistory=nil then fCompilingHistory:=TStringList.Create;
i:=length('Compiling ');
if (length(s)>=i+2) and (s[i+1]='.') and (s[i+2]=PathDelim) then
inc(p,length('Compiling '));
if (length(s)>=i+1) and (s[i]='.') and (s[i+1]=PathDelim) then
inc(i,2);
AFilename:=TrimFilename(copy(s,i+1,length(s)-i));
AFilename:=TrimFilename(copy(s,i,length(s)));
fCompilingHistory.Add(AFilename);
CurrentMessageParts.Values['Stage']:='FPC';
CurrentMessageParts.Values['Type']:='Compiling';
@ -439,11 +446,10 @@ var i, j, FilenameEndPos: integer;
end;
end;
function CheckForAssemblingState: boolean;
function CheckForAssemblingState(p: integer): boolean;
begin
Result:=false;
if ('Assembling '=copy(s,1,length('Assembling ')))
then begin
if CompStr('Assembling ',s,p) then begin
fLastMessageType:=omtFPC;
fLastErrorType:=etNone;
CurrentMessageParts.Values['Stage']:='FPC';
@ -452,27 +458,27 @@ var i, j, FilenameEndPos: integer;
end;
end;
function CheckForUrgentMessages: boolean;
function CheckForUrgentMessages(p: integer): boolean;
var
NewLine: String;
LastFile: string;
FullFilename: String;
begin
Result:=false;
if ('Fatal: '=copy(s,1,length('Fatal: ')))
or ('Panic'=copy(s,1,length('Panic')))
or ('Error: '=copy(s,1,length('Error: ')))
or ('Closing script ppas.sh'=s)
if CompStr('Fatal: ',s,p)
or CompStr('Panic',s,p)
or CompStr('Error: ',s,p)
or CompStr('Closing script ppas.sh',s,p)
then begin
// always show fatal, panic and linker errors
fLastMessageType:=omtFPC;
if ('Panic'=copy(s,1,length('Panic'))) then
if CompStr('Panic',s,p) then
fLastErrorType:=etPanic
else if ('Fatal: '=copy(s,1,length('Fatal: '))) then
else if CompStr('Fatal: ',s,p) then
fLastErrorType:=etFatal
else if ('Error: '=copy(s,1,length('Error: '))) then
else if CompStr('Error: ',s,p) then
fLastErrorType:=etError
else if ('Closing script ppas.sh'=s) then begin
else if CompStr('Closing script ppas.sh',s,p) then begin
// linker error
fLastMessageType:=omtLinker;
fLastErrorType:=etFatal;
@ -483,7 +489,7 @@ var i, j, FilenameEndPos: integer;
CurrentMessageParts.Values['Stage']:='FPC';
CurrentMessageParts.Values['Type']:=ErrorTypeNames[fLastErrorType];
NewLine:=s;
NewLine:=copy(s,p,length(s));
if fLastErrorType in [etPanic,etFatal] then begin
// fatal and panic errors are not very informative
// -> prepend current file
@ -512,11 +518,11 @@ var i, j, FilenameEndPos: integer;
end;
end;
function CheckForNoteMessages: boolean;
function CheckForNoteMessages(p: integer): boolean;
begin
Result:=false;
if ('Note: '=copy(s,1,length('Note: '))) then begin
DoAddFilteredLine(s);
if CompStr('Note: ',s,p) then begin
DoAddFilteredLine(copy(s,p,length(s)));
fLastErrorType:=etNote;
CurrentMessageParts.Values['Stage']:='FPC';
CurrentMessageParts.Values['Type']:=ErrorTypeNames[fLastErrorType];
@ -543,17 +549,13 @@ var i, j, FilenameEndPos: integer;
function CheckForString(const Str: string; var p: integer;
const Find: string): boolean;
begin
Result:=(p+length(Find)-1<=length(Str))
and (CompareText(Find,copy(s,p,length(Find)))=0);
Result:=CompStr(Find,Str,p);
if Result then inc(p,length(Find));
end;
function CheckForLineProgress: boolean;
var
p: Integer;
function CheckForLineProgress(p: integer): boolean;
begin
Result:=false;
p:=1;
if not CheckForNumber(s,p) then exit;
if not CheckForChar(s,p,' ') then exit;
if not CheckForNumber(s,p) then exit;
@ -564,12 +566,12 @@ var i, j, FilenameEndPos: integer;
// I don't think it should be shown in filtered lines: DoAddFilteredLine(s);
end;
function CheckForLinesCompiled: boolean;
function CheckForLinesCompiled(p: integer): boolean;
var
p: Integer;
OldStart: LongInt;
begin
Result:=false;
p:=1;
OldStart:=p;
if not CheckForNumber(s,p) then exit;
if not CheckForString(s,p,' Lines compiled, ') then exit;
if not CheckForNumber(s,p) then exit;
@ -579,7 +581,7 @@ var i, j, FilenameEndPos: integer;
Result:=true;
if (CompilerOptions<>nil)
and (CompilerOptions.ShowAll or CompilerOptions.ShowSummary) then
DoAddFilteredLine(s);
DoAddFilteredLine(copy(s,OldStart,length(s)));
end;
{ For example:
@ -589,12 +591,12 @@ var i, j, FilenameEndPos: integer;
Stack space reserved: 262144 bytes
Stack space commited: 4096 bytes
}
function CheckForExecutableInfo: boolean;
function CheckForExecutableInfo(p: integer): boolean;
var
p: Integer;
OldStart: LongInt;
begin
Result:=false;
p:=1;
OldStart:=p;
if not (CheckForString(s,p,'Size of Code: ') or
CheckForString(s,p,'Size of initialized data: ') or
CheckForString(s,p,'Size of uninitialized data: ') or
@ -606,44 +608,60 @@ var i, j, FilenameEndPos: integer;
Result:=true;
if (CompilerOptions<>nil)
and (CompilerOptions.ShowAll or CompilerOptions.ShowExecInfo) then
DoAddFilteredLine(s);
DoAddFilteredLine(copy(s,OldStart,length(s)));
end;
{ For example:
linkerror.o(.text$_main+0x9):linkerror.pas: undefined reference to `NonExistingFunction'
}
function CheckForLinkingErrors: boolean;
function CheckForLinkingErrors(p: integer): boolean;
var
OldStart: LongInt;
begin
Result:=false;
OldStart:=p;
while (p<=length(s)) and (s[p] in ['0'..'9','a'..'z','A'..'Z','_']) do
inc(p);
if not CompStr('.o(',s,p) then exit;
Result:=true;
DoAddFilteredLine(copy(s,OldStart,length(s)));
end;
begin
Result:=false;
if s='' then exit;
i:=1;
// skip time [0.000]
if (s<>'') and (s[1]='[') then begin
inc(i);
while (i<=length(s)) and (s[i] in ['0'..'9','.']) do inc(i);
if (i<=length(s)) and (s[i]=']') then inc(i);
while (i<=length(s)) and (s[i] in [' ']) do inc(i);
end;
// check for 'Compiling <filename>'
Result:=CheckForCompilingState;
Result:=CheckForCompilingState(i);
if Result then exit;
// check for 'Assembling <filename>'
Result:=CheckForAssemblingState;
Result:=CheckForAssemblingState(i);
if Result then exit;
// check for 'Fatal: ', 'Panic: ', 'Error: ', 'Closing script ppas.sh'
Result:=CheckForUrgentMessages;
Result:=CheckForUrgentMessages(i);
if Result then exit;
// check for 'Note: '
Result:=CheckForNoteMessages;
Result:=CheckForNoteMessages(i);
if Result then exit;
// check for '<line> <kb>/<kb>'...
Result:=CheckForLineProgress;
Result:=CheckForLineProgress(i);
if Result then exit;
// check for '<int> Lines compiled, <int>.<int> sec'
Result:=CheckForLinesCompiled;
Result:=CheckForLinesCompiled(i);
if Result then exit;
// check for -vx output
Result:=CheckForExecutableInfo;
Result:=CheckForExecutableInfo(i);
if Result then exit;
// check for linking errors
Result:=CheckForLinkingErrors;
Result:=CheckForLinkingErrors(i);
if Result then exit;
// search for round bracket open