mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 07:55:58 +02:00
renamed one Rect
git-svn-id: trunk@3828 -
This commit is contained in:
parent
2eacf15226
commit
df9de104a3
@ -236,6 +236,11 @@ type
|
||||
// gather identifiers
|
||||
function GatherIdentifiers(Code: TCodeBuffer; X,Y: integer): boolean;
|
||||
|
||||
// expressions
|
||||
function GetExpressionBounds(Code: TCodeBuffer; X,Y: integer;
|
||||
var StartCode: TCodeBuffer; var StartX, StartY: integer;
|
||||
var EndCode: TCodeBuffer; var EndX, EndY: integer): boolean;
|
||||
|
||||
// functions for events in the object inspector
|
||||
function GetCompatiblePublishedMethods(Code: TCodeBuffer;
|
||||
const AClassName: string; TypeData: PTypeData;
|
||||
@ -254,7 +259,8 @@ type
|
||||
function CreatePublishedMethod(Code: TCodeBuffer; const AClassName,
|
||||
NewMethodName: string; ATypeInfo: PTypeInfo): boolean;
|
||||
|
||||
// code completion = auto class completion, auto forward proc completion
|
||||
// code completion = auto class completion, auto forward proc completion,
|
||||
// local var assignment completion, event assignment completion
|
||||
function CompleteCode(Code: TCodeBuffer; X,Y,TopLine: integer;
|
||||
var NewCode: TCodeBuffer;
|
||||
var NewX, NewY, NewTopLine: integer): boolean;
|
||||
@ -792,6 +798,35 @@ begin
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
function TCodeToolManager.GetExpressionBounds(Code: TCodeBuffer; X, Y: integer;
|
||||
var StartCode: TCodeBuffer; var StartX, StartY: integer;
|
||||
var EndCode: TCodeBuffer; var EndX, EndY: integer): boolean;
|
||||
var
|
||||
CursorPos, StartPos, EndPos: TCodeXYPosition;
|
||||
begin
|
||||
Result:=false;
|
||||
{$IFDEF CTDEBUG}
|
||||
writeln('TCodeToolManager.GetExpressionBounds A ',Code.Filename,' x=',x,' y=',y);
|
||||
{$ENDIF}
|
||||
if not InitCurCodeTool(Code) then exit;
|
||||
CursorPos.X:=X;
|
||||
CursorPos.Y:=Y;
|
||||
CursorPos.Code:=Code;
|
||||
try
|
||||
Result:=FCurCodeTool.GetExpressionBounds(CursorPos,StartPos,EndPos);
|
||||
if Result then begin
|
||||
StartCode:=StartPos.Code;
|
||||
StartX:=StartPos.X;
|
||||
StartY:=StartPos.Y;
|
||||
EndCode:=EndPos.Code;
|
||||
EndX:=EndPos.X;
|
||||
EndY:=EndPos.Y;
|
||||
end;
|
||||
except
|
||||
on e: Exception do Result:=HandleException(e);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TCodeToolManager.GuessMisplacedIfdefEndif(Code: TCodeBuffer; X,Y: integer;
|
||||
var NewCode: TCodeBuffer;
|
||||
var NewX, NewY, NewTopLine: integer): boolean;
|
||||
|
@ -68,7 +68,6 @@ type
|
||||
EParserAbort = class(ECodeToolError)
|
||||
end;
|
||||
|
||||
|
||||
{ TCustomCodeTool }
|
||||
|
||||
TCustomCodeTool = class(TObject)
|
||||
@ -149,6 +148,8 @@ type
|
||||
var Caret:TCodeXYPosition): boolean; // true=ok, false=invalid CleanPos
|
||||
function CleanPosToCaretAndTopLine(CleanPos: integer;
|
||||
var Caret:TCodeXYPosition; var NewTopLine: integer): boolean; // true=ok, false=invalid CleanPos
|
||||
procedure GetCleanPosInfo(CodePosInFront, CleanPos: integer;
|
||||
ResolveComments: boolean; var SameArea: TAtomPosition);
|
||||
procedure GetLineInfo(ACleanPos: integer;
|
||||
var ALineStart, ALineEnd, AFirstAtomStart, ALastAtomEnd: integer);
|
||||
function FindLineEndOrCodeAfterPosition(StartPos: integer): integer;
|
||||
@ -171,6 +172,7 @@ type
|
||||
function IsPCharInSrc(ACleanPos: PChar): boolean;
|
||||
function ReadTilBracketClose(ExceptionOnNotFound: boolean): boolean;
|
||||
function ReadBackTilBracketOpen(ExceptionOnNotFound: boolean): boolean;
|
||||
procedure ReadTillCommentEnd;
|
||||
function DoAtom: boolean; virtual;
|
||||
procedure ReadNextAtom;
|
||||
procedure UndoReadNextAtom;
|
||||
@ -665,11 +667,7 @@ begin
|
||||
{$R-}
|
||||
if (CurPos.StartPos<CurPos.EndPos) then
|
||||
LastAtoms.Add(CurPos);
|
||||
if NextPos.StartPos>=1 then begin
|
||||
CurPos:=NextPos;
|
||||
NextPos.StartPos:=-1;
|
||||
exit;
|
||||
end;
|
||||
if NextPos.StartPos<1 then begin
|
||||
CurPos.StartPos:=CurPos.EndPos;
|
||||
CurPos.Flag:=cafNone;
|
||||
if CurPos.StartPos>SrcLen then
|
||||
@ -689,21 +687,26 @@ begin
|
||||
begin
|
||||
CommentLvl:=1;
|
||||
inc(CurPos.StartPos);
|
||||
while (CurPos.StartPos<=SrcLen) and (CommentLvl>0) do begin
|
||||
while true do begin
|
||||
case Src[CurPos.StartPos] of
|
||||
#0: if CurPos.StartPos>SrcLen then break;
|
||||
'{': if Scanner.NestedComments then inc(CommentLvl);
|
||||
'}': dec(CommentLvl);
|
||||
'}':
|
||||
begin
|
||||
dec(CommentLvl);
|
||||
if CommentLvl=0 then break;
|
||||
end;
|
||||
end;
|
||||
inc(CurPos.StartPos);
|
||||
end;
|
||||
inc(CurPos.StartPos);
|
||||
end;
|
||||
'/': // Delphi comment
|
||||
if (Src[CurPos.StartPos+1]<>'/') then begin
|
||||
break;
|
||||
end else begin
|
||||
inc(CurPos.StartPos,2);
|
||||
while (CurPos.StartPos<=SrcLen)
|
||||
and (not (Src[CurPos.StartPos] in [#10,#13])) do
|
||||
while (not (Src[CurPos.StartPos] in [#10,#13,#0])) do
|
||||
inc(CurPos.StartPos);
|
||||
inc(CurPos.StartPos);
|
||||
if (CurPos.StartPos<=SrcLen) and (Src[CurPos.StartPos] in [#10,#13])
|
||||
@ -725,11 +728,10 @@ begin
|
||||
end;
|
||||
end;
|
||||
CurPos.EndPos:=CurPos.StartPos;
|
||||
if CurPos.StartPos>SrcLen then
|
||||
exit;
|
||||
// read atom
|
||||
c1:=UpperSrc[CurPos.EndPos];
|
||||
case c1 of
|
||||
#0: ;
|
||||
'_','A'..'Z':
|
||||
begin
|
||||
inc(CurPos.EndPos);
|
||||
@ -906,11 +908,17 @@ begin
|
||||
or ((c1='*') and (c2='*'))
|
||||
then inc(CurPos.EndPos);
|
||||
if ((c1='@') and (c2='@')) then begin
|
||||
// @@ label
|
||||
repeat
|
||||
inc(CurPos.EndPos);
|
||||
until (CurPos.EndPos>SrcLen) or (not IsIdentChar[Src[CurPos.EndPos]]);
|
||||
end;
|
||||
end;
|
||||
end else begin
|
||||
CurPos:=NextPos;
|
||||
NextPos.StartPos:=-1;
|
||||
exit;
|
||||
end;
|
||||
{$IFDEF RangeChecking}{$R+}{$ENDIF}
|
||||
end;
|
||||
|
||||
@ -1389,6 +1397,53 @@ begin
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
procedure TCustomCodeTool.ReadTillCommentEnd;
|
||||
var
|
||||
CommentLvl: Integer;
|
||||
begin
|
||||
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
|
||||
{$R-}
|
||||
case Src[CurPos.StartPos] of
|
||||
'{': // pascal comment
|
||||
begin
|
||||
CommentLvl:=1;
|
||||
inc(CurPos.StartPos);
|
||||
while true do begin
|
||||
case Src[CurPos.StartPos] of
|
||||
#0: if CurPos.StartPos>SrcLen then break;
|
||||
'{': if Scanner.NestedComments then inc(CommentLvl);
|
||||
'}':
|
||||
begin
|
||||
dec(CommentLvl);
|
||||
if CommentLvl=0 then break;
|
||||
end;
|
||||
end;
|
||||
inc(CurPos.StartPos);
|
||||
end;
|
||||
inc(CurPos.StartPos);
|
||||
end;
|
||||
'/': // Delphi comment
|
||||
if (Src[CurPos.StartPos+1]='/') then begin
|
||||
inc(CurPos.StartPos,2);
|
||||
while (not (Src[CurPos.StartPos] in [#10,#13,#0])) do
|
||||
inc(CurPos.StartPos);
|
||||
inc(CurPos.StartPos);
|
||||
if (CurPos.StartPos<=SrcLen) and (Src[CurPos.StartPos] in [#10,#13])
|
||||
and (Src[CurPos.StartPos-1]<>Src[CurPos.StartPos]) then
|
||||
inc(CurPos.StartPos);
|
||||
end;
|
||||
'(': // old turbo pascal comment
|
||||
if (Src[CurPos.StartPos+1]='*') then begin
|
||||
inc(CurPos.StartPos,3);
|
||||
while (CurPos.StartPos<=SrcLen)
|
||||
and ((Src[CurPos.StartPos-1]<>'*') or (Src[CurPos.StartPos]<>')')) do
|
||||
inc(CurPos.StartPos);
|
||||
inc(CurPos.StartPos);
|
||||
end;
|
||||
end;
|
||||
{$IFDEF RangeChecking}{$R+}{$ENDIF}
|
||||
end;
|
||||
|
||||
procedure TCustomCodeTool.BeginParsing(DeleteNodes,
|
||||
OnlyInterfaceNeeded: boolean);
|
||||
begin
|
||||
@ -1806,6 +1861,71 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCustomCodeTool.GetCleanPosInfo(CodePosInFront, CleanPos: integer;
|
||||
ResolveComments: boolean; var SameArea: TAtomPosition);
|
||||
var
|
||||
ANode: TCodeTreeNode;
|
||||
begin
|
||||
if CodePosInFront<1 then begin
|
||||
ANode:=FindDeepestNodeAtPos(CleanPos,True);
|
||||
CodePosInFront:=ANode.StartPos;
|
||||
end;
|
||||
MoveCursorToCleanPos(CodePosInFront);
|
||||
repeat
|
||||
ReadNextAtom;
|
||||
if (CleanPos>=CurPos.StartPos) and (CleanPos<CurPos.EndPos) then begin
|
||||
// clean pos on token
|
||||
SameArea:=CurPos;
|
||||
exit;
|
||||
end;
|
||||
if CleanPos<CurPos.StartPos then begin
|
||||
// clean pos between tokens
|
||||
SameArea.Flag:=cafNone;
|
||||
// get range of space behind last atom
|
||||
if LastAtoms.Count>0 then begin
|
||||
SameArea.StartPos:=LastAtoms.GetValueAt(0).EndPos;
|
||||
end else begin
|
||||
SameArea.StartPos:=CodePosInFront;
|
||||
end;
|
||||
SameArea.EndPos:=SameArea.StartPos;
|
||||
repeat
|
||||
while (SameArea.EndPos<=SrcLen)
|
||||
and (IsSpaceChar[Src[SameArea.EndPos]]) do
|
||||
inc(SameArea.EndPos);
|
||||
if (SameArea.EndPos>CleanPos) or (SameArea.EndPos>SrcLen) then begin
|
||||
// cursor is in normal space (i.e. not comment)
|
||||
exit;
|
||||
end;
|
||||
// still between the two tokens, but end of space
|
||||
// -> here starts a comment
|
||||
SameArea.StartPos:=SameArea.EndPos;
|
||||
MoveCursorToCleanPos(SameArea.StartPos);
|
||||
ReadTillCommentEnd;
|
||||
SameArea.EndPos:=CurPos.EndPos;
|
||||
if (SameArea.StartPos=SameArea.EndPos) then
|
||||
RaiseException('TCustomCodeTool.GetCleanPosInfo Internal Error A');
|
||||
if CleanPos<SameArea.EndPos then begin
|
||||
// cursor is in comment
|
||||
if ResolveComments then begin
|
||||
// take comment as normal code and search again
|
||||
CodePosInFront:=SameArea.StartPos;
|
||||
case Src[CodePosInFront] of
|
||||
'{': inc(CodePosInFront);
|
||||
'(','/': inc(CodePosInFront,2);
|
||||
else
|
||||
RaiseException('TCustomCodeTool.GetCleanPosInfo Internal Error B');
|
||||
end;
|
||||
GetCleanPosInfo(CodePosInFront,CleanPos,true,SameArea);
|
||||
end;
|
||||
exit;
|
||||
end;
|
||||
SameArea.StartPos:=SameArea.EndPos;
|
||||
until false;
|
||||
end;
|
||||
until (CurPos.Flag=cafNone) or (CurPos.EndPos>CleanPos);
|
||||
SameArea:=CurPos;
|
||||
end;
|
||||
|
||||
procedure TCustomCodeTool.GetLineInfo(ACleanPos: integer;
|
||||
var ALineStart, ALineEnd, AFirstAtomStart, ALastAtomEnd: integer);
|
||||
begin
|
||||
|
@ -196,6 +196,7 @@ type
|
||||
procedure BuildSubTreeForProcHead(ProcNode: TCodeTreeNode); virtual;
|
||||
procedure BuildSubTreeForProcHead(ProcNode: TCodeTreeNode;
|
||||
var FunctionResult: TCodeTreeNode);
|
||||
procedure BuildSubTree(CleanCursorPos: integer); virtual;
|
||||
|
||||
function DoAtom: boolean; override;
|
||||
|
||||
@ -3927,15 +3928,20 @@ begin
|
||||
RaiseLastError;
|
||||
// check if cursor is in interface
|
||||
Dummy:=CaretToCleanPos(CursorPos, CleanCursorPos);
|
||||
if (Dummy=0) or (Dummy=-1) then
|
||||
if (Dummy=0) or (Dummy=-1) then begin
|
||||
BuildSubTree(CleanCursorPos);
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
BuildTree(TreeRange=trInterface);
|
||||
if (not IgnoreErrorAfterValid) and (not EndOfSourceFound) then
|
||||
SaveRaiseException(ctsEndOfSourceNotFound);
|
||||
// find the CursorPos in cleaned source
|
||||
Dummy:=CaretToCleanPos(CursorPos, CleanCursorPos);
|
||||
if (Dummy<>0) and (Dummy<>-1) then
|
||||
if (Dummy=0) or (Dummy=-1) then begin
|
||||
BuildSubTree(CleanCursorPos);
|
||||
exit;
|
||||
end;
|
||||
RaiseException(ctsCursorPosOutsideOfCode);
|
||||
end;
|
||||
|
||||
@ -4276,6 +4282,21 @@ begin
|
||||
FunctionResult:=FunctionResult.NextBrother;
|
||||
end;
|
||||
|
||||
procedure TPascalParserTool.BuildSubTree(CleanCursorPos: integer);
|
||||
var
|
||||
ANode: TCodeTreeNode;
|
||||
begin
|
||||
ANode:=FindDeepestNodeAtPos(CleanCursorPos,true);
|
||||
case ANode.Desc of
|
||||
ctnClass,ctnClassInterface:
|
||||
BuildSubTreeForClass(ANode);
|
||||
ctnProcedure,ctnProcedureHead:
|
||||
BuildSubTreeForProcHead(ANode);
|
||||
ctnBeginBlock:
|
||||
BuildSubTreeForBeginBlock(ANode);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
end.
|
||||
|
||||
|
@ -57,10 +57,6 @@ type
|
||||
function ReadForwardTilAnyBracketClose: boolean;
|
||||
function ReadBackwardTilAnyBracketClose: boolean;
|
||||
public
|
||||
// search & replace
|
||||
function ReplaceIdentifiers(IdentList: TStrings;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
|
||||
// source name e.g. 'unit UnitName;'
|
||||
function GetSourceNamePos(var NamePos: TAtomPosition): boolean;
|
||||
function GetSourceName: string;
|
||||
@ -155,6 +151,14 @@ type
|
||||
var NewPos: TCodeXYPosition; var NewTopLine: integer): boolean;
|
||||
function FindEnclosingIncludeDirective(CursorPos: TCodeXYPosition;
|
||||
var NewPos: TCodeXYPosition; var NewTopLine: integer): boolean;
|
||||
|
||||
// search & replace
|
||||
function ReplaceIdentifiers(IdentList: TStrings;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
|
||||
// expressions
|
||||
function GetExpressionBounds(CursorPos: TCodeXYPosition;
|
||||
var StartPos, EndPos: TCodeXYPosition): boolean;
|
||||
end;
|
||||
|
||||
|
||||
@ -1180,6 +1184,20 @@ begin
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
function TStandardCodeTool.GetExpressionBounds(CursorPos: TCodeXYPosition;
|
||||
var StartPos, EndPos: TCodeXYPosition): boolean;
|
||||
var
|
||||
CleanCursorPos: integer;
|
||||
CursorNode: TCodeTreeNode;
|
||||
begin
|
||||
Result:=false;
|
||||
BuildTreeAndGetCleanPos(trAll,CursorPos,CleanCursorPos,[]);
|
||||
CursorNode:=FindDeepestNodeAtPos(CleanCursorPos,true);
|
||||
MoveCursorToNodeStart(CursorNode);
|
||||
ReadNextAtom;
|
||||
|
||||
end;
|
||||
|
||||
function TStandardCodeTool.FindPublishedVariable(const UpperClassName,
|
||||
UpperVarName: string): TCodeTreeNode;
|
||||
var ClassNode, SectionNode: TCodeTreeNode;
|
||||
|
Loading…
Reference in New Issue
Block a user