浏览代码

* Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
are worth comitting.

daniel 23 年之前
父节点
当前提交
46b8ed0657
共有 8 个文件被更改,包括 227 次插入85 次删除
  1. 7 3
      compiler/browlog.pas
  2. 32 53
      compiler/defbase.pas
  3. 7 3
      compiler/ncnv.pas
  4. 6 2
      compiler/nmem.pas
  5. 7 3
      compiler/pexpr.pas
  6. 18 10
      compiler/symdef.pas
  7. 143 1
      compiler/symsym.pas
  8. 7 10
      compiler/symtable.pas

+ 7 - 3
compiler/browlog.pas

@@ -369,13 +369,13 @@ implementation
                   end;
                 procsym :
                   begin
-                     symt:=tprocsym(sym).defs^.def.parast;
+                     symt:=tprocsym(sym).first_procdef.parast;
                      symb:=tstoredsym(symt.search(ss));
                      if symb=nil then
                        symb:=tstoredsym(symt.search(upper(ss)));
                      if not assigned(symb) then
                        begin
-                          symt:=tprocsym(sym).defs^.def.localst;
+                          symt:=tprocsym(sym).first_procdef.localst;
                           sym:=tstoredsym(symt.search(ss));
                           if symb=nil then
                             symb:=tstoredsym(symt.search(upper(ss)));
