Преглед изворни кода

* changed is_assignment_overloaded into
function assignment_overloaded : pprocdef
to allow overloading of assignment with only different result type

pierre пре 26 година
родитељ
комит
ba80b732e0
4 измењених фајлова са 55 додато и 18 уклоњено
  1. 13 7
      compiler/htypechk.pas
  2. 9 1
      compiler/pexpr.pas
  3. 19 4
      compiler/pstatmnt.pas
  4. 14 6
      compiler/tccnv.pas

+ 13 - 7
compiler/htypechk.pas

@@ -50,7 +50,7 @@ interface
     function  valid_for_formal_const(p : ptree) : boolean;
     function  is_procsym_load(p:Ptree):boolean;
     function  is_procsym_call(p:Ptree):boolean;
-    function  is_assignment_overloaded(from_def,to_def : pdef) : boolean;
+    function  assignment_overloaded(from_def,to_def : pdef) : pprocdef;
 
 
 implementation
@@ -460,7 +460,7 @@ implementation
            else
              begin
              { assignment overwritten ?? }
-               if is_assignment_overloaded(def_from,def_to) then
+               if assigned(assignment_overloaded(def_from,def_to)) then
                 b:=2;
              end;
          end;
@@ -636,12 +636,12 @@ implementation
       end;
 
 
-    function is_assignment_overloaded(from_def,to_def : pdef) : boolean;
+    function assignment_overloaded(from_def,to_def : pdef) : pprocdef;
        var
           passproc : pprocdef;
           convtyp : tconverttype;
        begin
-          is_assignment_overloaded:=false;
+          assignment_overloaded:=nil;
           if assigned(overloaded_operators[assignment]) then
             passproc:=overloaded_operators[assignment]^.definition
           else
@@ -649,9 +649,10 @@ implementation
           while passproc<>nil do
             begin
               if is_equal(passproc^.retdef,to_def) and
-                 (isconvertable(from_def,passproc^.para1^.data,convtyp,ordconstn,false)=1) then
+                 (is_equal(passproc^.para1^.data,from_def) or
+                 (isconvertable(from_def,passproc^.para1^.data,convtyp,ordconstn,false)=1)) then
                 begin
-                   is_assignment_overloaded:=true;
+                   assignment_overloaded:=passproc;
                    break;
                 end;
               passproc:=passproc^.nextoverloaded;
