瀏覽代碼

* symtable.pas:
+ search_management_operator function to find Tprocdef for selected management operator in record definition

tokens.pas:
+ new constants: first_managment_operator and last_managment_operator used in search_management_operator

git-svn-id: trunk@35444 -

maciej-izak 8 年之前
父節點
當前提交
25db29d0a6
共有 2 個文件被更改,包括 36 次插入0 次删除
  1. 34 0
      compiler/symtable.pas
  2. 2 0
      compiler/tokens.pas

+ 34 - 0
compiler/symtable.pas

@@ -346,6 +346,7 @@ interface
     function  search_struct_member_no_helper(pd : tabstractrecorddef;const s : string):tsym;
     function  search_assignment_operator(from_def,to_def:Tdef;explicit:boolean):Tprocdef;
     function  search_enumerator_operator(from_def,to_def:Tdef):Tprocdef;
+    function  search_management_operator(mop:tmanagementoperator;pd:Tdef):Tprocdef;
     { searches for the helper definition that's currently active for pd }
     function  search_last_objectpascal_helper(pd : tdef;contextclassh : tabstractrecorddef;out odef : tobjectdef):boolean;
     { searches whether the symbol s is available in the currently active }
@@ -436,6 +437,14 @@ interface
     { _OP_INC        }  'inc',
     { _OP_DEC        }  'dec');
 
+      managementoperator2tok:array[tmanagementoperator] of ttoken = (
+    { mop_none       }  NOTOKEN,
+    { mop_initialize }  _OP_INITIALIZE,
+    { mop_finalize   }  _OP_FINALIZE,
+    { mop_addref     }  _OP_ADDREF,
+    { mop_copy       }  _OP_COPY
+    );
+
 
 
 implementation
@@ -3738,6 +3747,31 @@ implementation
     end;
 
 
+    function search_management_operator(mop:tmanagementoperator;pd:Tdef):Tprocdef;
+      var
+        sym : Tprocsym;
+        hashedid : THashedIDString;
+        optoken: ttoken;
+      begin
+        optoken := managementoperator2tok[mop];
+        if (optoken<first_managment_operator) or
+           (optoken>last_managment_operator) then
+          internalerror(201602280);
+        hashedid.id:=overloaded_names[optoken];
+        if not (pd.typ in [recorddef]) then
+          internalerror(201602281);
+        sym:=Tprocsym(tabstractrecorddef(pd).symtable.FindWithHash(hashedid));
+        if sym<>nil then
+          begin
+            if sym.typ<>procsym then
+              internalerror(201602282);
+            result:=sym.find_procdef_bytype(potype_operator);
+          end
+        else
+          result:=nil;
+      end;
+
+
     function search_system_type(const s: TIDString): ttypesym;
       var
         sym : tsym;

+ 2 - 0
compiler/tokens.pas

@@ -334,6 +334,8 @@ const
   first_overloaded = succ(NOTOKEN);
   last_overloaded  = _OP_DEC;
   last_operator = _GENERICSPECIALTOKEN;
+  first_managment_operator = _OP_INITIALIZE;
+  last_managment_operator = _OP_COPY;
 
   highest_precedence = oppower;