codetools: linkscanner: simplified AddLink

git-svn-id: trunk@38210 -
This commit is contained in:
mattias 2012-08-09 07:45:50 +00:00
parent cfa24e7773
commit 9d1394675c
2 changed files with 45 additions and 36 deletions

View File

@ -29,7 +29,7 @@
<PackageName Value="CodeTools"/> <PackageName Value="CodeTools"/>
</Item1> </Item1>
</RequiredPackages> </RequiredPackages>
<Units Count="3"> <Units Count="4">
<Unit0> <Unit0>
<Filename Value="finddeclaration.lpr"/> <Filename Value="finddeclaration.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
@ -45,10 +45,14 @@
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="OverloadedFunction"/> <UnitName Value="OverloadedFunction"/>
</Unit2> </Unit2>
<Unit3>
<Filename Value="../../../../../amat/test/test.inc"/>
<IsPartOfProject Value="True"/>
</Unit3>
</Units> </Units>
</ProjectOptions> </ProjectOptions>
<CompilerOptions> <CompilerOptions>
<Version Value="10"/> <Version Value="11"/>
<SearchPaths> <SearchPaths>
<OtherUnitFiles Value="scanexamples"/> <OtherUnitFiles Value="scanexamples"/>
</SearchPaths> </SearchPaths>

View File

