fixed targetos for clean all

git-svn-id: trunk@4329 -
This commit is contained in:
mattias 2003-06-27 22:07:39 +00:00
parent d6126baede
commit 3cfdaeef38
10 changed files with 282 additions and 117 deletions

View File

@ -2017,7 +2017,7 @@ var CleanCursorPos, Indent, insertPos: integer;
// -> find it and jump to
// reparse code
BuildTreeAndGetCleanPos(trAll,CursorPos,CleanCursorPos,[],true);
BuildTreeAndGetCleanPos(trAll,CursorPos,CleanCursorPos,[]);
// find CodeTreeNode at cursor
CursorNode:=FindDeepestNodeAtPos(CleanCursorPos,true);
@ -2400,7 +2400,7 @@ begin
Result:=false;
if (SourceChangeCache=nil) then
RaiseException('need a SourceChangeCache');
BuildTreeAndGetCleanPos(trAll,CursorPos, CleanCursorPos,[],true);
BuildTreeAndGetCleanPos(trAll,CursorPos, CleanCursorPos,[]);
// find CodeTreeNode at cursor
CursorNode:=FindDeepestNodeAtPos(CleanCursorPos,true);

View File

@ -36,6 +36,7 @@ interface
{$I codetools.inc}
{ $DEFINE ShowIgnoreError}
{$DEFINE ShowDirtySrc}
uses
{$IFDEF MEM_CHECK}
@ -74,8 +75,10 @@ type
TDirtySource = class
public
CursorPos: TCodeXYPosition;
Src: string;
GapSrc: string;
GapUpperSrc: string;
Code: TCodeBuffer;
Valid: boolean;
CurPos: TAtomPosition;
@ -83,11 +86,24 @@ type
GapStart: integer;
GapEnd: integer;
LockCount: integer;
Owner: TCustomCodeTool;
procedure BeginUpdate;
procedure EndUpdate;
procedure SetCode(NewCode: TCodeBuffer);
procedure SetGap(NewDirtyStartPos,NewDirtyGapStart,NewDirtyGapEnd: integer);
procedure SetGap(const NewCursorPos: TCodeXYPosition;
NewDirtyStartPos, NewDirtyGapStart, NewDirtyGapEnd: integer);
constructor Create(TheOwner: TCustomCodeTool);
procedure Clear;
procedure SetCursorToIdentStartEndAtPosition;
function GetCursorSrcPos: PChar;
function IsPCharInSrc(p: PChar): boolean;
procedure MoveCursorToPos(APos: integer);
procedure MoveCursorToPos(APos: PChar);
end;
THybridCursorType = (
hcClean,
hcDirty
);
// types for user aborts
@ -160,6 +176,7 @@ type
CursorBeyondEOL: boolean;
DirtySrc: TDirtySource;
HybridCursorType: THybridCursorType;
ErrorPosition: TCodeXYPosition;
@ -196,20 +213,28 @@ type
procedure BeginParsingAndGetCleanPos(DeleteNodes,
OnlyInterfaceNeeded: boolean; CursorPos: TCodeXYPosition;
var CleanCursorPos: integer);
function IsDirtySrcValid: boolean;
function StringIsKeyWord(const Word: string): boolean;
// cursor moving
procedure MoveCursorToNodeStart(ANode: TCodeTreeNode);
procedure MoveCursorToCleanPos(ACleanPos: integer);
procedure MoveCursorToCleanPos(ACleanPos: PChar);
function IsPCharInSrc(ACleanPos: PChar): boolean;
function ReadTilBracketClose(ExceptionOnNotFound: boolean): boolean;
function ReadBackTilBracketOpen(ExceptionOnNotFound: boolean): boolean;
procedure ReadTillCommentEnd;
function DoAtom: boolean; virtual;
procedure MoveHybridCursorToPos(DirtyPos: PChar);
function GetHybridCursorStart: integer;
// read atoms
procedure ReadNextAtom;
procedure UndoReadNextAtom;
procedure ReadPriorAtom;
// read blocks
function ReadTilBracketClose(ExceptionOnNotFound: boolean): boolean;
function ReadBackTilBracketOpen(ExceptionOnNotFound: boolean): boolean;
procedure ReadTillCommentEnd;
function AtomIs(const AnAtom: shortstring): boolean;
function UpAtomIs(const AnAtom: shortstring): boolean;
function ReadNextAtomIs(const AnAtom: shortstring): boolean;
@ -246,7 +271,8 @@ type
procedure CreateChildNode;
procedure EndChildNode;
function DoAtom: boolean; virtual;
procedure ActivateGlobalWriteLock; virtual;
procedure DeactivateGlobalWriteLock; virtual;
property OnGetGlobalWriteLockInfo: TOnGetWriteLockInfo
@ -386,14 +412,15 @@ var
BestLinkIndex: Integer;
BestLink: TSourceLink;
begin
if DirtySrc=nil then DirtySrc:=TDirtySource.Create;
DirtySrc.SetCode(CursorPos.Code);
writeln('TCustomCodeTool.LoadDirtySource X=',CursorPos.X,' Y=',CursorPos.Y,
' ',ExtractFilename(CursorPos.Code.Filename));
if DirtySrc=nil then DirtySrc:=TDirtySource.Create(Self);
CursorPos.Code.LineColToPosition(CursorPos.Y,CursorPos.X,NewDirtyStartPos);
if NewDirtyStartPos<1 then
RaiseCatchableException('NewDirtyStartPos<1');
CursorInLink:=false;
BestLinkIndex:=Scanner.LinkIndexNearCursorPos(NewDirtyStartPos,
DirtySrc.Code,CursorInLink);
CursorPos.Code,CursorInLink);
if BestLinkIndex<0 then
RaiseCatchableException('BestLinkIndex<0');
if CursorInLink then
@ -403,8 +430,8 @@ begin
if BestLinkIndex<Scanner.LinkCount then
NewDirtyGapEnd:=Scanner.Links[BestLinkIndex+1].SrcPos
else
NewDirtyGapEnd:=DirtySrc.Code.SourceLength;
DirtySrc.SetGap(NewDirtyStartPos,NewDirtyGapStart,NewDirtyGapEnd);
NewDirtyGapEnd:=CursorPos.Code.SourceLength;
DirtySrc.SetGap(CursorPos,NewDirtyStartPos,NewDirtyGapStart,NewDirtyGapEnd);
end;
@ -1582,6 +1609,11 @@ begin
RaiseException(ctsCursorPosOutsideOfCode);
end;
function TCustomCodeTool.IsDirtySrcValid: boolean;
begin
Result:=(DirtySrc<>nil) and (DirtySrc.Code<>nil);
end;
function TCustomCodeTool.IgnoreErrAfterPositionIsInFrontOfLastErrMessage: boolean;
var
IgnoreErrorAfterCleanPos: integer;
@ -1688,6 +1720,7 @@ begin
LastAtoms.Clear;
NextPos.StartPos:=-1;
CurNode:=nil;
HybridCursorType:=hcClean;
end;
procedure TCustomCodeTool.MoveCursorToCleanPos(ACleanPos: PChar);
@ -1723,6 +1756,23 @@ begin
Result:=true;
end;
procedure TCustomCodeTool.MoveHybridCursorToPos(DirtyPos: PChar);
begin
if IsDirtySrcValid and (not IsPCharInSrc(DirtyPos)) then begin
DirtySrc.MoveCursorToPos(DirtyPos);
HybridCursorType:=hcDirty;
end else
MoveCursorToCleanPos(DirtyPos);
end;
function TCustomCodeTool.GetHybridCursorStart: integer;
begin
if HybridCursorType=hcDirty then
Result:=DirtySrc.CurPos.StartPos
else
Result:=CurPos.StartPos;
end;
procedure TCustomCodeTool.CreateChildNode;
var NewNode: TCodeTreeNode;
begin
@ -2280,26 +2330,113 @@ begin
dec(LockCount);
end;
procedure TDirtySource.SetCode(NewCode: TCodeBuffer);
procedure TDirtySource.SetGap(const NewCursorPos: TCodeXYPosition;
NewDirtyStartPos, NewDirtyGapStart, NewDirtyGapEnd: integer);
begin
if (LockCount>0) and (Code<>NewCode) then
RaiseCatchableException('TDirtySource.SetCode');
Code:=NewCode;
Src:=Code.Source;
end;
// check for conflicts
if (LockCount>0) then begin
if (Code<>nil) and (Code<>NewCursorPos.Code) then
RaiseCatchableException('TDirtySource.SetGap Code change');
if (GapStart>0) then
if (NewDirtyStartPos<>StartPos)
or (NewDirtyGapStart<>GapStart)
or (NewDirtyGapEnd<>GapEnd) then
RaiseCatchableException('TDirtySource.SetGap Gap change');
end;
if (NewDirtyGapStart>NewDirtyStartPos)
or (NewDirtyStartPos>NewDirtyGapEnd) then
RaiseCatchableException('TDirtySource.SetGap Gap Bounds');
procedure TDirtySource.SetGap(NewDirtyStartPos, NewDirtyGapStart,
NewDirtyGapEnd: integer);
begin
if (LockCount>0) then
if (NewDirtyStartPos<>StartPos)
or (NewDirtyGapStart<>GapStart)
or (NewDirtyGapEnd<>GapEnd) then
RaiseCatchableException('TDirtySource.SetGap');
// set values
CursorPos:=NewCursorPos;
Code:=CursorPos.Code;
StartPos:=NewDirtyStartPos;
GapStart:=NewDirtyGapStart;
GapEnd:=NewDirtyGapEnd;
GapSrc:=copy(Src,GapStart,GapEnd-GapStart);
CurPos.StartPos:=StartPos;
CurPos.EndPos:=StartPos;
CurPos.Flag:=cafNone;
// get source
if Code<>nil then
Src:=Code.Source
else
Src:='';
if (GapStart>0) then begin
GapSrc:=copy(Src,GapStart,GapEnd-GapStart);
GapUpperSrc:=UpperCaseStr(GapSrc);
{$IFDEF ShowDirtySrc}
writeln('TDirtySource.SetGap Owner=',ExtractFilename(Owner.MainFilename),
' Code=',ExtractFilename(Code.Filename),
' Gap(',GapStart,',',StartPos,',',GapEnd,')',
'"',StringToPascalConst(copy(GapSrc,1,20)),'"..',
'"',StringToPascalConst(copy(GapSrc,length(GapSrc)-19,20)),'"'
);
{$ENDIF}
end else begin
GapSrc:='';
GapUpperSrc:='';
end;
end;
constructor TDirtySource.Create(TheOwner: TCustomCodeTool);
begin
Owner:=TheOwner;
end;
procedure TDirtySource.Clear;
begin
SetGap(CodeXYPosition(0,0,nil),0,0,0);
end;
procedure TDirtySource.SetCursorToIdentStartEndAtPosition;
begin
GetIdentStartEndAtPosition(GapSrc,CurPos.StartPos,
CurPos.StartPos,CurPos.EndPos);
end;
function TDirtySource.GetCursorSrcPos: PChar;
begin
Result:=@Src[CurPos.StartPos];
end;
function TDirtySource.IsPCharInSrc(p: PChar): boolean;
var NewPos: integer;
begin
Result:=false;
if Src='' then exit;
NewPos:=Integer(p)-Integer(@Src[1])+1;
if (NewPos<1) or (NewPos>length(Src)) then exit;
Result:=true;
end;
procedure TDirtySource.MoveCursorToPos(APos: integer);
begin
CurPos.StartPos:=APos;
CurPos.EndPos:=APos;
CurPos.Flag:=cafNone;
end;
procedure TDirtySource.MoveCursorToPos(APos: PChar);
procedure RaiseSrcEmpty;
begin
RaiseCatchableException('[TDirtySource.MoveCursorToPos - PChar] Src empty');
end;
procedure RaiseNotInSrc;
begin
RaiseCatchableException('[TDirtySource.MoveCursorToPos - PChar] Pos not in Src');
end;
var NewPos: integer;
begin
if Src='' then
RaiseSrcEmpty;
NewPos:=Integer(APos)-Integer(@Src[1])+1;
if (NewPos<1) or (NewPos>length(Src)) then
RaiseNotInSrc;
MoveCursorToPos(NewPos);
end;
initialization

