home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 February / Chip_2000-02_cd.bin / zkuste / Delphi / navody / tt / objvm.exe / UNITS / CodeGenStack.pas < prev    next >
Pascal/Delphi Source File  |  1998-03-10  |  2KB  |  65 lines

  1. unit CodeGenStack;
  2.  
  3. interface
  4. uses
  5.      Classes,ObjCodeGeneration,Code;
  6. type TCodeGenStack=class
  7.      protected
  8.        fItems:TList;
  9.      public
  10.        constructor Create;
  11.        function Count:integer;
  12.        destructor  Destroy;override;
  13.        function Top:TObjCodeGeneration;
  14.        function Second:TObjCodeGeneration;
  15.        procedure Push(a:TObjCodeGeneration);
  16.        procedure PopDef;
  17.        procedure Pop;
  18.        procedure RemoveTop;
  19.      end;
  20. implementation
  21. constructor TCodeGenStack.Create;
  22.             begin
  23.               Inherited Create;
  24.               fItems:=TList.Create;
  25.             end;
  26. function    TCodeGenStack.Count;
  27.             begin
  28.               result:=fItems.Count;
  29.             end;
  30. destructor  TCodeGenStack.Destroy;
  31.             Var i:Integer;
  32.             begin
  33.               fItems.Free;
  34.               Inherited Destroy;
  35.             end;
  36. function    TCodeGenStack.Top;
  37.             begin
  38.               Result:=fItems[Count-1];
  39.             end;
  40. function    TCodeGenStack.Second;
  41.             begin
  42.               Result:=fItems[Count-2];
  43.             end;
  44. procedure   TCodeGenStack.Push;
  45.             begin
  46.               fItems.Add(a);
  47.             end;
  48. procedure   TCodeGenStack.PopDef;
  49.             begin
  50.               Second.cGen(Top);
  51.               Pop;
  52.             end;
  53. procedure   TCodeGenStack.Pop;
  54.             begin
  55.               Top.Code.Free;
  56.               Top.Free;
  57.               RemoveTop;
  58.             end;
  59. procedure   TCodeGenStack.RemoveTop;
  60.             begin
  61.               fItems.Delete(Count-1);
  62.             end;
  63.  
  64. end.
  65.