From 6afd88f967c54d45cca22a7d8e362ae76e0cff05 Mon Sep 17 00:00:00 2001 From: mattias Date: Thu, 9 Mar 2006 21:20:19 +0000 Subject: [PATCH] fixed commenting units in case of last needs commenting git-svn-id: trunk@8896 - --- components/codetools/examples/fixfilenames.pas | 7 ++++++- .../examples/scanexamples/brokenfilenames.pas | 2 +- components/codetools/stdcodetools.pas | 17 +++++++++-------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/components/codetools/examples/fixfilenames.pas b/components/codetools/examples/fixfilenames.pas index b1d3b28774..07fc20c572 100644 --- a/components/codetools/examples/fixfilenames.pas +++ b/components/codetools/examples/fixfilenames.pas @@ -79,8 +79,13 @@ begin MissingUnits:=nil; if not CodeToolBoss.FindMissingUnits(Code,MissingUnits,true) then raise Exception.Create('unable to fix unit names in '+Filename+' '+CodeToolBoss.ErrorMessage); - if MissingUnits<>nil then + + if MissingUnits<>nil then 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); + end; + writeln('=================================================================='); writeln(Code.Source); end. diff --git a/components/codetools/examples/scanexamples/brokenfilenames.pas b/components/codetools/examples/scanexamples/brokenfilenames.pas index c7f0999618..6367570f72 100644 --- a/components/codetools/examples/scanexamples/brokenfilenames.pas +++ b/components/codetools/examples/scanexamples/brokenfilenames.pas @@ -10,7 +10,7 @@ uses biglettersunit, // must be fixed to BigLettersUnit biglettersunit in 'biglettersunit.pas',// -> BigLettersUnit.pas biglettersunit in '..\ScanExamples\biglettersunit.pas',// -> ../scanexamples/BigLettersUnit - SysUtils; + NonExistingUnit1, SysUtils, NonExistingUnit2; {$I BROKENincfiles.inc}// must be fixed to brokenincfiles.inc {$I ../ScanExamples/BROKENincfiles.inc}// must be fixed to ../scanexamples/brokenincfiles.inc diff --git a/components/codetools/stdcodetools.pas b/components/codetools/stdcodetools.pas index 0504d80528..9b1be32602 100644 --- a/components/codetools/stdcodetools.pas +++ b/components/codetools/stdcodetools.pas @@ -1051,13 +1051,14 @@ function TStandardCodeTool.CommentUnitsInUsesSections(MissingUnits: TStrings; // 3. uses {a, b,} c; commenting several units not at end // 4. uses a{, b, c} ; commenting units at end // 5. {uses a, b, c;} commenting all units + // 6. uses {a,} b{, c}; commenting several units var i: Integer; CurUnitName: String; CommentCurUnit: Boolean; FirstCommentUnitStart: Integer; LastCommaAfterCommentUnitsStart: Integer; - FirstNormalUnitEnd: Integer; + LastNormalUnitEnd: Integer; LastCommentUnitEnd: Integer; begin Result:=true; @@ -1065,7 +1066,7 @@ function TStandardCodeTool.CommentUnitsInUsesSections(MissingUnits: TStrings; MoveCursorToUsesStart(UsesNode); FirstCommentUnitStart:=-1; LastCommaAfterCommentUnitsStart:=-1; - FirstNormalUnitEnd:=-1; + LastNormalUnitEnd:=-1; LastCommentUnitEnd:=-1; repeat // check if unit should be commented @@ -1084,10 +1085,10 @@ function TStandardCodeTool.CommentUnitsInUsesSections(MissingUnits: TStrings; LastCommentUnitEnd:=CurPos.EndPos; end else begin // unit should be kept - if FirstNormalUnitEnd<1 then FirstNormalUnitEnd:=CurPos.EndPos; + LastNormalUnitEnd:=CurPos.EndPos; if FirstCommentUnitStart>=1 then begin // there are some units to be commented - // See examples: 1., 2., 3. + // See examples: 1., 2., 3. and 6. Comment(FirstCommentUnitStart,LastCommaAfterCommentUnitsStart); FirstCommentUnitStart:=-1; LastCommentUnitEnd:=-1; @@ -1100,8 +1101,8 @@ function TStandardCodeTool.CommentUnitsInUsesSections(MissingUnits: TStrings; ReadNextAtom; // read filename if not AtomIsStringConstant then RaiseExceptionFmt(ctsStrExpectedButAtomFound,[ctsStringConstant,GetAtom]); - if (not CommentCurUnit) and (FirstNormalUnitEnd<1) then - FirstNormalUnitEnd:=CurPos.EndPos; + if (not CommentCurUnit) then + LastNormalUnitEnd:=CurPos.EndPos; if CommentCurUnit then LastCommentUnitEnd:=CurPos.EndPos; ReadNextAtom; // read comma or semicolon @@ -1113,10 +1114,10 @@ function TStandardCodeTool.CommentUnitsInUsesSections(MissingUnits: TStrings; if CurPos.Flag<>cafComma then begin if CommentCurUnit then begin // last unit must be commented - if FirstNormalUnitEnd>=1 then begin + if LastNormalUnitEnd>=1 then begin // there are some units to be kept // See example: 4. - Comment(FirstNormalUnitEnd,LastCommentUnitEnd); + Comment(LastNormalUnitEnd,LastCommentUnitEnd); end else begin // all units should be commented // See example: 5.