浏览代码

* support inherited; support for overload as it is handled by
delphi. This is only for delphi mode as it is working is
undocumented and hard to predict what is done

peter 23 年之前
父节点
当前提交
9d0437f8aa
共有 3 个文件被更改,包括 64 次插入22 次删除
  1. 49 20
      compiler/ncal.pas
  2. 7 1
      compiler/node.pas
  3. 8 1
      compiler/pexpr.pas

+ 49 - 20
compiler/ncal.pas

@@ -148,7 +148,7 @@ implementation
       verbose,globals,
       verbose,globals,
       symconst,paramgr,defbase,
       symconst,paramgr,defbase,
       htypechk,pass_1,cpuinfo,cpubase,
       htypechk,pass_1,cpuinfo,cpubase,
-      ncnv,nld,ninl,nadd,ncon,
+      nbas,ncnv,nld,ninl,nadd,ncon,
       rgobj,cgbase
       rgobj,cgbase
       ;
       ;
 
 
@@ -1468,6 +1468,7 @@ implementation
 
 
       var
       var
         i,j : longint;
         i,j : longint;
+        has_overload_directive,
         found,
         found,
         is_const : boolean;
         is_const : boolean;
         bestord  : torddef;
         bestord  : torddef;
@@ -1476,6 +1477,7 @@ implementation
       begin
       begin
          result:=nil;
          result:=nil;
          procs:=nil;
          procs:=nil;
+         has_overload_directive:=false;
 
 
          oldcallprocdef:=aktcallprocdef;
          oldcallprocdef:=aktcallprocdef;
          aktcallprocdef:=nil;
          aktcallprocdef:=nil;
@@ -1565,13 +1567,17 @@ implementation
                             hp^.nextpara:=hp^.firstpara;
                             hp^.nextpara:=hp^.firstpara;
                             procs:=hp;
                             procs:=hp;
                          end;
                          end;
-                     end;
+                      end;
+
+                   { remember if the procedure is declared with the overload directive,
+                     it's information is still needed also after all procs are removed }
+                   has_overload_directive:=(po_overload in symtableprocentry.first_procdef.procoptions);
 
 
                    { when the definition has overload directive set, we search for
                    { when the definition has overload directive set, we search for
                      overloaded definitions in the symtablestack. The found
                      overloaded definitions in the symtablestack. The found
                      entries are only added to the procs list and not the procsym, because
                      entries are only added to the procs list and not the procsym, because
                      the list can change in every situation }
                      the list can change in every situation }
-                   if (po_overload in symtableprocentry.first_procdef.procoptions) and
+                   if has_overload_directive and
                       (symtableprocentry.owner.symtabletype<>objectsymtable) then
                       (symtableprocentry.owner.symtabletype<>objectsymtable) then
                      begin
                      begin
                        srsymtable:=symtableprocentry.owner.next;
                        srsymtable:=symtableprocentry.owner.next;
@@ -1638,24 +1644,42 @@ implementation
                      with the parameter size }
                      with the parameter size }
                    if not assigned(procs) then
                    if not assigned(procs) then
                     begin
                     begin
