Converter: Fix function replacement to handle nested brackets correctly. Issue #22537

git-svn-id: trunk@38273 -
This commit is contained in:
juha 2012-08-18 12:33:39 +00:00
parent f6f3d00b54
commit 9f602bf564

View File

@ -530,7 +530,9 @@ var
procedure ReadParams(FuncInfo: TFuncReplacement); procedure ReadParams(FuncInfo: TFuncReplacement);
var var
ExprStartPos, ExprEndPos, BracketCount: integer; ExprStartPos, ExprEndPos: integer;
RoundBrLvl, SquareBrLvl: integer;
ShouldReadNextAtom: Boolean;
begin begin
FuncInfo.InclSemiColon:=''; FuncInfo.InclSemiColon:='';
FuncInfo.StartPos:=xStart; FuncInfo.StartPos:=xStart;
@ -541,22 +543,33 @@ var
if AtomIsChar('(') then begin if AtomIsChar('(') then begin
// read parameter list // read parameter list
ReadNextAtom; ReadNextAtom;
// Don't read twice inside a loop. Atom can be for example '['
ShouldReadNextAtom:=False;
if not AtomIsChar(')') then begin if not AtomIsChar(')') then begin
// read all expressions // read all expressions
BracketCount:=0; RoundBrLvl:=0;
SquareBrLvl:=0;
while true do begin while true do begin
ExprStartPos:=CurPos.StartPos; ExprStartPos:=CurPos.StartPos;
// read til comma or bracket close // read til comma or bracket close
repeat repeat
ReadNextAtom; if ShouldReadNextAtom then
if (CurPos.StartPos>SrcLen) or (CurPos.Flag=cafComma) then ReadNextAtom;
ShouldReadNextAtom:=True;
if CurPos.StartPos>SrcLen then
break; break;
if CurPos.Flag=cafRoundBracketOpen then if (CurPos.Flag=cafComma) and (RoundBrLvl=0) and (SquareBrLvl=0) then
Inc(BracketCount) break;
if CurPos.Flag=cafEdgedBracketOpen then
Inc(SquareBrLvl)
else if CurPos.Flag=cafEdgedBracketClose then
Dec(SquareBrLvl)
else if CurPos.Flag=cafRoundBracketOpen then
Inc(RoundBrLvl)
else if CurPos.Flag=cafRoundBracketClose then begin else if CurPos.Flag=cafRoundBracketClose then begin
if BracketCount=0 then if RoundBrLvl=0 then
break; break; // Closing bracket, end of parameters
Dec(BracketCount); Dec(RoundBrLvl);
end; end;
until false; until false;
ExprEndPos:=CurPos.StartPos; ExprEndPos:=CurPos.StartPos;