nstate.pas 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Daniel Mantione
  4. This unit contains support routines for the state tracker
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit nstate;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses cclasses,node;
  22. type Tstate_entry=class(Tlinkedlistitem)
  23. what:Tnode;
  24. value:Tnode;
  25. constructor create(w,v:Tnode);
  26. end;
  27. Tstate_storage=class
  28. storage:Tlinkedlist;
  29. constructor create;
  30. procedure store_fact(w,v:Tnode);
  31. function find_fact(what:Tnode):Tnode;
  32. procedure delete_fact(what:Tnode);
  33. end;
  34. var aktstate:Tstate_storage;
  35. implementation
  36. constructor Tstate_entry.create(w,v:Tnode);
  37. begin
  38. inherited create;
  39. what:=w;
  40. value:=v;
  41. end;
  42. constructor Tstate_storage.create;
  43. begin
  44. storage:=Tlinkedlist.create;
  45. end;
  46. procedure Tstate_storage.store_fact(w,v:Tnode);
  47. var se:Tstate_entry;
  48. begin
  49. { writeln('fact:');
  50. writenode(w);
  51. writeln('=');
  52. writenode(v);}
  53. se:=Tstate_entry(storage.first);
  54. while assigned(se) do
  55. begin
  56. if se.what.isequal(w) then
  57. begin
  58. storage.remove(se);
  59. se.destroy;
  60. break;
  61. end;
  62. se:=Tstate_entry(se.next);
  63. end;
  64. se:=Tstate_entry.create(w,v);
  65. storage.concat(se);
  66. end;
  67. function Tstate_storage.find_fact(what:Tnode):Tnode;
  68. var se:Tstate_entry;
  69. begin
  70. find_fact:=nil;
  71. se:=storage.first as Tstate_entry;
  72. while assigned(se) do
  73. begin
  74. if se.what.isequal(what) then
  75. begin
  76. find_fact:=se.value;
  77. break;
  78. end;
  79. se:=se.next as Tstate_entry;
  80. end;
  81. end;
  82. procedure Tstate_storage.delete_fact(what:Tnode);
  83. var se:Tstate_entry;
  84. begin
  85. se:=storage.first as Tstate_entry;
  86. while assigned(se) do
  87. begin
  88. if se.what.isequal(what) then
  89. begin
  90. storage.remove(se);
  91. se.destroy;
  92. break;
  93. end;
  94. se:=se.next as Tstate_entry;
  95. end;
  96. end;
  97. end.
  98. {
  99. $Log$
  100. Revision 1.3 2002-09-07 15:25:05 peter
  101. * old logs removed and tabs fixed
  102. Revision 1.2 2002/07/15 18:03:15 florian
  103. * readded removed changes
  104. Revision 1.1 2002/07/14 18:00:44 daniel
  105. + Added the beginning of a state tracker. This will track the values of
  106. variables through procedures and optimize things away.
  107. }