mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-23 20:59:36 +02:00
codetools: var completion of for-var-in-genericarray, from Pascal Riekenberg, issue #37076
git-svn-id: trunk@63160 -
This commit is contained in:
parent
9083125eb6
commit
c64cd287c5
@ -844,7 +844,8 @@ type
|
||||
function FindEnumerationTypeOfSetType(SetTypeNode: TCodeTreeNode;
|
||||
out Context: TFindContext): boolean;
|
||||
function FindElementTypeOfArrayType(ArrayNode: TCodeTreeNode;
|
||||
out ExprType: TExpressionType; AliasType: PFindContext): boolean;
|
||||
out ExprType: TExpressionType; AliasType: PFindContext;
|
||||
ParentParams: TFindDeclarationParams = nil): boolean;
|
||||
function CheckOperatorEnumerator(Params: TFindDeclarationParams;
|
||||
const FoundContext: TFindContext): TIdentifierFoundResult;
|
||||
function CheckModifierEnumeratorCurrent({%H-}Params: TFindDeclarationParams;
|
||||
@ -12734,7 +12735,7 @@ function TFindDeclarationTool.FindForInTypeAsString(TermPos: TAtomPosition;
|
||||
begin
|
||||
AliasType:=CleanFindContext;
|
||||
if SubExprType.Context.Tool.FindElementTypeOfArrayType(
|
||||
SubExprType.Context.Node,ExprType,@AliasType)
|
||||
SubExprType.Context.Node,ExprType,@AliasType,Params)
|
||||
then begin
|
||||
Result:=FindExprTypeAsString(ExprType,TermPos.StartPos,@AliasType);
|
||||
end;
|
||||
@ -13131,7 +13132,7 @@ end;
|
||||
|
||||
function TFindDeclarationTool.FindElementTypeOfArrayType(
|
||||
ArrayNode: TCodeTreeNode; out ExprType: TExpressionType;
|
||||
AliasType: PFindContext): boolean;
|
||||
AliasType: PFindContext; ParentParams: TFindDeclarationParams): boolean;
|
||||
var
|
||||
Params: TFindDeclarationParams;
|
||||
p: LongInt;
|
||||
@ -13142,27 +13143,36 @@ begin
|
||||
if (ArrayNode=nil) then exit;
|
||||
if (ArrayNode.Desc<>ctnOpenArrayType) and (ArrayNode.Desc<>ctnRangedArrayType)
|
||||
then exit;
|
||||
MoveCursorToNodeStart(ArrayNode);
|
||||
ReadNextAtom; // array
|
||||
if not UpAtomIs('ARRAY') then exit;
|
||||
ReadNextAtom; // of
|
||||
if CurPos.Flag=cafEdgedBracketOpen then begin
|
||||
ReadTilBracketClose(true);
|
||||
ReadNextAtom;
|
||||
end;
|
||||
if not UpAtomIs('OF') then exit;
|
||||
ReadNextAtom;
|
||||
if not AtomIsIdentifier then exit;
|
||||
Params:=TFindDeclarationParams.Create;
|
||||
try
|
||||
Params.Flags:=fdfDefaultForExpressions;
|
||||
Params.ContextNode:=ArrayNode;
|
||||
p:=CurPos.StartPos;
|
||||
Params.SetIdentifier(Self,@Src[p],nil);
|
||||
ExprType:=FindExpressionResultType(Params,p,-1,AliasType);
|
||||
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;
|
||||
finally
|
||||
Params.Free;
|
||||
end else begin
|
||||
MoveCursorToNodeStart(ArrayNode);
|
||||
ReadNextAtom; // array
|
||||
if not UpAtomIs('ARRAY') then exit;
|
||||
ReadNextAtom; // of
|
||||
if CurPos.Flag=cafEdgedBracketOpen then begin
|
||||
ReadTilBracketClose(true);
|
||||
ReadNextAtom;
|
||||
end;
|
||||
if not UpAtomIs('OF') then exit;
|
||||
ReadNextAtom;
|
||||
if not AtomIsIdentifier then exit;
|
||||
Params:=TFindDeclarationParams.Create;
|
||||
try
|
||||
Params.Flags:=fdfDefaultForExpressions;
|
||||
Params.ContextNode:=ArrayNode;
|
||||
p:=CurPos.StartPos;
|
||||
Params.SetIdentifier(Self,@Src[p],nil);
|
||||
ExprType:=FindExpressionResultType(Params,p,-1,AliasType);
|
||||
Result:=true;
|
||||
finally
|
||||
Params.Free;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -111,6 +111,8 @@ type
|
||||
TOL3 = TOL2;
|
||||
TOL4 = class(TOL2);
|
||||
|
||||
generic TArray<T> = array of T;
|
||||
|
||||
var
|
||||
OL_P1_1: TOL_P1_1;
|
||||
OL_P1_2: TOL_P1_2;
|
||||
@ -124,6 +126,7 @@ var
|
||||
OL2: TOL2;
|
||||
OL3: TOL3;
|
||||
OL4: TOL4;
|
||||
A: specialize TArray<TObj>;
|
||||
|
||||
begin
|
||||
for o_p1_1{guesstype:TObj} in OL_P1_1 do ;
|
||||
@ -138,6 +141,7 @@ begin
|
||||
for o2{guesstype:TObj} in OL2 do ;
|
||||
for o3{guesstype:TObj} in OL3 do ;
|
||||
for o4{guesstype:TObj} in OL4 do ;
|
||||
for i{guesstype:TObj} in A do;
|
||||
end.
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user