View File

@ -925,6 +925,8 @@ var CleanCursorPos: integer;
var
CleanPosInFront: integer;
CursorAtIdentifier: boolean;
IdentifierStart: Pchar;
begin
Result:=false;
SkipChecks:=false;
@ -934,9 +936,10 @@ begin
{$IFDEF CTDEBUG}
writeln(DebugPrefix,'TFindDeclarationTool.FindDeclaration A CursorPos=',CursorPos.X,',',CursorPos.Y);
{$ENDIF}
if DirtySrc<>nil then DirtySrc.Clear;
BuildTreeAndGetCleanPos(trTillCursor,CursorPos,CleanCursorPos,
[{$IFDEF IgnoreErrorAfterCursor}btSetIgnoreErrorPos{$ENDIF}],
false);
[{$IFDEF IgnoreErrorAfterCursor}btSetIgnoreErrorPos{$ENDIF}
btLoadDirtySource,btCursorPosOutAllowed]);
{$IFDEF CTDEBUG}
writeln(DebugPrefix,'TFindDeclarationTool.FindDeclaration C CleanCursorPos=',CleanCursorPos);
{$ENDIF}
@ -948,7 +951,8 @@ begin
CleanPosInFront:=1;
CursorNode:=nil;
end;
if IsIncludeDirectiveAtPos(CleanCursorPos,CleanPosInFront,NewPos.Code)
if (not IsDirtySrcValid)
and IsIncludeDirectiveAtPos(CleanCursorPos,CleanPosInFront,NewPos.Code)
then begin
// include directive
NewPos.X:=1;
@ -965,7 +969,8 @@ begin
{$IFDEF CTDEBUG}
writeln('TFindDeclarationTool.FindDeclaration D CursorNode=',NodeDescriptionAsString(CursorNode.Desc));
{$ENDIF}
if CursorNode.Desc=ctnUsesSection then begin
if (not IsDirtySrcValid)
and (CursorNode.Desc=ctnUsesSection) then begin
// in uses section
Result:=FindDeclarationInUsesSection(CursorNode,CleanCursorPos,
NewPos,NewTopLine);
@ -980,20 +985,29 @@ begin
CheckIfCursorInBeginNode;
CheckIfCursorInProcNode;
CheckIfCursorInPropertyNode;
// set cursor
// set cursor on identifier
MoveCursorToCleanPos(CleanCursorPos);
GetIdentStartEndAtPosition(Src,CleanCursorPos,
CurPos.StartPos,CurPos.EndPos);
if (CurPos.StartPos<CurPos.EndPos) then begin
if IsDirtySrcValid then begin
DirtySrc.SetCursorToIdentStartEndAtPosition;
CursorAtIdentifier:=DirtySrc.CurPos.StartPos<DirtySrc.CurPos.EndPos;
IdentifierStart:=DirtySrc.GetCursorSrcPos;
end else begin
GetIdentStartEndAtPosition(Src,CleanCursorPos,
CurPos.StartPos,CurPos.EndPos);
CursorAtIdentifier:=CurPos.StartPos<CurPos.EndPos;
IdentifierStart:=@Src[CurPos.StartPos];
end;
if CursorAtIdentifier then begin
// find declaration of identifier
Params:=TFindDeclarationParams.Create;
try
Params.ContextNode:=CursorNode;
Params.SetIdentifier(Self,@Src[CurPos.StartPos],@CheckSrcIdentifier);
Params.SetIdentifier(Self,IdentifierStart,@CheckSrcIdentifier);
Params.Flags:=[fdfSearchInParentNodes,fdfExceptionOnNotFound,
fdfExceptionOnPredefinedIdent,
fdfTopLvlResolving,fdfSearchInAncestors];
if not DirectSearch then begin
// ToDo: DirtySrc
Result:=FindDeclarationOfIdentAtCursor(Params);
end else begin
Include(Params.Flags,fdfIgnoreCurContextNode);
@ -1021,7 +1035,9 @@ begin
NewTopLine:=Params.NewTopLine;
if NewPos.Code=nil then begin
if Params.IdentifierTool.IsPCharInSrc(Params.Identifier) then
Params.IdentifierTool.MoveCursorToCleanPos(Params.Identifier);
Params.IdentifierTool.MoveCursorToCleanPos(Params.Identifier)
else
MoveCursorToCleanPos(CleanCursorPos);
Params.IdentifierTool.RaiseExceptionFmt(ctsIdentifierNotFound,
[GetIdentifier(Params.Identifier)]);
end;
@ -1030,7 +1046,7 @@ begin
Params.Free;
end;
end else begin
// find declaration of not identifier, e.g. numeric label
// find declaration of non identifier, e.g. numeric label
end;
finally
@ -1530,8 +1546,9 @@ function TFindDeclarationTool.FindDeclarationOfIdentAtCursor(
Result:
true, if NewPos+NewTopLine valid
For example:
Examples:
A^.B().C[].Identifier
inherited Identifier(p1,p2)
}
var
StartPos, EndPos: integer;
@ -1544,9 +1561,12 @@ begin
' "',copy(Src,Params.ContextNode.StartPos,20),'"');
{$ENDIF}
Result:=false;
// search in cleaned source
MoveCursorToCleanPos(Params.Identifier);
StartPos:=CurPos.StartPos;
if Params.ContextNode.Desc<>ctnIdentifier then StartPos:=-1;
if Params.ContextNode.Desc<>ctnIdentifier then
StartPos:=-1
else
StartPos:=GetHybridCursorStart;
ReadNextAtom;
EndPos:=CurPos.EndPos;
ReadNextAtom;

