///////////////////////////////////////////////////////////////////////////////
//                             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    := READ_SLOT;

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

  
  - author  := "Sonntag Benoit (bsonntag@loria.fr)";
  - comment := "Read for slot";
  
Section Inherit
  
  + parent_read:Expanded READ;
    
Section Public
  
  - is_slot:BOOLEAN <- TRUE;
  
  - is_invariant:BOOLEAN <- slot.is_invariant receiver;  
  
  + slot:SLOT_DATA;
  
  + receiver:EXPR;
  
  - variable:VARIABLE <- slot;
  
  - get_last_value:EXPR <- variable.get_last_value receiver;  
  
  //
  // Comparison.
  //
  
  - '==' Right 60 other:EXPR :BOOLEAN <- 
  ( + rd:READ_SLOT;
    
    rd ?= other;
    ((rd != NULL) && {slot = rd.slot} && {receiver == rd.receiver})    
  );
    
  //
  // Creation.
  //
    
  - create p:POSITION with (r:EXPR,s:SLOT_DATA) :SELF <-
  ( + result:SELF;
    
    result := clone;
    result.make p with (r,s);
    result    
  );
  
  - make p:POSITION with (r:EXPR,s:SLOT_DATA) <-
  (
    position := p;
    receiver := r;
    slot     := s;
  );
  
  - my_copy:SELF <-
  ( + result:SELF;
    
    result ?= slot.read position with (receiver.my_copy);
    result
  );
      
  //
  // Executing pass.
  //
    
  - remove <-
  (
    receiver.remove;
    parent_read.remove;
  );
  
  - execute_access_unlink:INSTR <- 
  (
    (slot.value != NULL).if {
      slot.execute;
    };
    receiver.execute_unlink
  );
    
  - execute_access_link <- 
  ( 
    (slot.value != NULL).if {
      slot.execute;
    };
    receiver := receiver.execute_link;        
  );

  //
  // Genere
  //
  
  - genere buffer:STRING <-
  ( + tf:TYPE_FULL;
    + t:TYPE;
    
    (slot.intern_name = ALIAS_STR.slot_self).if {
      buffer.append "((";
      tf := slot.type;
      tf.genere_declaration buffer;	
      buffer.add_last ' ';
      tf.genere_star_declaration buffer;	
      buffer.add_last ')';
      receiver.genere buffer;
      buffer.append ".self)";
    } else {
      tf := receiver.static_type;    
      ((tf.is_strict) || {tf.is_expanded_ref}).if {
	receiver.genere buffer;
	buffer.append "->";
      }.elseif {tf.is_expanded} then {      
	receiver.genere buffer;
	buffer.add_last '.';          
      } else {
	buffer.append "((";
	t := slot.receiver_type;
	t.put_reference_declaration buffer;	
	buffer.add_last ' ';
	t.put_reference_star_declaration buffer;	
	buffer.add_last ')';
	receiver.genere buffer;
	buffer.append ")->";
      };
      buffer.append (variable.intern_name);
    };    
  );
  
  //
  // Display.
  //
  
  - display buffer:STRING <-
  (
    receiver.display buffer;
    buffer.append "->";
    parent_read.display buffer;    
  );










