Code coverage for type_block.li

///////////////////////////////////////////////////////////////////////////////
//                             Lisaac Compiler                               //
//                                                                           //
//                   LSIIT - ULP - CNRS - INRIA - FRANCE                     //
//                                                                           //
//   This program is free software: you can redistribute it and/or modify    //
//   it under the terms of the GNU General Public License as published by    //
//   the Free Software Foundation, either version 3 of the License, or       //
//   (at your option) any later version.                                     //
//                                                                           //
//   This program is distributed in the hope that it will be useful,         //
//   but WITHOUT ANY WARRANTY; without even the implied warranty of          //
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
//   GNU General Public License for more details.                            //
//                                                                           //
//   You should have received a copy of the GNU General Public License       //
//   along with this program.  If not, see <http://www.gnu.org/licenses/>.   //
//                                                                           //
//                     http://isaacproject.u-strasbg.fr/                     //
///////////////////////////////////////////////////////////////////////////////
Section Header

  + name    := TYPE_BLOCK;

  - copyright   := "2003-2007 Benoit Sonntag";


  - author  := "Sonntag Benoit (bsonntag@loria.fr)";
  - comment := "Virtual type for BLOCK manager";

Section Inherit

  + parent_type:Expanded TYPE;

Section Private

  - dico:FAST_ARRAY(TYPE_BLOCK) := FAST_ARRAY(TYPE_BLOCK).create_with_capacity 2048;

Section TYPE_BLOCK //,PROFIL_BLOCK

  //
  // Creation.
  //

  - create a_list:FAST_ARRAY(TYPE_FULL) and_result r_list:FAST_ARRAY(TYPE_FULL) :SELF <-
  ( + result:SELF;
    result := clone;
    result.make a_list and_result r_list;
    result
  );

  - make a_list:FAST_ARRAY(TYPE_FULL) and_result r_list:FAST_ARRAY(TYPE_FULL) <-
  (
    argument_list := a_list;
    result_list   := r_list;
    default := TYPE_FULL.create Self with 0;
  );

Section Public

  - set_late_binding <-
  (
    type_block.set_late_binding;
  );

  - intern_name:STRING_CONSTANT <- type_block.intern_name;

  - is_block:BOOLEAN := TRUE;

  + argument_list:FAST_ARRAY(TYPE_FULL);
  + result_list:FAST_ARRAY(TYPE_FULL);

  - get_expr_for p:POSITION :EXPR <-
  ( + result:EXPR;
    + lst:FAST_ARRAY(EXPR);

    (result_list.count > 1).if {
      lst := FAST_ARRAY(EXPR).create_with_capacity (result_list.count);
      (result_list.lower).to (result_list.upper) do { j:INTEGER;
        lst.add_last (result_list.item j.get_temporary_expr p);
      };
      result := EXPR_MULTIPLE.create lst;
    }.elseif {result_list.count = 1} then {
      result := result_list.first.get_temporary_expr p;
    } else {
      result := PROTOTYPE_CST.create p type (TYPE_VOID.default);
    };
    result
  );

  - get t:ITM_TYPE_BLOCK with p:PARAMETER_TO_TYPE :TYPE_FULL <-
  ( + a_list:FAST_ARRAY(TYPE_FULL);
    + r_list:FAST_ARRAY(TYPE_FULL);

    // Argument.
    a_list := ALIAS_ARRAY(TYPE_FULL).new;
    (t.type_argument != NULL).if {
      t.type_argument.to_run_in a_list for p;
    };
    a_list := ALIAS_ARRAY(TYPE_FULL).alias a_list;
    // Result.
    r_list := ALIAS_ARRAY(TYPE_FULL).new;
    (t.type_result != NULL).if {
      t.type_result.to_run_in r_list for p;
    };
    r_list := ALIAS_ARRAY(TYPE_FULL).alias r_list;
    //
    get_direct a_list and_result r_list.default
  );

  - get_direct a_list:FAST_ARRAY(TYPE_FULL) and_result r_list:FAST_ARRAY(TYPE_FULL) :TYPE_BLOCK <-
  ( + idx:INTEGER;
    + result:TYPE_BLOCK;

    idx := dico.lower;
    {
      (idx <= dico.upper)    {
        {dico.item idx.argument_list != a_list} ||
        {dico.item idx.result_list   != r_list}
      }
    }.while_do {
      idx := idx + 1;
    };
    (idx <= dico.upper).if {
      result := dico.item idx;
    } else {
      result := create a_list and_result r_list;
      dico.add_last result;
    };
    result
  );

  - prototype:PROTOTYPE <- type_block.prototype;

  - get_slot n:STRING_CONSTANT :SLOT <-
  (
    type_block.get_slot n
  );

  - get_local_slot n:STRING_CONSTANT :SLOT <-
  (
    type_block.get_local_slot n
  );

  - get_path_slot n:STRING_CONSTANT :SLOT <-
  (
    type_block.get_path_slot n
  );

  - genere_struct <- type_block.genere_struct;

  //
  // Code source generation.
  //

  - put_id buffer:STRING <- index.append_in buffer;

  - put_access_id e:EXPR in buffer:STRING <-
  (
    buffer.append "(int)";
    e.genere buffer;
  );

  - put_value buffer:STRING <-
  (
    buffer.append "(void *)";
    index.append_in buffer;
  );

  - is_sub_type other:TYPE :BOOLEAN <-
  ( + me:TYPE_BLOCK;

    me ?= other;
    (me != NULL)   
    {me.argument_list = argument_list}   
    {me.result_list = result_list}
  );

  - is_sub_type_result other:TYPE_BLOCK :BOOLEAN <-
  ( + result:BOOLEAN;
    + j:INTEGER;
    (result_list = other.result_list) ||
    {
      (result_list != NULL)   
      {other.result_list != NULL}   
      {result_list.count = other.result_list.count}   
      {
        result := TRUE;
        j := result_list.lower;
        {(j <= result_list.upper)    {result}}.while_do {
          result := result_list.item j.is_sub_type (other.result_list.item j);
          j := j + 1;
        };
        result
      }
    }
  );

  //
  // Display.
  //

  - append_name_in buf:STRING <-
  (
    buf.add_last '{';
    (argument_list.is_empty).if_false {
      (argument_list.count > 1).if {
        buf.add_last '(';
        (argument_list.lower).to (argument_list.upper-1) do { j:INTEGER;
          argument_list.item j.display buf;
          buf.add_last ',';
        };
        argument_list.last.display buf;
        buf.add_last ')';
      } else {
        argument_list.first.display buf;
      };
      buf.add_last ';';
      buf.add_last ' ';
    };
    (result_list.is_empty).if_false {
      (result_list.lower).to (result_list.upper-1) do { j:INTEGER;
        result_list.item j.display buf;
        buf.add_last ',';
      };
      result_list.last.display buf;
    };
    buf.add_last '}';
    // Debug
    buf.append "(TYPE_BLOCK)";
  );