From 98aef1c56880347599150b52c049369aceff7c0b Mon Sep 17 00:00:00 2001 From: juha Date: Sun, 16 Jun 2013 12:15:49 +0000 Subject: [PATCH] Converter: cleanup + remove dead code git-svn-id: trunk@41726 - --- converter/convcodetool.pas | 48 ++++++-------------------------- converter/convertdelphi.pas | 55 +++++-------------------------------- 2 files changed, 16 insertions(+), 87 deletions(-) diff --git a/converter/convcodetool.pas b/converter/convcodetool.pas index 3c66806395..226a28e5cf 100644 --- a/converter/convcodetool.pas +++ b/converter/convcodetool.pas @@ -54,19 +54,18 @@ type fCodeTool: TCodeTool; fCode: TCodeBuffer; fSrcCache: TSourceChangeCache; - fAskAboutError: Boolean; + fAskAboutError: boolean; fSettings: TConvertSettings; // Conversion settings. procedure InitCodeTool; public constructor Create(ACode: TCodeBuffer); destructor Destroy; override; procedure ResetMainScanner; -// function HandleCodetoolError: TModalResult; public property CodeTool: TCodeTool read fCodeTool; property Code: TCodeBuffer read fCode; property SrcCache: TSourceChangeCache read fSrcCache; - property AskAboutError: Boolean read fAskAboutError write fAskAboutError; + property AskAboutError: boolean read fAskAboutError write fAskAboutError; property Settings: TConvertSettings read fSettings write fSettings; end; @@ -76,7 +75,7 @@ type private fCTLink: TCodeToolLink; fCTLinkCreated: boolean; - fIsConsoleApp: Boolean; + fIsConsoleApp: boolean; fHasFormFile: boolean; fResAction: TResAction; fAddUnitEvent: TAddUnitEvent; @@ -100,7 +99,7 @@ type function FixMainClassAncestor(const AClassName: string; AReplaceTypes: TStringToStringTree): boolean; public - property IsConsoleApp: Boolean read fIsConsoleApp write fIsConsoleApp; + property IsConsoleApp: boolean read fIsConsoleApp write fIsConsoleApp; property HasFormFile: boolean read fHasFormFile write fHasFormFile; property ResAction: TResAction read fResAction write fResAction; property AddUnitEvent: TAddUnitEvent read fAddUnitEvent write fAddUnitEvent; @@ -130,41 +129,17 @@ begin fCodeTool:=nil; fSrcCache:=nil; if not CodeToolBoss.InitCurCodeTool(fCode) then exit; -// try - fCodeTool:=CodeToolBoss.CurCodeTool; - fSrcCache:=CodeToolBoss.SourceChangeCache; - ResetMainScanner; - fCodeTool.Scanner.IgnoreMissingIncludeFiles:=True; -{ except - on e: Exception do - CodeToolBoss.HandleException(e); - end; } + fCodeTool:=CodeToolBoss.CurCodeTool; + fSrcCache:=CodeToolBoss.SourceChangeCache; + ResetMainScanner; + fCodeTool.Scanner.IgnoreMissingIncludeFiles:=True; end; procedure TCodeToolLink.ResetMainScanner; begin fSrcCache.MainScanner:=fCodeTool.Scanner; end; -{ -function TCodeToolLink.HandleCodetoolError: TModalResult; -// returns mrOk or mrAbort -const - CodetoolsFoundError='The codetools found an error in unit %s:%s%s%s'; -var - ErrMsg: String; -begin - ErrMsg:=CodeToolBoss.ErrorMessage; - LazarusIDE.DoJumpToCodeToolBossError; - if fAskAboutError then begin - Result:=QuestionDlg(lisCCOErrorCaption, - Format(CodetoolsFoundError, [ExtractFileName(fCode.Filename), LineEnding, ErrMsg, LineEnding]), - mtWarning, [mrIgnore, lisIgnoreAndContinue, mrAbort], 0); - if Result=mrIgnore then Result:=mrOK; - end else begin - Result:=mrOK; - end; -end; -} + { TConvDelphiCodeTool } constructor TConvDelphiCodeTool.Create(APascalBuffer: TCodeBuffer); @@ -178,12 +153,7 @@ begin fIsConsoleApp:=False; fCTLinkCreated:=True; if Assigned(fCTLink.CodeTool) then -// try fCTLink.CodeTool.BuildTree(lsrInitializationStart); -{ except - on e: Exception do - CodeToolBoss.HandleException(e); - end; } end; constructor TConvDelphiCodeTool.Create(ACTLink: TCodeToolLink); diff --git a/converter/convertdelphi.pas b/converter/convertdelphi.pas index 7c260883f2..997fcfa4ee 100644 --- a/converter/convertdelphi.pas +++ b/converter/convertdelphi.pas @@ -294,16 +294,9 @@ type { TConvertedDelphiPackageDescriptor = class(TPackageDescriptor) private - public // ToDo - procedure InitPackage(APackage: TLazPackage); override; + public + procedure InitPackage(APackage: TLazPackage); override; // ToDo end; - - // Some global functions from delphiunit2laz are not (yet) converted to class methods. - function ConvertDelphiAbsoluteToRelativeFile(const Filename: string; - AProjPack: TConvertDelphiProjPack): string; - function ExpandDelphiFilename(const Filename: string; AProjPack: TConvertDelphiProjPack): string; - function ExpandDelphiSearchPath(const SearchPath: string; - AProjPack: TConvertDelphiProjPack): string; } implementation @@ -421,7 +414,7 @@ begin fn:=ExtractFileName(RelPath); sUnitName:=ExtractFileNameOnly(fn); if (SubPath<>'') and (sUnitName<>'') then begin - //DebugLn(['RelPath=',RelPath,'SubPath=',SubPath,'fn=',fn,'sUnitName=',sUnitName]); + DebugLn(['RelPath=',RelPath,'SubPath=',SubPath,'fn=',fn,'sUnitName=',sUnitName]); // Map path by unit name. fConverter.fCachedUnitNames[sUnitName]:=SubPath; // Map real unit name by uppercase unit name. @@ -1534,25 +1527,8 @@ begin if CurUnitInfo=nil then begin if FilenameIsPascalUnit(AFileName) then begin CurUnitInfo:=LazProject.UnitWithUnitname(PureUnitName); - if CurUnitInfo<>nil then begin - raise Exception.CreateFmt('TConvertDelphiProject.AddUnit: Unitname %s exists twice', - [PureUnitName]); -{ Result:=QuestionDlg(lisConvDelphiUnitnameExistsTwice, - Format(lisConvDelphiTwoUnitsWithSameName, - [LineEnding, CurUnitInfo.Filename, LineEnding, AFileName, LineEnding]), - mtWarning, [mrYes,lisConvDelphiRemoveFirst,mrNo,lisConvDelphiRemoveSecond, - mrIgnore,lisConvDelphiKeepBoth,mrAbort], 0); - case Result of - mrYes: CurUnitInfo.IsPartOfProject:=false; - mrNo: exit(mrNo); - mrIgnore: ; - else begin - fErrorMsg:='User selected to end conversion with file '+fOrigFilename; - exit(mrAbort); - end; - end; -} - end; + Assert(CurUnitInfo=nil, + Format('TConvertDelphiProject.AddUnit: Unitname %s exists twice',[PureUnitName])); end; CurUnitInfo:=TUnitInfo.Create(nil); CurUnitInfo.Filename:=AFileName; @@ -1601,8 +1577,6 @@ begin end; for i:=0 to NormalUnits.Count-1 do begin CurFilename:=NormalUnits[i]; - //AllPath:=CodeToolBoss.DirectoryCachePool.FindDiskFilename( - // fSettings.MainPath+CurFilename+'.pas', true); AllPath:=FindDiskFileCaseInsensitive(fSettings.MainPath+CurFilename+'.pas'); if AllPath<>'' then begin Result:=AddUnit(AllPath, ui); @@ -1887,23 +1861,8 @@ begin if FilenameIsPascalUnit(AFileName) then begin // Check unitname OffendingUnit:=LazPackage.FindUnit(PureUnitName); - if OffendingUnit<>nil then begin - raise Exception.CreateFmt('TConvertDelphiPackage.AddUnit: Unitname %s exists twice', - [PureUnitName]); -{ Result:=QuestionDlg(lisConvDelphiUnitnameExistsTwice, - Format(lisConvDelphiTwoUnitsWithSameName, - [LineEnding, OffendingUnit.Filename, LineEnding, AFileName, LineEnding]), - mtWarning, [mrNo, lisConvDelphiRemoveSecond, mrAbort], 0); - case Result of - mrNo: exit(mrNo); - mrIgnore: ; - else begin - fErrorMsg:='User selected to end conversion with file '+fOrigFilename; - exit(mrAbort); - end; - end; -} - end; + Assert(OffendingUnit=nil, + Format('TConvertDelphiPackage.AddUnit: Unitname %s exists twice',[PureUnitName])); end; Flags:=[pffAddToPkgUsesSection]; // Check if the unit has a Register procedure.