From 202608c307b9ddc49dc30aa1995ff14af5eb8546 Mon Sep 17 00:00:00 2001 From: juha Date: Mon, 29 Aug 2011 20:53:37 +0000 Subject: [PATCH] Codetools: fix parsing with generics in method parameters. Issue #20073, patch from Anthony Walter git-svn-id: trunk@32099 - --- components/codetools/pascalparsertool.pas | 53 ++++++++++++++--------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/components/codetools/pascalparsertool.pas b/components/codetools/pascalparsertool.pas index b3b4bc068b..8b93be81aa 100644 --- a/components/codetools/pascalparsertool.pas +++ b/components/codetools/pascalparsertool.pas @@ -182,6 +182,7 @@ type function UnexpectedKeyWord: boolean; function EndOfSourceExpected: boolean; // read functions + procedure ReadGenericParam; function ReadTilProcedureHeadEnd(ParseAttr: TParseProcHeadAttributes; var HasForwardModifier: boolean): boolean; function ReadConstant(ExceptionOnError, Extract: boolean; @@ -1342,6 +1343,34 @@ begin Result:=true; end; +// Support generics in methods parameters and return types +procedure TPascalParserTool.ReadGenericParam; +var + Atom: string; + Level: Integer; +begin + Atom := GetAtom; + if Atom='<' then begin + Level:=1; + repeat + ReadNextAtom; + Atom := GetAtom; + if CurPos.Flag in [cafPoint, cafComma] then begin + ReadNextAtom; + AtomIsIdentifier(true); + end + else if Atom='<' then begin + ReadNextAtom; + AtomIsIdentifier(true); + Inc(Level); + end + else if Atom='>' then + Dec(Level); + until Level=0; + ReadNextAtom; + end; +end; + function TPascalParserTool.ReadParamType(ExceptionOnError, Extract: boolean; const Attr: TProcHeadAttributes): boolean; // after reading, CurPos is the atom after the type @@ -1435,6 +1464,7 @@ begin RaiseStringExpectedButAtomFound(ctsIdentifier) else exit; end; + ReadGenericParam; Result:=true; end; @@ -1485,7 +1515,6 @@ function TPascalParserTool.ReadTilProcedureHeadEnd( var IsSpecifier: boolean; Attr: TProcHeadAttributes; - Level: Integer; begin //DebugLn('[TPascalParserTool.ReadTilProcedureHeadEnd] ', //'Method=',IsMethod,', Function=',IsFunction,', Type=',IsType); @@ -1497,6 +1526,7 @@ begin Include(Attr,phpCreateNodes); ReadParamList(true,false,Attr); end; + if (pphIsOperator in ParseAttr) and (CurPos.Flag<>cafColon) then begin // read operator result identifier AtomIsIdentifier(true); @@ -1508,6 +1538,7 @@ begin end; ReadNextAtom; end; + if ([pphIsFunction,pphIsOperator]*ParseAttr<>[]) then begin // read function result type if CurPos.Flag=cafColon then begin @@ -1532,25 +1563,7 @@ begin end; ReadNextAtom; end; - // Support generics in the function return type - Level:=1; - if GetAtom='<' then begin - while Level>0 do begin - ReadNextAtom; - if CurPos.Flag in [cafPoint, cafComma] then begin - ReadNextAtom; - AtomIsIdentifier(true); - end - else if GetAtom='<' then begin - ReadNextAtom; - AtomIsIdentifier(true); - Inc(Level); - end - else if GetAtom='>' then - Dec(Level); - end; - ReadNextAtom; - end; + ReadGenericParam; end else begin if (Scanner.CompilerMode<>cmDelphi) then RaiseCharExpectedButAtomFound(':')