diff --git a/components/codetools/pascalparsertool.pas b/components/codetools/pascalparsertool.pas index 756bfe980e..4588f1ba79 100644 --- a/components/codetools/pascalparsertool.pas +++ b/components/codetools/pascalparsertool.pas @@ -176,7 +176,8 @@ type procedure ReadGenericParamList(Must, AllowConstraints: boolean); procedure ReadAttribute; procedure FixLastAttributes; - procedure ReadTypeReference(CreateNodes: boolean); + procedure ReadTypeReference(CreateNodes: boolean; Extract: boolean = false; + Copying: boolean = false; const Attr: TProcHeadAttributes = []); procedure ReadClassInterfaceContent; function KeyWordFuncTypeClass: boolean; function KeyWordFuncTypeClassInterface(IntfDesc: TCodeTreeNodeDesc): boolean; @@ -249,7 +250,8 @@ type Copying: boolean = false; const Attr: TProcHeadAttributes = []); procedure ReadSpecializeParams(CreateChildNodes: boolean; Extract: boolean = false; Copying: boolean = false; const Attr: TProcHeadAttributes = []); - procedure ReadAnsiStringParams; + procedure ReadAnsiStringParams(Extract: boolean = false; + Copying: boolean = false; const Attr: TProcHeadAttributes = []); function ReadClosure(ExceptionOnError, CreateNodes: boolean): boolean; function SkipTypeReference(ExceptionOnError: boolean): boolean; function SkipSpecializeParams(ExceptionOnError: boolean): boolean; @@ -4388,7 +4390,8 @@ begin until Attr=nil; end; -procedure TPascalParserTool.ReadTypeReference(CreateNodes: boolean); +procedure TPascalParserTool.ReadTypeReference(CreateNodes: boolean; Extract: boolean; + Copying: boolean; const Attr: TProcHeadAttributes); { After reading CurPos is on atom behind the identifier Examples: @@ -4399,23 +4402,32 @@ procedure TPascalParserTool.ReadTypeReference(CreateNodes: boolean); specialize TGenericClass atype.subtype } + + procedure Next; inline; + begin + if not Extract then + ReadNextAtom + else + ExtractNextAtom(Copying,Attr); + end; + var Cnt: Integer; begin if (Scanner.CompilerMode=cmOBJFPC) and UpAtomIs('SPECIALIZE') then begin - ReadSpecialize(CreateNodes); + ReadSpecialize(CreateNodes,Extract,Copying,Attr); exit; end; if CreateNodes then begin CreateChildNode; CurNode.Desc:=ctnIdentifier; end; - ReadNextAtom; + Next; Cnt:=1; while CurPos.Flag=cafPoint do begin - ReadNextAtom; + Next; AtomIsIdentifierSaveE(20180411194207); - ReadNextAtom; + Next; inc(Cnt,2); end; if AtomIsChar('<') then begin @@ -4423,8 +4435,8 @@ begin or ((Cnt=3) and LastUpAtomIs(3,'SYSTEM') and LastUpAtomIs(1,'STRING')) then begin // e.g. string - ReadAnsiStringParams; - ReadNextAtom; + ReadAnsiStringParams(Extract,Copying,Attr); + Next; end else if (Scanner.CompilerMode in [cmDELPHI,cmDELPHIUNICODE]) then begin // e.g. atype @@ -4436,13 +4448,13 @@ begin CurNode.EndPos:=CurPos.StartPos; EndChildNode; end; - ReadSpecializeParams(CreateNodes); - ReadNextAtom; + ReadSpecializeParams(CreateNodes,Extract,Copying,Attr); + Next; while CurPos.Flag=cafPoint do begin // e.g. atype.subtype - ReadNextAtom; + Next; AtomIsIdentifierSaveE(20180411194209); - ReadNextAtom; + Next; end; end; end; @@ -6068,23 +6080,7 @@ begin repeat // read identifier (a parameter of the generic type) Next; - AtomIsIdentifierSaveE(20180411194303); - if CreateChildNodes then begin - CreateChildNode; - CurNode.Desc:=ctnSpecializeParam; - CurNode.EndPos:=CurPos.EndPos; - end; - Next; - while Curpos.Flag=cafPoint do begin - // first identifier was unitname, now read the type - Next; - AtomIsIdentifierSaveE(20180411194305); - if CreateChildNodes then - CurNode.EndPos:=CurPos.EndPos; - Next; - end; - if CreateChildNodes then - EndChildNode; // close ctnSpecializeParam + ReadTypeReference(CreateChildNodes,Extract,Copying,Attr); if AtomIsChar('>') then break else if CurPos.Flag=cafComma then begin @@ -6099,11 +6095,14 @@ begin end; end; -procedure TPascalParserTool.ReadAnsiStringParams; +procedure TPascalParserTool.ReadAnsiStringParams(Extract: boolean; Copying: boolean; const Attr: TProcHeadAttributes); begin // string repeat - ReadNextAtom; + if not Extract then + ReadNextAtom + else + ExtractNextAtom(Copying,Attr); if AtomIsChar('>') then break; case CurPos.Flag of cafRoundBracketOpen,cafEdgedBracketOpen: ReadTilBracketClose(true);