home *** CD-ROM | disk | FTP | other *** search
/ Hacker / Hacker.iso / HACKER / DECOMP / DECAF / flags.adb < prev    next >
Encoding:
Text File  |  1996-09-19  |  5.8 KB  |  197 lines

  1. --
  2. -- Copyright (C) 1996 Ada Resource Association (ARA), Columbus, Ohio.
  3. -- Author: Gilles Demailly
  4. --
  5. --
  6. -- Permission to use, copy, modify, and distribute this software and its
  7. -- documentation for any purpose and without fee is hereby granted,
  8. -- provided that the above copyright and authorship notice appear in all
  9. -- copies and that both that copyright notice and this permission notice
  10. -- appear in supporting documentation.
  11. -- 
  12. -- The ARA makes no representations about the suitability of this software
  13. -- for any purpose.  It is provided "as is" without express
  14. -- or implied warranty.
  15. -- 
  16.  
  17. with Ada.Text_Io;
  18.  
  19. package body Flags is
  20.  
  21.    --
  22.    -- Category masks are used for flag correctness checking
  23.    --
  24.    
  25.    Class_Mask    : constant Unsigned_16 := 16#0611#;
  26.          
  27.    Method_Mask   : constant Unsigned_16 := 16#053F#;
  28.          
  29.    Variable_Mask : constant Unsigned_16 := 16#00DF#;
  30.  
  31.    -- 
  32.    -- Bit position of different flag values
  33.    --
  34.    
  35.    Public_Bit       : constant Natural := 15;
  36.    Private_Bit      : constant Natural := 14;
  37.    Protected_Bit    : constant Natural := 13;
  38.    Static_Bit       : constant Natural := 12;
  39.    Final_Bit        : constant Natural := 11;
  40.    Synchronized_Bit : constant Natural := 10;
  41.    Volatile_Bit     : constant Natural := 9;
  42.    Transient_Bit    : constant Natural := 8;
  43.    Native_Bit       : constant Natural := 7;
  44.    Interface_Bit    : constant Natural := 6;
  45.    Abstract_Bit     : constant Natural := 5;
  46.    
  47.    --
  48.    -- flag access functions
  49.    --
  50.    
  51.    function Is_Public       (Flag : Unsigned_16) return Boolean is
  52.    begin
  53.       return Bit_At (Flag, Public_Bit);
  54.    end Is_Public;
  55.  
  56.    function Is_Private      (Flag : Unsigned_16) return Boolean is
  57.    begin
  58.       return Bit_At (Flag, Private_Bit);
  59.    end Is_Private;
  60.  
  61.    function Is_Protected    (Flag : Unsigned_16) return Boolean is
  62.    begin
  63.       return Bit_At (Flag, Protected_Bit);
  64.    end Is_Protected;
  65.  
  66.    function Is_Static       (Flag : Unsigned_16) return Boolean is
  67.    begin
  68.       return Bit_At (Flag, Static_Bit);
  69.    end Is_Static;
  70.  
  71.    function Is_Final        (Flag : Unsigned_16) return Boolean is
  72.    begin
  73.       return Bit_At (Flag, Final_Bit);
  74.    end Is_Final;
  75.  
  76.    function Is_Synchronized (Flag : Unsigned_16) return Boolean is
  77.    begin
  78.       return Bit_At (Flag, Synchronized_Bit);
  79.    end Is_Synchronized;
  80.  
  81.    function Is_Volatile     (Flag : Unsigned_16) return Boolean is
  82.    begin
  83.       return Bit_At (Flag, Volatile_Bit);
  84.    end Is_Volatile;
  85.  
  86.    function Is_Transient    (Flag : Unsigned_16) return Boolean is
  87.    begin
  88.       return Bit_At (Flag, Transient_Bit);
  89.    end Is_Transient;
  90.  
  91.    function Is_Native       (Flag : Unsigned_16) return Boolean is
  92.    begin
  93.       return Bit_At (Flag, Native_Bit);
  94.    end Is_Native;
  95.  
  96.    function Is_Interface    (Flag : Unsigned_16) return Boolean is
  97.    begin
  98.       return Bit_At (Flag, Interface_Bit);
  99.    end Is_Interface;
  100.  
  101.    function Is_Abstract     (Flag : Unsigned_16) return Boolean is
  102.    begin
  103.       return Bit_At (Flag, Abstract_Bit);
  104.    end Is_Abstract;
  105.  
  106.  
  107.    -- This function is used for file checking.
  108.    -- it returns True if the Flag corresponds to the
  109.    -- flag category.
  110.    -------------------------------------------------
  111.    function Is_Correct (Flag     : Unsigned_16;
  112.                         Category : Flag_Category) return Boolean is
  113.    begin
  114.       case Category is
  115.          when Class_Flag    =>
  116.             return (Flag or Class_Mask) = Class_Mask;
  117.          when Method_Flag   =>
  118.             return (Flag or Method_Mask) = Method_Mask;
  119.          when Variable_Flag =>
  120.             return (Flag or Variable_Mask) = Variable_Mask;
  121.       end case;
  122.    end Is_Correct;
  123.  
  124.  
  125.    procedure Display (Flag     : Unsigned_16;
  126.                       Category : Flag_Category) is
  127.    begin
  128.       -- displays the name of each access right corresponding 
  129.       -- to the input Flag value
  130.       case Category is
  131.          when Class_Flag    =>
  132.             if Is_Public (Flag) then
  133.                Ada.Text_Io.Put ("public ");
  134.             end if;
  135.             if Is_Final (Flag) then
  136.                Ada.Text_Io.Put ("final ");
  137.             end if;
  138.             if Is_Interface (Flag) then
  139.                Ada.Text_Io.Put ("interface ");
  140.             end if;
  141.             if Is_Abstract (Flag) then
  142.                Ada.Text_Io.Put ("abstract ");
  143.             end if;
  144.          when Method_Flag   =>
  145.             if Is_Public (Flag) then
  146.                Ada.Text_Io.Put ("public ");
  147.             end if;
  148.             if Is_Private (Flag) then
  149.                Ada.Text_Io.Put ("private ");
  150.             end if;
  151.             if Is_Protected (Flag) then
  152.                Ada.Text_Io.Put ("protected ");
  153.             end if;
  154.             if Is_Static (Flag) then
  155.                Ada.Text_Io.Put ("static ");
  156.             end if;
  157.             if Is_Final (Flag) then
  158.                Ada.Text_Io.Put ("final ");
  159.             end if;
  160.             if Is_Synchronized (Flag) then
  161.                Ada.Text_Io.Put ("synchronized ");
  162.             end if;
  163.             if Is_Native (Flag) then
  164.                Ada.Text_Io.Put ("native ");
  165.             end if;
  166.             if Is_Abstract (Flag) then
  167.                Ada.Text_Io.Put ("abstract ");
  168.             end if;
  169.          when Variable_Flag =>
  170.             if Is_Public (Flag) then
  171.                Ada.Text_Io.Put ("public ");
  172.             end if;
  173.             if Is_Private (Flag) then
  174.                Ada.Text_Io.Put ("private ");
  175.             end if;
  176.             if Is_Protected (Flag) then
  177.                Ada.Text_Io.Put ("protected ");
  178.             end if;
  179.             if Is_Static (Flag) then
  180.                Ada.Text_Io.Put ("static ");
  181.             end if;
  182.             if Is_Final (Flag) then
  183.                Ada.Text_Io.Put ("final ");
  184.             end if;
  185.             if Is_Volatile (Flag) then
  186.                Ada.Text_Io.Put ("volatile ");
  187.             end if;
  188.             if Is_Transient (Flag) then
  189.                Ada.Text_Io.Put ("transient ");
  190.             end if;
  191.       end case;
  192.    end Display;
  193.  
  194.  
  195.    
  196. end Flags;
  197.