mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-16 09:39:09 +02:00
Converter: Improve function replacement support.
git-svn-id: trunk@26610 -
This commit is contained in:
parent
87e25ee778
commit
38555de5d8
39
converter/convcodetool.pas
Normal file → Executable file
39
converter/convcodetool.pas
Normal file → Executable file
@ -31,7 +31,8 @@ type
|
|||||||
fReplacement: string;
|
fReplacement: string;
|
||||||
fStartPos: Integer;
|
fStartPos: Integer;
|
||||||
fEndPos: Integer;
|
fEndPos: Integer;
|
||||||
fParams: TStringList; // fParamTypes: TExprTypeList;
|
fInclSemiColon: string;
|
||||||
|
fParams: TStringList;
|
||||||
public
|
public
|
||||||
constructor Create(aFuncName, aReplacement: string);
|
constructor Create(aFuncName, aReplacement: string);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -605,12 +606,11 @@ var
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
FuncInfo: TCalledFuncInfo;
|
FuncInfo: TCalledFuncInfo;
|
||||||
PossibleCommPos: Integer; // Start looking for comments here.
|
PossibleCommPos: Integer; // Start looking for comments here.
|
||||||
i: Integer;
|
i: Integer;
|
||||||
s, NewFunc, NewParamStr, Comment: String;
|
s, NewFunc, NewParamStr, Comment: String;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
ParamList:=TStringList.Create;
|
ParamList:=TStringList.Create;
|
||||||
@ -626,8 +626,8 @@ begin
|
|||||||
if BodyEnd=-1 then
|
if BodyEnd=-1 then
|
||||||
BodyEnd:=Length(FuncInfo.fReplacement);
|
BodyEnd:=Length(FuncInfo.fReplacement);
|
||||||
NewFunc:=Trim(Copy(FuncInfo.fReplacement, 1, BodyEnd));
|
NewFunc:=Trim(Copy(FuncInfo.fReplacement, 1, BodyEnd));
|
||||||
NewFunc:=Format('%s(%s) { *Converted from %s* %s }',
|
NewFunc:=Format('%s(%s)%s { *Converted from %s* %s }',
|
||||||
[NewFunc, NewParamStr, FuncInfo.fFuncName, Comment]);
|
[NewFunc, NewParamStr, FuncInfo.fInclSemiColon, FuncInfo.fFuncName, Comment]);
|
||||||
// Old function call with params for IDE message output.
|
// Old function call with params for IDE message output.
|
||||||
s:=copy(fCodeTool.Src, FuncInfo.fStartPos, FuncInfo.fEndPos-FuncInfo.fStartPos);
|
s:=copy(fCodeTool.Src, FuncInfo.fStartPos, FuncInfo.fEndPos-FuncInfo.fStartPos);
|
||||||
s:=StringReplace(s, sLineBreak, '', [rfReplaceAll]);
|
s:=StringReplace(s, sLineBreak, '', [rfReplaceAll]);
|
||||||
@ -667,13 +667,22 @@ function TConvDelphiCodeTool.ReplaceFuncCalls: boolean;
|
|||||||
// implementation section. Add their positions to another list for replacement.
|
// implementation section. Add their positions to another list for replacement.
|
||||||
var
|
var
|
||||||
FuncNames: TStringList;
|
FuncNames: TStringList;
|
||||||
Node: TCodeTreeNode;
|
|
||||||
StartPos: Integer;
|
StartPos: Integer;
|
||||||
|
|
||||||
|
procedure CheckSemiColon(FuncInfo: TCalledFuncInfo);
|
||||||
|
begin
|
||||||
|
with fCodeTool do
|
||||||
|
if AtomIsChar(';') then begin
|
||||||
|
FuncInfo.fEndPos:=CurPos.EndPos;
|
||||||
|
FuncInfo.fInclSemiColon:=';';
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure ReadParams(FuncInfo: TCalledFuncInfo);
|
procedure ReadParams(FuncInfo: TCalledFuncInfo);
|
||||||
var
|
var
|
||||||
ExprStartPos, ExprEndPos: integer;
|
ExprStartPos, ExprEndPos: integer;
|
||||||
begin
|
begin
|
||||||
|
FuncInfo.fInclSemiColon:='';
|
||||||
FuncInfo.fStartPos:=StartPos;
|
FuncInfo.fStartPos:=StartPos;
|
||||||
with fCodeTool do begin
|
with fCodeTool do begin
|
||||||
MoveCursorToCleanPos(StartPos);
|
MoveCursorToCleanPos(StartPos);
|
||||||
@ -700,6 +709,8 @@ var
|
|||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
if AtomIsChar(')') then begin
|
if AtomIsChar(')') then begin
|
||||||
FuncInfo.fEndPos:=CurPos.EndPos;
|
FuncInfo.fEndPos:=CurPos.EndPos;
|
||||||
|
ReadNextAtom;
|
||||||
|
CheckSemiColon(FuncInfo);
|
||||||
break;
|
break;
|
||||||
end;
|
end;
|
||||||
if not AtomIsChar(',') then
|
if not AtomIsChar(',') then
|
||||||
@ -708,9 +719,8 @@ var
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
else if AtomIsChar(';') then
|
else
|
||||||
FuncInfo.fEndPos:=CurPos.EndPos;
|
CheckSemiColon(FuncInfo);
|
||||||
//raise EConverterError.Create('The called function is not ended like it should.');
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -835,7 +845,8 @@ var
|
|||||||
Result:=aNode.NextSkipChilds;
|
Result:=aNode.NextSkipChilds;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
Node: TCodeTreeNode;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
with fCodeTool do begin
|
with fCodeTool do begin
|
||||||
|
2
converter/convertsettings.pas
Normal file → Executable file
2
converter/convertsettings.pas
Normal file → Executable file
@ -253,7 +253,7 @@ begin
|
|||||||
|
|
||||||
// Map Delphi function names to FCL/LCL functions.
|
// Map Delphi function names to FCL/LCL functions.
|
||||||
TheMap:=fReplaceFuncs;
|
TheMap:=fReplaceFuncs;
|
||||||
MapReplacement('ShellExecute', 'OpenURL($3)');
|
MapReplacement('ShellExecute', 'OpenURL($3) // Can be also OpenDocument depending on parameter.');
|
||||||
// File name encoding. ToDo: add other similar funcs with UTF8 counterparts.
|
// File name encoding. ToDo: add other similar funcs with UTF8 counterparts.
|
||||||
MapReplacement('FileExists', 'FileExistsUTF8($1)');
|
MapReplacement('FileExists', 'FileExistsUTF8($1)');
|
||||||
// File functions using a handle.
|
// File functions using a handle.
|
||||||
|
Loading…
Reference in New Issue
Block a user