diff --git a/components/codetools/finddeclarationtool.pas b/components/codetools/finddeclarationtool.pas index 36aab00a6f..70c9c388bc 100644 --- a/components/codetools/finddeclarationtool.pas +++ b/components/codetools/finddeclarationtool.pas @@ -6470,6 +6470,7 @@ var ExprType: TExpressionType; ExprStartPos, ExprEndPos: integer; CurIgnoreErrorAfterPos: Integer; OldFlags: TFindDeclarationFlags; + ok: Boolean; procedure RaiseBracketNotFound; begin @@ -6482,60 +6483,66 @@ begin '"',copy(Src,StartPos,40),'" Context=',Params.ContextNode.DescAsString); {$ENDIF} Result:=TExprTypeList.Create; - MoveCursorToCleanPos(StartPos); - ReadNextAtom; // reads first atom after proc name - if AtomIsChar('(') then - BracketClose:=')' - else if AtomIsChar('[') then - BracketClose:=']' - else - BracketClose:=#0; - if IgnoreErrorAfterValid then - CurIgnoreErrorAfterPos:=IgnoreErrorAfterCleanedPos - else - CurIgnoreErrorAfterPos:=-1; - OldFlags:=Params.Flags; - if BracketClose<>#0 then begin - // read parameter list - ReadNextAtom; - if not AtomIsChar(BracketClose) then begin - // read all expressions - while true do begin - ExprStartPos:=CurPos.StartPos; - // read til comma or bracket close - repeat - if CurPos.Flag in [cafRoundBracketOpen,cafEdgedBracketOpen] then begin - ReadTilBracketClose(true); - end; + ok:=false; + try + MoveCursorToCleanPos(StartPos); + ReadNextAtom; // reads first atom after proc name + if AtomIsChar('(') then + BracketClose:=')' + else if AtomIsChar('[') then + BracketClose:=']' + else + BracketClose:=#0; + if IgnoreErrorAfterValid then + CurIgnoreErrorAfterPos:=IgnoreErrorAfterCleanedPos + else + CurIgnoreErrorAfterPos:=-1; + OldFlags:=Params.Flags; + if BracketClose<>#0 then begin + // read parameter list + ReadNextAtom; + if not AtomIsChar(BracketClose) then begin + // read all expressions + while true do begin + ExprStartPos:=CurPos.StartPos; + // read til comma or bracket close + repeat + if CurPos.Flag in [cafRoundBracketOpen,cafEdgedBracketOpen] then begin + ReadTilBracketClose(true); + end; + ReadNextAtom; + if (CurPos.StartPos>SrcLen) + or (CurPos.Flag in [cafRoundBracketClose,cafEdgedBracketClose,cafComma]) + then + break; + until false; + ExprEndPos:=CurPos.StartPos; + // find expression type + if (CurIgnoreErrorAfterPos>=ExprStartPos) then + Params.Flags:=Params.Flags-[fdfExceptionOnNotFound]; + //DebugLn('TFindDeclarationTool.CreateParamExprListFromStatement CurIgnoreErrorAfterPos=',dbgs(CurIgnoreErrorAfterPos),' ExprStartPos=',dbgs(ExprStartPos)); + ExprType:=FindExpressionResultType(Params,ExprStartPos,ExprEndPos); + // add expression type to list + Result.Add(ExprType); + MoveCursorToCleanPos(ExprEndPos); ReadNextAtom; - if (CurPos.StartPos>SrcLen) - or (CurPos.Flag in [cafRoundBracketClose,cafEdgedBracketClose,cafComma]) - then - break; - until false; - ExprEndPos:=CurPos.StartPos; - // find expression type - if (CurIgnoreErrorAfterPos>=ExprStartPos) then - Params.Flags:=Params.Flags-[fdfExceptionOnNotFound]; - //DebugLn('TFindDeclarationTool.CreateParamExprListFromStatement CurIgnoreErrorAfterPos=',dbgs(CurIgnoreErrorAfterPos),' ExprStartPos=',dbgs(ExprStartPos)); - ExprType:=FindExpressionResultType(Params,ExprStartPos,ExprEndPos); - // add expression type to list - Result.Add(ExprType); - MoveCursorToCleanPos(ExprEndPos); - ReadNextAtom; - if AtomIsChar(BracketClose) then break; - if not AtomIsChar(',') then - RaiseBracketNotFound; - ReadNextAtom; + if AtomIsChar(BracketClose) then break; + if not AtomIsChar(',') then + RaiseBracketNotFound; + ReadNextAtom; + end; end; end; + Params.Flags:=OldFlags; + {$IFDEF ShowExprEval} + DebugLn('[TFindDeclarationTool.CreateParamExprListFromStatement] END ', + 'ParamCount=',dbgs(Result.Count),' "',copy(Src,StartPos,40),'"'); + DebugLn(' ExprList=[',Result.AsString,']'); + {$ENDIF} + Ok:=true; + finally + if not Ok then Result.Free; end; - Params.Flags:=OldFlags; - {$IFDEF ShowExprEval} - DebugLn('[TFindDeclarationTool.CreateParamExprListFromStatement] END ', - 'ParamCount=',dbgs(Result.Count),' "',copy(Src,StartPos,40),'"'); - DebugLn(' ExprList=[',Result.AsString,']'); - {$ENDIF} end; function TFindDeclarationTool.CreateParamExprListFromProcNode(