Browse Source

* Some work on notifications

daniel 22 years ago
parent
commit
038fec836e
3 changed files with 84 additions and 11 deletions
  1. 31 2
      compiler/nflw.pas
  2. 31 8
      compiler/nld.pas
  3. 22 1
      compiler/symsym.pas

+ 31 - 2
compiler/nflw.pas

@@ -45,7 +45,9 @@ interface
          { Do a test at the begin of the loop?}
          lnf_testatbegin,
          { Negate the loop test? }
-         lnf_checknegate);
+         lnf_checknegate,
+         { Should the value of the loop variable on exit be correct. }
+         lnf_dont_mind_loopvar_on_exit);
     const
          { loop flags which must match to consider loop nodes equal regarding the flags }
          loopflagsequal = [lnf_backward];
@@ -661,6 +663,16 @@ implementation
                                        symbol:Tsym);
 
     begin
+      {If there is a read access, the value of the loop counter is important;
+       at the end of the loop the loop variable should contain the value it
+       had in the last iteration.}
+      if not_type=vn_onwrite then
+        begin
+          include(loopflags,lnf_dont_mind_loopvar_on_exit);
+        writeln('Loopvar does not matter on exit');
+        end
+      else
+        writeln('Loopvar does matter on exit');
     end;
 {$endif}
 
@@ -742,17 +754,20 @@ implementation
          resulttypepass(right);
          set_varstate(right,true);
          inserttypeconv(right,t2.resulttype);
+(*
       {$ifdef var_notification}
          if (hp.nodetype=loadn) and (Tloadnode(hp).symtableentry.typ=varsym) then
             loopvar_notid:=Tvarsym(Tloadnode(hp).symtableentry).
              register_notification([vn_onread,vn_onwrite],@loop_var_access);
       {$endif}
+*)
       end;
 
 
     function tfornode.pass_1 : tnode;
       var
          old_t_times : longint;
+         hp : Tnode;
      begin
          result:=nil;
          { Calc register weight }
@@ -800,6 +815,17 @@ implementation
 
          rg.cleartempgen;
          firstpass(right);
+      {$ifdef var_notification}
+         { Check count var, record fields are also allowed in tp7 }
+         hp:=t2;
+         while (hp.nodetype=subscriptn) or
+               ((hp.nodetype=vecn) and
+                is_constintnode(tvecnode(hp).right)) do
+           hp:=tunarynode(hp).left;
+         if (hp.nodetype=loadn) and (Tloadnode(hp).symtableentry.typ=varsym) then
+            loopvar_notid:=Tvarsym(Tloadnode(hp).symtableentry).
+             register_notification([vn_onread,vn_onwrite],@loop_var_access);
+      {$endif}
          if right.registers32>registers32 then
            registers32:=right.registers32;
          if right.registersfpu>registersfpu then
@@ -1437,7 +1463,10 @@ begin
 end.
 {
   $Log$
-  Revision 1.58  2002-12-27 15:25:40  peter
+  Revision 1.59  2002-12-30 22:44:53  daniel
+  * Some work on notifications
+
+  Revision 1.58  2002/12/27 15:25:40  peter
     * do not allow threadvar as loop counter
 
   Revision 1.57  2002/11/28 11:17:02  florian

+ 31 - 8
compiler/nld.pas

@@ -158,6 +158,9 @@ implementation
       symtable,paramgr,defutil,defcmp,
       htypechk,pass_1,
       ncon,ninl,ncnv,nmem,ncal,cpubase,rgobj,cginfo,cgbase
+{$ifdef var_notification}
+      ,symnot
+{$endif}
       ;
 
 {*****************************************************************************
@@ -358,13 +361,23 @@ implementation
                    internalerror(22799);
               end;
             varsym :
-                begin
-                  { if it's refered by absolute then it's used }
-                  if nf_absolute in flags then
-                   tvarsym(symtableentry).varstate:=vs_used
-                  else
-                   resulttype:=tvarsym(symtableentry).vartype;
-                end;
+              begin
+                { if it's refered by absolute then it's used }
+                if nf_absolute in flags then
+                  tvarsym(symtableentry).varstate:=vs_used
+                else
+                  begin
+                    resulttype:=tvarsym(symtableentry).vartype;
+(*
+{$ifdef var_notification}                   
+                    if nf_write in flags then
+                      Tvarsym(symtableentry).trigger_notifications(vn_onwrite)
+                    else
+                      Tvarsym(symtableentry).trigger_notifications(vn_onread);
+{$endif}
+*)
+                  end;
+              end;
             typedconstsym :
                 if not(nf_absolute in flags) then
                   resulttype:=ttypedconstsym(symtableentry).typedconsttype;
@@ -422,6 +435,7 @@ implementation
 
     begin
       include(flags,nf_write);
+      writeln('Mark ',symtableentry.name);
     end;
 {$endif}
 
@@ -479,6 +493,12 @@ implementation
 
                    if ([vo_is_thread_var,vo_is_dll_var]*tvarsym(symtableentry).varoptions)<>[] then
                      registers32:=1;
+{$ifdef var_notification}                   
+                    if nf_write in flags then
+                      Tvarsym(symtableentry).trigger_notifications(vn_onwrite)
+                    else
+                      Tvarsym(symtableentry).trigger_notifications(vn_onread);
+{$endif}
                    { count variable references }
 
                      { this will create problem with local var set by
@@ -1278,7 +1298,10 @@ begin
 end.
 {
   $Log$
-  Revision 1.75  2002-12-27 15:27:25  peter
+  Revision 1.76  2002-12-30 22:44:53  daniel
+  * Some work on notifications
+
+  Revision 1.75  2002/12/27 15:27:25  peter
     * remove property indicator when calling internal helpers
 
   Revision 1.74  2002/12/24 16:53:19  peter

+ 22 - 1
compiler/symsym.pas

@@ -195,6 +195,7 @@ interface
           function  getsize : longint;
           function  getvaluesize : longint;
 {$ifdef var_notification}
+          procedure trigger_notifications(what:Tnotification_flag);
           function register_notification(flags:Tnotification_flags;
                                          callback:Tnotification_callback):cardinal;
 {$endif}
@@ -1713,6 +1714,23 @@ implementation
 
 
 {$ifdef var_notification}
+    procedure Tvarsym.trigger_notifications(what:Tnotification_flag);
+    
+    var p:Tnotification;
+    
+    begin
+        if assigned(notifications) then
+          begin
+            p:=Tnotification(notifications.first);
+            while assigned(p) do
+              begin
+                if what in p.flags then
+                  p.callback(what,self);
+                p:=Tnotification(p.next);
+              end;
+          end;
+    end;
+    
     function Tvarsym.register_notification(flags:Tnotification_flags;callback:
                                            Tnotification_callback):cardinal;
 
@@ -2520,7 +2538,10 @@ implementation
 end.
 {
   $Log$
-  Revision 1.85  2002-12-27 18:07:44  peter
+  Revision 1.86  2002-12-30 22:44:53  daniel
+  * Some work on notifications
+
+  Revision 1.85  2002/12/27 18:07:44  peter
     * fix crashes when searching symbols
 
   Revision 1.84  2002/12/20 16:02:22  peter