codetools: var completion of for-var-in-genericarray, from Pascal Riekenberg, issue #37076

git-svn-id: trunk@63160 -
This commit is contained in:
mattias 2020-05-15 09:37:49 +00:00
parent 9083125eb6
commit c64cd287c5
2 changed files with 37 additions and 23 deletions

View File

@ -844,7 +844,8 @@ type
function FindEnumerationTypeOfSetType(SetTypeNode: TCodeTreeNode; function FindEnumerationTypeOfSetType(SetTypeNode: TCodeTreeNode;
out Context: TFindContext): boolean; out Context: TFindContext): boolean;
function FindElementTypeOfArrayType(ArrayNode: TCodeTreeNode; function FindElementTypeOfArrayType(ArrayNode: TCodeTreeNode;
out ExprType: TExpressionType; AliasType: PFindContext): boolean; out ExprType: TExpressionType; AliasType: PFindContext;
ParentParams: TFindDeclarationParams = nil): boolean;
function CheckOperatorEnumerator(Params: TFindDeclarationParams; function CheckOperatorEnumerator(Params: TFindDeclarationParams;
const FoundContext: TFindContext): TIdentifierFoundResult; const FoundContext: TFindContext): TIdentifierFoundResult;
function CheckModifierEnumeratorCurrent({%H-}Params: TFindDeclarationParams; function CheckModifierEnumeratorCurrent({%H-}Params: TFindDeclarationParams;
@ -12734,7 +12735,7 @@ function TFindDeclarationTool.FindForInTypeAsString(TermPos: TAtomPosition;
begin begin
AliasType:=CleanFindContext; AliasType:=CleanFindContext;
if SubExprType.Context.Tool.FindElementTypeOfArrayType( if SubExprType.Context.Tool.FindElementTypeOfArrayType(
SubExprType.Context.Node,ExprType,@AliasType) SubExprType.Context.Node,ExprType,@AliasType,Params)
then begin then begin
Result:=FindExprTypeAsString(ExprType,TermPos.StartPos,@AliasType); Result:=FindExprTypeAsString(ExprType,TermPos.StartPos,@AliasType);
end; end;
@ -13131,7 +13132,7 @@ end;
function TFindDeclarationTool.FindElementTypeOfArrayType( function TFindDeclarationTool.FindElementTypeOfArrayType(
ArrayNode: TCodeTreeNode; out ExprType: TExpressionType; ArrayNode: TCodeTreeNode; out ExprType: TExpressionType;
AliasType: PFindContext): boolean; AliasType: PFindContext; ParentParams: TFindDeclarationParams): boolean;
var var
Params: TFindDeclarationParams; Params: TFindDeclarationParams;
p: LongInt; p: LongInt;
@ -13142,6 +13143,14 @@ begin
if (ArrayNode=nil) then exit; if (ArrayNode=nil) then exit;
if (ArrayNode.Desc<>ctnOpenArrayType) and (ArrayNode.Desc<>ctnRangedArrayType) if (ArrayNode.Desc<>ctnOpenArrayType) and (ArrayNode.Desc<>ctnRangedArrayType)
then exit; then exit;
if (ArrayNode.Parent <> nil)
and (ArrayNode.Parent.Desc = ctnGenericType)
and (ParentParams <> nil) then begin
ExprType.Desc := xtContext;
ExprType.Context.Node := ParentParams.GenParamValueMappings.SpecializeParamsNode.FirstChild;
ExprType.Context.Tool := ParentParams.GenParamValueMappings.SpecializeParamsTool;
Result:=true;
end else begin
MoveCursorToNodeStart(ArrayNode); MoveCursorToNodeStart(ArrayNode);
ReadNextAtom; // array ReadNextAtom; // array
if not UpAtomIs('ARRAY') then exit; if not UpAtomIs('ARRAY') then exit;
@ -13164,6 +13173,7 @@ begin
finally finally
Params.Free; Params.Free;
end; end;
end;
end; end;
function TFindDeclarationTool.CheckOperatorEnumerator( function TFindDeclarationTool.CheckOperatorEnumerator(

View File

@ -111,6 +111,8 @@ type
TOL3 = TOL2; TOL3 = TOL2;
TOL4 = class(TOL2); TOL4 = class(TOL2);
generic TArray<T> = array of T;
var var
OL_P1_1: TOL_P1_1; OL_P1_1: TOL_P1_1;
OL_P1_2: TOL_P1_2; OL_P1_2: TOL_P1_2;
@ -124,6 +126,7 @@ var
OL2: TOL2; OL2: TOL2;
OL3: TOL3; OL3: TOL3;
OL4: TOL4; OL4: TOL4;
A: specialize TArray<TObj>;
begin begin
for o_p1_1{guesstype:TObj} in OL_P1_1 do ; for o_p1_1{guesstype:TObj} in OL_P1_1 do ;
@ -138,6 +141,7 @@ begin
for o2{guesstype:TObj} in OL2 do ; for o2{guesstype:TObj} in OL2 do ;
for o3{guesstype:TObj} in OL3 do ; for o3{guesstype:TObj} in OL3 do ;
for o4{guesstype:TObj} in OL4 do ; for o4{guesstype:TObj} in OL4 do ;
for i{guesstype:TObj} in A do;
end. end.