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