@@ -661,7 +662,12 @@ implementation
 end.
 {
   $Log$
-  Revision 1.27  1999-06-01 19:27:47  peter
+  Revision 1.27.2.1  1999-06-17 12:51:42  pierre
+   * changed is_assignment_overloaded into
+      function assignment_overloaded : pprocdef
+      to allow overloading of assignment with only different result type
+
+  Revision 1.27  1999/06/01 19:27:47  peter
     * better checks for procvar and methodpointer
 
   Revision 1.26  1999/05/20 14:58:26  peter

+ 9 - 1
compiler/pexpr.pas

@@ -838,6 +838,9 @@ unit pexpr;
                   (not ((m_tp in aktmodeswitches) and
                   (afterassignment or in_args))) then
                  begin
+                    if ((pvarsym(sym)=opsym) and
+                       ((p^.flags and pi_operator)<>0)) then
+                       inc(opsym^.refs);
                     p1:=genzeronode(funcretn);
                     pd:=p^.retdef;
                     p1^.funcretprocinfo:=p;
@@ -2024,7 +2027,12 @@ unit pexpr;
 end.
 {
   $Log$
-  Revision 1.112.2.2  1999-06-15 18:54:52  peter
+  Revision 1.112.2.3  1999-06-17 12:51:44  pierre
+   * changed is_assignment_overloaded into
+      function assignment_overloaded : pprocdef
+      to allow overloading of assignment with only different result type
+
+  Revision 1.112.2.2  1999/06/15 18:54:52  peter
     * more procvar fixes
 
   Revision 1.112.2.1  1999/06/13 22:38:09  peter

+ 19 - 4
compiler/pstatmnt.pas

@@ -808,12 +808,18 @@ unit pstatmnt;
                 tt:=hdisposen;
             end;
           consume(LKLAMMER);
+
+          { displaced here to avoid warnings in BP mode (PM) }
+          Store_valid := Must_be_valid;
+          if tt=hnewn then
+            Must_be_valid := False
+          else
+            Must_be_valid:=true;
+
           p:=comp_expr(true);
 
           { calc return type }
           cleartempgen;
-          Store_valid := Must_be_valid;
-          Must_be_valid := False;
           do_firstpass(p);
           Must_be_valid := Store_valid;
 
@@ -1152,7 +1158,8 @@ unit pstatmnt;
                 begin
                    { the space has been set in the local symtable }
                    procinfo.retoffset:=-funcretsym^.address;
-                   if (procinfo.flags and pi_operator)<>0 then
+                   if ((procinfo.flags and pi_operator)<>0) and
+                     assigned(opsym) then
                      {opsym^.address:=procinfo.call_offset; is wrong PM }
                      opsym^.address:=-procinfo.retoffset;
                    { eax is modified by a function }
@@ -1265,7 +1272,15 @@ unit pstatmnt;
 end.
 {
   $Log$
-  Revision 1.87  1999-05-27 19:44:50  peter
+  Revision 1.88.2.1  1999-06-17 12:51:46  pierre
+   * changed is_assignment_overloaded into
+      function assignment_overloaded : pprocdef
+      to allow overloading of assignment with only different result type
+
+  Revision 1.88  1999/06/15 13:19:46  pierre
+   * better uninitialized var tests for TP mode
+
+  Revision 1.87  1999/05/27 19:44:50  peter
     * removed oldasm
     * plabel -> pasmlabel
     * -a switches to source writing automaticly

+ 14 - 6
compiler/tccnv.pas

@@ -625,11 +625,13 @@ implementation
               exit;
             end;
          end;
-
-       if is_assignment_overloaded(p^.left^.resulttype,p^.resulttype) then
+       aprocdef:=assignment_overloaded(p^.left^.resulttype,p^.resulttype);
+       if assigned(aprocdef) then
          begin
             procinfo.flags:=procinfo.flags or pi_do_call;
             hp:=gencallnode(overloaded_operators[assignment],nil);
+            { tell explicitly which def we must use !! (PM) }
+            hp^.procdefinition:=aprocdef;
             hp^.left:=gencallparanode(p^.left,nil);
             putnode(p);
             p:=hp;
@@ -809,9 +811,10 @@ implementation
                { possible, if the source is no register    }
                if ((p^.resulttype^.deftype in [recorddef,stringdef,arraydef]) or
                    ((p^.resulttype^.deftype=objectdef) and not(pobjectdef(p^.resulttype)^.isclass))
-                  ) and (p^.left^.location.loc in [LOC_REGISTER,LOC_CREGISTER]) and
-                  {it also works if the assignment is overloaded }
-                  not is_assignment_overloaded(p^.left^.resulttype,p^.resulttype) then
+                  ) and (p^.left^.location.loc in [LOC_REGISTER,LOC_CREGISTER]) { and
+                   it also works if the assignment is overloaded
+                   YES but this code is not executed if assignment is overloaded (PM)
+                  not assigned(assignment_overloaded(p^.left^.resulttype,p^.resulttype))} then
                  CGMessage(cg_e_illegal_type_conversion);
             end
            else
@@ -912,7 +915,12 @@ implementation
 end.
 {
   $Log$
-  Revision 1.35.2.2  1999-06-15 18:54:53  peter
+  Revision 1.35.2.3  1999-06-17 12:51:48  pierre
+   * changed is_assignment_overloaded into
+      function assignment_overloaded : pprocdef
+      to allow overloading of assignment with only different result type
+
+  Revision 1.35.2.2  1999/06/15 18:54:53  peter
     * more procvar fixes
 
   Revision 1.35.2.1  1999/06/13 22:39:19  peter