Browse Source

Merged revisions 2526 via svnmerge from
http://[email protected]/svn/fpc/trunk

........
r2526 | peter | 2006-02-11 23:49:00 +0100 (Sat, 11 Feb 2006) | 3 lines

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

........

git-svn-id: branches/fixes_2_0@2795 -

peter 19 years ago
parent
commit
30c69f9ab4
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

@@ -313,7 +313,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

@@ -905,6 +905,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
@@ -2105,7 +2114,7 @@ implementation
                         Message(parser_e_methode_id_expected);
                         p1:=cerrornode.create;
                       end;
-                     do_member_read(classh,false,sym,p1,again,[cnf_inherited,cnf_anon_inherited]);
+                     do_member_read(classh,getaddr,sym,p1,again,[cnf_inherited,cnf_anon_inherited]);
                    end
                   else
                    begin