Converter: Fix a crash when a replaced function had brackets '()' without parameters.

git-svn-id: trunk@43195 -
This commit is contained in:
juha 2013-10-10 15:53:36 +00:00
parent cc878b3646
commit 41d824bbe4
2 changed files with 19 additions and 10 deletions

View File

@ -506,7 +506,7 @@ begin
if (FuncInfo.Params.Count>0) or (ReplacementParams.Count=0) then begin
NewFunc:=InsertParams2Replacement(FuncInfo);
// Separate function body
NewFunc:=NewFunc+FuncInfo.InclSemiColon;
NewFunc:=NewFunc+FuncInfo.InclEmptyBrackets+FuncInfo.InclSemiColon;
if fCTLink.fSettings.FuncReplaceComment then
NewFunc:=NewFunc+' { *Converted from '+FuncInfo.FuncName+'* }';
Comment:=GetComment(FuncInfo.ReplFunc, PossibleCommentPos);
@ -569,20 +569,23 @@ var
var
ExprStartPos, ExprEndPos: integer;
RoundBrLvl, SquareBrLvl: integer;
ShouldReadNextAtom: Boolean;
HasParams, ShouldReadNextAtom: Boolean;
begin
FuncInfo.InclEmptyBrackets:='';
FuncInfo.InclSemiColon:='';
FuncInfo.StartPos:=xStart;
with fCTLink.CodeTool do begin
MoveCursorToCleanPos(xStart);
ReadNextAtom; // Read proc name.
ReadNextAtom; // Read first atom after proc name.
if AtomIsChar('(') then begin
HasParams:=AtomIsChar('(');
if HasParams then begin
// read parameter list
ReadNextAtom;
// Don't read twice inside a loop. Atom can be for example '['
ShouldReadNextAtom:=False;
if not AtomIsChar(')') then begin
HasParams:=not AtomIsChar(')');
if HasParams then begin
// read all expressions
RoundBrLvl:=0;
SquareBrLvl:=0;
@ -624,9 +627,13 @@ var
raise EDelphiConverterError.Create('Bracket not found');
ReadNextAtom;
end;
end
else begin
FuncInfo.InclEmptyBrackets:='()';
ReadNextAtom;
end;
end
else begin
end;
if not HasParams then begin
FuncInfo.EndPos:=CurPos.StartPos;
CheckSemiColon(FuncInfo);
end;

View File

@ -37,11 +37,12 @@ type
fPackageName: string;
fUnitName: string;
// Calculated for each actual replacement:
fReplFunc: string; // May be extracted from a conditional expression.
fStartPos: Integer; // Start and end positions of original func+params.
fReplFunc: string; // May be extracted from a conditional expression.
fStartPos: Integer; // Start and end positions of original func+params.
fEndPos: Integer;
fInclSemiColon: string; // Ending semiColon is included in the replacement.
fParams: TStringList; // Parameters of the original function call.
fInclEmptyBrackets: string; // '()' is included in the replacement.
fInclSemiColon: string; // Ending semiColon is included in the replacement.
fParams: TStringList; // Parameters of the original function call.
function ParseIf(var aStart: integer): boolean;
public
constructor Create(const aCategory, aFuncName, aReplacement, aPackageName, aUnitName: string);
@ -57,6 +58,7 @@ type
property UnitName: string read fUnitName;
property StartPos: Integer read fStartPos write fStartPos;
property EndPos: Integer read fEndPos write fEndPos;
property InclEmptyBrackets: string read fInclEmptyBrackets write fInclEmptyBrackets;
property InclSemiColon: string read fInclSemiColon write fInclSemiColon;
property Params: TStringList read fParams;
end;