Bläddra i källkod

compiler: add reference for the enumerator operator when it is used + another test for operator enumerator for a class

git-svn-id: branches/paul/features@13944 -
paul 16 år sedan
förälder
incheckning
5ef751eeed
3 ändrade filer med 49 tillägg och 0 borttagningar
  1. 1 0
      .gitattributes
  2. 1 0
      compiler/pstatmnt.pas
  3. 47 0
      tests/test/tforin5.pp

+ 1 - 0
.gitattributes

@@ -8213,6 +8213,7 @@ tests/test/tforin1.pp svneol=native#text/pascal
 tests/test/tforin2.pp svneol=native#text/pascal
 tests/test/tforin3.pp svneol=native#text/pascal
 tests/test/tforin4.pp svneol=native#text/pascal
+tests/test/tforin5.pp svneol=native#text/pascal
 tests/test/tfpu1.pp svneol=native#text/plain
 tests/test/tfpu2.pp svneol=native#text/plain
 tests/test/tfpu3.pp svneol=native#text/plain

+ 1 - 0
compiler/pstatmnt.pas

@@ -710,6 +710,7 @@ implementation
             enum_get_params:=ccallparanode.create(expr.getcopy,nil);
             enum_get:=ccallnode.create(enum_get_params, tprocsym(enumerator_get.procsym), nil, nil, []);
             tcallnode(enum_get).procdefinition:=enumerator_get;
+            addsymref(enumerator_get.procsym);
           end
           else
             enum_get:=ccallnode.create(nil, tprocsym(enumerator_get.procsym), enumerator_get.owner, expr.getcopy, []);

+ 47 - 0
tests/test/tforin5.pp

@@ -0,0 +1,47 @@
+program Project18;
+
+{$APPTYPE CONSOLE}
+
+type
+  TMyList = class
+  end;
+
+  { TMyListEnumerator }
+
+  TMyListEnumerator = class
+  private
+    FCurrent: Integer;
+  public
+    constructor Create;
+    function MoveNext: Boolean;
+    property Current: Integer read FCurrent;
+  end;
+
+{ TMyListEnumerator }
+
+constructor TMyListEnumerator.Create;
+begin
+  FCurrent := 0;
+end;
+
+function TMyListEnumerator.MoveNext: Boolean;
+begin
+  inc(FCurrent);
+  Result := FCurrent <= 3;
+end;
+
+operator enumerator (AList: TMyList): TMyListEnumerator;
+begin
+  Result := TMyListEnumerator.Create;
+end;
+
+var
+  List: TMyList;
+  i: integer;
+begin
+  List := TMyList.Create;
+  for i in List do
+    WriteLn(i);
+  List.Free;
+end.
+