Bladeren bron

compiler: if method has no self node then load it as a usual identifier (issue #0024871)

git-svn-id: trunk@25273 -
paul 12 jaren geleden
bovenliggende
commit
89e154bc10
4 gewijzigde bestanden met toevoegingen van 78 en 3 verwijderingen
  1. 1 0
      .gitattributes
  2. 17 3
      compiler/pexpr.pas
  3. 3 0
      compiler/procinfo.pas
  4. 57 0
      tests/webtbs/tw24871.pp

+ 1 - 0
.gitattributes

@@ -13477,6 +13477,7 @@ tests/webtbs/tw2481.pp svneol=native#text/plain
 tests/webtbs/tw2483.pp svneol=native#text/plain
 tests/webtbs/tw2483.pp svneol=native#text/plain
 tests/webtbs/tw24848.pp svneol=native#text/pascal
 tests/webtbs/tw24848.pp svneol=native#text/pascal
 tests/webtbs/tw24863.pp svneol=native#text/plain
 tests/webtbs/tw24863.pp svneol=native#text/plain
+tests/webtbs/tw24871.pp svneol=native#text/pascal
 tests/webtbs/tw2492.pp svneol=native#text/plain
 tests/webtbs/tw2492.pp svneol=native#text/plain
 tests/webtbs/tw2494.pp svneol=native#text/plain
 tests/webtbs/tw2494.pp svneol=native#text/plain
 tests/webtbs/tw2503.pp svneol=native#text/plain
 tests/webtbs/tw2503.pp svneol=native#text/plain

+ 17 - 3
compiler/pexpr.pas

@@ -2788,6 +2788,22 @@ implementation
            factor_read_set:=buildp;
            factor_read_set:=buildp;
          end;
          end;
 
 
+         function can_load_self_node: boolean;
+         var
+           procinfo: tprocinfo;
+         begin
+           result:=false;
+           if (block_type in [bt_const,bt_type,bt_const_type,bt_var_type]) or
+              not assigned(current_structdef) or
+              not assigned(current_procinfo) then
+             exit;
+           procinfo:=current_procinfo;
+           if procinfo.procdef.parast.symtablelevel<normal_function_level then
+             exit;
+           while assigned(procinfo.parent)and(procinfo.procdef.parast.symtablelevel>normal_function_level) do
+             procinfo:=procinfo.parent;
+           result:=not procinfo.procdef.no_self_node;
+         end;
 
 
       {---------------------------------------------
       {---------------------------------------------
                       Factor (Main)
                       Factor (Main)
@@ -2822,9 +2838,7 @@ implementation
          begin
          begin
            again:=true;
            again:=true;
            { Handle references to self }
            { Handle references to self }
-           if (idtoken=_SELF) and
-              not(block_type in [bt_const,bt_type,bt_const_type,bt_var_type]) and
-              assigned(current_structdef) then
+           if (idtoken=_SELF) and can_load_self_node then
              begin
              begin
                p1:=load_self_node;
                p1:=load_self_node;
                consume(_ID);
                consume(_ID);

+ 3 - 0
compiler/procinfo.pas

@@ -52,6 +52,9 @@ unit procinfo;
        { This object gives information on the current routine being
        { This object gives information on the current routine being
          compiled.
          compiled.
        }
        }
+
+       { tprocinfo }
+
        tprocinfo = class(tlinkedlistitem)
        tprocinfo = class(tlinkedlistitem)
        private
        private
           { list to store the procinfo's of the nested procedures }
           { list to store the procinfo's of the nested procedures }

+ 57 - 0
tests/webtbs/tw24871.pp

@@ -0,0 +1,57 @@
+program tw24871;
+
+{$mode delphi}
+{$APPTYPE CONSOLE}
+
+type
+  TRec = record
+    class procedure Foo(Self: TObject); static;
+  end;
+
+  { TClass }
+
+  TClass = class
+    class procedure Foo(Self: TObject); static;
+  end;
+
+{ TRec }
+
+class procedure TRec.Foo(Self: TObject);
+
+  procedure Foo1;
+
+    procedure Foo2;
+    begin
+      Self.ClassName;
+    end;
+
+  begin
+    Self.ClassName;
+  end;
+
+begin
+  Self.ClassName;
+end;
+
+{ TClass }
+
+class procedure TClass.Foo(Self: TObject);
+
+  procedure Foo1;
+
+    procedure Foo2;
+    begin
+      Self.ClassName;
+    end;
+
+  begin
+    Self.ClassName;
+  end;
+
+begin
+  Self.ClassName;
+end;
+
+begin
+end.
+