Browse Source

* bug #793 fixed

florian 25 years ago
parent
commit
9836bd406b
1 changed files with 38 additions and 9 deletions
  1. 38 9
      compiler/cg386cal.pas

+ 38 - 9
compiler/cg386cal.pas

@@ -684,13 +684,36 @@ implementation
                              { member call, ESI isn't modified }
                              { member call, ESI isn't modified }
                              loadesi:=false;
                              loadesi:=false;
                           end;
                           end;
-                        emit_reg(A_PUSH,S_L,R_ESI);
-                        { but a con- or destructor here would probably almost }
-                        { always be placed wrong }
-                        if is_con_or_destructor then
+                        { direct call to destructor: don't remove data! }
+                        if procinfo^._class^.is_class then
+                          begin
+                             if (p^.procdefinition^.proctypeoption=potype_destructor) then
+                               begin
+                                  emit_const(A_PUSH,S_L,0);
+                                  emit_reg(A_PUSH,S_L,R_ESI);
+                               end
+                             else if (p^.procdefinition^.proctypeoption=potype_constructor) then
+                               emit_const(A_PUSH,S_L,0)
+                             else
+                               emit_reg(A_PUSH,S_L,R_ESI);
+                          end
+                        else
                           begin
                           begin
-                             CGMessage(cg_w_member_cd_call_from_method);
-                             push_int(0);
+                             if is_con_or_destructor then
+                               begin
+                                  if (p^.procdefinition^.proctypeoption=potype_constructor) then
+                                    begin
+                                       { it's no bad idea, to insert the VMT }
+                                       emit_sym(A_PUSH,S_L,newasmsymbol(
+                                         pobjectdef(p^.methodpointer^.resulttype)^.vmt_mangledname));
+                                    end
+                                  { destructors haven't to dispose the instance, if this is }
+                                  { a direct call                                           }
+                                  else
+                                    push_int(0);
+                               end
+                             else
+                               emit_reg(A_PUSH,S_L,R_ESI);
                           end;
                           end;
                      end;
                      end;
                 end;
                 end;
@@ -762,7 +785,10 @@ implementation
                         ((p^.methodpointer=nil) or (p^.methodpointer^.treetype=typen)))
                         ((p^.methodpointer=nil) or (p^.methodpointer^.treetype=typen)))
                         or
                         or
                         (po_staticmethod in p^.procdefinition^.procoptions) or
                         (po_staticmethod in p^.procdefinition^.procoptions) or
-                        (p^.procdefinition^.proctypeoption=potype_constructor) or
+                        ((p^.procdefinition^.proctypeoption=potype_constructor) and
+                        { if we call a constructor from anther constructor }
+                        { esi contains self }
+                         (assigned(p^.methodpointer))) or
                         { ESI is loaded earlier }
                         { ESI is loaded earlier }
                         (po_classmethod in p^.procdefinition^.procoptions) then
                         (po_classmethod in p^.procdefinition^.procoptions) then
                          begin
                          begin
@@ -1292,7 +1318,10 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.117  2000-01-16 22:17:11  peter
+  Revision 1.118  2000-01-20 12:14:47  florian
+    * bug 793 fixed
+
+  Revision 1.117  2000/01/16 22:17:11  peter
     * renamed call_offset to para_offset
     * renamed call_offset to para_offset
 
 
   Revision 1.116  2000/01/09 12:35:00  jonas
   Revision 1.116  2000/01/09 12:35:00  jonas
@@ -1404,4 +1433,4 @@ end.
   Revision 1.90.2.3  1999/06/22 13:30:08  peter
   Revision 1.90.2.3  1999/06/22 13:30:08  peter
     * fixed return with packenum
     * fixed return with packenum
 
 
-}
+}