@ -44,6 +44,7 @@ unit LinkScanner;
{$I codetools.inc} {$I codetools.inc}
{ $DEFINE ShowIgnoreErrorAfter} { $DEFINE ShowIgnoreErrorAfter}
{ $DEFINE EnableIncludeSkippedCode}
// debugging // debugging
{ $DEFINE ShowUpdateCleanedSrc} { $DEFINE ShowUpdateCleanedSrc}
@ -136,7 +137,11 @@ type
lsrEnd // scan till 'end.' lsrEnd // scan till 'end.'
); );
TCommentStyle = (CommentNone, CommentTP, CommentOldTP, CommentDelphi); TCommentStyle = (CommentNone,
CommentCurly, // {}
CommentRound, // (* *)
CommentLine // //
);
TCompilerMode = ( TCompilerMode = (
cmFPC, cmFPC,
@ -149,19 +154,19 @@ type
cmISO); cmISO);
{ TCompilerModeSwitch - see fpc/compiler/globtype.pas } { TCompilerModeSwitch - see fpc/compiler/globtype.pas }
TCompilerModeSwitch = ( TCompilerModeSwitch = (
cmsClass, { delphi class model } cmsClass, { delphi class model }
cmsObjpas, { load objpas unit } cmsObjpas, { load objpas unit }
cmsResult, { result in functions } cmsResult, { result in functions }
cmsString_pchar, { pchar 2 string conversion } cmsString_pchar, { pchar 2 string conversion }
cmsCvar_support, { cvar variable directive } cmsCvar_support, { cvar variable directive }
cmsNested_comment,{ nested comments } cmsNested_comment, { nested comments }
cmsTp_procvar, { tp style procvars (no @ needed) } cmsTp_procvar, { tp style procvars (no @ needed) }
cmsMac_procvar, { macpas style procvars } cmsMac_procvar, { macpas style procvars }
cmsRepeat_forward, { repeating forward declarations is needed } cmsRepeat_forward, { repeating forward declarations is needed }
cmsPointer_2_procedure, { allows the assignement of pointers to procedure variables } cmsPointer_2_procedure,{ allows the assignement of pointers to procedure variables }
cmsAutoderef, { does auto dereferencing of struct. vars, e.g. a.b -> a^.b } cmsAutoderef, { does auto dereferencing of struct. vars, e.g. a.b -> a^.b }
cmsInitfinal, { initialization/finalization for units } cmsInitfinal, { initialization/finalization for units }
cmsAdd_pointer, cmsAdd_pointer, { ? }
cmsDefault_ansistring, { ansistring turned on by default } cmsDefault_ansistring, { ansistring turned on by default }
cmsOut, { support the calling convention OUT } cmsOut, { support the calling convention OUT }
cmsDefault_para, { support default parameters } cmsDefault_para, { support default parameters }
@ -317,7 +322,7 @@ type
procedure SetLinks(Index: integer; const Value: TSourceLink); procedure SetLinks(Index: integer; const Value: TSourceLink);
procedure SetSource(ACode: Pointer); // set current source procedure SetSource(ACode: Pointer); // set current source
procedure AddSourceChangeStep(ACode: pointer; AChangeStep: integer); procedure AddSourceChangeStep(ACode: pointer; AChangeStep: integer);
procedure AddLink(ACleanedPos, ASrcPos: integer; ACode: Pointer); procedure AddLink(ASrcPos: integer; ACode: Pointer);
procedure IncreaseChangeStep; procedure IncreaseChangeStep;
procedure SetMainCode(const Value: pointer); procedure SetMainCode(const Value: pointer);
procedure SetScanTill(const Value: TLinkScannerRange); procedure SetScanTill(const Value: TLinkScannerRange);
@ -735,7 +740,7 @@ end;
{ TLinkScanner } { TLinkScanner }
procedure TLinkScanner.AddLink(ACleanedPos, ASrcPos: integer; ACode: pointer); procedure TLinkScanner.AddLink(ASrcPos: integer; ACode: pointer);
var var
NewCapacity: Integer; NewCapacity: Integer;
begin begin
@ -746,7 +751,7 @@ begin
FLinkCapacity:=NewCapacity; FLinkCapacity:=NewCapacity;
end; end;
with FLinks[FLinkCount] do begin with FLinks[FLinkCount] do begin
CleanedPos:=ACleanedPos; CleanedPos:=CleanedLen+1;
SrcPos:=ASrcPos; SrcPos:=ASrcPos;
Code:=ACode; Code:=ACode;
end; end;
@ -1346,7 +1351,7 @@ begin
FMacrosOn:=(Values.Variables['MACROS']<>'0'); FMacrosOn:=(Values.Variables['MACROS']<>'0');
if Src='' then exit; if Src='' then exit;
// begin scanning // begin scanning
AddLink(1,SrcPos,Code); AddLink(SrcPos,Code);
LastTokenType:=lsttNone; LastTokenType:=lsttNone;
LastProgressPos:=0; LastProgressPos:=0;
CheckForAbort:=Assigned(OnProgress); CheckForAbort:=Assigned(OnProgress);
@ -1422,13 +1427,13 @@ procedure TLinkScanner.SkipCurlyComment;
var var
p: PChar; p: PChar;
begin begin
CommentStyle:=CommentTP; CommentStyle:=CommentCurly;
CommentStartPos:=SrcPos; CommentStartPos:=SrcPos;
IncCommentLevel; IncCommentLevel;
CommentInnerStartPos:=SrcPos+1; CommentInnerStartPos:=SrcPos+1;
p:=@Src[SrcPos]; p:=@Src[SrcPos];
inc(p); inc(p);
{ HandleSwitches can dec CommentLevel } // HandleSwitches can dec CommentLevel
while true do begin while true do begin
case p^ of case p^ of
#0: #0:
@ -1454,7 +1459,7 @@ begin
CommentEndPos:=SrcPos; CommentEndPos:=SrcPos;
CommentInnerEndPos:=SrcPos-1; CommentInnerEndPos:=SrcPos-1;
if (CommentLevel>0) then CommentEndNotFound; if (CommentLevel>0) then CommentEndNotFound;
{ handle compiler switches } // handle compiler switches
if Src[CommentInnerStartPos]='$' then HandleDirectives; if Src[CommentInnerStartPos]='$' then HandleDirectives;
EndComment; EndComment;
end; end;
@ -1464,7 +1469,7 @@ procedure TLinkScanner.SkipLineComment;
var var
p: PChar; p: PChar;
begin begin
CommentStyle:=CommentDelphi; CommentStyle:=CommentLine;
CommentStartPos:=SrcPos; CommentStartPos:=SrcPos;
IncCommentLevel; IncCommentLevel;
p:=@Src[SrcPos]; p:=@Src[SrcPos];
@ -1476,16 +1481,16 @@ begin
SrcPos:=p-PChar(Src)+1; SrcPos:=p-PChar(Src)+1;
CommentEndPos:=SrcPos; CommentEndPos:=SrcPos;
CommentInnerEndPos:=SrcPos-1; CommentInnerEndPos:=SrcPos-1;
{ handle compiler switches (ignore) } // handle compiler switches (ignore)
EndComment; EndComment;
end; end;
procedure TLinkScanner.SkipRoundComment; procedure TLinkScanner.SkipRoundComment;
// a (* *) comment // a delphi comment (* *)
var var
p: PChar; p: PChar;
begin begin
CommentStyle:=CommentDelphi; CommentStyle:=CommentLine;
CommentStartPos:=SrcPos; CommentStartPos:=SrcPos;
IncCommentLevel; IncCommentLevel;
CommentInnerStartPos:=SrcPos+2; CommentInnerStartPos:=SrcPos+2;
@ -1524,7 +1529,7 @@ begin
CommentEndPos:=SrcPos; CommentEndPos:=SrcPos;
CommentInnerEndPos:=SrcPos-2; CommentInnerEndPos:=SrcPos-2;
if (CommentLevel>0) then CommentEndNotFound; if (CommentLevel>0) then CommentEndNotFound;
{ handle compiler switches } // handle compiler switches
if Src[CommentInnerStartPos]='$' then HandleDirectives; if Src[CommentInnerStartPos]='$' then HandleDirectives;
EndComment; EndComment;
end; end;
@ -3229,7 +3234,7 @@ begin
if Assigned(FOnIncludeCode) then if Assigned(FOnIncludeCode) then
FOnIncludeCode(FMainCode,NewCode); FOnIncludeCode(FMainCode,NewCode);
SetSource(NewCode); SetSource(NewCode);
AddLink(CleanedLen+1,SrcPos,Code); AddLink(SrcPos,Code);
end else begin end else begin
if MissingIncludeFile<>nil then begin if MissingIncludeFile<>nil then begin
if FMissingIncludeFiles=nil then if FMissingIncludeFiles=nil then
@ -3240,8 +3245,8 @@ begin
RaiseExceptionFmt(ctsIncludeFileNotFound,[AFilename]) RaiseExceptionFmt(ctsIncludeFileNotFound,[AFilename])
end else begin end else begin
// add a dummy link // add a dummy link
AddLink(CleanedLen+1,SrcPos,MissingIncludeFileCode); AddLink(SrcPos,MissingIncludeFileCode);
AddLink(CleanedLen+1,SrcPos,Code); AddLink(SrcPos,Code);
end; end;
end; end;
end; end;
@ -3445,7 +3450,7 @@ begin
OldSrcFilename:=SrcFilename; OldSrcFilename:=SrcFilename;
//DebugLn(['TLinkScanner.AddMacroSource BEFORE CleanedSrc=',dbgstr(copy(FCleanedSrc,CleanedLen-19,20))]); //DebugLn(['TLinkScanner.AddMacroSource BEFORE CleanedSrc=',dbgstr(copy(FCleanedSrc,CleanedLen-19,20))]);
// add macro source // add macro source
AddLink(CleanedLen+1,Macro^.StartPos,Macro^.Code); AddLink(Macro^.StartPos,Macro^.Code);
Code:=Macro^.Code; Code:=Macro^.Code;
Src:=Macro^.Src; Src:=Macro^.Src;
SrcLen:=length(Src); SrcLen:=length(Src);
@ -3459,7 +3464,7 @@ begin
SrcLen:=length(Src); SrcLen:=length(Src);
SrcFilename:=OldSrcFilename; SrcFilename:=OldSrcFilename;
CopiedSrcPos:=SrcPos-1; CopiedSrcPos:=SrcPos-1;
AddLink(CleanedLen+1,SrcPos,Code); AddLink(SrcPos,Code);
// clear token type // clear token type
TokenType:=lsttNone; TokenType:=lsttNone;
// SrcPos was not touched and still stands behind the macro name // SrcPos was not touched and still stands behind the macro name
@ -3482,7 +3487,7 @@ begin
SetSource(OldPos.Code); SetSource(OldPos.Code);
SrcPos:=OldPos.SrcPos; SrcPos:=OldPos.SrcPos;
CopiedSrcPos:=SrcPos-1; CopiedSrcPos:=SrcPos-1;
AddLink(CleanedLen+1,SrcPos,Code); AddLink(SrcPos,Code);
end; end;
Result:=SrcPos<=SrcLen; Result:=SrcPos<=SrcLen;
end; end;
@ -3642,7 +3647,7 @@ begin
{$ENDIF} {$ENDIF}
UpdateCleanedSource(SrcPos-1); UpdateCleanedSource(SrcPos-1);
// parse till $else, $elseif or $endif without adding the code to FCleanedSrc // parse till $else, $elseif or $endif
FSkipIfLevel:=IfLevel; FSkipIfLevel:=IfLevel;
if (SrcPos<=SrcLen) then begin if (SrcPos<=SrcLen) then begin
p:=@Src[SrcPos]; p:=@Src[SrcPos];
@ -3699,7 +3704,7 @@ begin
end; end;
if CommentStartPos>0 then begin if CommentStartPos>0 then begin
CopiedSrcPos:=CommentStartPos-1; CopiedSrcPos:=CommentStartPos-1;
AddLink(CleanedLen+1,CommentStartPos,Code); AddLink(CommentStartPos,Code);
end else begin end else begin
CopiedSrcPos:=SrcLen+1; CopiedSrcPos:=SrcLen+1;
end; end;