Browse Source

* support @inherited <method> to get the methodpointer
of <method> in a parent class

git-svn-id: trunk@2526 -

peter 19 years ago
parent
commit
b967ae8307
3 changed files with 13 additions and 2 deletions
  1. 2 1
      compiler/ncgld.pas
  2. 1 0
      compiler/node.pas
  3. 10 1
      compiler/pexpr.pas

+ 2 - 1
compiler/ncgld.pas

@@ -326,7 +326,8 @@ implementation
                       cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,hregister,href);
 
                       { virtual method ? }
-                      if (po_virtualmethod in procdef.procoptions) then
+                      if (po_virtualmethod in procdef.procoptions) and
+                         not(nf_inherited in flags) then
                         begin
                           { load vmt pointer }
                           reference_reset_base(href,hregister,0);

+ 1 - 0
compiler/node.pas

@@ -215,6 +215,7 @@ interface
          nf_absolute,
          nf_is_self,
          nf_load_self_pointer,
+         nf_inherited,
 
          { taddnode }
          nf_is_currency,

+ 10 - 1
compiler/pexpr.pas

@@ -892,6 +892,15 @@ implementation
              p2:=cloadnode.create_procvar(sym,aprocdef,st);
              if assigned(p1) then
               begin
+                { for loading methodpointer of an inherited function
+                  we use self as instance and load the address of
+                  the function directly and not through the vmt (PFV) }
+                if (cnf_inherited in callflags) then
+                  begin
+                    include(p2.flags,nf_inherited);
+                    p1.free;
+                    p1:=load_self_node;
+                  end;
                 if (p1.nodetype<>typen) then
                   tloadnode(p2).set_mp(p1)
                 else
@@ -2086,7 +2095,7 @@ implementation
                         Message(parser_e_methode_id_expected);
                         p1:=cerrornode.create;
                       end;
-                     do_member_read(classh,false,srsym,p1,again,[cnf_inherited,cnf_anon_inherited]);
+                     do_member_read(classh,getaddr,srsym,p1,again,[cnf_inherited,cnf_anon_inherited]);
                    end
                   else
                    begin