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

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

  
  - author  := "Sonntag Benoit (bsonntag@loria.fr)";
  - comment := "Write slot";
  
Section Inherit

  + parent_write:Expanded WRITE;
    
Section Public
  
  - is_invariant:BOOLEAN <- receiver.is_invariant && {value.is_invariant};
  
  + slot:SLOT_DATA;
  
  - variable:VARIABLE <- slot;
  
  + receiver:EXPR;
  
  //
  // Creation.
  //
  
  - create p:POSITION with val:EXPR in (r:EXPR,s:SLOT_DATA) :SELF <-
  ( + result:SELF;
    ? {p.code != 0};
    result := clone;
    result.make p with val in (r,s);
    result
  );
  
  - make p:POSITION with val:EXPR in (r:EXPR,s:SLOT_DATA) <-
  (     
    position := p;    
    value    := val;
    receiver := r;
    slot     := s;
  );
    
  - my_copy:SELF <-
  ( + new_val:EXPR;    
    + result:SELF;
    
    new_val := value.my_copy;
    result ?= variable.write position with (receiver.my_copy) value new_val;
    result
  );
  
  //
  // Execute.
  //

  - 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;        
  );
  
  - remove <-
  (
    receiver.remove;
    parent_write.remove;
  );
  
  //
  // Genere
  //
  
  - genere buffer:STRING <-
  ( + tf:TYPE_FULL;
    + t:TYPE;
                   
    slot.receiver_type.add_genere_list;
    // Receiver.
    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);
    //
    ((value.static_type.raw = TYPE_NULL) && {variable.type.raw = type_block}).if {
      buffer.append ".__id=0";
    } else {
      buffer.add_last '=';    
      genere_value buffer;
    };
  );
  
  //
  // Display.
  //

  - display buffer:STRING <-
  (
    receiver.display buffer;
    buffer.append "->";
    parent_write.display buffer;    
  );

  
  




