mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 15:39:30 +02:00
codetools: fixed commenting units with directives
git-svn-id: trunk@8993 -
This commit is contained in:
parent
dac3215c52
commit
9f07b81e81
@ -39,6 +39,8 @@ var
|
||||
Code: TCodeBuffer;
|
||||
Filename: String;
|
||||
MissingUnits: TStrings;
|
||||
ReplaceUnits: TStringList;
|
||||
MissingIncludeFilesCodeXYPos: TFPList;
|
||||
begin
|
||||
// setup the Options
|
||||
Options:=TCodeToolsOptions.Create;
|
||||
@ -72,8 +74,20 @@ begin
|
||||
raise Exception.Create('unable to read '+Filename);
|
||||
|
||||
// fix the filenames in the include directives
|
||||
if not CodeToolBoss.FixIncludeFilenames(Code,true) then
|
||||
MissingIncludeFilesCodeXYPos:=nil;
|
||||
if not CodeToolBoss.FixIncludeFilenames(Code,true,
|
||||
MissingIncludeFilesCodeXYPos)
|
||||
then
|
||||
raise Exception.Create('unable to fix include filesnames in '+Filename+' '+CodeToolBoss.ErrorMessage);
|
||||
CodeToolBoss.FreeListOfPCodeXYPosition(MissingIncludeFilesCodeXYPos);
|
||||
|
||||
// replace some unit names
|
||||
ReplaceUnits:=TStringList.Create;
|
||||
ReplaceUnits.Add('biglettersunit=SysUtils');
|
||||
ReplaceUnits.Free;
|
||||
|
||||
writeln('==================================================================');
|
||||
writeln(Code.Source);
|
||||
|
||||
// fix the unitnames in the uses section
|
||||
MissingUnits:=nil;
|
||||
@ -84,9 +98,12 @@ begin
|
||||
writeln('MissingUnits=',MissingUnits.Text);
|
||||
if not CodeToolBoss.CommentUnitsInUsesSections(Code,MissingUnits) then
|
||||
raise Exception.Create('unable to comment units in uses section in '+Filename+' '+CodeToolBoss.ErrorMessage);
|
||||
MissingUnits.Free;
|
||||
end;
|
||||
|
||||
writeln('==================================================================');
|
||||
writeln(Code.Source);
|
||||
|
||||
Options.Free;
|
||||
end.
|
||||
|
||||
|
@ -10,7 +10,12 @@ uses
|
||||
biglettersunit, // must be fixed to BigLettersUnit
|
||||
biglettersunit in 'biglettersunit.pas',// -> BigLettersUnit.pas
|
||||
biglettersunit in '..\ScanExamples\biglettersunit.pas',// -> ../scanexamples/BigLettersUnit
|
||||
NonExistingUnit1, NonExistingUnit2, SysUtils, NonExistingUnit3;
|
||||
NonExistingUnit1, NonExistingUnit2, SysUtils, NonExistingUnit3,
|
||||
{$IFDEF FPC}
|
||||
NonExistingUnit4
|
||||
{$ELSE}
|
||||
NonExistingUnit5
|
||||
{$ENDIF};
|
||||
|
||||
{$I BROKENincfiles.inc}// must be fixed to brokenincfiles.inc
|
||||
{$I ../ScanExamples/BROKENincfiles.inc}// must be fixed to ../scanexamples/brokenincfiles.inc
|
||||
|
@ -1000,36 +1000,39 @@ function TStandardCodeTool.CommentUnitsInUsesSections(MissingUnits: TStrings;
|
||||
procedure Comment(CommentStartPos, CommentEndPos: integer);
|
||||
var
|
||||
i: LongInt;
|
||||
CurStartPos: LongInt;
|
||||
CommentNeeded: Boolean;
|
||||
CurEndPos: LongInt;
|
||||
begin
|
||||
if CommentStartPos>=CommentEndPos then
|
||||
RaiseException('TStandardCodeTool Comment');
|
||||
|
||||
// try curly brackets {}
|
||||
// comment with curly brackets {}
|
||||
i:=CommentStartPos;
|
||||
while (i<CommentEndPos) and (Src[i]<>'}') do inc(i);
|
||||
if i=CommentEndPos then begin
|
||||
SourceChangeCache.Replace(gtNone,gtNone,CommentStartPos,CommentStartPos,'{');
|
||||
SourceChangeCache.Replace(gtNone,gtNone,CommentEndPos,CommentEndPos,'}');
|
||||
//debugln('Comment {} "',copy(Src,CommentStartPos,CommentEndPos-CommentStartPos));
|
||||
exit;
|
||||
CurStartPos:=CommentStartPos;
|
||||
CurEndPos:=CurStartPos;
|
||||
CommentNeeded:=false;
|
||||
repeat
|
||||
if (Src[i]='{') or (i>=CommentEndPos) then begin
|
||||
// the area contains a comment -> comment in front
|
||||
if CommentNeeded then begin
|
||||
SourceChangeCache.Replace(gtNone,gtNone,CurStartPos,CurStartPos,'{');
|
||||
SourceChangeCache.Replace(gtNone,gtNone,CurEndPos,CurEndPos,'}');
|
||||
//DebugLn('Comment "',copy(Src,CurStartPos,i-CurStartPos),'"');
|
||||
CommentNeeded:=false;
|
||||
end;
|
||||
// try (* *)
|
||||
i:=CommentStartPos;
|
||||
while (i<CommentEndPos-1) and ((Src[i]<>'*') or (Src[i+1]<>')')) do inc(i);
|
||||
if i=CommentEndPos-1 then begin
|
||||
SourceChangeCache.Replace(gtNone,gtNone,CommentStartPos,CommentStartPos,'(*');
|
||||
SourceChangeCache.Replace(gtNone,gtNone,CommentEndPos,CommentEndPos,'*)');
|
||||
//debugln('Comment (**) "',copy(Src,CommentStartPos,CommentEndPos-CommentStartPos));
|
||||
exit;
|
||||
if i>=CommentEndPos then break;
|
||||
// skip comment
|
||||
i:=FindCommentEnd(Src,i,Scanner.NestedComments);
|
||||
end else if not IsSpaceChar[Src[i]] then begin
|
||||
if not CommentNeeded then begin
|
||||
CurStartPos:=i;
|
||||
CommentNeeded:=true;
|
||||
end;
|
||||
// do it with // comments
|
||||
SourceChangeCache.Replace(gtNone,gtNone,CommentStartPos,CommentStartPos,'//');
|
||||
SourceChangeCache.Replace(gtNone,gtNewLine,CommentEndPos,CommentEndPos,' ');
|
||||
//debugln('Comment // "',copy(Src,CommentStartPos,CommentEndPos-CommentStartPos));
|
||||
for i:=CommentStartPos+1 to CommentEndPos-1 do
|
||||
if (Src[i-1] in [#10,#13]) and (not (Src[i] in [#10,#13])) then begin
|
||||
SourceChangeCache.Replace(gtNone,gtNone,i,i,'//');
|
||||
CurEndPos:=i+1;
|
||||
end;
|
||||
inc(i);
|
||||
until false;
|
||||
end;
|
||||
|
||||
function CommentUnitsInUsesSection(UsesNode: TCodeTreeNode): boolean;
|
||||
|
Loading…
Reference in New Issue
Block a user