mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 18:59:21 +02:00
h2pas wizard, IDE text converters: improved error handling
git-svn-id: trunk@12406 -
This commit is contained in:
parent
bcd769c266
commit
bb2d60019e
@ -1842,6 +1842,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TH2PasConverter.ConvertFile(AFile: TH2PasFile): TModalResult;
|
function TH2PasConverter.ConvertFile(AFile: TH2PasFile): TModalResult;
|
||||||
|
var
|
||||||
|
TextConverter: TIDETextConverter;
|
||||||
|
|
||||||
procedure CloseOrRevertEditorFile(const Filename: string);
|
procedure CloseOrRevertEditorFile(const Filename: string);
|
||||||
begin
|
begin
|
||||||
@ -1850,13 +1852,41 @@ function TH2PasConverter.ConvertFile(AFile: TH2PasFile): TModalResult;
|
|||||||
else
|
else
|
||||||
LazarusIDE.DoCloseEditorFile(Filename,[cfQuiet]);
|
LazarusIDE.DoCloseEditorFile(Filename,[cfQuiet]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function ExecuteTools(List: TComponent; const DefaultFilename: string
|
||||||
|
): TModalResult;
|
||||||
|
var
|
||||||
|
ErrorComponent: TComponent;
|
||||||
|
ErrorTool: TCustomTextConverterTool;
|
||||||
|
ErrMsg: String;
|
||||||
|
begin
|
||||||
|
Result:=TextConverter.Execute(List,ErrorComponent);
|
||||||
|
if Result=mrOk then exit;
|
||||||
|
if ErrorComponent is TCustomTextConverterTool then begin
|
||||||
|
ErrorTool:=TCustomTextConverterTool(ErrorComponent);
|
||||||
|
ErrMsg:=ErrorTool.ErrorFilename;
|
||||||
|
if ErrMsg='' then
|
||||||
|
ErrMsg:=DefaultFilename;
|
||||||
|
if ErrorTool.ErrorLine>0 then begin
|
||||||
|
ErrMsg:=ErrMsg+'('+IntToStr(ErrorTool.ErrorLine)+',';
|
||||||
|
if ErrorTool.ErrorColumn>0 then
|
||||||
|
ErrMsg:=ErrMsg+IntToStr(ErrorTool.ErrorColumn)
|
||||||
|
else
|
||||||
|
ErrMsg:=ErrMsg+'1';
|
||||||
|
ErrMsg:=ErrMsg+')';
|
||||||
|
end;
|
||||||
|
ErrMsg:=ErrMsg+' Error: '+ErrorTool.ErrorMsg+' ('+ErrorTool.Caption+')';
|
||||||
|
end else begin
|
||||||
|
ErrMsg:=DefaultFilename;
|
||||||
|
end;
|
||||||
|
DebugLn(['TH2PasConverter.ConvertFile Failed: ',ErrMsg]);
|
||||||
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
OutputFilename: String;
|
OutputFilename: String;
|
||||||
TempCHeaderFilename: String;
|
TempCHeaderFilename: String;
|
||||||
InputFilename: String;
|
InputFilename: String;
|
||||||
Tool: TH2PasTool;
|
Tool: TH2PasTool;
|
||||||
TextConverter: TIDETextConverter;
|
|
||||||
begin
|
begin
|
||||||
Result:=mrCancel;
|
Result:=mrCancel;
|
||||||
FLastUsedFilename:='';
|
FLastUsedFilename:='';
|
||||||
@ -1895,7 +1925,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
// run converters for .h file to make it compatible for h2pas
|
// run converters for .h file to make it compatible for h2pas
|
||||||
Result:=TextConverter.Execute(Project.PreH2PasTools);
|
Result:=ExecuteTools(Project.PreH2PasTools,TempCHeaderFilename);
|
||||||
if Result<>mrOk then begin
|
if Result<>mrOk then begin
|
||||||
DebugLn(['TH2PasConverter.ConvertFile Failed running Project.PreH2PasTools on ',TempCHeaderFilename]);
|
DebugLn(['TH2PasConverter.ConvertFile Failed running Project.PreH2PasTools on ',TempCHeaderFilename]);
|
||||||
exit;
|
exit;
|
||||||
@ -1925,10 +1955,10 @@ begin
|
|||||||
|
|
||||||
// run beautification tools for new pascal code
|
// run beautification tools for new pascal code
|
||||||
TextConverter.InitWithFilename(OutputFilename);
|
TextConverter.InitWithFilename(OutputFilename);
|
||||||
DebugLn(['TH2PasConverter.ConvertFile OutputFilename: ',copy(TextConverter.Source,1,300)]);
|
//DebugLn(['TH2PasConverter.ConvertFile Output: ',copy(TextConverter.Source,1,300)]);
|
||||||
Result:=TextConverter.Execute(Project.PostH2PasTools);
|
Result:=ExecuteTools(Project.PostH2PasTools,OutputFilename);
|
||||||
if Result<>mrOk then begin
|
if Result<>mrOk then begin
|
||||||
DebugLn(['TH2PasConverter.ConvertFile Failed running Project.PostH2PasTools on ',TempCHeaderFilename]);
|
DebugLn(['TH2PasConverter.ConvertFile Failed running Project.PostH2PasTools on ',OutputFilename]);
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
TextConverter.Filename:=OutputFilename;// save
|
TextConverter.Filename:=OutputFilename;// save
|
||||||
@ -2384,13 +2414,19 @@ begin
|
|||||||
end;
|
end;
|
||||||
SearchFor:='^\s*('+SearchFor+');\s*$';
|
SearchFor:='^\s*('+SearchFor+');\s*$';
|
||||||
Result:=IDESearchInText('',Source,SearchFor,'',Flags,Prompt,nil);
|
Result:=IDESearchInText('',Source,SearchFor,'',Flags,Prompt,nil);
|
||||||
if Result<>mrOk then exit;
|
if Result<>mrOk then begin
|
||||||
|
ErrorMsg:='deletion of "'+SearchFor+'" failed';
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
// replace NULL with nil
|
// replace NULL with nil
|
||||||
Flags:=[sesoReplace,sesoReplaceAll,sesoRegExpr,sesoMatchCase];
|
Flags:=[sesoReplace,sesoReplaceAll,sesoRegExpr,sesoMatchCase];
|
||||||
Result:=IDESearchInText('',Source,'\bNULL\b','nil',Flags,Prompt,nil);
|
Result:=IDESearchInText('',Source,'\bNULL\b','nil',Flags,Prompt,nil);
|
||||||
if Result<>mrOk then exit;
|
if Result<>mrOk then begin
|
||||||
|
ErrorMsg:='replacing of NULL with nil failed';
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
aText.Source:=Source;
|
aText.Source:=Source;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -2953,6 +2989,8 @@ var
|
|||||||
CurAtom: String;
|
CurAtom: String;
|
||||||
Identifier: String;
|
Identifier: String;
|
||||||
TypeDefStart: LongInt;
|
TypeDefStart: LongInt;
|
||||||
|
ErrLine: integer;
|
||||||
|
ErrCol: integer;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
ModalResult:=mrCancel;
|
ModalResult:=mrCancel;
|
||||||
@ -2982,6 +3020,10 @@ begin
|
|||||||
TypeDefStart:=Position;
|
TypeDefStart:=Position;
|
||||||
Result:=ReadTypeDefinition(Position);
|
Result:=ReadTypeDefinition(Position);
|
||||||
if not Result then begin
|
if not Result then begin
|
||||||
|
SrcPosToLineCol(Src,TypeStart,ErrLine,ErrCol);
|
||||||
|
ErrorColumn:=ErrCol;
|
||||||
|
ErrorLine:=ErrLine;
|
||||||
|
ErrorMsg:='FindExplicitTypes FAILED reading type definition '+Identifier;
|
||||||
DebugLn(['FindExplicitTypes FAILED reading type definition ',Identifier,' at ',PosToStr(TypeStart)]);
|
DebugLn(['FindExplicitTypes FAILED reading type definition ',Identifier,' at ',PosToStr(TypeStart)]);
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
@ -2997,6 +3039,10 @@ begin
|
|||||||
//DebugLn(['FindExplicitTypes Rereading type definition ',Identifier,' at ',PosToStr(TypeStart)]);
|
//DebugLn(['FindExplicitTypes Rereading type definition ',Identifier,' at ',PosToStr(TypeStart)]);
|
||||||
Result:=ReadTypeDefinition(Position);
|
Result:=ReadTypeDefinition(Position);
|
||||||
if not Result then begin
|
if not Result then begin
|
||||||
|
SrcPosToLineCol(Src,TypeStart,ErrLine,ErrCol);
|
||||||
|
ErrorColumn:=ErrCol;
|
||||||
|
ErrorLine:=ErrLine;
|
||||||
|
ErrorMsg:='FindExplicitTypes FAILED Rereading type definition '+Identifier;
|
||||||
DebugLn(['FindExplicitTypes FAILED Rereading type definition ',Identifier,' at ',PosToStr(TypeStart)]);
|
DebugLn(['FindExplicitTypes FAILED Rereading type definition ',Identifier,' at ',PosToStr(TypeStart)]);
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
@ -3013,6 +3059,10 @@ begin
|
|||||||
//DebugLn(['TReplaceImplicitTypes.FindExplicitTypesAndConstants finding end of const section ...']);
|
//DebugLn(['TReplaceImplicitTypes.FindExplicitTypesAndConstants finding end of const section ...']);
|
||||||
Result:=ReadConstSection(Position);
|
Result:=ReadConstSection(Position);
|
||||||
if not Result then begin
|
if not Result then begin
|
||||||
|
SrcPosToLineCol(Src,ConstSectionStart,ErrLine,ErrCol);
|
||||||
|
ErrorColumn:=ErrCol;
|
||||||
|
ErrorLine:=ErrLine;
|
||||||
|
ErrorMsg:='FindExplicitTypes FAILED reading const section';
|
||||||
DebugLn(['FindExplicitTypes FAILED reading const section at ',PosToStr(ConstSectionStart)]);
|
DebugLn(['FindExplicitTypes FAILED reading const section at ',PosToStr(ConstSectionStart)]);
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
@ -3022,6 +3072,10 @@ begin
|
|||||||
//DebugLn(['TReplaceImplicitTypes.FindExplicitTypesAndConstants collecting const identifiers ...']);
|
//DebugLn(['TReplaceImplicitTypes.FindExplicitTypesAndConstants collecting const identifiers ...']);
|
||||||
Result:=ReadConstSection(Position);
|
Result:=ReadConstSection(Position);
|
||||||
if not Result then begin
|
if not Result then begin
|
||||||
|
SrcPosToLineCol(Src,ConstSectionStart,ErrLine,ErrCol);
|
||||||
|
ErrorColumn:=ErrCol;
|
||||||
|
ErrorLine:=ErrLine;
|
||||||
|
ErrorMsg:='FindExplicitTypes FAILED reading const section';
|
||||||
DebugLn(['FindExplicitTypes FAILED reading const section at ',PosToStr(ConstSectionStart)]);
|
DebugLn(['FindExplicitTypes FAILED reading const section at ',PosToStr(ConstSectionStart)]);
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
@ -3330,6 +3384,7 @@ begin
|
|||||||
exit(mrOk);// ignore
|
exit(mrOk);// ignore
|
||||||
end;
|
end;
|
||||||
if not CodeToolBoss.RemoveAllRedefinitions(TCodeBuffer(aText.CodeBuffer)) then begin
|
if not CodeToolBoss.RemoveAllRedefinitions(TCodeBuffer(aText.CodeBuffer)) then begin
|
||||||
|
AssignCodeToolBossError;
|
||||||
DebugLn(['TRemoveRedefinitionsInUnit.Execute RemoveAllRedefinitions failed ',CodeToolBoss.ErrorMessage]);
|
DebugLn(['TRemoveRedefinitionsInUnit.Execute RemoveAllRedefinitions failed ',CodeToolBoss.ErrorMessage]);
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
@ -3357,6 +3412,7 @@ begin
|
|||||||
exit(mrOk);// ignore
|
exit(mrOk);// ignore
|
||||||
end;
|
end;
|
||||||
if not CodeToolBoss.FixAllAliasDefinitions(TCodeBuffer(aText.CodeBuffer)) then begin
|
if not CodeToolBoss.FixAllAliasDefinitions(TCodeBuffer(aText.CodeBuffer)) then begin
|
||||||
|
AssignCodeToolBossError;
|
||||||
DebugLn(['TFixAliasDefinitionsInUnit.Execute FixAllAliasDefinitions failed ',CodeToolBoss.ErrorMessage]);
|
DebugLn(['TFixAliasDefinitionsInUnit.Execute FixAllAliasDefinitions failed ',CodeToolBoss.ErrorMessage]);
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
@ -3379,7 +3435,11 @@ begin
|
|||||||
Result:=mrCancel;
|
Result:=mrCancel;
|
||||||
Changed:=false;
|
Changed:=false;
|
||||||
Code:=TCodeBuffer(aText.CodeBuffer);
|
Code:=TCodeBuffer(aText.CodeBuffer);
|
||||||
if not CodeToolBoss.FixMissingH2PasDirectives(Code,Changed) then exit;
|
if not CodeToolBoss.FixMissingH2PasDirectives(Code,Changed) then begin
|
||||||
|
AssignCodeToolBossError;
|
||||||
|
DebugLn(['TFixH2PasMissingIFDEFsInUnit.Execute failed ',CodeToolBoss.ErrorMessage]);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
Result:=mrOk;
|
Result:=mrOk;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -3428,8 +3488,11 @@ begin
|
|||||||
Changed:=false;
|
Changed:=false;
|
||||||
Code:=TCodeBuffer(aText.CodeBuffer);
|
Code:=TCodeBuffer(aText.CodeBuffer);
|
||||||
if not CodeToolBoss.ReduceCompilerDirectives(Code,Undefines,Defines,Changed)
|
if not CodeToolBoss.ReduceCompilerDirectives(Code,Undefines,Defines,Changed)
|
||||||
then
|
then begin
|
||||||
|
AssignCodeToolBossError;
|
||||||
|
DebugLn(['TReduceCompilerDirectivesInUnit.Execute failed ',ErrorMsg]);
|
||||||
exit;
|
exit;
|
||||||
|
end;
|
||||||
Result:=mrOk;
|
Result:=mrOk;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -3449,6 +3512,7 @@ begin
|
|||||||
exit(mrOk);// ignore
|
exit(mrOk);// ignore
|
||||||
end;
|
end;
|
||||||
if not CodeToolBoss.ReplaceAllConstFunctions(TCodeBuffer(aText.CodeBuffer)) then begin
|
if not CodeToolBoss.ReplaceAllConstFunctions(TCodeBuffer(aText.CodeBuffer)) then begin
|
||||||
|
AssignCodeToolBossError;
|
||||||
DebugLn(['TReplaceConstFunctionsInUnit.Execute ReplaceAllConstFunctions failed ',CodeToolBoss.ErrorMessage]);
|
DebugLn(['TReplaceConstFunctionsInUnit.Execute ReplaceAllConstFunctions failed ',CodeToolBoss.ErrorMessage]);
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
@ -3471,6 +3535,7 @@ begin
|
|||||||
exit(mrOk);// ignore
|
exit(mrOk);// ignore
|
||||||
end;
|
end;
|
||||||
if not CodeToolBoss.ReplaceAllTypeCastFunctions(TCodeBuffer(aText.CodeBuffer)) then begin
|
if not CodeToolBoss.ReplaceAllTypeCastFunctions(TCodeBuffer(aText.CodeBuffer)) then begin
|
||||||
|
AssignCodeToolBossError;
|
||||||
DebugLn(['TReplaceTypeCastFunctionsInUnit.Execute ReplaceAllTypeCastFunctions failed ',CodeToolBoss.ErrorMessage]);
|
DebugLn(['TReplaceTypeCastFunctionsInUnit.Execute ReplaceAllTypeCastFunctions failed ',CodeToolBoss.ErrorMessage]);
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
@ -3496,59 +3561,42 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TPreH2PasTools.Execute(aText: TIDETextConverter): TModalResult;
|
function TPreH2PasTools.Execute(aText: TIDETextConverter): TModalResult;
|
||||||
var
|
|
||||||
Tool: TCustomTextConverterTool;
|
function Run(Option: TPreH2PasToolsOption;
|
||||||
|
ToolClass: TCustomTextConverterToolClass;
|
||||||
|
out aResult: TModalResult): boolean;
|
||||||
|
var
|
||||||
|
Tool: TCustomTextConverterTool;
|
||||||
|
begin
|
||||||
|
Result:=true;
|
||||||
|
aResult:=mrOk;
|
||||||
|
if not (Option in Options) then exit;
|
||||||
|
DebugLn(['TPreH2PasTools.Execute.Run ',ToolClass.ClassName]);
|
||||||
|
Tool:=ToolClass.Create(nil);
|
||||||
|
try
|
||||||
|
Tool.ClearError;
|
||||||
|
aResult:=Tool.Execute(aText);
|
||||||
|
if aResult<>mrOk then begin
|
||||||
|
AssignError(Tool);
|
||||||
|
DebugLn(['TPreH2PasTools.Execute.Run failed: ',ToolClass.ClassName]);
|
||||||
|
exit(false);
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
Tool.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if phRemoveCPlusPlusExternCTool in Options then begin
|
if not Run(phRemoveCPlusPlusExternCTool,
|
||||||
Tool:=TRemoveCPlusPlusExternCTool.Create(nil);
|
TRemoveCPlusPlusExternCTool,Result) then exit;
|
||||||
try
|
if not Run(phRemoveEmptyCMacrosTool,
|
||||||
Result:=Tool.Execute(aText);
|
TRemoveEmptyCMacrosTool,Result) then exit;
|
||||||
if Result<>mrOk then exit;
|
if not Run(phReplaceEdgedBracketPairWithStar,
|
||||||
finally
|
TReplaceEdgedBracketPairWithStar,Result) then exit;
|
||||||
Tool.Free;
|
if not Run(phReplaceMacro0PointerWithNULL,
|
||||||
end;
|
TReplaceMacro0PointerWithNULL,Result) then exit;
|
||||||
end;
|
if not Run(phConvertFunctionTypesToPointers,
|
||||||
|
TConvertFunctionTypesToPointers,Result) then exit;
|
||||||
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;
|
|
||||||
|
|
||||||
if phConvertFunctionTypesToPointers in Options then begin
|
|
||||||
Tool:=TConvertFunctionTypesToPointers.Create(nil);
|
|
||||||
try
|
|
||||||
Result:=Tool.Execute(aText);
|
|
||||||
if Result<>mrOk then exit;
|
|
||||||
finally
|
|
||||||
Tool.Free;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
Result:=mrOk;
|
Result:=mrOk;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -3614,8 +3662,10 @@ function TPostH2PasTools.Execute(aText: TIDETextConverter): TModalResult;
|
|||||||
DebugLn(['TPostH2PasTools.Execute.Run ',ToolClass.ClassName]);
|
DebugLn(['TPostH2PasTools.Execute.Run ',ToolClass.ClassName]);
|
||||||
Tool:=ToolClass.Create(nil);
|
Tool:=ToolClass.Create(nil);
|
||||||
try
|
try
|
||||||
|
Tool.ClearError;
|
||||||
aResult:=Tool.Execute(aText);
|
aResult:=Tool.Execute(aText);
|
||||||
if aResult<>mrOk then begin
|
if aResult<>mrOk then begin
|
||||||
|
AssignError(Tool);
|
||||||
DebugLn(['TPostH2PasTools.Execute.Run failed: ',ToolClass.ClassName]);
|
DebugLn(['TPostH2PasTools.Execute.Run failed: ',ToolClass.ClassName]);
|
||||||
exit(false);
|
exit(false);
|
||||||
end;
|
end;
|
||||||
@ -3636,6 +3686,7 @@ function TPostH2PasTools.Execute(aText: TIDETextConverter): TModalResult;
|
|||||||
if not CodeToolBoss.ReduceCompilerDirectives(Code,Undefines,Defines,Changed)
|
if not CodeToolBoss.ReduceCompilerDirectives(Code,Undefines,Defines,Changed)
|
||||||
then begin
|
then begin
|
||||||
DebugLn(['TPostH2PasTools.Execute.ReduceCompilerDirectives failed']);
|
DebugLn(['TPostH2PasTools.Execute.ReduceCompilerDirectives failed']);
|
||||||
|
AssignCodeToolBossError;
|
||||||
aResult:=mrCancel;
|
aResult:=mrCancel;
|
||||||
exit(false);
|
exit(false);
|
||||||
end;
|
end;
|
||||||
@ -3656,6 +3707,7 @@ function TPostH2PasTools.Execute(aText: TIDETextConverter): TModalResult;
|
|||||||
Code:=TCodeBuffer(aText.CodeBuffer);
|
Code:=TCodeBuffer(aText.CodeBuffer);
|
||||||
if not CodeToolBoss.ReplaceAllConstFunctions(Code) then begin
|
if not CodeToolBoss.ReplaceAllConstFunctions(Code) then begin
|
||||||
DebugLn(['ReplaceAllConstFunctions failed']);
|
DebugLn(['ReplaceAllConstFunctions failed']);
|
||||||
|
AssignCodeToolBossError;
|
||||||
aResult:=mrCancel;
|
aResult:=mrCancel;
|
||||||
exit(false);
|
exit(false);
|
||||||
end;
|
end;
|
||||||
@ -3665,6 +3717,7 @@ function TPostH2PasTools.Execute(aText: TIDETextConverter): TModalResult;
|
|||||||
DebugLn(['TPostH2PasTools.Execute ReplaceAllTypeCastFunctions ']);
|
DebugLn(['TPostH2PasTools.Execute ReplaceAllTypeCastFunctions ']);
|
||||||
if not CodeToolBoss.ReplaceAllTypeCastFunctions(Code) then begin
|
if not CodeToolBoss.ReplaceAllTypeCastFunctions(Code) then begin
|
||||||
DebugLn(['ReplaceAllTypeCastFunctions failed']);
|
DebugLn(['ReplaceAllTypeCastFunctions failed']);
|
||||||
|
AssignCodeToolBossError;
|
||||||
aResult:=mrCancel;
|
aResult:=mrCancel;
|
||||||
exit(false);
|
exit(false);
|
||||||
end;
|
end;
|
||||||
@ -3688,6 +3741,7 @@ function TPostH2PasTools.Execute(aText: TIDETextConverter): TModalResult;
|
|||||||
Code:=TCodeBuffer(aText.CodeBuffer);
|
Code:=TCodeBuffer(aText.CodeBuffer);
|
||||||
if not CodeToolBoss.FixAllAliasDefinitions(Code) then begin
|
if not CodeToolBoss.FixAllAliasDefinitions(Code) then begin
|
||||||
DebugLn(['FixAliasDefinitions failed']);
|
DebugLn(['FixAliasDefinitions failed']);
|
||||||
|
AssignCodeToolBossError;
|
||||||
aResult:=mrCancel;
|
aResult:=mrCancel;
|
||||||
exit(false);
|
exit(false);
|
||||||
end;
|
end;
|
||||||
@ -3905,6 +3959,7 @@ begin
|
|||||||
exit(mrOk);// ignore
|
exit(mrOk);// ignore
|
||||||
end;
|
end;
|
||||||
if not CodeToolBoss.FixForwardDefinitions(TCodeBuffer(aText.CodeBuffer)) then begin
|
if not CodeToolBoss.FixForwardDefinitions(TCodeBuffer(aText.CodeBuffer)) then begin
|
||||||
|
AssignCodeToolBossError;
|
||||||
DebugLn(['TFixForwardDefinitions.Execute failed ',CodeToolBoss.ErrorMessage]);
|
DebugLn(['TFixForwardDefinitions.Execute failed ',CodeToolBoss.ErrorMessage]);
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
@ -4177,6 +4232,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
if not CodeToolBoss.Explore(TCodeBuffer(aText.CodeBuffer),Tool,true,false)
|
if not CodeToolBoss.Explore(TCodeBuffer(aText.CodeBuffer),Tool,true,false)
|
||||||
then begin
|
then begin
|
||||||
|
AssignCodeToolBossError;
|
||||||
DebugLn(['TAddMissingPointerTypes.Execute Explore failed ',CodeToolBoss.ErrorMessage]);
|
DebugLn(['TAddMissingPointerTypes.Execute Explore failed ',CodeToolBoss.ErrorMessage]);
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
@ -4187,6 +4243,7 @@ begin
|
|||||||
try
|
try
|
||||||
// collect definitions
|
// collect definitions
|
||||||
if not Tool.GatherUnitDefinitions(Definitions,true,false) then begin
|
if not Tool.GatherUnitDefinitions(Definitions,true,false) then begin
|
||||||
|
AssignCodeToolBossError;
|
||||||
DebugLn(['TAddMissingPointerTypes.Execute GatherUnitDefinitions failed ',CodeToolBoss.ErrorMessage]);
|
DebugLn(['TAddMissingPointerTypes.Execute GatherUnitDefinitions failed ',CodeToolBoss.ErrorMessage]);
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
@ -62,6 +62,7 @@ type
|
|||||||
const Filename: string;
|
const Filename: string;
|
||||||
UpdateFromDisk, Revert: Boolean;
|
UpdateFromDisk, Revert: Boolean;
|
||||||
out CodeBuffer: Pointer): boolean; override;
|
out CodeBuffer: Pointer): boolean; override;
|
||||||
|
procedure AssignCodeToolBossError(Target: TCustomTextConverterTool); override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure SetupTextConverters;
|
procedure SetupTextConverters;
|
||||||
@ -697,6 +698,19 @@ begin
|
|||||||
Result:=CodeBuffer<>nil;
|
Result:=CodeBuffer<>nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TLazTextConverterToolClasses.AssignCodeToolBossError(
|
||||||
|
Target: TCustomTextConverterTool);
|
||||||
|
begin
|
||||||
|
Target.ErrorMsg:=CodeToolBoss.ErrorMessage;
|
||||||
|
Target.ErrorLine:=CodeToolBoss.ErrorLine;
|
||||||
|
Target.ErrorColumn:=CodeToolBoss.ErrorColumn;
|
||||||
|
Target.ErrorTopLine:=CodeToolBoss.ErrorTopLine;
|
||||||
|
if CodeToolBoss.ErrorCode<>nil then
|
||||||
|
Target.ErrorFilename:=CodeToolBoss.ErrorCode.Filename
|
||||||
|
else
|
||||||
|
Target.ErrorFilename:='';
|
||||||
|
end;
|
||||||
|
|
||||||
function TLazTextConverterToolClasses.SupportsType(aTextType: TTextConverterType
|
function TLazTextConverterToolClasses.SupportsType(aTextType: TTextConverterType
|
||||||
): boolean;
|
): boolean;
|
||||||
begin
|
begin
|
||||||
|
@ -80,7 +80,7 @@ type
|
|||||||
procedure Clear;
|
procedure Clear;
|
||||||
procedure CheckType(aTextType: TTextConverterType);
|
procedure CheckType(aTextType: TTextConverterType);
|
||||||
function SupportsType(aTextType: TTextConverterType): boolean; virtual;
|
function SupportsType(aTextType: TTextConverterType): boolean; virtual;
|
||||||
function Execute(ToolList: TComponent): TModalResult;// run the tools
|
function Execute(ToolList: TComponent; out ErrorTool: TComponent): TModalResult;// run the tools
|
||||||
function LoadFromFile(const AFilename: string;
|
function LoadFromFile(const AFilename: string;
|
||||||
UseIDECache: Boolean = true;
|
UseIDECache: Boolean = true;
|
||||||
UpdateFromDisk: Boolean = true;
|
UpdateFromDisk: Boolean = true;
|
||||||
@ -107,6 +107,11 @@ type
|
|||||||
FCaption: string;
|
FCaption: string;
|
||||||
FDescription: string;
|
FDescription: string;
|
||||||
FEnabled: boolean;
|
FEnabled: boolean;
|
||||||
|
FErrorColumn: integer;
|
||||||
|
FErrorFilename: string;
|
||||||
|
FErrorLine: integer;
|
||||||
|
FErrorMsg: string;
|
||||||
|
FErrorTopLine: integer;
|
||||||
function IsCaptionStored: boolean;
|
function IsCaptionStored: boolean;
|
||||||
procedure SetCaption(const AValue: string);
|
procedure SetCaption(const AValue: string);
|
||||||
procedure SetDescription(const AValue: string);
|
procedure SetDescription(const AValue: string);
|
||||||
@ -116,6 +121,14 @@ type
|
|||||||
constructor Create(TheOwner: TComponent); override;
|
constructor Create(TheOwner: TComponent); override;
|
||||||
function Execute(aText: TIDETextConverter): TModalResult; virtual; abstract;
|
function Execute(aText: TIDETextConverter): TModalResult; virtual; abstract;
|
||||||
procedure Assign(Source: TPersistent); override;
|
procedure Assign(Source: TPersistent); override;
|
||||||
|
procedure ClearError; virtual;
|
||||||
|
procedure AssignError(Source: TCustomTextConverterTool);
|
||||||
|
procedure AssignCodeToolBossError;
|
||||||
|
property ErrorMsg: string read FErrorMsg write FErrorMsg;
|
||||||
|
property ErrorLine: integer read FErrorLine write FErrorLine;
|
||||||
|
property ErrorColumn: integer read FErrorColumn write FErrorColumn;
|
||||||
|
property ErrorTopLine: integer read FErrorTopLine write FErrorTopLine;
|
||||||
|
property ErrorFilename: string read FErrorFilename write FErrorFilename;
|
||||||
published
|
published
|
||||||
property Caption: string read FCaption write SetCaption stored IsCaptionStored;
|
property Caption: string read FCaption write SetCaption stored IsCaptionStored;
|
||||||
property Description: string read FDescription write SetDescription;
|
property Description: string read FDescription write SetDescription;
|
||||||
@ -198,6 +211,7 @@ type
|
|||||||
const Filename: string;
|
const Filename: string;
|
||||||
UpdateFromDisk, Revert: Boolean;
|
UpdateFromDisk, Revert: Boolean;
|
||||||
out CodeBuffer: Pointer): boolean; virtual; abstract;
|
out CodeBuffer: Pointer): boolean; virtual; abstract;
|
||||||
|
procedure AssignCodeToolBossError(Target: TCustomTextConverterTool); virtual; abstract;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
@ -634,22 +648,27 @@ begin
|
|||||||
and (TextConverterToolClasses.SupportsType(aTextType)));
|
and (TextConverterToolClasses.SupportsType(aTextType)));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TIDETextConverter.Execute(ToolList: TComponent): TModalResult;
|
function TIDETextConverter.Execute(ToolList: TComponent;
|
||||||
|
out ErrorTool: TComponent): TModalResult;
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
Tool: TCustomTextConverterTool;
|
Tool: TCustomTextConverterTool;
|
||||||
CurResult: TModalResult;
|
CurResult: TModalResult;
|
||||||
begin
|
begin
|
||||||
Result:=mrOk;
|
Result:=mrOk;
|
||||||
|
ErrorTool:=nil;
|
||||||
for i:=0 to ToolList.ComponentCount-1 do begin
|
for i:=0 to ToolList.ComponentCount-1 do begin
|
||||||
if ToolList.Components[i] is TCustomTextConverterTool then begin
|
if ToolList.Components[i] is TCustomTextConverterTool then begin
|
||||||
Tool:=TCustomTextConverterTool(ToolList.Components[i]);
|
Tool:=TCustomTextConverterTool(ToolList.Components[i]);
|
||||||
if Tool.Enabled then begin
|
if Tool.Enabled then begin
|
||||||
|
Tool.ClearError;
|
||||||
CurResult:=Tool.Execute(Self);
|
CurResult:=Tool.Execute(Self);
|
||||||
if CurResult=mrIgnore then
|
if CurResult=mrIgnore then
|
||||||
Result:=mrCancel
|
Result:=mrOk
|
||||||
else if CurResult<>mrOk then
|
else if CurResult<>mrOk then begin
|
||||||
|
ErrorTool:=Tool;
|
||||||
exit(mrAbort);
|
exit(mrAbort);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -758,6 +777,33 @@ begin
|
|||||||
inherited Assign(Source);
|
inherited Assign(Source);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCustomTextConverterTool.ClearError;
|
||||||
|
begin
|
||||||
|
FErrorMsg:='';
|
||||||
|
FErrorLine:=0;
|
||||||
|
FErrorColumn:=0;
|
||||||
|
FErrorTopLine:=0;
|
||||||
|
FErrorFilename:='';
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCustomTextConverterTool.AssignError(Source: TCustomTextConverterTool
|
||||||
|
);
|
||||||
|
begin
|
||||||
|
FErrorMsg:=Source.ErrorMsg;
|
||||||
|
FErrorLine:=Source.ErrorLine;
|
||||||
|
FErrorColumn:=Source.ErrorColumn;
|
||||||
|
FErrorTopLine:=Source.ErrorTopLine;
|
||||||
|
FErrorFilename:=Source.ErrorFilename;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCustomTextConverterTool.AssignCodeToolBossError;
|
||||||
|
begin
|
||||||
|
if Assigned(TextConverterToolClasses) then
|
||||||
|
TextConverterToolClasses.AssignCodeToolBossError(Self)
|
||||||
|
else
|
||||||
|
ClearError;
|
||||||
|
end;
|
||||||
|
|
||||||
class function TCustomTextConverterTool.FirstLineOfClassDescription: string;
|
class function TCustomTextConverterTool.FirstLineOfClassDescription: string;
|
||||||
var
|
var
|
||||||
p: Integer;
|
p: Integer;
|
||||||
|
Loading…
Reference in New Issue
Block a user