浏览代码

* 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,
       symconst,paramgr,defbase,
       htypechk,pass_1,cpuinfo,cpubase,
-      ncnv,nld,ninl,nadd,ncon,
+      nbas,ncnv,nld,ninl,nadd,ncon,
       rgobj,cgbase
       ;
 
@@ -1468,6 +1468,7 @@ implementation
 
       var
         i,j : longint;
+        has_overload_directive,
         found,
         is_const : boolean;
         bestord  : torddef;
@@ -1476,6 +1477,7 @@ implementation
       begin
          result:=nil;
          procs:=nil;
+         has_overload_directive:=false;
 
          oldcallprocdef:=aktcallprocdef;
          aktcallprocdef:=nil;
@@ -1565,13 +1567,17 @@ implementation
                             hp^.nextpara:=hp^.firstpara;
                             procs:=hp;
                          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
                      overloaded definitions in the symtablestack. The found
                      entries are only added to the procs list and not the procsym, because
                      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
                      begin
                        srsymtable:=symtableprocentry.owner.next;
@@ -1638,24 +1644,42 @@ implementation
                      with the parameter size }
                    if not assigned(procs) then
                     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
                         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;
                       goto errorexit;
                     end;
@@ -2604,7 +2628,12 @@ begin
 end.
 {
   $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
 
   Revision 1.100  2002/09/15 17:49:59  peter

+ 7 - 1
compiler/node.pas

@@ -222,6 +222,7 @@ interface
          { flags used by tcallnode }
          nf_return_value_used,
          nf_static_call,
+         nf_auto_inherited,
 
          { flags used by tcallparanode }
          nf_varargs_para,  { belongs this para to varargs }
@@ -978,7 +979,12 @@ implementation
 end.
 {
   $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
 
   Revision 1.42  2002/09/03 16:26:26  daniel

+ 8 - 1
compiler/pexpr.pas

@@ -650,6 +650,7 @@ implementation
                  end;
               end;
              p1:=ccallnode.create(para,tprocsym(sym),st,p1);
+             include(p1.flags,nf_auto_inherited);
            end
         else
            begin
@@ -914,6 +915,7 @@ implementation
                       do_resulttypepass(p1);
                       { now we know the real method e.g. we can check for a class method }
                       if isclassref and
+                         (p1.nodetype=calln) and
                          assigned(tcallnode(p1).procdefinition) and
                          not(po_classmethod in tcallnode(p1).procdefinition.procoptions) and
                          not(tcallnode(p1).procdefinition.proctypeoption=potype_constructor) then
@@ -2261,7 +2263,12 @@ implementation
 end.
 {
   $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
 
   Revision 1.84  2002/10/02 20:51:22  peter