home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / bit_constant.e < prev    next >
Text File  |  1999-06-05  |  6KB  |  284 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr
  4. --                       http://SmallEiffel.loria.fr
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License
  11. -- for  more  details.  You  should  have  received a copy of the GNU General
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class BIT_CONSTANT
  17.    --
  18.    -- For Manifest Constant BIT_N.
  19.    --
  20.  
  21. inherit EXPRESSION;
  22.  
  23. creation {EIFFEL_PARSER} make
  24.  
  25. feature
  26.  
  27.    start_position: POSITION;
  28.          -- Of the first bit.
  29.  
  30.    value: STRING;
  31.          -- Only '0' and '1'.
  32.  
  33.    result_type: TYPE_BIT_1;
  34.  
  35. feature {NONE}
  36.  
  37.    id: INTEGER;
  38.  
  39.    hexa: STRING;
  40.  
  41. feature
  42.  
  43.    is_writable: BOOLEAN is false;
  44.  
  45.    is_current: BOOLEAN is false;
  46.  
  47.    is_manifest_string: BOOLEAN is false;
  48.  
  49.    is_result: BOOLEAN is false;
  50.  
  51.    is_void: BOOLEAN is false;
  52.  
  53.    use_current: BOOLEAN is false;
  54.  
  55.    is_static: BOOLEAN is false;
  56.  
  57.    is_pre_computable: BOOLEAN is false;
  58.  
  59.    can_be_dropped: BOOLEAN is true;
  60.  
  61.    c_simple: BOOLEAN is true;
  62.  
  63. feature {NONE}
  64.  
  65.    make(sp: like start_position; s: STRING) is
  66.       require
  67.          s /= Void
  68.          -- `s' contains only '0' and '1'.
  69.       do
  70.          start_position := sp;
  71.          value := s;
  72.       ensure
  73.          value.count = s.count
  74.       end;
  75.  
  76. feature
  77.  
  78.    static_result_base_class: BASE_CLASS is
  79.       do
  80.          Result := small_eiffel.get_class(as_bit_n);
  81.       end;
  82.  
  83.    assertion_check(tag: CHARACTER) is
  84.       do
  85.       end;
  86.  
  87.    static_value: INTEGER is
  88.       do
  89.       end;
  90.  
  91.    isa_dca_inline_argument: INTEGER is
  92.       do
  93.       end;
  94.  
  95.    dca_inline_argument(formal_arg_type: TYPE) is
  96.       do
  97.       end;
  98.  
  99.    afd_check is
  100.       do
  101.       end;
  102.  
  103.    mapping_c_target(target_type: TYPE) is
  104.       do
  105.          mapping_c_arg(target_type);
  106.       end;
  107.  
  108.    mapping_c_arg(formal_arg_type: TYPE) is
  109.       do
  110.          compile_to_c;
  111.       end;
  112.  
  113.    collect_c_tmp is
  114.       do
  115.       end;
  116.  
  117.    compile_to_c is
  118.       do
  119.          if result_type.is_c_unsigned_ptr then
  120.             cpp.register_bit_constant(Current);
  121.          else
  122.             cpp.put_string(fz_0x);
  123.             cpp.put_string(hexa);
  124.          end;
  125.       end;
  126.  
  127.    c_declare_for_old is
  128.       do
  129.       end;
  130.  
  131.    compile_to_c_old is
  132.       do
  133.       end;
  134.  
  135.    compile_to_jvm_old is
  136.       do
  137.       end;
  138.  
  139.    compile_target_to_jvm, compile_to_jvm is
  140.       local
  141.          i, idx: INTEGER;
  142.          ca: like code_attribute;
  143.          cp: like constant_pool;
  144.       do
  145.          ca := code_attribute;
  146.          cp := constant_pool;
  147.          idx := cp.idx_class2(fz_a0);
  148.          ca.opcode_new(idx);
  149.          ca.opcode_dup;
  150.          ca.opcode_push_integer(value.count);
  151.          idx := cp.idx_methodref3(fz_a0,fz_35,fz_27);
  152.          ca.opcode_invokespecial(idx,0);
  153.          from
  154.             i := value.count;
  155.          until
  156.             i = 0
  157.          loop
  158.             if value.item(i) = '1' then
  159.                ca.opcode_dup;
  160.                ca.opcode_push_integer(i - 1);
  161.                idx := cp.idx_methodref3(fz_a0,fz_a4,fz_27);
  162.                ca.opcode_invokevirtual(idx,-2);
  163.             end;
  164.             i := i - 1;
  165.          end;
  166.       end;
  167.  
  168.    jvm_branch_if_false: INTEGER is
  169.       do
  170.       end;
  171.  
  172.    jvm_branch_if_true: INTEGER is
  173.       do
  174.       end;
  175.  
  176.    compile_to_jvm_into(dest: TYPE): INTEGER is
  177.       do
  178.          Result := standard_compile_to_jvm_into(dest);
  179.       end;
  180.  
  181.    jvm_assign is
  182.       do
  183.       end;
  184.  
  185.    to_runnable(ct: TYPE): like Current is
  186.       local
  187.          ic: INTEGER_CONSTANT;
  188.       do
  189.          if result_type = Void then
  190.             !!ic.make(value.count,start_position);
  191.             !!result_type.make(start_position,ic);
  192.             result_type.run_class.set_at_run_time;
  193.             hexa := value.twin;
  194.             hexa.to_hexadecimal;
  195.          end;
  196.          Result := Current;
  197.       end;
  198.  
  199.    precedence: INTEGER is
  200.       do
  201.          Result := atomic_precedence;
  202.       end;
  203.  
  204.    bracketed_pretty_print, pretty_print is
  205.       do
  206.          fmt.put_string(value);
  207.          fmt.put_character('B');
  208.       end;
  209.  
  210.    print_as_target is
  211.       do
  212.          fmt.put_character('(');
  213.          pretty_print;
  214.          fmt.put_character(')');
  215.          fmt.put_character('.');
  216.       end;
  217.  
  218.    short is
  219.       local
  220.          i: INTEGER;
  221.       do
  222.          from
  223.             i := 1;
  224.          until
  225.             i > value.count
  226.          loop
  227.             short_print.a_character(value.item(i));
  228.             i := i + 1;
  229.          end;
  230.          short_print.a_character('B');
  231.       end;
  232.  
  233.    short_target is
  234.       do
  235.          bracketed_short;
  236.          short_print.a_dot;
  237.       end;
  238.  
  239. feature {C_PRETTY_PRINTER}
  240.  
  241.    c_define is
  242.       local
  243.          i, k, digit_nb: INTEGER;
  244.  
  245.       do
  246.          digit_nb := (1).object_size * 2;
  247.          k := hexa.count \\ digit_nb;
  248.          i := 1;
  249.          if k > 0 then
  250.             from
  251.                cpp.put_string(fz_0x);
  252.             until
  253.                k = 0
  254.             loop
  255.                cpp.put_character(hexa.item(i));
  256.                i := i + 1;
  257.                k := k - 1;
  258.             end;
  259.             cpp.put_character(',');
  260.          end;
  261.          from
  262.          until
  263.             i > hexa.count
  264.          loop
  265.             cpp.put_string(fz_0x);
  266.             from
  267.                k := digit_nb;
  268.             until
  269.                k = 0
  270.             loop
  271.                cpp.put_character(hexa.item(i));
  272.                i := i + 1;
  273.                k := k - 1;
  274.             end;
  275.             if i <= hexa.count then
  276.                cpp.put_character(',');
  277.             end;
  278.          end;
  279.       end;
  280.  
  281. end -- BIT_CONSTANT
  282.  
  283.  
  284.