home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / tmp_feature.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  7.7 KB  |  311 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://www.loria.fr/SmallEiffel
  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 TMP_FEATURE
  17. --
  18. -- Temporary object used during syntax analysis.
  19. -- At the end, the good effective E_FEATURE is choose.
  20. --   
  21.  
  22. inherit GLOBALS;
  23.    
  24. feature {EIFFEL_PARSER,TMP_NAME}
  25.    
  26.    arguments: FORMAL_ARG_LIST;
  27.    type: TYPE;
  28.    header_comment: COMMENT;
  29.    obsolete_mark: MANIFEST_STRING;
  30.    require_assertion: E_REQUIRE;
  31.    local_vars: LOCAL_VAR_LIST;
  32.    routine_body: COMPOUND;
  33.             
  34. feature {EIFFEL_PARSER}
  35.    
  36.    names: ARRAY[FEATURE_NAME] is
  37.       once
  38.      !!Result.make(1,5);
  39.       end;
  40.    
  41.    initialize is
  42.       do
  43.      names.clear; 
  44.      arguments := Void;
  45.      type := Void;
  46.      header_comment := Void;
  47.      obsolete_mark := Void;
  48.          require_assertion := Void;
  49.      local_vars := Void;
  50.      routine_body := Void;
  51.       end;
  52.       
  53.    add_synonym(a_name: FEATURE_NAME) is
  54.       require
  55.      a_name /= Void
  56.       do
  57.      names.add_last(a_name);
  58.       end;
  59.    
  60.    set_arguments(args: like arguments) is
  61.       require
  62.      args /= Void
  63.       do
  64.      arguments:= args;
  65.       end;
  66.    
  67.    set_type(t: like type) is
  68.       require
  69.      t /= Void
  70.       do
  71.      type := t;
  72.       ensure
  73.      type = t;
  74.       end;
  75.    
  76.    set_header_comment(hc: like header_comment) is
  77.       do
  78.      header_comment := hc;
  79.       end;
  80.    
  81.    set_obsolete_mark(om: like obsolete_mark) is
  82.       do
  83.      obsolete_mark := om;
  84.       end;
  85.    
  86.    set_local_vars(lv: like local_vars) is
  87.       do
  88.      local_vars := lv;
  89.       end;
  90.    
  91.    set_require(sp: POSITION; hc: COMMENT; al: ARRAY[ASSERTION]) is
  92.       do
  93.      if hc /= Void or else al /= Void then
  94.         !!require_assertion.make(sp,hc,al);
  95.      end;
  96.       end; 
  97.    
  98.    set_require_else(sp: POSITION; hc: COMMENT; al: ARRAY[ASSERTION]) is
  99.       do
  100.      if hc /= Void or else al /= Void then
  101.         !!require_assertion.make(sp,hc,al);
  102.         require_assertion.set_require_else;
  103.      end;
  104.       end; 
  105.    
  106.    set_routine_body(rb: like routine_body) is
  107.       do
  108.      routine_body := rb;
  109.       end;
  110.    
  111.    to_writable_attribute: WRITABLE_ATTRIBUTE is
  112.       do
  113.      if type = Void then
  114.         error(names.first.start_position,
  115.           "Bad feature definition.");
  116.      elseif arguments /= Void then
  117.         error(eiffel_parser.current_position,
  118.            "Attribute must not have formal arguments.");
  119.      end;
  120.      !!Result.make(n,type);
  121.       end;
  122.    
  123.    to_cst_att_boolean(value: BOOLEAN_CONSTANT): CST_ATT_BOOLEAN is
  124.       do
  125.      if type /= Void and then type.is_boolean then
  126.         !!Result.make(n,type,value);
  127.      else
  128.         error(names.first.start_position,
  129.           "The type of this constant feature should be BOOLEAN.");
  130.      end;
  131.       end;
  132.          
  133.    to_cst_att_bit(value: BIT_CONSTANT): CST_ATT_BIT is
  134.       do
  135.      if type /= Void and then type.is_bit then
  136.         !!Result.make(n,type,value);
  137.      else
  138.         error(names.first.start_position,
  139.           "The type of this constant feature should be BIT.");
  140.      end;
  141.       end;
  142.          
  143.    to_cst_att_character(value: CHARACTER_CONSTANT): CST_ATT_CHARACTER is
  144.       do
  145.      if type /= Void and then type.is_character then
  146.         !!Result.make(n,type,value);
  147.      else
  148.         error(names.first.start_position,
  149.           "The type of this constant feature should be CHARACTER.");
  150.      end;
  151.       end;
  152.          
  153.    to_cst_att_integer(value: INTEGER_CONSTANT): CST_ATT is
  154.       do
  155.      if type /= Void then
  156.         if type.is_integer then
  157.            !CST_ATT_INTEGER!Result.make(n,type,value);
  158.         elseif type.is_real then
  159.            !CST_ATT_REAL!Result.make(n,type,value.to_real_constant);
  160.         elseif type.is_double then
  161.            !CST_ATT_DOUBLE!Result.make(n,type,value.to_real_constant);
  162.         else
  163.            error(names.first.start_position,
  164.               "The type of this constant feature should be INTEGER %
  165.                % or REAL.");
  166.         end;
  167.      else
  168.         error(names.first.start_position,
  169.            "This constant feature should have a result type (INTEGER).");
  170.      end;
  171.       end;
  172.          
  173.    to_cst_att_real(value: REAL_CONSTANT): CST_ATT is
  174.       do
  175.      if type /= Void then
  176.         if type.is_real then
  177.            !CST_ATT_REAL!Result.make(n,type,value);
  178.         elseif type.is_double then
  179.            !CST_ATT_DOUBLE!Result.make(n,type,value);
  180.         else
  181.            eh.add_position(value.start_position);
  182.            eh.add_position(names.first.start_position);
  183.            fatal_error("The type of this constant feature should be REAL.");
  184.         end;
  185.      else
  186.         error(names.first.start_position,
  187.           "This constant feature should have a result type (REAL).");
  188.      end;
  189.       end;
  190.          
  191.    to_cst_att_string(value: MANIFEST_STRING): CST_ATT_STRING is
  192.       do
  193.      if type /= Void and then type.is_string then
  194.         !!Result.make(n,type,value);
  195.      else
  196.         error(names.first.start_position,
  197.           "The type of this constant feature should be STRING.");
  198.      end;
  199.       end;
  200.          
  201.    to_deferred_routine: DEFERRED_ROUTINE is
  202.       do
  203.      if type = Void then
  204.         !DEFERRED_PROCEDURE!Result.make(n,
  205.                         arguments,
  206.                         obsolete_mark,
  207.                         header_comment,
  208.                         require_assertion);
  209.      else
  210.         !DEFERRED_FUNCTION!Result.make(n,
  211.                        arguments,
  212.                        type,
  213.                        obsolete_mark,
  214.                        header_comment,
  215.                        require_assertion);
  216.      end;
  217.       end;
  218.    
  219.    to_external_routine(lgg: NATIVE; external_name: STRING): 
  220.       EXTERNAL_ROUTINE is
  221.       do
  222.      if type = Void then
  223.         !EXTERNAL_PROCEDURE!Result.make(n,
  224.                         arguments,
  225.                         obsolete_mark,
  226.                         header_comment,
  227.                         require_assertion,
  228.                         lgg,
  229.                         external_name);
  230.      else
  231.         !EXTERNAL_FUNCTION!Result.make(n,
  232.                        arguments,
  233.                        type, 
  234.                        obsolete_mark,
  235.                        header_comment,
  236.                        require_assertion,
  237.                        lgg,external_name);
  238.      end;
  239.       end;
  240.       
  241.    to_once_routine: ONCE_ROUTINE is
  242.       do
  243.      if type = Void then
  244.         !ONCE_PROCEDURE!Result.make(n,
  245.                     arguments,
  246.                     obsolete_mark,
  247.                     header_comment,
  248.                     require_assertion,
  249.                     local_vars,
  250.                     routine_body);
  251.      else
  252.         !ONCE_FUNCTION!Result.make(n,
  253.                        arguments,
  254.                        type,
  255.                        obsolete_mark,
  256.                        header_comment,
  257.                        require_assertion,
  258.                        local_vars,
  259.                        routine_body);
  260.      end;
  261.       end;
  262.          
  263.    to_procedure_or_function: EFFECTIVE_ROUTINE is
  264.       do
  265.      if type = Void then
  266.         !PROCEDURE!Result.make(n, 
  267.                    arguments, 
  268.                    obsolete_mark,
  269.                    header_comment, 
  270.                    require_assertion,
  271.                    local_vars, 
  272.                    routine_body);
  273.      else
  274.         !FUNCTION!Result.make(n,
  275.                   arguments,
  276.                   type, 
  277.                   obsolete_mark,
  278.                   header_comment,
  279.                   require_assertion,
  280.                   local_vars,
  281.                   routine_body);
  282.      end;
  283.       end;
  284.          
  285.    to_cst_att_unique: CST_ATT_UNIQUE is
  286.       local
  287.      sp: POSITION;
  288.       do
  289.      if type = Void then
  290.         sp := names.first.start_position;
  291.         error(sp,"Unique feature must have a result type.");
  292.      end;
  293.      if not type.is_integer then
  294.         error(type.start_position,"Unique feature must have INTEGER type.");
  295.      end;
  296.      !!Result.make(n,type);
  297.       end;
  298.    
  299. feature {NONE}
  300.    
  301.    n: FEATURE_NAME_LIST is
  302.       do
  303.      check
  304.         not names.empty;
  305.      end;
  306.      !!Result.make(names.twin);
  307.       end;
  308.    
  309. end -- TMP_FEATURE
  310.  
  311.