mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-16 16:29:32 +02:00
codetools: explode with block: started $else
git-svn-id: trunk@45439 -
This commit is contained in:
parent
f42dd644c8
commit
9d5f6711af
@ -1217,11 +1217,8 @@ var
|
|||||||
until (CurPos.StartPos>=EndPos) or (CurPos.StartPos>SrcLen);
|
until (CurPos.StartPos>=EndPos) or (CurPos.StartPos>SrcLen);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function Replace: boolean;
|
function RemoveWithHeader: boolean;
|
||||||
var
|
var
|
||||||
AVLNode: TAVLTreeNode;
|
|
||||||
CleanPos: LongInt;
|
|
||||||
WithVar: String;
|
|
||||||
StartPos: LongInt;
|
StartPos: LongInt;
|
||||||
EndPos: LongInt;
|
EndPos: LongInt;
|
||||||
WithKeywordStartPos: Integer;
|
WithKeywordStartPos: Integer;
|
||||||
@ -1233,8 +1230,6 @@ var
|
|||||||
KeepBeginEnd: Boolean;
|
KeepBeginEnd: Boolean;
|
||||||
NeedBeginEnd: Boolean;
|
NeedBeginEnd: Boolean;
|
||||||
begin
|
begin
|
||||||
SourceChangeCache.MainScanner:=Scanner;
|
|
||||||
|
|
||||||
if (WithVarNode.FirstChild<>nil)
|
if (WithVarNode.FirstChild<>nil)
|
||||||
and ((WithVarNode.PriorBrother=nil)
|
and ((WithVarNode.PriorBrother=nil)
|
||||||
or (WithVarNode.PriorBrother.Desc<>ctnWithVariable)
|
or (WithVarNode.PriorBrother.Desc<>ctnWithVariable)
|
||||||
@ -1318,7 +1313,16 @@ var
|
|||||||
if not SourceChangeCache.Replace(gtSpace,gtNone,StartPos,EndPos,'') then
|
if not SourceChangeCache.Replace(gtSpace,gtNone,StartPos,EndPos,'') then
|
||||||
exit(false);
|
exit(false);
|
||||||
end;
|
end;
|
||||||
|
Result:=true;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function PrefixSubIdentifiers: boolean;
|
||||||
|
var
|
||||||
|
WithVar: String;
|
||||||
|
AVLNode: TAVLTreeNode;
|
||||||
|
CleanPos: Integer;
|
||||||
|
begin
|
||||||
|
// insert all 'variable.'
|
||||||
if WithIdentifiers<>nil then begin
|
if WithIdentifiers<>nil then begin
|
||||||
WithVar:=ExtractCode(WithVarNode.StartPos,WithVarEndPos,[]);
|
WithVar:=ExtractCode(WithVarNode.StartPos,WithVarEndPos,[]);
|
||||||
if NeedBrackets(WithVarNode.StartPos,WithVarEndPos) then
|
if NeedBrackets(WithVarNode.StartPos,WithVarEndPos) then
|
||||||
@ -1336,7 +1340,62 @@ var
|
|||||||
AVLNode:=WithIdentifiers.FindSuccessor(AVLNode);
|
AVLNode:=WithIdentifiers.FindSuccessor(AVLNode);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
Result:=SourceChangeCache.Apply;
|
Result:=true;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function EncloseSkippedCode: boolean;
|
||||||
|
var
|
||||||
|
p: Integer;
|
||||||
|
EndPos: Integer;
|
||||||
|
WithHeader: String;
|
||||||
|
InsertPos: Integer;
|
||||||
|
Indent: Integer;
|
||||||
|
WithFooter: String;
|
||||||
|
begin
|
||||||
|
{$IFNDEF ExplodeWithEncloseSkipped}
|
||||||
|
exit(true);
|
||||||
|
{$ENDIF}
|
||||||
|
// enclose all $ELSE code in WITH blocks
|
||||||
|
WithHeader:='';
|
||||||
|
WithFooter:='';
|
||||||
|
p:=StatementNode.StartPos;
|
||||||
|
EndPos:=StatementNode.EndPos;
|
||||||
|
if EndPos>SrcLen then EndPos:=SrcLen;
|
||||||
|
while (p<EndPos) do begin
|
||||||
|
if (Src[p]=#3) and (Src[p-1]='{') then begin
|
||||||
|
// start of skipped code
|
||||||
|
if WithHeader='' then begin
|
||||||
|
WithHeader:=ExtractCode(WithVarNode.StartPos,WithVarEndPos,[]);
|
||||||
|
if NeedBrackets(WithVarNode.StartPos,WithVarEndPos) then
|
||||||
|
WithHeader:='('+WithHeader+')';
|
||||||
|
WithHeader:=Beauty.BeautifyKeyWord('with')+' '+WithHeader+' '
|
||||||
|
+Beauty.BeautifyKeyWord('do')
|
||||||
|
+' '+Beauty.BeautifyKeyWord('begin')+Beauty.LineEnd;
|
||||||
|
end;
|
||||||
|
InsertPos:=p+1;
|
||||||
|
Indent:=Beauty.GetLineIndent(Src,p);
|
||||||
|
debugln(['EncloseSkippedCode Header=',dbgstr(WithHeader)]);
|
||||||
|
if not SourceChangeCache.Replace(gtNone,gtNone,InsertPos,InsertPos,
|
||||||
|
WithHeader+Beauty.GetIndentStr(Indent))
|
||||||
|
then
|
||||||
|
exit(false);
|
||||||
|
end else if (Src[p]=#3) and (Src[p+1]=')') then begin
|
||||||
|
// end of skipped code
|
||||||
|
InsertPos:=p;
|
||||||
|
Indent:=Beauty.GetLineIndent(Src,p);
|
||||||
|
if WithFooter='' then begin
|
||||||
|
WithFooter:=Beauty.BeautifyKeyWord('end')+';'+Beauty.LineEnd;
|
||||||
|
end;
|
||||||
|
debugln(['EncloseSkippedCode Footer=',dbgstr(WithFooter)]);
|
||||||
|
if not SourceChangeCache.Replace(gtNone,gtNone,InsertPos,InsertPos,
|
||||||
|
WithFooter+Beauty.GetIndentStr(Indent))
|
||||||
|
then
|
||||||
|
exit(false);
|
||||||
|
end;
|
||||||
|
inc(p);
|
||||||
|
end;
|
||||||
|
|
||||||
|
Result:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
@ -1381,9 +1440,15 @@ begin
|
|||||||
debugln(['TExtractProcTool.RemoveWithBlock Statement=',copy(Src,StatementNode.StartPos,StatementNode.EndPos-StatementNode.StartPos)]);
|
debugln(['TExtractProcTool.RemoveWithBlock Statement=',copy(Src,StatementNode.StartPos,StatementNode.EndPos-StatementNode.StartPos)]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
// replace
|
// RemoveWithHeader
|
||||||
Result:=Replace;
|
SourceChangeCache.MainScanner:=Scanner;
|
||||||
|
if not RemoveWithHeader then exit;
|
||||||
|
if not PrefixSubIdentifiers then exit;
|
||||||
|
if not EncloseSkippedCode then exit;
|
||||||
|
|
||||||
|
Result:=SourceChangeCache.Apply;
|
||||||
|
//debugln(['TExtractProcTool.RemoveWithBlock SOURCE:']);
|
||||||
|
//debugln(TCodeBuffer(Scanner.MainCode).Source);
|
||||||
finally
|
finally
|
||||||
WithIdentifiers.Free;
|
WithIdentifiers.Free;
|
||||||
if WithVarCache<>nil then begin
|
if WithVarCache<>nil then begin
|
||||||
|
Loading…
Reference in New Issue
Block a user