mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 07:39:29 +02:00
h2pas wizard: added combo tools for pre and post h2pas tools
git-svn-id: trunk@11822 -
This commit is contained in:
parent
04703e3b42
commit
fe72c7716c
@ -77,6 +77,7 @@ type
|
|||||||
FAddInheritedCodeToOverrideMethod: boolean;
|
FAddInheritedCodeToOverrideMethod: boolean;
|
||||||
FAdjustTopLineDueToComment: boolean;
|
FAdjustTopLineDueToComment: boolean;
|
||||||
FCatchExceptions: boolean;
|
FCatchExceptions: boolean;
|
||||||
|
FChangeStep: integer;
|
||||||
FCheckFilesOnDisk: boolean;
|
FCheckFilesOnDisk: boolean;
|
||||||
FCompleteProperties: boolean;
|
FCompleteProperties: boolean;
|
||||||
FCurCodeTool: TCodeTool; // current codetool
|
FCurCodeTool: TCodeTool; // current codetool
|
||||||
@ -164,6 +165,8 @@ type
|
|||||||
|
|
||||||
procedure ActivateWriteLock;
|
procedure ActivateWriteLock;
|
||||||
procedure DeactivateWriteLock;
|
procedure DeactivateWriteLock;
|
||||||
|
property ChangeStep: integer read FChangeStep;
|
||||||
|
procedure IncreaseChangeStep;
|
||||||
|
|
||||||
// file handling
|
// file handling
|
||||||
property SourceExtensions: string
|
property SourceExtensions: string
|
||||||
@ -314,8 +317,12 @@ type
|
|||||||
const Filename: string = ''): boolean;
|
const Filename: string = ''): boolean;
|
||||||
function AddResourceDirective(Code: TCodeBuffer; const Filename: string
|
function AddResourceDirective(Code: TCodeBuffer; const Filename: string
|
||||||
): boolean;
|
): boolean;
|
||||||
function FixIncludeFilenames(Code: TCodeBuffer;
|
function FixIncludeFilenames(Code: TCodeBuffer; Recursive: boolean;
|
||||||
Recursive: boolean; out MissingIncludeFilesCodeXYPos: TFPList): boolean;
|
out MissingIncludeFilesCodeXYPos: TFPList): boolean;
|
||||||
|
function FixMissingH2PasDirectives(Code: TCodeBuffer;
|
||||||
|
var Changed: boolean): boolean;
|
||||||
|
function ReduceCompilerDirectives(Code: TCodeBuffer;
|
||||||
|
Undefines, Defines: TStrings; var Changed: boolean): boolean;
|
||||||
|
|
||||||
// keywords and comments
|
// keywords and comments
|
||||||
function IsKeyword(Code: TCodeBuffer; const KeyWord: string): boolean;
|
function IsKeyword(Code: TCodeBuffer; const KeyWord: string): boolean;
|
||||||
@ -2459,6 +2466,36 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCodeToolManager.FixMissingH2PasDirectives(Code: TCodeBuffer;
|
||||||
|
var Changed: boolean): boolean;
|
||||||
|
begin
|
||||||
|
Result:=false;
|
||||||
|
try
|
||||||
|
if InitCurDirectivesTool(Code) then begin
|
||||||
|
FCurDirectivesTool.Parse;
|
||||||
|
FCurDirectivesTool.FixMissingH2PasDirectives(Changed);
|
||||||
|
Result:=true;
|
||||||
|
end;
|
||||||
|
except
|
||||||
|
on e: Exception do Result:=HandleException(e);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TCodeToolManager.ReduceCompilerDirectives(Code: TCodeBuffer;
|
||||||
|
Undefines, Defines: TStrings; var Changed: boolean): boolean;
|
||||||
|
begin
|
||||||
|
Result:=false;
|
||||||
|
try
|
||||||
|
if InitCurDirectivesTool(Code) then begin
|
||||||
|
FCurDirectivesTool.Parse;
|
||||||
|
FCurDirectivesTool.ReduceCompilerDirectives(Undefines,Defines,Changed);
|
||||||
|
Result:=true;
|
||||||
|
end;
|
||||||
|
except
|
||||||
|
on e: Exception do Result:=HandleException(e);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function TCodeToolManager.IsKeyword(Code: TCodeBuffer; const KeyWord: string
|
function TCodeToolManager.IsKeyword(Code: TCodeBuffer; const KeyWord: string
|
||||||
): boolean;
|
): boolean;
|
||||||
begin
|
begin
|
||||||
@ -4113,6 +4150,7 @@ end;
|
|||||||
|
|
||||||
procedure TCodeToolManager.BeforeApplyingChanges(var Abort: boolean);
|
procedure TCodeToolManager.BeforeApplyingChanges(var Abort: boolean);
|
||||||
begin
|
begin
|
||||||
|
IncreaseChangeStep;
|
||||||
if Assigned(FOnBeforeApplyChanges) then
|
if Assigned(FOnBeforeApplyChanges) then
|
||||||
FOnBeforeApplyChanges(Self,Abort);
|
FOnBeforeApplyChanges(Self,Abort);
|
||||||
end;
|
end;
|
||||||
@ -4321,6 +4359,14 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCodeToolManager.IncreaseChangeStep;
|
||||||
|
begin
|
||||||
|
if FChangeStep<>$7fffffff then
|
||||||
|
inc(FChangeStep)
|
||||||
|
else
|
||||||
|
FChangeStep:=-$7fffffff;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCodeToolManager.OnToolGetWriteLockInfo(out WriteLockIsSet: boolean;
|
procedure TCodeToolManager.OnToolGetWriteLockInfo(out WriteLockIsSet: boolean;
|
||||||
out WriteLockStep: integer);
|
out WriteLockStep: integer);
|
||||||
begin
|
begin
|
||||||
|
@ -26,7 +26,7 @@ uses
|
|||||||
Classes, SysUtils, LCLProc, LResources, LazConfigStorage, XMLPropStorage,
|
Classes, SysUtils, LCLProc, LResources, LazConfigStorage, XMLPropStorage,
|
||||||
Forms, Controls, Dialogs, FileUtil, FileProcs, AvgLvlTree,
|
Forms, Controls, Dialogs, FileUtil, FileProcs, AvgLvlTree,
|
||||||
// CodeTools
|
// CodeTools
|
||||||
KeywordFuncLists, BasicCodeTools, CodeCache, DirectivesTree, CodeToolManager,
|
KeywordFuncLists, BasicCodeTools, CodeCache, CodeToolManager,
|
||||||
// IDEIntf
|
// IDEIntf
|
||||||
TextTools, IDEExternToolIntf, IDEDialogs, LazIDEIntf, SrcEditorIntf,
|
TextTools, IDEExternToolIntf, IDEDialogs, LazIDEIntf, SrcEditorIntf,
|
||||||
IDEMsgIntf, IDETextConverter;
|
IDEMsgIntf, IDETextConverter;
|
||||||
@ -60,7 +60,7 @@ type
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ TReplace0PointerWithNULL -
|
{ TReplaceMacro0PointerWithNULL -
|
||||||
Replace macro values 0 pointer like (char *)0 with NULL }
|
Replace macro values 0 pointer like (char *)0 with NULL }
|
||||||
|
|
||||||
TReplaceMacro0PointerWithNULL = class(TCustomTextConverterTool)
|
TReplaceMacro0PointerWithNULL = class(TCustomTextConverterTool)
|
||||||
@ -80,6 +80,15 @@ type
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
{ TRemoveIncludeDirectives - Remove all $i filename }
|
||||||
|
|
||||||
|
TRemoveIncludeDirectives = class(TCustomTextReplaceTool)
|
||||||
|
public
|
||||||
|
class function ClassDescription: string; override;
|
||||||
|
constructor Create(TheOwner: TComponent); override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ TRemoveSystemTypes -
|
{ TRemoveSystemTypes -
|
||||||
Remove type redefinitons like PLongint }
|
Remove type redefinitons like PLongint }
|
||||||
|
|
||||||
@ -171,7 +180,7 @@ type
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ TFixAliasDefinitionsInUnit
|
{ TFixAliasDefinitionsInUnit - fix section type of alias definitions
|
||||||
NOT COMPLETE YET
|
NOT COMPLETE YET
|
||||||
|
|
||||||
Checks all alias definitions of the form
|
Checks all alias definitions of the form
|
||||||
@ -185,7 +194,7 @@ type
|
|||||||
function Execute(aText: TIDETextConverter): TModalResult; override;
|
function Execute(aText: TIDETextConverter): TModalResult; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TFixH2PasMissingIFDEFsInUnit }
|
{ TFixH2PasMissingIFDEFsInUnit - add missing IFDEFs for function bodies }
|
||||||
|
|
||||||
TFixH2PasMissingIFDEFsInUnit = class(TCustomTextConverterTool)
|
TFixH2PasMissingIFDEFsInUnit = class(TCustomTextConverterTool)
|
||||||
public
|
public
|
||||||
@ -193,7 +202,7 @@ type
|
|||||||
function Execute(aText: TIDETextConverter): TModalResult; override;
|
function Execute(aText: TIDETextConverter): TModalResult; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TReduceCompilerDirectivesInUnit }
|
{ TReduceCompilerDirectivesInUnit - removes unneeded directives }
|
||||||
|
|
||||||
TReduceCompilerDirectivesInUnit = class(TCustomTextConverterTool)
|
TReduceCompilerDirectivesInUnit = class(TCustomTextConverterTool)
|
||||||
private
|
private
|
||||||
@ -211,7 +220,7 @@ type
|
|||||||
property Defines: TStrings read FDefines write SetDefines;
|
property Defines: TStrings read FDefines write SetDefines;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TReplaceConstFunctionsInUnit }
|
{ TReplaceConstFunctionsInUnit - replace simple assignment functions with constants }
|
||||||
|
|
||||||
TReplaceConstFunctionsInUnit = class(TCustomTextConverterTool)
|
TReplaceConstFunctionsInUnit = class(TCustomTextConverterTool)
|
||||||
public
|
public
|
||||||
@ -219,7 +228,7 @@ type
|
|||||||
function Execute(aText: TIDETextConverter): TModalResult; override;
|
function Execute(aText: TIDETextConverter): TModalResult; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TReplaceTypeCastFunctionsInUnit }
|
{ TReplaceTypeCastFunctionsInUnit - replace simple type cast functions with types }
|
||||||
|
|
||||||
TReplaceTypeCastFunctionsInUnit = class(TCustomTextConverterTool)
|
TReplaceTypeCastFunctionsInUnit = class(TCustomTextConverterTool)
|
||||||
public
|
public
|
||||||
@ -227,6 +236,74 @@ type
|
|||||||
function Execute(aText: TIDETextConverter): TModalResult; override;
|
function Execute(aText: TIDETextConverter): TModalResult; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
type
|
||||||
|
{ TPretH2PasTools - Combines the common tools. }
|
||||||
|
|
||||||
|
TPreH2PasToolsOption = (
|
||||||
|
phRemoveCPlusPlusExternCTool, // Remove C++ 'extern "C"' lines
|
||||||
|
phRemoveEmptyCMacrosTool, // Remove empty C macros
|
||||||
|
phReplaceEdgedBracketPairWithStar, // Replace [] with *
|
||||||
|
phReplaceMacro0PointerWithNULL // Replace macro values 0 pointer like (char *)0
|
||||||
|
);
|
||||||
|
TPreH2PasToolsOptions = set of TPreH2PasToolsOption;
|
||||||
|
const
|
||||||
|
DefaultPreH2PasToolsOptions =
|
||||||
|
[Low(TPreH2PasToolsOption)..High(TPreH2PasToolsOption)];
|
||||||
|
|
||||||
|
type
|
||||||
|
{ TPreH2PasTools }
|
||||||
|
|
||||||
|
TPreH2PasTools = class(TCustomTextConverterTool)
|
||||||
|
private
|
||||||
|
FOptions: TPreH2PasToolsOptions;
|
||||||
|
public
|
||||||
|
constructor Create(TheOwner: TComponent); override;
|
||||||
|
class function ClassDescription: string; override;
|
||||||
|
function Execute(aText: TIDETextConverter): TModalResult; override;
|
||||||
|
published
|
||||||
|
property Options: TPreH2PasToolsOptions read FOptions write FOptions default DefaultPreH2PasToolsOptions;
|
||||||
|
end;
|
||||||
|
|
||||||
|
type
|
||||||
|
{ TPostH2PasTools - Combines the common tools. }
|
||||||
|
TPostH2PasToolsOption = (
|
||||||
|
phReplaceUnitFilenameWithUnitName, // Replace "unit filename;" with "unit name;"
|
||||||
|
phRemoveIncludeDirectives, // remove include directives
|
||||||
|
phRemoveSystemTypes, // Remove type redefinitons like PLongint
|
||||||
|
phFixH2PasMissingIFDEFsInUnit, // add missing IFDEFs for function bodies
|
||||||
|
phReduceCompilerDirectivesInUnit, // removes unneeded directives
|
||||||
|
phRemoveRedefinedPointerTypes, // Remove redefined pointer types
|
||||||
|
phRemoveEmptyTypeVarConstSections, // Remove empty type/var/const sections
|
||||||
|
phReplaceImplicitTypes, // Search implicit types in parameters and add types for them
|
||||||
|
phFixArrayOfParameterType, // Replace "array of )" with "array of const)"
|
||||||
|
phRemoveRedefinitionsInUnit, // Removes redefinitions of types, variables, constants and resourcestrings
|
||||||
|
phFixAliasDefinitionsInUnit, // fix section type of alias definitions
|
||||||
|
phReplaceConstFunctionsInUnit, // replace simple assignment functions with constants
|
||||||
|
phReplaceTypeCastFunctionsInUnit // replace simple type cast functions with types
|
||||||
|
);
|
||||||
|
TPostH2PasToolsOptions = set of TPostH2PasToolsOption;
|
||||||
|
const
|
||||||
|
DefaultPostH2PasToolsOptions =
|
||||||
|
[Low(TPostH2PasToolsOption)..High(TPostH2PasToolsOption)];
|
||||||
|
type
|
||||||
|
TPostH2PasTools = class(TCustomTextConverterTool)
|
||||||
|
private
|
||||||
|
FDefines: TStrings;
|
||||||
|
FOptions: TPostH2PasToolsOptions;
|
||||||
|
FUndefines: TStrings;
|
||||||
|
procedure SetDefines(const AValue: TStrings);
|
||||||
|
procedure SetUndefines(const AValue: TStrings);
|
||||||
|
public
|
||||||
|
constructor Create(TheOwner: TComponent); override;
|
||||||
|
destructor Destroy; override;
|
||||||
|
class function ClassDescription: string; override;
|
||||||
|
function Execute(aText: TIDETextConverter): TModalResult; override;
|
||||||
|
published
|
||||||
|
property Undefines: TStrings read FUndefines write SetUndefines;
|
||||||
|
property Defines: TStrings read FDefines write SetDefines;
|
||||||
|
property Options: TPostH2PasToolsOptions read FOptions write FOptions default DefaultPostH2PasToolsOptions;
|
||||||
|
end;
|
||||||
|
|
||||||
{ Proposal:
|
{ Proposal:
|
||||||
- A tool to fix "constant A=B;" to type A=B; or functions
|
- A tool to fix "constant A=B;" to type A=B; or functions
|
||||||
- A tool to reorder a unit to fix forward definitions
|
- A tool to reorder a unit to fix forward definitions
|
||||||
@ -1414,27 +1491,12 @@ end;
|
|||||||
|
|
||||||
procedure TH2PasProject.AddDefaultPreH2PasTools;
|
procedure TH2PasProject.AddDefaultPreH2PasTools;
|
||||||
begin
|
begin
|
||||||
AddNewTextConverterTool(FPreH2PasTools,TRemoveCPlusPlusExternCTool);
|
AddNewTextConverterTool(FPreH2PasTools,TPreH2PasTools);
|
||||||
AddNewTextConverterTool(FPreH2PasTools,TRemoveEmptyCMacrosTool);
|
|
||||||
AddNewTextConverterTool(FPreH2PasTools,TReplaceEdgedBracketPairWithStar);
|
|
||||||
AddNewTextConverterTool(FPreH2PasTools,TReplaceMacro0PointerWithNULL);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TH2PasProject.AddDefaultPostH2PasTools;
|
procedure TH2PasProject.AddDefaultPostH2PasTools;
|
||||||
begin
|
begin
|
||||||
AddNewTextConverterTool(FPostH2PasTools,TReplaceUnitFilenameWithUnitName);
|
AddNewTextConverterTool(FPostH2PasTools,TPostH2PasTools);
|
||||||
AddNewTextConverterTool(FPostH2PasTools,TRemoveSystemTypes);
|
|
||||||
AddNewTextConverterTool(FPostH2PasTools,TRemoveRedefinedPointerTypes);
|
|
||||||
AddNewTextConverterTool(FPostH2PasTools,TRemoveEmptyTypeVarConstSections);
|
|
||||||
AddNewTextConverterTool(FPostH2PasTools,TFixH2PasMissingIFDEFsInUnit);
|
|
||||||
AddNewTextConverterTool(FPostH2PasTools,TReduceCompilerDirectivesInUnit);
|
|
||||||
AddNewTextConverterTool(FPostH2PasTools,TReplaceImplicitTypes);
|
|
||||||
AddNewTextConverterTool(FPostH2PasTools,TFixArrayOfParameterType);
|
|
||||||
// the above tools fixed the syntax
|
|
||||||
// now improve the declarations
|
|
||||||
AddNewTextConverterTool(FPostH2PasTools,TRemoveRedefinitionsInUnit);
|
|
||||||
AddNewTextConverterTool(FPostH2PasTools,TReplaceConstFunctionsInUnit);
|
|
||||||
AddNewTextConverterTool(FPostH2PasTools,TReplaceTypeCastFunctionsInUnit);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TH2PasProject.SearchIncludedCHeaderFile(aFile: TH2PasFile;
|
function TH2PasProject.SearchIncludedCHeaderFile(aFile: TH2PasFile;
|
||||||
@ -3225,21 +3287,13 @@ end;
|
|||||||
function TFixH2PasMissingIFDEFsInUnit.Execute(aText: TIDETextConverter
|
function TFixH2PasMissingIFDEFsInUnit.Execute(aText: TIDETextConverter
|
||||||
): TModalResult;
|
): TModalResult;
|
||||||
var
|
var
|
||||||
Tree: TCompilerDirectivesTree;
|
|
||||||
Code: TCodeBuffer;
|
Code: TCodeBuffer;
|
||||||
Changed: Boolean;
|
Changed: Boolean;
|
||||||
begin
|
begin
|
||||||
Result:=mrCancel;
|
Result:=mrCancel;
|
||||||
Tree:=nil;
|
|
||||||
try
|
|
||||||
Tree:=TCompilerDirectivesTree.Create;
|
|
||||||
Code:=TCodeBuffer(aText.CodeBuffer);
|
|
||||||
Tree.Parse(Code,CodeToolBoss.GetNestedCommentsFlagForFile(Code.Filename));
|
|
||||||
Changed:=false;
|
Changed:=false;
|
||||||
Tree.FixMissingH2PasDirectives(Changed);
|
Code:=TCodeBuffer(aText.CodeBuffer);
|
||||||
finally
|
if not CodeToolBoss.FixMissingH2PasDirectives(Code,Changed) then exit;
|
||||||
Tree.Free;
|
|
||||||
end;
|
|
||||||
Result:=mrOk;
|
Result:=mrOk;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -3281,24 +3335,15 @@ end;
|
|||||||
function TReduceCompilerDirectivesInUnit.Execute(aText: TIDETextConverter
|
function TReduceCompilerDirectivesInUnit.Execute(aText: TIDETextConverter
|
||||||
): TModalResult;
|
): TModalResult;
|
||||||
var
|
var
|
||||||
Tree: TCompilerDirectivesTree;
|
|
||||||
Code: TCodeBuffer;
|
|
||||||
Changed: Boolean;
|
Changed: Boolean;
|
||||||
|
Code: TCodeBuffer;
|
||||||
begin
|
begin
|
||||||
Result:=mrCancel;
|
Result:=mrCancel;
|
||||||
Tree:=nil;
|
|
||||||
try
|
|
||||||
Tree:=TCompilerDirectivesTree.Create;
|
|
||||||
Code:=TCodeBuffer(aText.CodeBuffer);
|
|
||||||
Tree.Parse(Code,CodeToolBoss.GetNestedCommentsFlagForFile(Code.Filename));
|
|
||||||
repeat
|
|
||||||
Changed:=false;
|
Changed:=false;
|
||||||
Tree.ReduceCompilerDirectives(Undefines,Defines,Changed);
|
Code:=TCodeBuffer(aText.CodeBuffer);
|
||||||
//Tree.WriteDebugReport;
|
if not CodeToolBoss.ReduceCompilerDirectives(Code,Undefines,Defines,Changed)
|
||||||
until not Changed;
|
then
|
||||||
finally
|
exit;
|
||||||
Tree.Free;
|
|
||||||
end;
|
|
||||||
Result:=mrOk;
|
Result:=mrOk;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -3346,4 +3391,267 @@ begin
|
|||||||
Result:=mrOk;
|
Result:=mrOk;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TPreH2PasTools }
|
||||||
|
|
||||||
|
constructor TPreH2PasTools.Create(TheOwner: TComponent);
|
||||||
|
begin
|
||||||
|
inherited Create(TheOwner);
|
||||||
|
FOptions:=DefaultPreH2PasToolsOptions;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TPreH2PasTools.ClassDescription: string;
|
||||||
|
begin
|
||||||
|
Result:='Pre H2Pas - a set of common tools to run before h2pas'#13
|
||||||
|
+'phRemoveCPlusPlusExternCTool - Remove C++ ''extern "C"'' lines'#13
|
||||||
|
+'phRemoveEmptyCMacrosTool - Remove empty C macros'#13
|
||||||
|
+'phReplaceEdgedBracketPairWithStar - Replace [] with *'#13
|
||||||
|
+'phReplace0PointerWithNULL - Replace macro values 0 pointer like (char *)0'#13;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TPreH2PasTools.Execute(aText: TIDETextConverter): TModalResult;
|
||||||
|
var
|
||||||
|
Tool: TCustomTextConverterTool;
|
||||||
|
begin
|
||||||
|
if phRemoveCPlusPlusExternCTool in Options then begin
|
||||||
|
Tool:=TRemoveCPlusPlusExternCTool.Create(nil);
|
||||||
|
try
|
||||||
|
Result:=Tool.Execute(aText);
|
||||||
|
if Result<>mrOk then exit;
|
||||||
|
finally
|
||||||
|
Tool.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
if phRemoveEmptyCMacrosTool in Options then begin
|
||||||
|
Tool:=TRemoveEmptyCMacrosTool.Create(nil);
|
||||||
|
try
|
||||||
|
Result:=Tool.Execute(aText);
|
||||||
|
if Result<>mrOk then exit;
|
||||||
|
finally
|
||||||
|
Tool.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
if phReplaceEdgedBracketPairWithStar in Options then begin
|
||||||
|
Tool:=TReplaceEdgedBracketPairWithStar.Create(nil);
|
||||||
|
try
|
||||||
|
Result:=Tool.Execute(aText);
|
||||||
|
if Result<>mrOk then exit;
|
||||||
|
finally
|
||||||
|
Tool.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
if phReplaceMacro0PointerWithNULL in Options then begin
|
||||||
|
Tool:=TReplaceMacro0PointerWithNULL.Create(nil);
|
||||||
|
try
|
||||||
|
Result:=Tool.Execute(aText);
|
||||||
|
if Result<>mrOk then exit;
|
||||||
|
finally
|
||||||
|
Tool.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Result:=mrOk;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TPostH2PasTools }
|
||||||
|
|
||||||
|
procedure TPostH2PasTools.SetDefines(const AValue: TStrings);
|
||||||
|
begin
|
||||||
|
if FDefines=AValue then exit;
|
||||||
|
FDefines.Assign(AValue);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TPostH2PasTools.SetUndefines(const AValue: TStrings);
|
||||||
|
begin
|
||||||
|
if FUndefines=AValue then exit;
|
||||||
|
FUndefines.Assign(AValue);
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TPostH2PasTools.Create(TheOwner: TComponent);
|
||||||
|
begin
|
||||||
|
inherited Create(TheOwner);
|
||||||
|
FDefines:=TStringList.Create;
|
||||||
|
FUndefines:=TStringList.Create;
|
||||||
|
FOptions:=DefaultPostH2PasToolsOptions;
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor TPostH2PasTools.Destroy;
|
||||||
|
begin
|
||||||
|
FreeAndNil(FDefines);
|
||||||
|
FreeAndNil(FUndefines);
|
||||||
|
inherited Destroy;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TPostH2PasTools.ClassDescription: string;
|
||||||
|
begin
|
||||||
|
Result:='Post H2Pas - a set of common tools to run after h2pas'#13
|
||||||
|
+'phReplaceUnitFilenameWithUnitName - Replace "unit filename;" with "unit name;"'#13
|
||||||
|
+'phRemoveIncludeDirectives - Remove include directives'
|
||||||
|
+'phRemoveSystemTypes - Remove type redefinitons like PLongint'#13
|
||||||
|
+'phFixH2PasMissingIFDEFsInUnit - add missing IFDEFs for function bodies'#13
|
||||||
|
+'phReduceCompilerDirectivesInUnit - removes unneeded directives'#13
|
||||||
|
+'phRemoveRedefinedPointerTypes - Remove redefined pointer types'#13
|
||||||
|
+'phRemoveEmptyTypeVarConstSections - Remove empty type/var/const sections'#13
|
||||||
|
+'phReplaceImplicitTypes - Search implicit types in parameters and add types for them'#13
|
||||||
|
+'phFixArrayOfParameterType - Replace "array of )" with "array of const)"'#13
|
||||||
|
+'phRemoveRedefinitionsInUnit - Removes redefinitions of types, variables, constants and resourcestrings'#13
|
||||||
|
+'phFixAliasDefinitionsInUnit - fix section type of alias definitions'#13
|
||||||
|
+'phReplaceConstFunctionsInUnit - replace simple assignment functions with constants'#13
|
||||||
|
+'phReplaceTypeCastFunctionsInUnit - replace simple type cast functions with types'#13;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TPostH2PasTools.Execute(aText: TIDETextConverter): TModalResult;
|
||||||
|
|
||||||
|
function Run(Option: TPostH2PasToolsOption;
|
||||||
|
ToolClass: TCustomTextConverterToolClass;
|
||||||
|
var aResult: TModalResult): boolean;
|
||||||
|
var
|
||||||
|
Tool: TCustomTextConverterTool;
|
||||||
|
begin
|
||||||
|
Result:=true;
|
||||||
|
aResult:=mrOk;
|
||||||
|
if not (Option in Options) then exit;
|
||||||
|
DebugLn(['TPostH2PasTools.Execute.Run ',ToolClass.ClassName]);
|
||||||
|
Tool:=ToolClass.Create(nil);
|
||||||
|
try
|
||||||
|
aResult:=Tool.Execute(aText);
|
||||||
|
if aResult<>mrOk then begin
|
||||||
|
DebugLn(['TPostH2PasTools.Execute.Run failed: ',ToolClass.ClassName]);
|
||||||
|
exit(false);
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
Tool.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function ReduceCompilerDirectives(var Changed: boolean;
|
||||||
|
var aResult: TModalResult): boolean;
|
||||||
|
var
|
||||||
|
Code: TCodeBuffer;
|
||||||
|
begin
|
||||||
|
aResult:=mrOk;
|
||||||
|
if not (phReduceCompilerDirectivesInUnit in Options) then exit;
|
||||||
|
DebugLn(['TPostH2PasTools.Execute.ReduceCompilerDirectives ']);
|
||||||
|
Code:=TCodeBuffer(aText.CodeBuffer);
|
||||||
|
if not CodeToolBoss.ReduceCompilerDirectives(Code,Undefines,Defines,Changed)
|
||||||
|
then begin
|
||||||
|
DebugLn(['TPostH2PasTools.Execute.ReduceCompilerDirectives failed']);
|
||||||
|
aResult:=mrCancel;
|
||||||
|
exit(false);
|
||||||
|
end;
|
||||||
|
aResult:=mrOk;
|
||||||
|
Result:=true;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function ConvertSimpleFunctions(var Changed: boolean;
|
||||||
|
var aResult: TModalResult): boolean;
|
||||||
|
var
|
||||||
|
Code: TCodeBuffer;
|
||||||
|
OldChangeStep: LongInt;
|
||||||
|
begin
|
||||||
|
aResult:=mrOk;
|
||||||
|
OldChangeStep:=CodeToolBoss.ChangeStep;
|
||||||
|
if (phReplaceConstFunctionsInUnit in Options) then begin
|
||||||
|
DebugLn(['TPostH2PasTools.Execute ReplaceAllConstFunctions ']);
|
||||||
|
Code:=TCodeBuffer(aText.CodeBuffer);
|
||||||
|
if not CodeToolBoss.ReplaceAllConstFunctions(Code) then begin
|
||||||
|
DebugLn(['ReplaceAllConstFunctions failed']);
|
||||||
|
aResult:=mrCancel;
|
||||||
|
exit(false);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
if (phReplaceTypeCastFunctionsInUnit in Options) then begin
|
||||||
|
Code:=TCodeBuffer(aText.CodeBuffer);
|
||||||
|
DebugLn(['TPostH2PasTools.Execute ReplaceAllTypeCastFunctions ']);
|
||||||
|
if not CodeToolBoss.ReplaceAllTypeCastFunctions(Code) then begin
|
||||||
|
DebugLn(['ReplaceAllTypeCastFunctions failed']);
|
||||||
|
aResult:=mrCancel;
|
||||||
|
exit(false);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
if OldChangeStep<>CodeToolBoss.ChangeStep then
|
||||||
|
Changed:=true;
|
||||||
|
aResult:=mrOk;
|
||||||
|
Result:=true;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function FixAliasDefinitions(var Changed: boolean;
|
||||||
|
var aResult: TModalResult): boolean;
|
||||||
|
var
|
||||||
|
Code: TCodeBuffer;
|
||||||
|
OldChangeStep: LongInt;
|
||||||
|
begin
|
||||||
|
aResult:=mrOk;
|
||||||
|
OldChangeStep:=CodeToolBoss.ChangeStep;
|
||||||
|
if (phFixAliasDefinitionsInUnit in Options) then begin
|
||||||
|
DebugLn(['TPostH2PasTools.Execute FixAllAliasDefinitions ']);
|
||||||
|
Code:=TCodeBuffer(aText.CodeBuffer);
|
||||||
|
if not CodeToolBoss.FixAllAliasDefinitions(Code) then begin
|
||||||
|
DebugLn(['FixAliasDefinitions failed']);
|
||||||
|
aResult:=mrCancel;
|
||||||
|
exit(false);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
if OldChangeStep<>CodeToolBoss.ChangeStep then
|
||||||
|
Changed:=true;
|
||||||
|
aResult:=mrOk;
|
||||||
|
Result:=true;
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
Changed: boolean;
|
||||||
|
begin
|
||||||
|
Result:=mrOk;
|
||||||
|
Changed:=false;
|
||||||
|
// basic h2pas fixes (unit name, system types, missing IFDEFs)
|
||||||
|
if not Run(phReplaceUnitFilenameWithUnitName,
|
||||||
|
TReplaceUnitFilenameWithUnitName,Result) then exit;
|
||||||
|
if not Run(phRemoveIncludeDirectives,
|
||||||
|
TRemoveIncludeDirectives,Result) then exit;
|
||||||
|
if not Run(phRemoveSystemTypes,
|
||||||
|
TRemoveSystemTypes,Result) then exit;
|
||||||
|
if not Run(phFixH2PasMissingIFDEFsInUnit,
|
||||||
|
TFixH2PasMissingIFDEFsInUnit,Result) then exit;
|
||||||
|
// reduce compiler directives so that other tools can work with less double data
|
||||||
|
if not ReduceCompilerDirectives(Changed,Result) then exit;
|
||||||
|
// remove h2pas redefinitions, so data get unambiguous types
|
||||||
|
if not Run(phRemoveRedefinedPointerTypes,
|
||||||
|
TRemoveRedefinedPointerTypes,Result) then exit;
|
||||||
|
if not Run(phRemoveEmptyTypeVarConstSections,
|
||||||
|
TRemoveEmptyTypeVarConstSections,Result) then exit;
|
||||||
|
// replace implicit types, not converted by h2pas
|
||||||
|
if not Run(phReplaceImplicitTypes,
|
||||||
|
TReplaceImplicitTypes,Result) then exit;
|
||||||
|
if not Run(phFixArrayOfParameterType,
|
||||||
|
TFixArrayOfParameterType,Result) then exit;
|
||||||
|
// remove redefinitions, so data get unambiguous types
|
||||||
|
if not Run(phRemoveRedefinitionsInUnit,
|
||||||
|
TRemoveRedefinitionsInUnit,Result) then exit;
|
||||||
|
|
||||||
|
// optimization
|
||||||
|
repeat
|
||||||
|
Changed:=false;
|
||||||
|
if not ReduceCompilerDirectives(Changed,Result) then exit;
|
||||||
|
//if not FixAliasDefinitions(Changed,Result) then exit;
|
||||||
|
if not ConvertSimpleFunctions(Changed,Result) then exit;
|
||||||
|
until Changed=false;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TRemoveIncludeDirectives }
|
||||||
|
|
||||||
|
class function TRemoveIncludeDirectives.ClassDescription: string;
|
||||||
|
begin
|
||||||
|
Result:='Remove all include directives';
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TRemoveIncludeDirectives.Create(TheOwner: TComponent);
|
||||||
|
begin
|
||||||
|
inherited Create(TheOwner);
|
||||||
|
SearchFor:='\{\$(include|i)\b.*\}';
|
||||||
|
ReplaceWith:='';
|
||||||
|
Options:=Options+[trtRegExpr];
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -209,10 +209,12 @@ begin
|
|||||||
CmdH2PasTool);
|
CmdH2PasTool);
|
||||||
|
|
||||||
// register text converter tools
|
// register text converter tools
|
||||||
|
TextConverterToolClasses.RegisterClass(TPreH2PasTools);
|
||||||
TextConverterToolClasses.RegisterClass(TRemoveCPlusPlusExternCTool);
|
TextConverterToolClasses.RegisterClass(TRemoveCPlusPlusExternCTool);
|
||||||
TextConverterToolClasses.RegisterClass(TRemoveEmptyCMacrosTool);
|
TextConverterToolClasses.RegisterClass(TRemoveEmptyCMacrosTool);
|
||||||
TextConverterToolClasses.RegisterClass(TReplaceEdgedBracketPairWithStar);
|
TextConverterToolClasses.RegisterClass(TReplaceEdgedBracketPairWithStar);
|
||||||
TextConverterToolClasses.RegisterClass(TReplaceMacro0PointerWithNULL);
|
TextConverterToolClasses.RegisterClass(TReplaceMacro0PointerWithNULL);
|
||||||
|
TextConverterToolClasses.RegisterClass(TPostH2PasTools);
|
||||||
TextConverterToolClasses.RegisterClass(TReplaceUnitFilenameWithUnitName);
|
TextConverterToolClasses.RegisterClass(TReplaceUnitFilenameWithUnitName);
|
||||||
TextConverterToolClasses.RegisterClass(TRemoveSystemTypes);
|
TextConverterToolClasses.RegisterClass(TRemoveSystemTypes);
|
||||||
TextConverterToolClasses.RegisterClass(TRemoveRedefinedPointerTypes);
|
TextConverterToolClasses.RegisterClass(TRemoveRedefinedPointerTypes);
|
||||||
|
@ -2197,7 +2197,7 @@ begin
|
|||||||
|
|
||||||
// load the dependencies
|
// load the dependencies
|
||||||
LoadPkgDependencyList(XMLConfig,Path+'RequiredPackages/',
|
LoadPkgDependencyList(XMLConfig,Path+'RequiredPackages/',
|
||||||
FFirstRequiredDependency,pdlRequires,Self,true);
|
FFirstRequiredDependency,pdlRequires,Self,true,false);
|
||||||
|
|
||||||
// load session info
|
// load session info
|
||||||
LoadSessionInfo(XMLConfig,Path,false);
|
LoadSessionInfo(XMLConfig,Path,false);
|
||||||
|
@ -870,7 +870,7 @@ function FileNameToPkgFileType(const AFilename: string): TPkgFileType;
|
|||||||
procedure SortDependencyList(Dependencies: TFPList);
|
procedure SortDependencyList(Dependencies: TFPList);
|
||||||
procedure LoadPkgDependencyList(XMLConfig: TXMLConfig; const ThePath: string;
|
procedure LoadPkgDependencyList(XMLConfig: TXMLConfig; const ThePath: string;
|
||||||
var First: TPkgDependency; ListType: TPkgDependencyList; Owner: TObject;
|
var First: TPkgDependency; ListType: TPkgDependencyList; Owner: TObject;
|
||||||
HoldPackages: boolean);
|
HoldPackages, SortList: boolean);
|
||||||
procedure SavePkgDependencyList(XMLConfig: TXMLConfig; const ThePath: string;
|
procedure SavePkgDependencyList(XMLConfig: TXMLConfig; const ThePath: string;
|
||||||
First: TPkgDependency; ListType: TPkgDependencyList);
|
First: TPkgDependency; ListType: TPkgDependencyList);
|
||||||
procedure ListPkgIDToDependencyList(ListOfTLazPackageID: TFPList;
|
procedure ListPkgIDToDependencyList(ListOfTLazPackageID: TFPList;
|
||||||
@ -957,7 +957,7 @@ end;
|
|||||||
|
|
||||||
procedure LoadPkgDependencyList(XMLConfig: TXMLConfig; const ThePath: string;
|
procedure LoadPkgDependencyList(XMLConfig: TXMLConfig; const ThePath: string;
|
||||||
var First: TPkgDependency; ListType: TPkgDependencyList; Owner: TObject;
|
var First: TPkgDependency; ListType: TPkgDependencyList; Owner: TObject;
|
||||||
HoldPackages: boolean);
|
HoldPackages, SortList: boolean);
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
PkgDependency: TPkgDependency;
|
PkgDependency: TPkgDependency;
|
||||||
@ -978,6 +978,7 @@ begin
|
|||||||
else
|
else
|
||||||
PkgDependency.Free;
|
PkgDependency.Free;
|
||||||
end;
|
end;
|
||||||
|
if SortList then
|
||||||
SortDependencyList(List);
|
SortDependencyList(List);
|
||||||
for i:=0 to List.Count-1 do begin
|
for i:=0 to List.Count-1 do begin
|
||||||
TPkgDependency(List[i]).AddToList(First,ListType);
|
TPkgDependency(List[i]).AddToList(First,ListType);
|
||||||
@ -2532,7 +2533,7 @@ begin
|
|||||||
UpdateSourceDirectories;
|
UpdateSourceDirectories;
|
||||||
LoadFlags(Path);
|
LoadFlags(Path);
|
||||||
LoadPkgDependencyList(XMLConfig,Path+'RequiredPkgs/',
|
LoadPkgDependencyList(XMLConfig,Path+'RequiredPkgs/',
|
||||||
FFirstRequiredDependency,pdlRequires,Self,false);
|
FFirstRequiredDependency,pdlRequires,Self,false,false);
|
||||||
if FileVersion<2 then
|
if FileVersion<2 then
|
||||||
FCompilerOptions.LoadFromXMLConfig(XMLConfig,'CompilerOptions/')
|
FCompilerOptions.LoadFromXMLConfig(XMLConfig,'CompilerOptions/')
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user