mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-05 17:40:15 +02:00
codetools: fixed AddWithBlock on ((i)), bug #29749
git-svn-id: trunk@52786 -
This commit is contained in:
parent
697fe56615
commit
a4ddf094a2
@ -46,6 +46,7 @@ unit ExtractProcTool;
|
|||||||
{$mode objfpc}{$H+}
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
{ $define CTDEBUG}
|
{ $define CTDEBUG}
|
||||||
|
{off $Define VerboseAddWithBlock}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
@ -1544,12 +1545,14 @@ var
|
|||||||
end;
|
end;
|
||||||
end else begin
|
end else begin
|
||||||
if Candidates=nil then exit;
|
if Candidates=nil then exit;
|
||||||
|
{$IFDEF VerboseAddWithBlock}
|
||||||
|
debugln(['TExtractProcTool.AddWithBlock.Add Candidate="',Identifier,'"']);
|
||||||
|
{$ENDIF}
|
||||||
i:=Candidates.IndexOf(Identifier);
|
i:=Candidates.IndexOf(Identifier);
|
||||||
if i<0 then
|
if i<0 then
|
||||||
Candidates.AddObject(Identifier,TObject(Pointer(1)))
|
Candidates.AddObject(Identifier,TObject(Pointer(1)))
|
||||||
else
|
else
|
||||||
Candidates.Objects[i]:=TObject(PtrUInt(Candidates.Objects[i])+1);
|
Candidates.Objects[i]:=TObject(PtrUInt(Candidates.Objects[i])+1);
|
||||||
//debugln(['TExtractProcTool.AddWithBlock.Add ',Identifier]);
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1560,13 +1563,16 @@ var
|
|||||||
StartFlag: TCommonAtomFlag;
|
StartFlag: TCommonAtomFlag;
|
||||||
IdentifierStart, aStartPos: Integer;
|
IdentifierStart, aStartPos: Integer;
|
||||||
begin
|
begin
|
||||||
|
{$IFDEF VerboseAddWithBlock}
|
||||||
|
debugln(['TExtractProcTool.AddWithBlock.ReadBlock START Atom=',GetAtom]);
|
||||||
|
{$ENDIF}
|
||||||
Result:=false;
|
Result:=false;
|
||||||
StartFlag:=CurPos.Flag;
|
StartFlag:=CurPos.Flag;
|
||||||
aStartPos:=CurPos.StartPos;
|
aStartPos:=CurPos.StartPos;
|
||||||
while true do begin
|
while true do begin
|
||||||
//debugln(['TExtractProcTool.AddWithBlock Atom=',GetAtom]);
|
{$IFDEF VerboseAddWithBlock}
|
||||||
if Code<>nil then
|
debugln([' ReadBlock Atom="',GetAtom,'"']);
|
||||||
Code^:=Code^+GetAtom;
|
{$ENDIF}
|
||||||
if (CurPos.EndPos>CleanEndPos) or (CurPos.StartPos>SrcLen)
|
if (CurPos.EndPos>CleanEndPos) or (CurPos.StartPos>SrcLen)
|
||||||
or (CurPos.StartPos>StartNode.EndPos) then
|
or (CurPos.StartPos>StartNode.EndPos) then
|
||||||
break;
|
break;
|
||||||
@ -1576,18 +1582,20 @@ var
|
|||||||
// nested brackets
|
// nested brackets
|
||||||
if not ReadBlock(Code) then exit;
|
if not ReadBlock(Code) then exit;
|
||||||
end;
|
end;
|
||||||
cafRoundBracketClose,cafEdgedBracketClose:
|
cafRoundBracketClose:
|
||||||
if (StartFlag=cafRoundBracketOpen) then begin
|
if (StartFlag=cafRoundBracketOpen) then
|
||||||
if (CurPos.Flag=cafRoundBracketClose) then
|
|
||||||
break
|
break
|
||||||
|
else if StartFlag=cafEdgedBracketOpen then
|
||||||
|
RaiseCharExpectedButAtomFound(']')
|
||||||
else
|
else
|
||||||
RaiseCharExpectedButAtomFound(')');
|
RaiseStringExpectedButAtomFound('end');
|
||||||
end else if (StartFlag=cafEdgedBracketOpen) then begin
|
cafEdgedBracketClose:
|
||||||
if (CurPos.Flag=cafEdgedBracketClose) then
|
if (StartFlag=cafEdgedBracketOpen) then
|
||||||
break
|
break
|
||||||
|
else if StartFlag=cafRoundBracketOpen then
|
||||||
|
RaiseCharExpectedButAtomFound(')')
|
||||||
else
|
else
|
||||||
RaiseCharExpectedButAtomFound(']');
|
RaiseStringExpectedButAtomFound('end');
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
if AtomIsIdentifier then begin
|
if AtomIsIdentifier then begin
|
||||||
LastPos:=LastAtoms.GetValueAt(0);
|
LastPos:=LastAtoms.GetValueAt(0);
|
||||||
@ -1595,33 +1603,43 @@ var
|
|||||||
or LastUpAtomIs(0,'INHERITED'))
|
or LastUpAtomIs(0,'INHERITED'))
|
||||||
then begin
|
then begin
|
||||||
// start of identifier
|
// start of identifier
|
||||||
//debugln(['TExtractProcTool.AddWithBlock identifier start ',GetAtom]);
|
{$IFDEF VerboseAddWithBlock}
|
||||||
|
debugln([' ReadBlock identifier START Atom="',GetAtom,'"']);
|
||||||
|
{$ENDIF}
|
||||||
Identifier:=GetAtom;
|
Identifier:=GetAtom;
|
||||||
IdentifierStart:=CurPos.StartPos;
|
IdentifierStart:=CurPos.StartPos;
|
||||||
repeat
|
repeat
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
//debugln(['TExtractProcTool.AddWithBlock identifier next ',GetAtom]);
|
{$IFDEF VerboseAddWithBlock}
|
||||||
|
debugln([' ReadBlock identifier NEXT Atom="',GetAtom,'" Identifier="',Identifier,'"']);
|
||||||
|
{$ENDIF}
|
||||||
if CurPos.Flag in [cafRoundBracketOpen,cafEdgedBracketOpen] then
|
if CurPos.Flag in [cafRoundBracketOpen,cafEdgedBracketOpen] then
|
||||||
begin
|
begin
|
||||||
if not ReadBlock(@Identifier) then exit;
|
if not ReadBlock(@Identifier) then exit;
|
||||||
end else if (CurPos.Flag=cafPoint) then begin
|
end else if (CurPos.Flag=cafPoint) then begin
|
||||||
if not Add(IdentifierStart,CurPos.EndPos,Identifier) then exit;
|
if not Add(IdentifierStart,CurPos.EndPos,Identifier) then exit;
|
||||||
Identifier:=Identifier+GetAtom;
|
|
||||||
end else if AtomIsChar('^') then begin
|
end else if AtomIsChar('^') then begin
|
||||||
Identifier:=Identifier+GetAtom;
|
end else if AtomIsIdentifier and (LastAtomIs(0,'.')) then begin
|
||||||
end else if AtomIsIdentifier and (LastAtomIs(0,'.')) then
|
|
||||||
begin
|
|
||||||
Identifier:=Identifier+GetAtom;
|
|
||||||
end else begin
|
end else begin
|
||||||
if Code<>nil then
|
|
||||||
Code^:=Code^+Identifier;
|
|
||||||
break;
|
break;
|
||||||
end;
|
end;
|
||||||
|
Identifier:=Identifier+GetAtom;
|
||||||
until false;
|
until false;
|
||||||
|
{$IFDEF VerboseAddWithBlock}
|
||||||
|
debugln([' ReadBlock identifier END Atom="',GetAtom,'" Identifier="',Identifier,'"']);
|
||||||
|
{$ENDIF}
|
||||||
|
if Code<>nil then
|
||||||
|
Code^:=Code^+Identifier;
|
||||||
|
continue;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
if Code<>nil then
|
||||||
|
Code^:=Code^+GetAtom;
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
end;
|
end;
|
||||||
|
{$IFDEF VerboseAddWithBlock}
|
||||||
|
debugln(['ReadBlock END Atom="',GetAtom,'"']);
|
||||||
|
{$ENDIF}
|
||||||
Result:=true;
|
Result:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1632,8 +1650,10 @@ begin
|
|||||||
Result:=false;
|
Result:=false;
|
||||||
if not CheckIfRangeOnSameLevel(StartPos,EndPos,CleanStartPos,CleanEndPos,
|
if not CheckIfRangeOnSameLevel(StartPos,EndPos,CleanStartPos,CleanEndPos,
|
||||||
StartNode) then exit;
|
StartNode) then exit;
|
||||||
//debugln(['TExtractProcTool.AddWithBlock ',SrcLen,' ',CleanStartPos,' ',CleanEndPos]);
|
{$IFDEF VerboseAddWithBlock}
|
||||||
//debugln(['TExtractProcTool.AddWithBlock Src="',copy(Src,CleanStartPos,CleanEndPos-CleanStartPos),'"']);
|
debugln(['TExtractProcTool.AddWithBlock ',SrcLen,' ',CleanStartPos,' ',CleanEndPos]);
|
||||||
|
debugln(['TExtractProcTool.AddWithBlock Src="',copy(Src,CleanStartPos,CleanEndPos-CleanStartPos),'"']);
|
||||||
|
{$ENDIF}
|
||||||
MoveCursorToNodeStart(StartNode);
|
MoveCursorToNodeStart(StartNode);
|
||||||
if WithExpr<>'' then
|
if WithExpr<>'' then
|
||||||
SourceChangeCache.MainScanner:=Scanner;
|
SourceChangeCache.MainScanner:=Scanner;
|
||||||
@ -1648,20 +1668,28 @@ begin
|
|||||||
Indent:=Beauty.GetLineIndent(Src,CleanStartPos);
|
Indent:=Beauty.GetLineIndent(Src,CleanStartPos);
|
||||||
Code:='with '+WithExpr+' do begin';
|
Code:='with '+WithExpr+' do begin';
|
||||||
Code:=Beauty.BeautifyStatement(Code,Indent);
|
Code:=Beauty.BeautifyStatement(Code,Indent);
|
||||||
//debugln(['TExtractProcTool.AddWithBlock Header=',Code]);
|
{$IFDEF VerboseAddWithBlock}
|
||||||
|
debugln(['TExtractProcTool.AddWithBlock Header=',Code]);
|
||||||
|
{$ENDIF}
|
||||||
if not SourceChangeCache.Replace(gtNewLine,gtNewLine,
|
if not SourceChangeCache.Replace(gtNewLine,gtNewLine,
|
||||||
CleanStartPos,CleanStartPos,Code) then exit;
|
CleanStartPos,CleanStartPos,Code) then exit;
|
||||||
// add 'end;'
|
// add 'end;'
|
||||||
Code:='end;';
|
Code:='end;';
|
||||||
Code:=Beauty.BeautifyStatement(Code,Indent);
|
Code:=Beauty.BeautifyStatement(Code,Indent);
|
||||||
//debugln(['TExtractProcTool.AddWithBlock Footer=',Code]);
|
{$IFDEF VerboseAddWithBlock}
|
||||||
|
debugln(['TExtractProcTool.AddWithBlock Footer=',Code]);
|
||||||
|
{$ENDIF}
|
||||||
if not SourceChangeCache.Replace(gtNewLine,gtNewLine,
|
if not SourceChangeCache.Replace(gtNewLine,gtNewLine,
|
||||||
CleanEndPos,CleanEndPos,Code) then exit;
|
CleanEndPos,CleanEndPos,Code) then exit;
|
||||||
// indent all between
|
// indent all between
|
||||||
//debugln(['TExtractProcTool.AddWithBlock Indent...']);
|
{$IFDEF VerboseAddWithBlock}
|
||||||
|
debugln(['TExtractProcTool.AddWithBlock Indent...']);
|
||||||
|
{$ENDIF}
|
||||||
if not SourceChangeCache.IndentBlock(CleanStartPos,CleanEndPos,
|
if not SourceChangeCache.IndentBlock(CleanStartPos,CleanEndPos,
|
||||||
Beauty.Indent) then exit;
|
Beauty.Indent) then exit;
|
||||||
//debugln(['TExtractProcTool.AddWithBlock Apply']);
|
{$IFDEF VerboseAddWithBlock}
|
||||||
|
debugln(['TExtractProcTool.AddWithBlock Apply']);
|
||||||
|
{$ENDIF}
|
||||||
if not SourceChangeCache.Apply then exit;
|
if not SourceChangeCache.Apply then exit;
|
||||||
end;
|
end;
|
||||||
Result:=true;
|
Result:=true;
|
||||||
|
Loading…
Reference in New Issue
Block a user