@@ -514,7 +514,11 @@ implementation
 end.
 {
   $Log$
-  Revision 1.13  2002-05-18 13:34:05  peter
+  Revision 1.14  2002-07-23 09:51:22  daniel
+  * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
+    are worth comitting.
+
+  Revision 1.13  2002/05/18 13:34:05  peter
     * readded missing revisions
 
   Revision 1.12  2002/05/16 19:46:35  carl

+ 32 - 53
compiler/defbase.pas

@@ -237,7 +237,7 @@ interface
     { used to test compatibility between two pprocvardefs (JM)               }
     function proc_to_procvar_equal(def1:tabstractprocdef;def2:tprocvardef;exact:boolean) : boolean;
 
-    function get_proc_2_procvar_def(p:tprocsym;d:tprocvardef):tprocdef;
+{    function get_proc_2_procvar_def(p:tprocsym;d:tprocvardef):tprocdef;}
 
     {# If @var(l) isn't in the range of def a range check error (if not explicit) is generated and
       the value is placed within the range
@@ -468,56 +468,6 @@ implementation
            proc_to_procvar_equal:=false;
       end;
 
-
-    function get_proc_2_procvar_def(p:tprocsym;d:tprocvardef):tprocdef;
-      var
-        matchprocdef : tprocdef;
-        pd : pprocdeflist;
-      begin
-        { This function will return the pprocdef of pprocsym that
-          is the best match for procvardef. When there are multiple
-          matches it returns nil }
-        { exact match }
-        matchprocdef:=nil;
-        pd:=p.defs;
-        while assigned(pd) do
-         begin
-           if proc_to_procvar_equal(pd^.def,d,true) then
-            begin
-              { already found a match ? Then stop and return nil }
-              if assigned(matchprocdef) then
-               begin
-                 matchprocdef:=nil;
-                 break;
-               end;
-              matchprocdef:=pd^.def;
-            end;
-           pd:=pd^.next;
-         end;
-        { convertable match, if no exact match was found }
-        if not assigned(matchprocdef) and
-           not assigned(pd) then
-         begin
-           pd:=p.defs;
-           while assigned(pd) do
-            begin
-              if proc_to_procvar_equal(pd^.def,d,false) then
-               begin
-                 { already found a match ? Then stop and return nil }
-                 if assigned(matchprocdef) then
-                  begin
-                    matchprocdef:=nil;
-                    break;
-                  end;
-                 matchprocdef:=pd^.def;
-               end;
-              pd:=pd^.next;
-            end;
-         end;
-        get_proc_2_procvar_def:=matchprocdef;
-      end;
-
-
     { returns true, if def uses FPU }
     function is_fpu(def : tdef) : boolean;
       begin
@@ -1262,7 +1212,7 @@ implementation
         end; { endif assigned ... }
       end;
 
-    function assignment_overloaded(from_def,to_def : tdef) : tprocdef;
+(*    function assignment_overloaded(from_def,to_def : tdef) : tprocdef;
        var
           passprocs : pprocdeflist;
           convtyp : tconverttype;
@@ -1310,6 +1260,31 @@ implementation
               passprocs:=passprocs^.next;
             end;
        end;
+*)
+
+    function assignment_overloaded(from_def,to_def : tdef) : tprocdef;
+
+       begin
+          assignment_overloaded:=nil;
+          if not assigned(overloaded_operators[_ASSIGNMENT]) then
+            exit;
+	
+          { look for an exact match first }
+	  assignment_overloaded:=overloaded_operators[_ASSIGNMENT].
+	   search_procdef_byretdef_by1paradef(to_def,from_def,dm_exact);
+	  if assigned(assignment_overloaded) then
+	    exit;
+
+          { .... then look for an equal match }
+	  assignment_overloaded:=overloaded_operators[_ASSIGNMENT].
+	   search_procdef_byretdef_by1paradef(to_def,from_def,dm_equal);
+	  if assigned(assignment_overloaded) then
+	    exit;
+
+          {  .... then for convert level 1 }
+	  assignment_overloaded:=overloaded_operators[_ASSIGNMENT].
+	   search_procdef_byretdef_by1paradef(to_def,from_def,dm_convertl1);
+       end;
 
 
     { Returns:
@@ -1906,7 +1881,11 @@ implementation
 end.
 {
   $Log$
-  Revision 1.1  2002-07-20 11:57:53  florian
+  Revision 1.2  2002-07-23 09:51:22  daniel
+  * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
+    are worth comitting.
+
+  Revision 1.1  2002/07/20 11:57:53  florian
     * types.pas renamed to defbase.pas because D6 contains a types
       unit so this would conflicts if D6 programms are compiled
     + Willamette/SSE2 instructions to assembler added

+ 7 - 3
compiler/ncnv.pas

@@ -921,7 +921,7 @@ implementation
                begin
                  if is_procsym_call(left) then
                   begin
-                    currprocdef:=get_proc_2_procvar_def(tprocsym(tcallnode(left).symtableprocentry),tprocvardef(resulttype.def));
+		    currprocdef:=Tprocsym(Tcallnode(left).symtableprocentry).search_procdef_byprocvardef(Tprocvardef(resulttype.def));
                     hp:=cloadnode.create_procvar(tprocsym(tcallnode(left).symtableprocentry),
                         currprocdef,tcallnode(left).symtableproc);
                     if (tcallnode(left).symtableprocentry.owner.symtabletype=objectsymtable) and
@@ -935,7 +935,7 @@ implementation
                  else
                   begin
                     if (left.nodetype<>addrn) then
-                      aprocdef:=tprocsym(tloadnode(left).symtableentry).defs^.def;
+                      aprocdef:=tprocsym(tloadnode(left).symtableentry).first_procdef;
                   end;
                  convtype:=tc_proc_2_procvar;
                  { Now check if the procedure we are going to assign to
@@ -1751,7 +1751,11 @@ begin
 end.
 {
   $Log$
-  Revision 1.62  2002-07-22 11:48:04  daniel
+  Revision 1.63  2002-07-23 09:51:22  daniel
+  * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
+    are worth comitting.
+
+  Revision 1.62  2002/07/22 11:48:04  daniel
   * Sets are now internally sets.
 
   Revision 1.61  2002/07/20 17:16:02  florian

+ 6 - 2
compiler/nmem.pas

@@ -326,7 +326,7 @@ implementation
                  if assigned(getprocvardef) then
                   hp3:=getprocvardef
                  else
-                  hp3:=tabstractprocdef(tprocsym(tloadnode(left).symtableentry).defs^.def);
+                  hp3:=tabstractprocdef(tprocsym(tloadnode(left).symtableentry).first_procdef);
 
                  { create procvardef }
                  resulttype.setdef(tprocvardef.create);
@@ -894,7 +894,11 @@ begin
 end.
 {
   $Log$
-  Revision 1.34  2002-07-20 11:57:54  florian
+  Revision 1.35  2002-07-23 09:51:23  daniel
+  * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
+    are worth comitting.
+
+  Revision 1.34  2002/07/20 11:57:54  florian
     * types.pas renamed to defbase.pas because D6 contains a types
       unit so this would conflicts if D6 programms are compiled
     + Willamette/SSE2 instructions to assembler added

+ 7 - 3
compiler/pexpr.pas

@@ -670,7 +670,7 @@ implementation
               { generate a methodcallnode or proccallnode }
               { we shouldn't convert things like @tcollection.load }
               if assigned(getprocvardef) then
-               aprocdef:=get_proc_2_procvar_def(tprocsym(sym),getprocvardef)
+	       aprocdef:=Tprocsym(sym).search_procdef_byprocvardef(getprocvardef)
               else
                aprocdef:=nil;
               p2:=cloadnode.create_procvar(sym,aprocdef,st);
@@ -692,7 +692,7 @@ implementation
           currprocdef : tprocdef;
         begin
           hp:=nil;
-          currprocdef:=get_proc_2_procvar_def(tcallnode(t).symtableprocentry,procvar);
+          currprocdef:=tcallnode(t).symtableprocentry.search_procdef_byprocvardef(procvar);
           if assigned(currprocdef) then
            begin
              hp:=cloadnode.create_procvar(tprocsym(tcallnode(t).symtableprocentry),currprocdef,tcallnode(t).symtableproc);
@@ -2251,7 +2251,11 @@ implementation
 end.
 {
   $Log$
-  Revision 1.72  2002-07-20 11:57:55  florian
+  Revision 1.73  2002-07-23 09:51:23  daniel
+  * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
+    are worth comitting.
+
+  Revision 1.72  2002/07/20 11:57:55  florian
     * types.pas renamed to defbase.pas because D6 contains a types
       unit so this would conflicts if D6 programms are compiled
     + Willamette/SSE2 instructions to assembler added

+ 18 - 10
compiler/symdef.pas

@@ -617,6 +617,7 @@ interface
           procedure write_child_rtti_data(rt:trttitype);override;
        end;
 
+       Tdefmatch=(dm_exact,dm_equal,dm_convertl1);
 
     var
        aktobjectdef : tobjectdef;  { used for private functions check !! }
@@ -4330,7 +4331,7 @@ implementation
      end;
 
 
-   procedure tobjectdef._searchdestructor(sym : tnamedindexitem;arg:pointer);
+(*   procedure tobjectdef._searchdestructor(sym : tnamedindexitem;arg:pointer);
 
      var
         p : pprocdeflist;
@@ -4352,7 +4353,15 @@ implementation
                   p:=p^.next;
                end;
           end;
-     end;
+     end;*)
+
+    procedure Tobjectdef._searchdestructor(sym:Tnamedindexitem;arg:pointer);
+    
+    begin
+        { if we found already a destructor, then we exit }
+        if (sd=nil) and (Tsym(sym).typ=procsym) then
+    	    sd:=Tprocsym(sym).search_procdef_bytype(potype_destructor);
+    end;
 
    function tobjectdef.searchdestructor : tprocdef;
 
@@ -4435,15 +4444,10 @@ implementation
       begin
         If tsym(p).typ = procsym then
          begin
-           pd := tprocsym(p).defs^.def;
+           pd := tprocsym(p).first_procdef;
            { this will be used for full implementation of object stabs
            not yet done }
-           pdl:=tprocsym(p).defs;
-           while assigned(pdl) do
-            begin
-              ipd:=pdl^.def;
-              pdl:=pdl^.next;
-            end;
+	   ipd := Tprocsym(p).last_procdef;
            if (po_virtualmethod in pd.procoptions) then
              begin
                lindex := pd.extnumber;
@@ -5482,7 +5486,11 @@ implementation
 end.
 {
   $Log$
-  Revision 1.84  2002-07-20 11:57:57  florian
+  Revision 1.85  2002-07-23 09:51:24  daniel
+  * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
+    are worth comitting.
+
+  Revision 1.84  2002/07/20 11:57:57  florian
     * types.pas renamed to defbase.pas because D6 contains a types
       unit so this would conflicts if D6 programms are compiled
     + Willamette/SSE2 instructions to assembler added

+ 143 - 1
compiler/symsym.pas

@@ -106,7 +106,9 @@ interface
        end;
 
        tprocsym = class(tstoredsym)
+{       protected}
           defs      : pprocdeflist; { linked list of overloaded procdefs }
+       public
           is_global : boolean;
           overloadchecked : boolean;
           overloadcount   : longint; { amount of overloaded functions in this module }
@@ -122,6 +124,13 @@ interface
           procedure write(ppufile:tcompilerppufile);override;
           procedure deref;override;
           procedure addprocdef(p:tprocdef);
+	  procedure concat_procdefs_to(s:Tprocsym);
+	  function first_procdef:Tprocdef;
+	  function last_procdef:Tprocdef;
+	  function search_procdef_bytype(pt:Tproctypeoption):Tprocdef;
+	  function search_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
+	  function search_procdef_byretdef_by1paradef(retdef,firstpara:Tdef;
+						      matchtype:Tdefmatch):Tprocdef;
           function  write_references(ppufile:tcompilerppufile;locals:boolean):boolean;override;
 {$ifdef GDB}
           function stabstring : pchar;override;
@@ -361,6 +370,8 @@ implementation
 {$ifdef GDB}
        gdb,
 {$endif GDB}
+       { tree }
+       node,
        { aasm }
        aasmcpu,
        { module }
@@ -859,7 +870,134 @@ implementation
         pd^.next:=defs;
         defs:=pd;
       end;
+    
+    procedure Tprocsym.concat_procdefs_to(s:Tprocsym);
+    
+    var pd:Pprocdeflist;
+    
+    begin
+	pd:=defs;
+	while assigned(defs) do
+	    begin
+		s.addprocdef(pd^.def);
+		pd:=pd^.next;
+	    end;
+    end;
+
+    function Tprocsym.first_procdef:Tprocdef;
+
+    begin
+	first_procdef:=defs^.def;
+    end;
+
+    function Tprocsym.last_procdef:Tprocdef;
+
+    var pd:Pprocdeflist;
 
+    begin
+	pd:=defs;
+	while assigned(pd) do
+	    begin
+		last_procdef:=pd^.def;
+		pd:=pd^.next;
+	    end;
+    end;
+
+    function Tprocsym.search_procdef_bytype(pt:Tproctypeoption):Tprocdef;
+    
+    var p:Pprocdeflist;
+    
+    begin
+	search_procdef_bytype:=nil;
+	p:=defs;
+	while p<>nil do
+	    begin
+		if p^.def.proctypeoption=pt then
+		    begin
+			search_procdef_bytype:=p^.def;
+			break;
+		    end;
+		p:=p^.next;
+	    end;
+    end;
+    
+    function Tprocsym.search_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
+
+    var pd:Pprocdeflist;
+    
+    begin
+        {This function will return the pprocdef of pprocsym that
+         is the best match for procvardef. When there are multiple
+         matches it returns nil.}
+        {Try to find an exact match first.}
+        search_procdef_byprocvardef:=nil;
+        pd:=defs;
+        while assigned(pd) do
+	    begin
+		if proc_to_procvar_equal(pd^.def,d,true) then
+		    begin
+			{ already found a match ? Then stop and return nil }
+            		if assigned(search_procdef_byprocvardef) then
+            		    begin
+                		search_procdef_byprocvardef:=nil;
+                		break;
+            		    end;
+        		search_procdef_byprocvardef:=pd^.def;
+		    end;
+		pd:=pd^.next;
+	    end;
+        {Try a convertable match, if no exact match was found.}
+        if not assigned(search_procdef_byprocvardef) and not assigned(pd) then
+    	    begin
+    		pd:=defs;
+    	        while assigned(pd) do
+        	    begin
+            		if proc_to_procvar_equal(pd^.def,d,false) then
+            		    begin
+                		{ already found a match ? Then stop and return nil }
+                		if assigned(search_procdef_byprocvardef) then
+                		    begin
+                			search_procdef_byprocvardef:=nil;
+                			break;
+                		    end;
+                		search_procdef_byprocvardef:=pd^.def;
+            		    end;
+            		pd:=pd^.next;
+        	    end;
+	    end;
+    end;
+
+    function Tprocsym.search_procdef_byretdef_by1paradef(retdef,firstpara:Tdef;
+		      matchtype:Tdefmatch):Tprocdef;
+
+    var pd:Pprocdeflist;
+	convtyp:Tconverttype;
+	a,b:boolean;
+
+    begin
+	search_procdef_byretdef_by1paradef:=nil;
+	pd:=defs;
+	while assigned(pd) do
+	    begin
+		a:=is_equal(retdef,pd^.def.rettype.def);
+		if a then
+		    case matchtype of
+			dm_exact:
+			    b:=TParaItem(pd^.def.para.first).paratype.def=firstpara;
+			dm_equal:
+			    b:=is_equal(Tparaitem(pd^.def.para.first).paratype.def,firstpara);
+			dm_convertl1:
+			    b:=isconvertable(firstpara,Tparaitem(pd^.def.para.first).paratype.def,
+				convtyp,ordconstn,false)=1;
+		    end;
+		if a and b then
+		    begin
+			search_procdef_byretdef_by1paradef:=pd^.def;
+			break;
+		    end;
+		pd:=pd^.next;
+	    end;
+    end;
 
     procedure tprocsym.write(ppufile:tcompilerppufile);
       var
@@ -2528,7 +2666,11 @@ implementation
 end.
 {
   $Log$
-  Revision 1.44  2002-07-20 17:45:29  daniel
+  Revision 1.45  2002-07-23 09:51:26  daniel
+  * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
+    are worth comitting.
+
+  Revision 1.44  2002/07/20 17:45:29  daniel
   * Register variables are now possible for global variables too. This is
     important for small programs without procedures.
 

+ 7 - 10
compiler/symtable.pas

@@ -860,17 +860,10 @@ implementation
                          internalerror(12344321);
                        { use this procsym as start ? }
                        if not assigned(overloaded_operators[t]) then
-                        overloaded_operators[t]:=tprocsym(srsym)
+                          overloaded_operators[t]:=tprocsym(srsym)
                        else
-                        begin
                           { already got a procsym, only add defs of the current procsym }
-                          pd:=tprocsym(srsym).defs;
-                          while assigned(pd) do
-                           begin
-                             overloaded_operators[t].addprocdef(pd^.def);
-                             pd:=pd^.next;
-                           end;
-                        end;
+			  Tprocsym(srsym).concat_procdefs_to(overloaded_operators[t]);
                        symtablestack:=srsym.owner.next;
                     end
                   else
@@ -2065,7 +2058,11 @@ implementation
 end.
 {
   $Log$
-  Revision 1.64  2002-07-16 15:34:21  florian
+  Revision 1.65  2002-07-23 09:51:27  daniel
+  * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
+    are worth comitting.
+
+  Revision 1.64  2002/07/16 15:34:21  florian
     * exit is now a syssym instead of a keyword
 
   Revision 1.63  2002/07/15 19:44:53  florian