View File

@ -813,7 +813,7 @@ begin
writeln('TIdentCompletionTool.GatherIdentifiers A CursorPos=',CursorPos.X,',',CursorPos.Y);
{$ENDIF}
BuildTreeAndGetCleanPos(trTillCursor,CursorPos,CleanCursorPos,
[{$IFDEF IgnoreErrorAfterCursor}btSetIgnoreErrorPos{$ENDIF}],true);
[{$IFDEF IgnoreErrorAfterCursor}btSetIgnoreErrorPos,{$ENDIF}]);
// find node at position
CursorNode:=FindDeepestExpandedNodeAtPos(CleanCursorPos,true);

View File

@ -663,12 +663,12 @@ begin
if LinkIndex>=0 then begin
LastIndex:=LinkIndex;
while (Result>=0) do begin
if Links[Result].Code=Links[LinkIndex].Code then begin
if Links[Result].SrcPos>Links[LastIndex].SrcPos then begin
if FLinks[Result].Code=FLinks[LinkIndex].Code then begin
if Links[Result].SrcPos>FLinks[LastIndex].SrcPos then begin
// the include file was (in-)directly included by itself
// -> skip
Result:=FindParentLink(Result);
end else if Links[Result].SrcPos=1 then begin
end else if FLinks[Result].SrcPos=1 then begin
// start found
exit;
end;
@ -741,16 +741,16 @@ begin
while l<=r do begin
m:=(l+r) div 2;
if m<LinkCount-1 then begin
if ACleanPos<Links[m].CleanedPos then
if ACleanPos<FLinks[m].CleanedPos then
r:=m-1
else if ACleanPos>=Links[m+1].CleanedPos then
else if ACleanPos>=FLinks[m+1].CleanedPos then
l:=m+1
else begin
Result:=m;
exit;
end;
end else begin
if ACleanPos>=Links[m].CleanedPos then begin
if ACleanPos>=FLinks[m].CleanedPos then begin
Result:=m;
exit;
end else
@ -1326,9 +1326,9 @@ begin
// links
for i:=0 to LinkCount-1 do begin
writeln(' Link ',i,':'
,' CleanedPos=',Links[i].CleanedPos
,' SrcPos=',Links[i].SrcPos
,' Code=',HexStr(Cardinal(Links[i].Code),8)
,' CleanedPos=',FLinks[i].CleanedPos
,' SrcPos=',FLinks[i].SrcPos
,' Code=',HexStr(Cardinal(FLinks[i].Code),8)
);
end;
end;
@ -1859,7 +1859,6 @@ function TLinkScanner.GuessMisplacedIfdefEndif(StartCursorPos: integer;
var
LinkID, i, BestSrcPos: integer;
CurLink: TSourceLink;
LastCode: Pointer;
SearchedCodes: TList;
begin
@ -1870,9 +1869,8 @@ begin
BestSrcPos:=0;
i:=0;
while i<LinkCount do begin
CurLink:=Links[i];
if (StartCode=CurLink.Code) and (StartCursorPos>=CurLink.SrcPos) then begin
if (LinkID<0) or (BestSrcPos<CurLink.SrcPos) then
if (StartCode=FLinks[i].Code) and (StartCursorPos>=FLinks[i].SrcPos) then begin
if (LinkID<0) or (BestSrcPos<FLinks[i].SrcPos) then
LinkID:=i;
end;
inc(i);
@ -1883,17 +1881,17 @@ begin
SearchedCodes:=TList.Create;
try
while LinkId<LinkCount do begin
Result:=GuessMisplacedIfdefEndifInCode(Links[LinkID].Code,
Result:=GuessMisplacedIfdefEndifInCode(FLinks[LinkID].Code,
StartCursorPos,StartCode,EndCursorPos,EndCode);
if Result then exit;
// search next code
LastCode:=Links[LinkID].Code;
LastCode:=FLinks[LinkID].Code;
SearchedCodes.Add(LastCode);
repeat
inc(LinkID);
if LinkID>=LinkCount then exit;
until (Links[LinkID].Code<>LastCode)
and (SearchedCodes.IndexOf(Links[LinkID].Code)<0);
until (FLinks[LinkID].Code<>LastCode)
and (SearchedCodes.IndexOf(FLinks[LinkID].Code)<0);
end;
finally
SearchedCodes.Free;
@ -2627,21 +2625,30 @@ begin
SkippedCleanPos:=-1;
while i<LinkCount do begin
//writeln('[TLinkScanner.CursorToCleanPos] A ACursorPos=',ACursorPos,', Code=',Links[i].Code=ACode,', Links[i].SrcPos=',Links[i].SrcPos,', Links[i].CleanedPos=',Links[i].CleanedPos);
if (Links[i].Code=ACode) and (Links[i].SrcPos<=ACursorPos) then begin
ACleanPos:=ACursorPos-Links[i].SrcPos+Links[i].CleanedPos;
if (FLinks[i].Code=ACode) and (FLinks[i].SrcPos<=ACursorPos) then begin
// link in same code found
ACleanPos:=ACursorPos-FLinks[i].SrcPos+FLinks[i].CleanedPos;
//writeln('[TLinkScanner.CursorToCleanPos] B ACleanPos=',ACleanPos);
if i+1<LinkCount then begin
// link has successor
//writeln('[TLinkScanner.CursorToCleanPos] C Links[i+1].CleanedPos=',Links[i+1].CleanedPos);
if ACleanPos<Links[i+1].CleanedPos then begin
if ACleanPos<FLinks[i+1].CleanedPos then begin
// link covers the cursor position
Result:=0; // valid position
exit;
end;
// set found cleanpos to end of link
ACleanPos:=FLinks[i].CleanedPos+LinkSize(i);
// link does not cover the cursor position
// find the next link in the same code
j:=i+1;
while (j<LinkCount) and (Links[j].Code<>ACode) do inc(j);
while (j<LinkCount) and (FLinks[j].Code<>ACode) do inc(j);
//writeln('[TLinkScanner.CursorToCleanPos] D j=',j);
if (j<LinkCount) and (Links[j].SrcPos>ACursorPos) then begin
if (j<LinkCount) and (FLinks[j].SrcPos>ACursorPos) then begin
if not SkippedPos then begin
// CursorPos was skipped, CleanPos is between two links
// but because include files can be parsed multiple times,
// search must continue
SkippedPos:=true;
SkippedCleanPos:=ACleanPos;
end;
@ -2653,25 +2660,20 @@ begin
end else begin
// in last link
//writeln('[TLinkScanner.CursorToCleanPos] E length(FCleanedSrc)=',length(FCleanedSrc));
if ACleanPos<=length(FCleanedSrc) then
Result:=0 // valid position
else begin
if SkippedPos then begin
Result:=-1;
ACleanPos:=SkippedCleanPos;
end else
Result:=1; // cursor beyond scanned code
if ACleanPos<=length(FCleanedSrc) then begin
Result:=0; // valid position
exit;
end;
exit;
break;
end;
end;
inc(i);
end;
if SkippedPos then begin
Result:=-1;
ACLeanPos:=SkippedCleanPos;
ACleanPos:=SkippedCleanPos;
end else
Result:=1;
Result:=1; // default: CursorPos beyond/outside scanned code
end;
function TLinkScanner.CleanedPosToCursor(ACleanedPos: integer;
@ -2693,19 +2695,19 @@ begin
while l<=r do begin
m:=(l+r) div 2;
if m<LinkCount-1 then begin
if ACleanedPos<Links[m].CleanedPos then
if ACleanedPos<FLinks[m].CleanedPos then
r:=m-1
else if ACleanedPos>=Links[m+1].CleanedPos then
else if ACleanedPos>=FLinks[m+1].CleanedPos then
l:=m+1
else begin
ACode:=Links[m].Code;
ACursorPos:=ACleanedPos-Links[m].CleanedPos+Links[m].SrcPos;
ACode:=FLinks[m].Code;
ACursorPos:=ACleanedPos-FLinks[m].CleanedPos+FLinks[m].SrcPos;
exit;
end;
end else begin
if ACleanedPos>=Links[m].CleanedPos then begin
ACode:=Links[m].Code;
ACursorPos:=ACleanedPos-Links[m].CleanedPos+Links[m].SrcPos;
if ACleanedPos>=FLinks[m].CleanedPos then begin
ACode:=FLinks[m].Code;
ACursorPos:=ACleanedPos-FLinks[m].CleanedPos+FLinks[m].SrcPos;
exit;
end else
ConsistencyCheckI(2);
@ -2726,18 +2728,18 @@ begin
or (CleanEndPos>CleanedLen+1) or (not Assigned(FOnGetSourceStatus)) then exit;
LinkIndex:=LinkIndexAtCleanPos(CleanStartPos);
if LinkIndex<0 then exit;
ACode:=Links[LinkIndex].Code;
ACode:=FLinks[LinkIndex].Code;
FOnGetSourceStatus(Self,ACode,CodeIsReadOnly);
if CodeIsReadOnly then exit;
repeat
inc(LinkIndex);
if (LinkIndex>=LinkCount) or (Links[LinkIndex].CleanedPos>CleanEndPos) then
if (LinkIndex>=LinkCount) or (FLinks[LinkIndex].CleanedPos>CleanEndPos) then
begin
Result:=true;
exit;
end;
if ACode<>Links[LinkIndex].Code then begin
ACode:=Links[LinkIndex].Code;
if ACode<>FLinks[LinkIndex].Code then begin
ACode:=FLinks[LinkIndex].Code;
FOnGetSourceStatus(Self,ACode,CodeIsReadOnly);
if CodeIsReadOnly then exit;
end;
@ -2753,14 +2755,14 @@ begin
or (CleanEndPos>CleanedLen+1) or (UniqueSortedCodeList=nil) then exit;
LinkIndex:=LinkIndexAtCleanPos(CleanStartPos);
if LinkIndex<0 then exit;
ACode:=Links[LinkIndex].Code;
ACode:=FLinks[LinkIndex].Code;
AddCodeToUniqueList(ACode,UniqueSortedCodeList);
repeat
inc(LinkIndex);
if (LinkIndex>=LinkCount) or (Links[LinkIndex].CleanedPos>CleanEndPos) then
if (LinkIndex>=LinkCount) or (FLinks[LinkIndex].CleanedPos>CleanEndPos) then
exit;
if ACode<>Links[LinkIndex].Code then begin
ACode:=Links[LinkIndex].Code;
if ACode<>FLinks[LinkIndex].Code then begin
ACode:=FLinks[LinkIndex].Code;
AddCodeToUniqueList(ACode,UniqueSortedCodeList);
end;
until false;
@ -2777,23 +2779,21 @@ procedure TLinkScanner.DeleteRange(CleanStartPos,CleanEndPos: integer);
ToDo: keep include directives
}
var LinkIndex, StartPos, Len, aLinkSize: integer;
Link: TSourceLink;
begin
if (CleanStartPos<1) or (CleanStartPos>=CleanEndPos)
or (CleanEndPos>CleanedLen+1) or (not Assigned(FOnDeleteSource)) then exit;
LinkIndex:=LinkIndexAtCleanPos(CleanEndPos-1);
while LinkIndex>=0 do begin
Link:=Links[LinkIndex];
StartPos:=CleanStartPos-Link.CleanedPos;
if Startpos<0 then StartPos:=0;
StartPos:=CleanStartPos-FLinks[LinkIndex].CleanedPos;
if StartPos<0 then StartPos:=0;
aLinkSize:=LinkSize(LinkIndex);
if CleanEndPos<Link.CleanedPos+aLinkSize then
Len:=CleanEndPos-Link.CleanedPos-StartPos
if CleanEndPos<FLinks[LinkIndex].CleanedPos+aLinkSize then
Len:=CleanEndPos-FLinks[LinkIndex].CleanedPos-StartPos
else
Len:=aLinkSize-StartPos;
inc(StartPos,Link.SrcPos);
FOnDeleteSource(Self,Links[LinkIndex].Code,StartPos,Len);
if Link.CleanedPos<=CleanStartPos then break;
inc(StartPos,FLinks[LinkIndex].SrcPos);
FOnDeleteSource(Self,FLinks[LinkIndex].Code,StartPos,Len);
if FLinks[LinkIndex].CleanedPos<=CleanStartPos then break;
dec(LinkIndex);
end;
end;

View File

@ -325,7 +325,7 @@ begin
{$IFDEF CTDEBUG}
writeln('TMethodJumpingCodeTool.FindJumpPoint A CursorPos=',CursorPos.X,',',CursorPos.Y);
{$ENDIF}
BuildTreeAndGetCleanPos(trAll,CursorPos,CleanCursorPos,[],true);
BuildTreeAndGetCleanPos(trAll,CursorPos,CleanCursorPos,[]);
GetLineInfo(CleanCursorPos,LineStart,LineEnd,FirstAtomStart,LastAtomEnd);
if CleanCursorPos<FirstAtomStart then CleanCursorPos:=FirstAtomStart;
if CleanCursorPos>=LastAtomEnd then CleanCursorPos:=LastAtomEnd-1;

View File

@ -91,7 +91,8 @@ type
TBuildTreeFlag = (
btSetIgnoreErrorPos,
btKeepIgnoreErrorPos,
btLoadDirtySource
btLoadDirtySource,
btCursorPosOutAllowed
);
TBuildTreeFlags = set of TBuildTreeFlag;
@ -200,7 +201,7 @@ type
procedure BuildTree(OnlyInterfaceNeeded: boolean); virtual;
procedure BuildTreeAndGetCleanPos(TreeRange: TTreeRange;
const CursorPos: TCodeXYPosition; var CleanCursorPos: integer;
BuildTreeFlags: TBuildTreeFlags; ExceptionOnCursorPosOut: boolean);
BuildTreeFlags: TBuildTreeFlags);
procedure BuildSubTreeForClass(ClassNode: TCodeTreeNode); virtual;
procedure BuildSubTreeForBeginBlock(BeginNode: TCodeTreeNode); virtual;
procedure BuildSubTreeForProcHead(ProcNode: TCodeTreeNode); virtual;
@ -3243,8 +3244,7 @@ end;
procedure TPascalParserTool.BuildTreeAndGetCleanPos(
TreeRange: TTreeRange; const CursorPos: TCodeXYPosition;
var CleanCursorPos: integer; BuildTreeFlags: TBuildTreeFlags;
ExceptionOnCursorPosOut: boolean);
var CleanCursorPos: integer; BuildTreeFlags: TBuildTreeFlags);
var
CaretType: integer;
IgnorePos: TCodePosition;
@ -3297,7 +3297,7 @@ begin
end;
exit;
end;
if (CaretType=-2) or ExceptionOnCursorPosOut then
if (CaretType=-2) or (not (btCursorPosOutAllowed in BuildTreeFlags)) then
RaiseException(ctsCursorPosOutsideOfCode);
// cursor outside of clean code
CleanCursorPos:=-1;

