home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / native_c.e < prev    next >
Text File  |  1999-06-05  |  4KB  |  138 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. deferred class NATIVE_C
  17.    --
  18.    -- Common root for NATIVE_WITHOUT_CURRENT, NATIVE_INLINE_WITHOUT_CURRENT,
  19.    -- NATIVE_WITH_CURRENT and NATIVE_INLINE_WITH_CURRENT.
  20.    --
  21.  
  22. inherit NATIVE;
  23.  
  24. feature
  25.  
  26.    need_prototype: BOOLEAN is
  27.       deferred
  28.       end;
  29.  
  30. feature
  31.  
  32.    frozen c_define_function(rf8: RUN_FEATURE_8; bcn, name: STRING) is
  33.       do
  34.          if need_prototype then
  35.             rf8.c_prototype;
  36.          end;
  37.          if run_control.no_check then
  38.             body.clear;
  39.             body.extend('R');
  40.             body.extend('=');
  41.             wrapped_external_call(rf8.base_feature,rf8.arg_count);
  42.             rf8.c_define_with_body(body);
  43.          end;
  44.       end;
  45.  
  46.    frozen c_mapping_function(rf8: RUN_FEATURE_8; bcn, name: STRING) is
  47.       do
  48.          if run_control.boost then
  49.             c_mapping_external(rf8.base_feature,rf8.arg_count);
  50.          else
  51.             rf8.default_mapping_function;
  52.          end;
  53.       end;
  54.  
  55.    frozen c_define_procedure(rf7: RUN_FEATURE_7; bcn, name: STRING) is
  56.       do
  57.          if need_prototype then
  58.             rf7.c_prototype;
  59.          end;
  60.          if run_control.no_check then
  61.             body.clear;
  62.             wrapped_external_call(rf7.base_feature,rf7.arg_count);
  63.             rf7.c_define_with_body(body);
  64.          end;
  65.       end;
  66.  
  67.    frozen c_mapping_procedure(rf7: RUN_FEATURE_7; bcn, name: STRING) is
  68.       do
  69.          if run_control.boost then
  70.             c_mapping_external(rf7.base_feature,rf7.arg_count);
  71.             cpp.put_string(fz_00);
  72.          else
  73.             rf7.default_mapping_procedure;
  74.          end;
  75.       end;
  76.  
  77. feature {NONE}
  78.  
  79.    c_mapping_external(er: EXTERNAL_ROUTINE; arg_count: INTEGER) is
  80.       local
  81.          eruc, tcbd: BOOLEAN;
  82.       do
  83.          eruc := use_current(er);
  84.          if not eruc then
  85.             tcbd := cpp.target_cannot_be_dropped;
  86.             if tcbd then
  87.                cpp.put_character(',');
  88.             end;
  89.          end;
  90.          cpp.put_string(er.external_c_name);
  91.          cpp.put_character('(');
  92.          if eruc then
  93.             cpp.put_target_as_value;
  94.          end;
  95.          if arg_count > 0 then
  96.             if eruc then
  97.                cpp.put_character(',');
  98.             end;
  99.             cpp.put_arguments;
  100.          end;
  101.          cpp.put_character(')');
  102.          if not eruc and then tcbd then
  103.             cpp.put_character(')');
  104.          end;
  105.       end;
  106.  
  107. feature {NONE}
  108.  
  109.    wrapped_external_call(er: EXTERNAL_ROUTINE; arg_count: INTEGER) is
  110.       local
  111.          i: INTEGER;
  112.       do
  113.          body.append(er.external_c_name);
  114.          body.extend('(');
  115.          if use_current(er) then
  116.             body.extend('C');
  117.             if arg_count > 0 then
  118.                body.extend(',');
  119.             end;
  120.          end;
  121.          from
  122.             i := 1;
  123.          until
  124.             i > arg_count
  125.          loop
  126.             body.extend('a');
  127.             i.append_in(body);
  128.             i := i + 1;
  129.             if i <= arg_count then
  130.                body.extend(',');
  131.             end;
  132.          end;
  133.          body.append(fz_14);
  134.       end;
  135.  
  136. end -- NATIVE_C
  137.  
  138.