瀏覽代碼

+ add utility function to retrieve the invoke procdef of a function reference interface

Sven/Sarah Barth 3 年之前
父節點
當前提交
22bbcf4b27
共有 1 個文件被更改,包括 27 次插入0 次删除
  1. 27 0
      compiler/defutil.pas

+ 27 - 0
compiler/defutil.pas

@@ -394,10 +394,14 @@ interface
     { returns the TTypeKind value of the def }
     function get_typekind(def: tdef): byte;
 
+    { returns the Invoke procdef of a function reference interface }
+    function get_invoke_procdef(def:tobjectdef):tprocdef;
+
 implementation
 
     uses
        verbose,cutils,
+       symsym,
        cpuinfo;
 
     { returns true, if def uses FPU }
@@ -2016,4 +2020,27 @@ implementation
         end;
       end;
 
+
+    function get_invoke_procdef(def:tobjectdef):tprocdef;
+      var
+        sym : tsym;
+      begin
+        repeat
+          if not is_invokable(def) then
+            internalerror(2022011701);
+          sym:=tsym(def.symtable.find(method_name_funcref_invoke_find));
+          if assigned(sym) and (sym.typ<>procsym) then
+            sym:=nil;
+          def:=def.childof;
+        until assigned(sym) or not assigned(def);
+        if not assigned(sym) then
+          internalerror(2021041001);
+        if sym.typ<>procsym then
+          internalerror(2021041002);
+        if tprocsym(sym).procdeflist.count=0 then
+          internalerror(2021041003);
+        result:=tprocdef(tprocsym(sym).procdeflist[0]);
+      end;
+
+
 end.