View File

@ -1252,7 +1252,7 @@ var
begin
Result:=nil;
if IdentTree=nil then exit;
BuildTreeAndGetCleanPos(trTillCursor,CursorPos,CleanCursorPos,[],true);
BuildTreeAndGetCleanPos(trTillCursor,CursorPos,CleanCursorPos,[]);
BestDiff:=SrcLen+1;
MoveCursorToCleanPos(1);
repeat
@ -1326,7 +1326,7 @@ begin
StartPos:=CursorPos;
EndPos:=CursorPos;
Result:=true;
BuildTreeAndGetCleanPos(trAll,CursorPos,CleanCursorPos,[],true);
BuildTreeAndGetCleanPos(trAll,CursorPos,CleanCursorPos,[]);
{$IFDEF VerboseGetStringConstBounds}
writeln('TStandardCodeTool.GetStringConstBounds A ',CleanCursorPos,' "',copy(Src,CleanCursorPos-5,5),'" | "',copy(Src,CleanCursorPos,5),'"');
{$ENDIF}
@ -1518,7 +1518,7 @@ var
begin
Result:=false;
//writeln('TStandardCodeTool.GatherResourceStringSections A ');
BuildTreeAndGetCleanPos(trAll,CursorPos,CleanCursorPos,[],true);
BuildTreeAndGetCleanPos(trAll,CursorPos,CleanCursorPos,[]);
CursorNode:=FindDeepestNodeAtPos(CleanCursorPos,true);
PositionList.Clear;
ANode:=CursorNode;
@ -1558,7 +1558,7 @@ begin
Result:=false;
if ResStrIdentifier='' then exit;
// parse source and find clean positions
BuildTreeAndGetCleanPos(trAll,CursorPos,CleanCursorPos,[],true);
BuildTreeAndGetCleanPos(trAll,CursorPos,CleanCursorPos,[]);
// find resource string section
ANode:=FindDeepestNodeAtPos(CleanCursorPos,true);
if (ANode=nil) then exit;
@ -1587,7 +1587,7 @@ begin
Result:=false;
if MaxLen<=0 then exit;
// parse source and find clean positions
BuildTreeAndGetCleanPos(trAll,StartCursorPos,StartPos,[],true);
BuildTreeAndGetCleanPos(trAll,StartCursorPos,StartPos,[]);
Dummy:=CaretToCleanPos(EndCursorPos, EndPos);
if (Dummy<>0) and (Dummy<>-1) then exit;
// read string constants and extract identifier characters
@ -1723,7 +1723,7 @@ var
begin
Result:=false;
// parse source and find clean positions
BuildTreeAndGetCleanPos(trAll,StartCursorPos,StartPos,[],true);
BuildTreeAndGetCleanPos(trAll,StartCursorPos,StartPos,[]);
Dummy:=CaretToCleanPos(EndCursorPos, EndPos);
if (Dummy<>0) and (Dummy<>-1) then exit;
// read string constants and convert it
@ -1809,7 +1809,7 @@ begin
Result:=false;
if PositionList=nil then exit;
// parse source and find clean positions
BuildTreeAndGetCleanPos(trAll,CursorPos,CleanCursorPos,[],true);
BuildTreeAndGetCleanPos(trAll,CursorPos,CleanCursorPos,[]);
// find resource string section
ANode:=FindDeepestNodeAtPos(CleanCursorPos,true);
if (ANode=nil) then exit;
@ -1834,7 +1834,7 @@ begin
Result:=false;
IdentTree:=nil;
// parse source and find clean positions
BuildTreeAndGetCleanPos(trAll,SectionPos,CleanCursorPos,[],true);
BuildTreeAndGetCleanPos(trAll,SectionPos,CleanCursorPos,[]);
// find resource string section
ANode:=FindDeepestNodeAtPos(CleanCursorPos,true);
if (ANode=nil) then exit;
@ -1906,7 +1906,7 @@ begin
SourceChangeCache.MainScanner:=Scanner;
// parse source and find clean positions
//writeln('TStandardCodeTool.AddResourcestring B');
BuildTreeAndGetCleanPos(trAll,SectionPos,CleanSectionPos,[],true);
BuildTreeAndGetCleanPos(trAll,SectionPos,CleanSectionPos,[]);
//writeln('TStandardCodeTool.AddResourcestring C');
// find resource string section
SectionNode:=FindDeepestNodeAtPos(CleanSectionPos,true);
@ -2312,7 +2312,7 @@ begin
Result:=false;
try
BuildTreeAndGetCleanPos(trTillCursor,CursorPos,CleanCursorPos,
[{$IFDEF IgnoreErrorAfterCursor}btSetIgnoreErrorPos{$ENDIF}],true);
[{$IFDEF IgnoreErrorAfterCursor}btSetIgnoreErrorPos{$ENDIF}]);
LinkIndex:=Scanner.LinkIndexAtCleanPos(CleanCursorPos);
LinkIndex:=Scanner.FindParentLink(LinkIndex);
if LinkIndex<0 then

View File

@ -307,6 +307,9 @@ begin
Tool.Title:=lisCleanLazarusSource;
Tool.WorkingDirectory:='$(LazarusDir)';
Tool.CmdLineParams:='cleanall';
// append target OS
if Options.TargetOS<>'' then
Tool.CmdLineParams:=Tool.CmdLineParams+' OS_TARGET='+Options.TargetOS;
Result:=ExternalTools.Run(Tool,Macros);
if Result<>mrOk then exit;
end;

View File

@ -2823,10 +2823,12 @@ end;
------------------------------------------------------------------------------}
procedure TWinControl.CMShowingChanged(var Message: TLMessage);
begin
// ToDo: do not send this while loading, send it after loading.
if HandleAllocated then
CNSendMessage(LM_ShowHide, Self, nil);
// SetWindowPos(FHandle, 0, 0, 0, 0, 0, ShowFlags[FShowing]);
end;
{------------------------------------------------------------------------------
Method: TWinControl.ShowControl
Params: AControl: Control to show
@ -2847,6 +2849,9 @@ end;
{ =============================================================================
$Log$
Revision 1.143 2003/06/27 22:07:39 mattias
fixed targetos for clean all
Revision 1.142 2002/08/17 23:41:34 mattias
many clipping fixes