-                      { in tp mode we can try to convert to procvar if
-                        there are no parameters specified }
-                      if not(assigned(left)) and
-                         (m_tp_procvar in aktmodeswitches) then
-                        begin
-                          hpt:=cloadnode.create(tprocsym(symtableprocentry),symtableproc);
-                          if (symtableprocentry.owner.symtabletype=objectsymtable) and
-                             assigned(methodpointer) then
-                            tloadnode(hpt).set_mp(methodpointer.getcopy);
-                          resulttypepass(hpt);
-                          result:=hpt;
-                        end
+                      { when it's an auto inherited call and there
+                        is no procedure found, but the procedures
+                        were defined with overload directive and at
+                        least two procedures are defined then we ignore
+                        this inherited by inserting a nothingn. Only
+                        do this ugly hack in Delphi mode as it looks more
+                        like a bug. It's also not documented }
+                      if (m_delphi in aktmodeswitches) and
+                         (nf_auto_inherited in flags) and
+                         (has_overload_directive) and
+                         (symtableprocentry.procdef_count>=2) then
+                        result:=cnothingnode.create
                       else
                       else
                         begin
                         begin
-                          if assigned(left) then
-                           aktfilepos:=left.fileinfo;
-                          CGMessage(parser_e_wrong_parameter_size);
-                          symtableprocentry.write_parameter_lists(nil);
+                          { in tp mode we can try to convert to procvar if
+                            there are no parameters specified. Only try it
+                            when there is only one proc definition, else the
+                            loadnode will give a strange error }
+                          if not(assigned(left)) and
+                             (m_tp_procvar in aktmodeswitches) and
+                             (symtableprocentry.procdef_count=1) then
+                            begin
+                              hpt:=cloadnode.create(tprocsym(symtableprocentry),symtableproc);
+                              if (symtableprocentry.owner.symtabletype=objectsymtable) and
+                                 assigned(methodpointer) then
+                                tloadnode(hpt).set_mp(methodpointer.getcopy);
+                              resulttypepass(hpt);
+                              result:=hpt;
+                            end
+                          else
+                            begin
+                              if assigned(left) then
+                               aktfilepos:=left.fileinfo;
+                              CGMessage(parser_e_wrong_parameter_size);
+                              symtableprocentry.write_parameter_lists(nil);
+                            end;
                         end;
                         end;
                       goto errorexit;
                       goto errorexit;
                     end;
                     end;
@@ -2604,7 +2628,12 @@ begin
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.101  2002-09-16 14:11:12  peter
+  Revision 1.102  2002-10-05 00:48:57  peter
+    * support inherited; support for overload as it is handled by
+      delphi. This is only for delphi mode as it is working is
+      undocumented and hard to predict what is done
+
+  Revision 1.101  2002/09/16 14:11:12  peter
     * add argument to equal_paras() to support default values or not
     * add argument to equal_paras() to support default values or not
 
 
   Revision 1.100  2002/09/15 17:49:59  peter
   Revision 1.100  2002/09/15 17:49:59  peter

+ 7 - 1
compiler/node.pas

@@ -222,6 +222,7 @@ interface
          { flags used by tcallnode }
          { flags used by tcallnode }
          nf_return_value_used,
          nf_return_value_used,
          nf_static_call,
          nf_static_call,
+         nf_auto_inherited,
 
 
          { flags used by tcallparanode }
          { flags used by tcallparanode }
          nf_varargs_para,  { belongs this para to varargs }
          nf_varargs_para,  { belongs this para to varargs }
@@ -978,7 +979,12 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.43  2002-09-07 15:25:03  peter
+  Revision 1.44  2002-10-05 00:48:57  peter
+    * support inherited; support for overload as it is handled by
+      delphi. This is only for delphi mode as it is working is
+      undocumented and hard to predict what is done
+
+  Revision 1.43  2002/09/07 15:25:03  peter
     * old logs removed and tabs fixed
     * old logs removed and tabs fixed
 
 
   Revision 1.42  2002/09/03 16:26:26  daniel
   Revision 1.42  2002/09/03 16:26:26  daniel

+ 8 - 1
compiler/pexpr.pas

@@ -650,6 +650,7 @@ implementation
                  end;
                  end;
               end;
               end;
              p1:=ccallnode.create(para,tprocsym(sym),st,p1);
              p1:=ccallnode.create(para,tprocsym(sym),st,p1);
+             include(p1.flags,nf_auto_inherited);
            end
            end
         else
         else
            begin
            begin
@@ -914,6 +915,7 @@ implementation
                       do_resulttypepass(p1);
                       do_resulttypepass(p1);
                       { now we know the real method e.g. we can check for a class method }
                       { now we know the real method e.g. we can check for a class method }
                       if isclassref and
                       if isclassref and
+                         (p1.nodetype=calln) and
                          assigned(tcallnode(p1).procdefinition) and
                          assigned(tcallnode(p1).procdefinition) and
                          not(po_classmethod in tcallnode(p1).procdefinition.procoptions) and
                          not(po_classmethod in tcallnode(p1).procdefinition.procoptions) and
                          not(tcallnode(p1).procdefinition.proctypeoption=potype_constructor) then
                          not(tcallnode(p1).procdefinition.proctypeoption=potype_constructor) then
@@ -2261,7 +2263,12 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.85  2002-10-04 21:13:59  peter
+  Revision 1.86  2002-10-05 00:48:57  peter
+    * support inherited; support for overload as it is handled by
+      delphi. This is only for delphi mode as it is working is
+      undocumented and hard to predict what is done
+
+  Revision 1.85  2002/10/04 21:13:59  peter
     * ignore vecn,subscriptn when checking for a procvar loadn
     * ignore vecn,subscriptn when checking for a procvar loadn
 
 
   Revision 1.84  2002/10/02 20:51:22  peter
   Revision 1.84  2002/10/02 20:51:22  peter