From 4567f3e78d3c27ca9955b9a021accca0401e083c Mon Sep 17 00:00:00 2001 From: lazarus Date: Wed, 1 May 2002 06:36:25 +0000 Subject: [PATCH] MG: fixed find property git-svn-id: trunk@1655 - --- components/codetools/customcodetool.pas | 418 ++++++++++--------- components/codetools/finddeclarationtool.pas | 2 +- 2 files changed, 212 insertions(+), 208 deletions(-) diff --git a/components/codetools/customcodetool.pas b/components/codetools/customcodetool.pas index dbdbcdf72c..c778e5bf88 100644 --- a/components/codetools/customcodetool.pas +++ b/components/codetools/customcodetool.pas @@ -595,6 +595,8 @@ procedure TCustomCodeTool.ReadNextAtom; var c1, c2: char; CommentLvl: integer; begin + {$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF} + {$R-} if (CurPos.StartPos=1 then begin @@ -604,51 +606,55 @@ begin end; CurPos.StartPos:=CurPos.EndPos; CurPos.Flag:=cafNone; + if CurPos.StartPos>SrcLen then + exit; // Skip all spaces and comments CommentLvl:=0; - while CurPos.StartPos<=SrcLen do begin - if IsCommentStartChar[Src[CurPos.StartPos]] then begin - case Src[CurPos.StartPos] of - '{': // pascal comment - begin - CommentLvl:=1; - inc(CurPos.StartPos); - while (CurPos.StartPos<=SrcLen) and (CommentLvl>0) do begin - case Src[CurPos.StartPos] of - '{': if Scanner.NestedComments then inc(CommentLvl); - '}': dec(CommentLvl); - end; - inc(CurPos.StartPos); - end; - end; - '/': // Delphi comment - if (CurPos.StartPosSrc[CurPos.StartPos]) then - inc(CurPos.StartPos); - end else - break; - '(': // old turbo pascal comment - if (CurPos.StartPos'*') or (Src[CurPos.StartPos]<>')')) do - inc(CurPos.StartPos); - inc(CurPos.StartPos); - end else - break; - end; - end else if IsSpaceChar[Src[CurPos.StartPos]] then begin - repeat + while true do begin + case Src[CurPos.StartPos] of + #0: + if CurPos.StartPos>SrcLen then + break + else inc(CurPos.StartPos); - until (CurPos.StartPos>SrcLen) - or (not (IsSpaceChar[Src[CurPos.StartPos]])); - end else begin + #1..#32: + inc(CurPos.StartPos); + '{': // pascal comment + begin + CommentLvl:=1; + inc(CurPos.StartPos); + while (CurPos.StartPos<=SrcLen) and (CommentLvl>0) do begin + case Src[CurPos.StartPos] of + '{': if Scanner.NestedComments then inc(CommentLvl); + '}': dec(CommentLvl); + end; + inc(CurPos.StartPos); + end; + 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 + 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 + break; + end else 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; + else break; end; end; @@ -658,190 +664,188 @@ begin // read atom c1:=UpperSrc[CurPos.EndPos]; case c1 of - '_','A'..'Z': - begin + '_','A'..'Z': + begin + inc(CurPos.EndPos); + while (IsIdentChar[UpperSrc[CurPos.EndPos]]) do inc(CurPos.EndPos); - while (CurPos.EndPos<=SrcLen) - and (IsIdentChar[UpperSrc[CurPos.EndPos]]) do - inc(CurPos.EndPos); - CurPos.Flag:=cafWord; - case UpperSrc[CurPos.StartPos] of - 'B': - if (CurPos.EndPos-CurPos.StartPos=5) - and UpAtomIs('BEGIN') - then - CurPos.Flag:=cafBegin; - 'E': - if (CurPos.EndPos-CurPos.StartPos=3) - and (UpperSrc[CurPos.StartPos+1]='N') - and (UpperSrc[CurPos.StartPos+2]='D') - then - CurPos.Flag:=cafEnd; - 'R': - if (CurPos.EndPos-CurPos.StartPos=7) - and UpAtomIs('RECORD') - then - CurPos.Flag:=cafRecord; - end; + CurPos.Flag:=cafWord; + case c1 of + 'B': + if (CurPos.EndPos-CurPos.StartPos=5) + and UpAtomIs('BEGIN') + then + CurPos.Flag:=cafBegin; + 'E': + if (CurPos.EndPos-CurPos.StartPos=3) + and (UpperSrc[CurPos.StartPos+1]='N') + and (UpperSrc[CurPos.StartPos+2]='D') + then + CurPos.Flag:=cafEnd; + 'R': + if (CurPos.EndPos-CurPos.StartPos=7) + and UpAtomIs('RECORD') + then + CurPos.Flag:=cafRecord; end; - '''','#': - begin - while (CurPos.EndPos<=SrcLen) do begin - case (Src[CurPos.EndPos]) of - '#': - begin - inc(CurPos.EndPos); - if (CurPos.EndPos<=SrcLen) then begin - if (IsNumberChar[Src[CurPos.EndPos]]) then begin - // decimal - repeat - inc(CurPos.EndPos); - until (CurPos.EndPos>SrcLen) - or (not IsNumberChar[Src[CurPos.EndPos]]); - end else if Src[CurPos.EndPos]='$' then begin - // hexadecimal - repeat - inc(CurPos.EndPos); - until (CurPos.EndPos>SrcLen) - or (not IsHexNumberChar[Src[CurPos.EndPos]]); - end; - end; - end; - '''': - begin - inc(CurPos.EndPos); - while (CurPos.EndPos<=SrcLen) do begin - case Src[CurPos.EndPos] of - - '''': - begin - inc(CurPos.EndPos); - break; - end; - - #10,#13: - break; - - else + end; + '''','#': + begin + while (CurPos.EndPos<=SrcLen) do begin + case (Src[CurPos.EndPos]) of + '#': + begin + inc(CurPos.EndPos); + if (CurPos.EndPos<=SrcLen) then begin + if (IsNumberChar[Src[CurPos.EndPos]]) then begin + // decimal + repeat inc(CurPos.EndPos); - end; + until (CurPos.EndPos>SrcLen) + or (not IsNumberChar[Src[CurPos.EndPos]]); + end else if Src[CurPos.EndPos]='$' then begin + // hexadecimal + repeat + inc(CurPos.EndPos); + until (CurPos.EndPos>SrcLen) + or (not IsHexNumberChar[Src[CurPos.EndPos]]); end; end; - else - break; end; + '''': + begin + inc(CurPos.EndPos); + while (CurPos.EndPos<=SrcLen) do begin + case Src[CurPos.EndPos] of + + '''': + begin + inc(CurPos.EndPos); + break; + end; + + #10,#13: + break; + + else + inc(CurPos.EndPos); + end; + end; + end; + else + break; end; end; - '0'..'9': - begin + end; + '0'..'9': + begin + inc(CurPos.EndPos); + while (CurPos.EndPos<=SrcLen) and (IsNumberChar[Src[CurPos.EndPos]]) do inc(CurPos.EndPos); - while (CurPos.EndPos<=SrcLen) and (IsNumberChar[Src[CurPos.EndPos]]) do + if (CurPos.EndPos'.') then begin + // real type number + inc(CurPos.EndPos); + while (CurPos.EndPos<=SrcLen) and (IsNumberChar[Src[CurPos.EndPos]]) + do inc(CurPos.EndPos); - if (CurPos.EndPos'.') then begin - // real type number + if (CurPos.EndPos<=SrcLen) and (UpperSrc[CurPos.EndPos]='E') then + begin + // read exponent inc(CurPos.EndPos); + if (CurPos.EndPos<=SrcLen) and (Src[CurPos.EndPos] in ['-','+']) + then inc(CurPos.EndPos); while (CurPos.EndPos<=SrcLen) and (IsNumberChar[Src[CurPos.EndPos]]) do inc(CurPos.EndPos); - if (CurPos.EndPos<=SrcLen) and (UpperSrc[CurPos.EndPos]='E') then - begin - // read exponent - inc(CurPos.EndPos); - if (CurPos.EndPos<=SrcLen) and (Src[CurPos.EndPos] in ['-','+']) - then inc(CurPos.EndPos); - while (CurPos.EndPos<=SrcLen) and (IsNumberChar[Src[CurPos.EndPos]]) - do - inc(CurPos.EndPos); - end; end; end; - '%': - begin - inc(CurPos.EndPos); - while (CurPos.EndPos<=SrcLen) and (Src[CurPos.EndPos] in ['0'..'1']) do - inc(CurPos.EndPos); - end; - '$': - begin - inc(CurPos.EndPos); - while (CurPos.EndPos<=SrcLen) - and (IsHexNumberChar[UpperSrc[CurPos.EndPos]]) do - inc(CurPos.EndPos); - end; - ';': - begin - inc(CurPos.EndPos); - CurPos.Flag:=cafSemicolon; - end; - ',': - begin - inc(CurPos.EndPos); - CurPos.Flag:=cafComma; - end; - '=': - begin - inc(CurPos.EndPos); - CurPos.Flag:=cafEqual; - end; - '(': - begin - inc(CurPos.EndPos); - CurPos.Flag:=cafRoundBracketOpen; - end; - ')': - begin - inc(CurPos.EndPos); - CurPos.Flag:=cafRoundBracketClose; - end; - '[': - begin - inc(CurPos.EndPos); - CurPos.Flag:=cafEdgedBracketOpen; - end; - ']': - begin - inc(CurPos.EndPos); - CurPos.Flag:=cafEdgedBracketClose; - end; - ':': - begin - inc(CurPos.EndPos); - if (CurPos.EndPos>SrcLen) or (Src[CurPos.EndPos]<>'=') then begin - CurPos.Flag:=cafColon; - end else begin - // := - inc(CurPos.EndPos); - end; - end; - '.': - begin - inc(CurPos.EndPos); - if (CurPos.EndPos>SrcLen) or (Src[CurPos.EndPos]<>'.') then begin - CurPos.Flag:=cafPoint; - end else begin - // .. - inc(CurPos.EndPos); - end; - end; - else + end; + '%': + begin inc(CurPos.EndPos); - if CurPos.EndPos<=SrcLen then begin - c2:=Src[CurPos.EndPos]; - // test for double char operators :=, +=, -=, /=, *=, <>, <=, >=, **, >< - if ((c2='=') and (IsEqualOperatorStartChar[c1])) - or ((c1='<') and (c2='>')) // not equal - or ((c1='>') and (c2='<')) - or ((c1='.') and (c2='.')) // subrange - or ((c1='*') and (c2='*')) - then inc(CurPos.EndPos); - if ((c1='@') and (c2='@')) then begin - repeat - inc(CurPos.EndPos); - until (CurPos.EndPos>SrcLen) or (not IsIdentChar[Src[CurPos.EndPos]]); - end; + while (CurPos.EndPos<=SrcLen) and (Src[CurPos.EndPos] in ['0'..'1']) do + inc(CurPos.EndPos); + end; + '$': + begin + inc(CurPos.EndPos); + while (CurPos.EndPos<=SrcLen) + and (IsHexNumberChar[UpperSrc[CurPos.EndPos]]) do + inc(CurPos.EndPos); + end; + ';': + begin + inc(CurPos.EndPos); + CurPos.Flag:=cafSemicolon; + end; + ',': + begin + inc(CurPos.EndPos); + CurPos.Flag:=cafComma; + end; + '=': + begin + inc(CurPos.EndPos); + CurPos.Flag:=cafEqual; + end; + '(': + begin + inc(CurPos.EndPos); + CurPos.Flag:=cafRoundBracketOpen; + end; + ')': + begin + inc(CurPos.EndPos); + CurPos.Flag:=cafRoundBracketClose; + end; + '[': + begin + inc(CurPos.EndPos); + CurPos.Flag:=cafEdgedBracketOpen; + end; + ']': + begin + inc(CurPos.EndPos); + CurPos.Flag:=cafEdgedBracketClose; + end; + ':': + begin + inc(CurPos.EndPos); + if (Src[CurPos.EndPos]<>'=') then begin + CurPos.Flag:=cafColon; + end else begin + // := + inc(CurPos.EndPos); end; + end; + '.': + begin + inc(CurPos.EndPos); + if (Src[CurPos.EndPos]<>'.') then begin + CurPos.Flag:=cafPoint; + end else begin + // .. + inc(CurPos.EndPos); + end; + end; + else + inc(CurPos.EndPos); + c2:=Src[CurPos.EndPos]; + // test for double char operators :=, +=, -=, /=, *=, <>, <=, >=, **, >< + if ((c2='=') and (IsEqualOperatorStartChar[c1])) + or ((c1='<') and (c2='>')) // not equal + or ((c1='>') and (c2='<')) + or ((c1='.') and (c2='.')) // subrange + or ((c1='*') and (c2='*')) + then inc(CurPos.EndPos); + if ((c1='@') and (c2='@')) then begin + repeat + inc(CurPos.EndPos); + until (CurPos.EndPos>SrcLen) or (not IsIdentChar[Src[CurPos.EndPos]]); + end; end; + {$IFDEF RangeChecking}{$R+}{$ENDIF} end; procedure TCustomCodeTool.ReadPriorAtom; diff --git a/components/codetools/finddeclarationtool.pas b/components/codetools/finddeclarationtool.pas index 10716b6f01..f18389e235 100644 --- a/components/codetools/finddeclarationtool.pas +++ b/components/codetools/finddeclarationtool.pas @@ -1793,7 +1793,7 @@ begin // this is an indexed property exit; end; - if CurPos.Flag=cafPoint then begin + if CurPos.Flag=cafColon then begin ReadNextAtom; AtomIsIdentifier(true); OldPos:=CurPos.StartPos;