home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / creation_clause.e < prev    next >
Text File  |  1999-06-05  |  5KB  |  184 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 CREATION_CLAUSE
  17.    --
  18.    -- The store the contents of one creation clause.
  19.    --   example 1
  20.    --                creation {ANY} make
  21.    --   example 2
  22.    --                creation make, foo
  23.    --   example 3
  24.    --                creation {NONE,ANY} make, foo
  25.    --   example 4
  26.    --                creation
  27.    --
  28.    -- Note : The original text of the source file can be stored
  29.    --        for pretty pretty_printing to be fine.
  30.    --
  31.  
  32. inherit GLOBALS;
  33.  
  34. creation make
  35.  
  36. feature
  37.  
  38.    start_position: POSITION;
  39.          -- Of the corresponding keyword.
  40.  
  41.    clients: CLIENT_LIST;
  42.  
  43.    comment: COMMENT;
  44.  
  45. feature {NONE}
  46.  
  47.    procedure_list: FEATURE_NAME_LIST;
  48.  
  49.    make(sp: like start_position; c: like clients;
  50.         cm: like comment; pl: like procedure_list) is
  51.       require
  52.          sp /= Void;
  53.          c /= Void;
  54.       do
  55.          start_position := sp;
  56.          clients := c;
  57.          comment := cm;
  58.          procedure_list := pl;
  59.       ensure
  60.          clients = c;
  61.          comment = cm
  62.          procedure_list = pl;
  63.       end;
  64.  
  65. feature
  66.  
  67.    pretty_print is
  68.       do
  69.          fmt.set_indent_level(0);
  70.          if not fmt.zen_mode then
  71.             fmt.skip(1);
  72.          else
  73.             fmt.indent;
  74.          end;
  75.          fmt.keyword("creation");
  76.          fmt.set_indent_level(1);
  77.          if clients /= Void then
  78.             clients.pretty_print;
  79.          end;
  80.          if comment /= void then
  81.             comment.pretty_print;
  82.          end;
  83.          fmt.set_indent_level(1);
  84.          if not fmt.zen_mode then
  85.             fmt.indent;
  86.          end;
  87.          if procedure_list /= Void then
  88.             procedure_list.pretty_print;
  89.          end;
  90.       end;
  91.  
  92.    short(heading_done: BOOLEAN): BOOLEAN is
  93.          -- True when at least one creation list is printed.
  94.       do
  95.          if clients.gives_permission_to_any then
  96.             if not heading_done then
  97.                short_print.hook_or("hook100","creation%N");
  98.             end;
  99.             if procedure_list /= Void then
  100.                procedure_list.short_for_creation;
  101.             end;
  102.             short_print.hook_or("hook101","");
  103.             Result := true;
  104.          else
  105.             eh.cancel;
  106.          end;
  107.       end;
  108.  
  109.    has(fn: FEATURE_NAME): BOOLEAN is
  110.       require
  111.          fn /= Void
  112.       do
  113.          if procedure_list /= Void then
  114.             Result := procedure_list.has(fn);
  115.          end;
  116.       end;
  117.  
  118. feature {CREATION_CLAUSE_LIST}
  119.  
  120.    root_procedure_name(procedure_name: STRING): SIMPLE_FEATURE_NAME is
  121.       do
  122.          if procedure_list = Void then
  123.          else
  124.             Result := procedure_list.root_procedure_name(procedure_name);
  125.          end;
  126.       end;
  127.  
  128.    check_expanded_with(t: TYPE) is
  129.       require
  130.          t.is_expanded;
  131.       local
  132.          rf: RUN_FEATURE;
  133.          rf3: RUN_FEATURE_3;
  134.          rc: RUN_CLASS;
  135.       do
  136.          if procedure_list = Void then
  137.             eh.add_position(start_position);
  138.             fatal_error("Cannot create a class with an empty creation list.");
  139.          end;
  140.          if procedure_list.count > 1 then
  141.             eh.add_type(t,fz_cbe);
  142.             eh.add_position(start_position);
  143.             fatal_error_vtec_2;
  144.          end;
  145.          rc := t.run_class;
  146.          rf := rc.get_feature(procedure_list.item(1));
  147.          if rf = Void then
  148.             eh.add_position(start_position);
  149.             eh.append("Creation procedure for ");
  150.             eh.add_type(t," not found.");
  151.             eh.print_as_fatal_error;
  152.          end;
  153.          rf3 ?= rf;
  154.          if rf3 = Void then
  155.             eh.add_position(start_position);
  156.             eh.add_position(rf.start_position);
  157.             fatal_error("Feature found is not a procedure.");
  158.          end;
  159.          if rf3.arguments /= Void then
  160.             eh.add_type(t,fz_cbe);
  161.             eh.add_position(start_position);
  162.             eh.add_position(rf3.start_position);
  163.             eh.append("Procedure found has arguments. ");
  164.             fatal_error_vtec_2;
  165.          end;
  166.       end;
  167.  
  168.    expanded_initializer(t: TYPE): RUN_FEATURE_3 is
  169.       require
  170.          t.is_expanded;
  171.          not t.is_basic_eiffel_expanded
  172.       do
  173.          if procedure_list /= Void then
  174.             Result ?= t.run_class.get_feature(procedure_list.item(1));
  175.          end;
  176.       end;
  177.  
  178. invariant
  179.  
  180.    clients /= Void;
  181.  
  182. end -- CREATION_CLAUSE
  183.  
  184.