home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / manifest_array_pool.e < prev    next >
Text File  |  1999-06-05  |  5KB  |  174 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 MANIFEST_ARRAY_POOL
  17.    --
  18.    -- Unique global object in charge of MANIFEST_ARRAY used.
  19.    --
  20.  
  21. inherit GLOBALS;
  22.  
  23. feature {NONE}
  24.  
  25.    manifest_array_types: DICTIONARY[TYPE,INTEGER] is
  26.          -- Gives the type for all kind of used MANIFEST_ARRAY.
  27.       once
  28.          !!Result.make;
  29.       end;
  30.  
  31.    as_se_ma: STRING is "se_ma";
  32.  
  33. feature {MANIFEST_ARRAY,E_STRIP}
  34.  
  35.    register(ma_type: TYPE) is
  36.       require
  37.          ma_type /= Void
  38.       local
  39.          id: INTEGER;
  40.       do
  41.          id := ma_type.id;
  42.          if not manifest_array_types.has(id) then
  43.             manifest_array_types.put(ma_type,id);
  44.          end;
  45.       end;
  46.  
  47.    c_call(ma_type: TYPE) is
  48.       require
  49.          small_eiffel.is_ready
  50.       local
  51.          id: INTEGER;
  52.       do
  53.          id := ma_type.id;
  54.          cpp.put_string(as_se_ma);
  55.          cpp.put_integer(id);
  56.       end;
  57.  
  58. feature {SMALL_EIFFEL}
  59.  
  60.    c_define is
  61.       require
  62.          small_eiffel.is_ready
  63.       local
  64.          i: INTEGER;
  65.       do
  66.          from
  67.             i := 1;
  68.          until
  69.             i > manifest_array_types.count
  70.          loop
  71.             c_define_for(manifest_array_types.item(i));
  72.             i := i + 1;
  73.          end;
  74.       end;
  75.  
  76. feature {NONE}
  77.  
  78.    c_define_for(ma_type: TYPE) is
  79.       local
  80.          ma_id, elt_id: INTEGER;
  81.          elt_type: TYPE;
  82.          rf: RUN_FEATURE;
  83.       do
  84.          ma_id := ma_type.id;
  85.          elt_type := ma_type.generic_list.item(1).run_type;
  86.          elt_id := elt_type.id;
  87.          -- Prepare header :
  88.          header.copy(fz_void);
  89.          header.extend('*');
  90.          header.append(as_se_ma);
  91.          ma_id.append_in(header);
  92.          header.append("(int argc,...)");
  93.          -- Prepare body :
  94.          body.clear;
  95.          body.extend('T');
  96.          ma_id.append_in(body);
  97.          body.append("*m;%N%
  98.                      %va_list pa;%N");
  99.          if elt_type.is_reference then
  100.             body.append(fz_t0_star);
  101.          else
  102.             body.extend('T');
  103.             elt_id.append_in(body);
  104.          end;
  105.          body.append("*s;%N%
  106.                      %m=");
  107.          if gc_handler.is_off then
  108.             body.append(
  109.                "malloc(sizeof(*m));%N%
  110.                %*m=M");
  111.             ma_id.append_in(body);
  112.             body.append(
  113.                ";%N%
  114.                %if(argc){%N%
  115.                %s=malloc(argc*sizeof(*s));%N");
  116.          else
  117.             body.append(fz_new);
  118.             ma_id.append_in(body);
  119.             body.append(
  120.                "();%N%
  121.                %if(argc){%N%
  122.                %s=((void*)new");
  123.             rf := ma_type.run_class.get_feature_with(as_storage);
  124.             rf.result_type.id.append_in(body);
  125.             body.append("(argc));%N");
  126.          end;
  127.          body.append(
  128.            "m->_storage=s;%N%
  129.            %m->_capacity=argc;%N%
  130.            %m->_lower=1;%N%
  131.            %m->_upper=argc;%N%
  132.            %va_start(pa,argc);%N%
  133.            %while(argc--){%N");
  134.          if (elt_type.is_integer or else
  135.              elt_type.is_boolean or else
  136.              elt_type.is_character)
  137.           then
  138.                body.append("*(s++)=va_arg(pa,int);%N");
  139.          elseif elt_type.is_real or else elt_type.is_double then
  140.                body.append("*(s++)=va_arg(pa,double);%N");
  141.          elseif elt_type.is_user_expanded then
  142.             body.append(
  143.              "memcpy(s++,va_arg(pa,char*),sizeof(*s));%N");
  144.          else
  145.             body.append("*(s++)=((void*)(va_arg(pa,char*)));%N");
  146.          end;
  147.          body.append("}%N%
  148.                      %va_end(pa);%N}%N%
  149.                      %else{%N%
  150.                      %m->_storage=NULL;%N%
  151.                      %m->_capacity=0;%N%
  152.                      %m->_lower=1;%N%
  153.                      %m->_upper=0;%N%
  154.                      %}%N%
  155.                      %return m;%N");
  156.          --
  157.          cpp.put_c_function(header,body);
  158.       end;
  159.  
  160. feature {NONE}
  161.  
  162.    header: STRING is
  163.       once
  164.          !!Result.make(64);
  165.       end;
  166.  
  167.    body: STRING is
  168.       once
  169.          !!Result.make(1024);
  170.       end;
  171.  
  172. end -- MANIFEST_ARRAY_POOL
  173.  
  174.