home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / cecil_pool.e < prev    next >
Text File  |  1999-06-05  |  7KB  |  227 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 CECIL_POOL
  17.    --
  18.    -- Unique global object in charge of CECIL calls.
  19.    --
  20.  
  21. inherit GLOBALS;
  22.  
  23. feature {NONE}
  24.  
  25.    -- User's entry points from cecil file :
  26.    user_cecil_list: FIXED_ARRAY[RUN_FEATURE];
  27.    user_cecil_name: FIXED_ARRAY[STRING];
  28.  
  29.    user_path_h: STRING;
  30.  
  31. feature {SMALL_EIFFEL}
  32.  
  33.    fill_up is
  34.       local
  35.          t: TYPE;
  36.          rta: FIXED_ARRAY[TYPE];
  37.          fna: FIXED_ARRAY[FEATURE_NAME];
  38.          fn: FEATURE_NAME;
  39.          rf: RUN_FEATURE;
  40.          i: INTEGER;
  41.          rc: RUN_CLASS;
  42.       do
  43.          -- For the user :
  44.          if run_control.cecil_path /= Void then
  45.             !!user_cecil_list.with_capacity(4);
  46.             !!user_cecil_name.with_capacity(4);
  47.             user_path_h := eiffel_parser.connect_to_cecil;
  48.             from
  49.                !!rta.with_capacity(4);
  50.                !!fna.with_capacity(4);
  51.             until
  52.                eiffel_parser.end_of_input
  53.             loop
  54.                user_cecil_name.add_last(eiffel_parser.parse_c_name);
  55.                rta.add_last(eiffel_parser.parse_run_type);
  56.                check
  57.                   nb_errors = 0
  58.                end;
  59.                fna.add_last(eiffel_parser.parse_feature_name);
  60.                check
  61.                   nb_errors = 0
  62.                end;
  63.             end;
  64.             eiffel_parser.disconnect;
  65.             echo.put_string("Loading cecil features.%N");
  66.             from
  67.                i := 0;
  68.             until
  69.                i > rta.upper
  70.             loop
  71.                t := rta.item(i).to_runnable(type_any);
  72.                fn := fna.item(i);
  73.                rc := t.run_class;
  74.                rf := rc.get_feature(fn);
  75.                if rf = Void then
  76.                   eh.add_position(fn.start_position);
  77.                   fatal_error("Error while loading feature of cecil file.");
  78.                end;
  79.                if rf.is_deferred then
  80.                elseif rc.running = Void then
  81.                   rc.set_at_run_time;
  82.                end;
  83.                user_cecil_list.add_last(rf);
  84.                switch_collection.update_with(rf);
  85.                i := i + 1;
  86.             end;
  87.          end;
  88.       end;
  89.  
  90. feature {C_PRETTY_PRINTER}
  91.  
  92.    c_define_users is
  93.       do
  94.          if user_cecil_list /= Void then
  95.             echo.put_string("Cecil (for user) :%N");
  96.             cpp.connect_cecil_out_h(user_path_h);
  97.             c_define_for_list(user_cecil_list,user_cecil_name);
  98.             cpp.disconnect_cecil_out_h;
  99.          end;
  100.       end;
  101.  
  102. feature {NONE}
  103.  
  104.    c_define_for_list(cecil_list: FIXED_ARRAY[RUN_FEATURE];
  105.                      cecil_name: FIXED_ARRAY[STRING]) is
  106.       require
  107.          cecil_name.count = cecil_list.count
  108.       local
  109.          i: INTEGER;
  110.       do
  111.          from
  112.             i := cecil_list.upper;
  113.          until
  114.             i < 0
  115.          loop
  116.             c_define_for(cecil_name.item(i),cecil_list.item(i));
  117.             i := i - 1;
  118.          end;
  119.       end;
  120.  
  121. feature {NONE}
  122.  
  123.    c_define_for(c_name: STRING; rf: RUN_FEATURE) is
  124.       require
  125.          not c_name.empty;
  126.          rf /= Void
  127.       local
  128.          rfct, rfrt: TYPE;
  129.          rfargs: FORMAL_ARG_LIST;
  130.       do
  131.          rfct := rf.current_type;
  132.          rfrt := rf.result_type;
  133.          rfargs := rf.arguments;
  134.          echo.put_string(rfct.run_time_mark);
  135.          echo.put_character('.');
  136.          echo.put_string(rf.name.to_string);
  137.          echo.put_character('%N');
  138.          -- (1) ------------------------- Define Cecil heading :
  139.          tmp_string.clear;
  140.          if rfrt /= Void then
  141.             rfrt.c_type_for_external_in(tmp_string);
  142.          else
  143.             tmp_string.append(fz_void);
  144.          end;
  145.          tmp_string.extend(' ');
  146.          tmp_string.append(c_name);
  147.          tmp_string.extend('(');
  148.          rfct.c_type_for_external_in(tmp_string);
  149.          tmp_string.extend(' ');
  150.          tmp_string.extend('C');
  151.          if rfargs /= Void then
  152.             tmp_string.extend(',');
  153.             rfargs.external_prototype_in(tmp_string);
  154.          end;
  155.          tmp_string.extend(')');
  156.          cpp.put_c_heading(tmp_string);
  157.          cpp.swap_on_c;
  158.          define_body_of(rf);
  159.       end;
  160.  
  161. feature {RUN_FEATURE}
  162.  
  163.    define_body_of(rf: RUN_FEATURE) is
  164.       local
  165.          rfct, rfrt: TYPE;
  166.          cecil_target: CECIL_TARGET;
  167.          cecil_arg_list: CECIL_ARG_LIST;
  168.          running: ARRAY[RUN_CLASS];
  169.       do
  170.          rfct := rf.current_type;
  171.          rfrt := rf.result_type;
  172.          running := rfct.run_class.running;
  173.          if running = Void then
  174.             eh.add_type(rfct," not created (type is not alive).");
  175.             eh.append(" Empty Cecil/Wrapper function ");
  176.             eh.append(rfct.run_time_mark);
  177.             eh.append(rf.name.to_key);
  178.             eh.extend('.');
  179.             eh.print_as_warning;
  180.          else
  181.             if run_control.no_check then
  182.                cpp.put_string(
  183.                "se_dump_stack ds={NULL,NULL,0,0,0,NULL,NULL};%N%
  184.                %ds.caller=se_dst;%N%
  185.                %se_dst=&ds;%N");
  186.             end;
  187.             if rfrt /= Void then
  188.                tmp_string.clear;
  189.                tmp_string.extend('{');
  190.                rfrt.c_type_for_external_in(tmp_string);
  191.                tmp_string.append(" R=");
  192.                cpp.put_string(tmp_string);
  193.             end;
  194.             !!cecil_target.make(rf);
  195.             if rf.arguments /= Void then
  196.                !!cecil_arg_list.run_feature(rf);
  197.             end;
  198.             if rfct.is_expanded then
  199.                cpp.push_direct(rf,cecil_target,cecil_arg_list);
  200.                rf.mapping_c;
  201.                cpp.pop;
  202.             else
  203.                cpp.push_cpc(rf,running,cecil_target,cecil_arg_list);
  204.             end;
  205.             if rfrt /= Void then
  206.                cpp.put_string(fz_00);
  207.             end;
  208.             if run_control.no_check then
  209.                cpp.put_string("se_dst=ds.caller;%N");
  210.             end;
  211.             if rfrt /= Void then
  212.                cpp.put_string("return R;%N}%N");
  213.             end;
  214.          end;
  215.          cpp.put_string(fz_12);
  216.       end;
  217.  
  218. feature {NONE}
  219.  
  220.    tmp_string: STRING is
  221.       once
  222.          !!Result.make(256);
  223.       end;
  224.  
  225. end -- CECIL_POOL
  226.  
  227.