codetools: FindCommentInFront: fixed range error

git-svn-id: trunk@38532 -
This commit is contained in:
mattias 2012-09-06 07:31:14 +00:00
parent 91d58f99ce
commit 3b88607393
2 changed files with 52 additions and 115 deletions

View File

@ -229,7 +229,7 @@ type
WithCommentBounds, CaseSensitive, IgnoreSpaces, WithCommentBounds, CaseSensitive, IgnoreSpaces,
CompareOnlyStart: boolean; CompareOnlyStart: boolean;
out CommentStart, CommentEnd: TCodeXYPosition): boolean; out CommentStart, CommentEnd: TCodeXYPosition): boolean;
function FindCommentInFront(const StartPos: integer; function FindCommentInFront(StartPos: integer;
const CommentText: string; SearchInParentNode, const CommentText: string; SearchInParentNode,
WithCommentBounds, CaseSensitive, IgnoreSpaces, WithCommentBounds, CaseSensitive, IgnoreSpaces,
CompareOnlyStart: boolean; CompareOnlyStart: boolean;
@ -2843,7 +2843,7 @@ begin
and CleanPosToCaret(CommentCleanEnd,CommentEnd); and CleanPosToCaret(CommentCleanEnd,CommentEnd);
end; end;
function TPascalReaderTool.FindCommentInFront(const StartPos: integer; function TPascalReaderTool.FindCommentInFront(StartPos: integer;
const CommentText: string; const CommentText: string;
SearchInParentNode, WithCommentBounds, CaseSensitive, SearchInParentNode, WithCommentBounds, CaseSensitive,
IgnoreSpaces, CompareOnlyStart: boolean; IgnoreSpaces, CompareOnlyStart: boolean;
@ -2869,7 +2869,12 @@ var
// chomp comment boundaries // chomp comment boundaries
case Src[CompareStartPos] of case Src[CompareStartPos] of
'/','(': inc(CompareStartPos,2); '/','(': inc(CompareStartPos,2);
'{': inc(CompareStartPos,1); '{':
if (CompareStartPos<SrcLen) and (Src[CompareStartPos+1]=#3) then
// the codetools skip comment is no real comment
exit
else
inc(CompareStartPos,1);
end; end;
case Src[CompareEndPos-1] of case Src[CompareEndPos-1] of
'}': dec(CompareEndPos); '}': dec(CompareEndPos);
@ -2883,6 +2888,8 @@ var
end; end;
end; end;
end; end;
if CompareStartPos>CompareEndPos then exit;
if IgnoreSpaces then begin if IgnoreSpaces then begin
while (CompareStartPos<=CompareEndPos) while (CompareStartPos<=CompareEndPos)
and IsSpaceChar[Src[CompareStartPos]] and IsSpaceChar[Src[CompareStartPos]]
@ -2916,10 +2923,11 @@ var
var var
ANode: TCodeTreeNode; ANode: TCodeTreeNode;
p: LongInt; p: LongInt;
CommentLvl: Integer;
CommentStartPos: LongInt; CommentStartPos: LongInt;
begin begin
Result:=false; Result:=false;
if StartPos>SrcLen then
StartPos:=SrcLen+1;
if CommentText='' then exit; if CommentText='' then exit;
{debugln('TPascalReaderTool.FindCommentInFront A CommentText="',CommentText,'" ', {debugln('TPascalReaderTool.FindCommentInFront A CommentText="',CommentText,'" ',
@ -2962,91 +2970,19 @@ begin
//DebugLn('TPascalReaderTool.FindCommentInFront Aode=',ANode.DescAsString); //DebugLn('TPascalReaderTool.FindCommentInFront Aode=',ANode.DescAsString);
MoveCursorToCleanPos(ANode.StartPos); MoveCursorToCleanPos(ANode.StartPos);
end; end;
p:=CurPos.EndPos;
//debugln('TPascalReaderTool.FindCommentInFront B Area="',copy(Src,CurPos.StartPos,StartPos-CurPos.StartPos),'"'); //debugln('TPascalReaderTool.FindCommentInFront B Area="',copy(Src,CurPos.StartPos,StartPos-CurPos.StartPos),'"');
FoundStartPos:=-1; FoundStartPos:=-1;
repeat repeat
p:=CurPos.EndPos;
//debugln('TPascalReaderTool.FindCommentInFront Atom=',GetAtom); //debugln('TPascalReaderTool.FindCommentInFront Atom=',GetAtom);
CommentStartPos:=FindNextComment(Src,p,StartPos);
// read space and comment till next atom if CommentStartPos>=StartPos then break;
CommentLvl:=0; p:=FindCommentEnd(Src,CommentStartPos,Scanner.NestedComments);
while true do begin if p>StartPos then break;
case Src[p] of CompareComment(CommentStartPos,p);
#0: until false;
if p>SrcLen then
break
else
inc(p);
#1..#32:
inc(p);
'{':
begin
CommentStartPos:=p;
if (p<SrcLen) and (Src[p+1]=#3) then begin
// codetools skip comment
inc(p,2);
while p<=SrcLen do begin
if (Src[p]=#3) and (p<SrcLen) and (Src[p+1]='}') then begin
inc(p,2);
end;
inc(p);
end;
end else begin
// pascal comment
CommentLvl:=1;
inc(p);
while p<=SrcLen do begin
case Src[p] of
'{': if Scanner.NestedComments then inc(CommentLvl);
'}':
begin
dec(CommentLvl);
if CommentLvl=0 then begin
inc(p);
break;
end;
end;
end;
inc(p);
end;
end;
CompareComment(CommentStartPos,p);
end;
'/': // Delphi comment
if (Src[p+1]<>'/') then begin
break;
end else begin
CommentStartPos:=p;
inc(p,2);
while (not (Src[p] in [#10,#13,#0])) do
inc(p);
inc(p);
if (p<=SrcLen) and (Src[p] in [#10,#13])
and (Src[p-1]<>Src[p]) then
inc(p);
CompareComment(CommentStartPos,p);
end;
'(': // old turbo pascal comment
if (Src[p+1]<>'*') then begin
break;
end else begin
CommentStartPos:=p;
inc(p,3);
while (p<=SrcLen)
and ((Src[p-1]<>'*') or (Src[p]<>')')) do
inc(p);
inc(p);
CompareComment(CommentStartPos,p);
end;
else
break;
end;
end;
ReadNextAtom;
//DebugLn('TPascalReaderTool.FindCommentInFront NextAtom=',GetAtom);
until (CurPos.StartPos>=StartPos) or (CurPos.EndPos>=SrcLen);
Result:=(FoundStartPos>=1); Result:=(FoundStartPos>=1);
CommentStart:=FoundStartPos; CommentStart:=FoundStartPos;

View File

@ -426,41 +426,42 @@ var
Profile: TBuildLazarusProfile; Profile: TBuildLazarusProfile;
begin begin
Clear; Clear;
if FileVersion<1 then case FileVersion of
begin
// Invalid config file.
ProfInd:=CreateDefaults;
end else if FileVersion=1 then
begin
// Older config file version. // Older config file version.
CreateDefaults; // Only one profile saved, create defaults always. 1: begin
// Then create MyProfile. CreateDefaults; // Only one profile saved, create defaults always.
Profile:=TBuildLazarusProfile.Create(Self, 'MyProfile'); // Then create MyProfile.
Profile.Load(XMLConfig, Path); Profile:=TBuildLazarusProfile.Create(Self, 'MyProfile');
Add(Profile); Profile.Load(XMLConfig, Path);
FRestartAfterBuild:=XMLConfig.GetValue(Path+'RestartAfterBuild/Value',true); Add(Profile);
FConfirmBuild :=XMLConfig.GetValue(Path+'ConfirmBuild/Value',true);
ProfInd:=Count-1; // Go to last MyProfile.
end else begin
// Latest config file version.
ProfCount:=XMLConfig.GetValue(Path+'Profiles/Count',0);
if ProfCount = 0 then
ProfInd:=CreateDefaults // No saved profiles were found, use defaults.
else begin
// Load list of profiles.
for i:=0 to ProfCount-1 do begin
ProfPath:=Path+'Profiles/Profile'+IntToStr(i)+'/';
ProfName:=XMLConfig.GetValue(ProfPath+'Name','Unknown');
Profile:=TBuildLazarusProfile.Create(Self, ProfName);
Profile.Load(XMLConfig, ProfPath);
Add(Profile);
end;
// Current profile ItemIndex.
ProfInd:=XMLConfig.GetValue(Path+'ProfileIndex/Value',0);
// Other global build values.
FRestartAfterBuild:=XMLConfig.GetValue(Path+'RestartAfterBuild/Value',true); FRestartAfterBuild:=XMLConfig.GetValue(Path+'RestartAfterBuild/Value',true);
FConfirmBuild :=XMLConfig.GetValue(Path+'ConfirmBuild/Value',true); FConfirmBuild :=XMLConfig.GetValue(Path+'ConfirmBuild/Value',true);
end ProfInd:=Count-1; // Go to last MyProfile.
end;
// Latest config file version.
2: begin
ProfCount:=XMLConfig.GetValue(Path+'Profiles/Count',0);
if ProfCount = 0 then
ProfInd:=CreateDefaults // No saved profiles were found, use defaults.
else begin
// Load list of profiles.
for i:=0 to ProfCount-1 do begin
ProfPath:=Path+'Profiles/Profile'+IntToStr(i)+'/';
ProfName:=XMLConfig.GetValue(ProfPath+'Name','Unknown');
Profile:=TBuildLazarusProfile.Create(Self, ProfName);
Profile.Load(XMLConfig, ProfPath);
Add(Profile);
end;
// Current profile ItemIndex.
ProfInd:=XMLConfig.GetValue(Path+'ProfileIndex/Value',0);
// Other global build values.
FRestartAfterBuild:=XMLConfig.GetValue(Path+'RestartAfterBuild/Value',true);
FConfirmBuild :=XMLConfig.GetValue(Path+'ConfirmBuild/Value',true);
end
end;
// Invalid config file.
else
ProfInd:=CreateDefaults;
end; end;
// Load defines, selected profiles and auto install packages. // Load defines, selected profiles and auto install packages.
LoadStringList(XMLConfig,fAllDefines,Path+'AllDefines/'); LoadStringList(XMLConfig,fAllDefines,Path+'AllDefines/');