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

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

  
  - author  := "Sonntag Benoit (bsonntag@loria.fr)";
  - comment := "Parent item object";
  
Section Inherit
  
  - parent_any:ANY := ANY;
  
  - parent_hashable:HASHABLE := HASHABLE;
  
Section Public
  
  - context_extern:LOCAL;
  
  - set_context_extern l:LOCAL <-
  (
    context_extern := l;
  );
      
  - lookup n:STRING_CONSTANT :LOCAL <-
  ( + result:LOCAL;
    + j:INTEGER;
    ? {n = ALIAS_STR.get n};
        
    j := stack_local.upper;
    {(j < stack_local_lower) || {stack_local.item j.name = n}}.until_do {	
      j := j - 1;
    };
    (j >= stack_local_lower).if {
      result := stack_local.item j;
      ((j < CONTEXT.limit_context) && {result.style != '-'}).if {
	context_extern := result;
      };
    }.elseif {profil_first != NULL} then {
      result := profil_first.lookup n;            
      ((result != NULL) && {result.name != ALIAS_STR.variable_self}).if {
	context_extern := result;
      };
    };
    result
  );
  
  //
  // Source position.
  //

  + position:POSITION;

  - set_position new_pos:POSITION <-
  (
    position := new_pos;
  );
  
  //
  //
  //
   
  - verify:BOOLEAN;
  
  - set_verify v:BOOLEAN <-
  (
    verify := v;
  );
  
  - pop_stack_until stack_top:INTEGER <-
  ( + var,var2:LOCAL;
    + n:STRING_CONSTANT;
    
    (verify).if {
      // Verify local.      
      {stack_local.upper >= stack_top}.while_do {
	var := stack_local.last;
	stack_local.remove_last;
	n := var.name;
	(
	  (n != ALIAS_STR.variable_self) && 	
	  {n != ALIAS_STR.variable_tmp}
	).if {
	  ((var.ensure_count = 0) && {var.style != ' '}).if {
	    string_tmp.copy "Local slot `";
	    string_tmp.append (var.name);
	    string_tmp.append "' not used.";
	    warning_error ((var.position),string_tmp);
	  };
	  var2 := lookup (var.name);
	  (var2 != NULL).if {
	    string_tmp.copy "Double declaration for `";
	    string_tmp.append n;
	    string_tmp.append "' slot.";
	    POSITION.put_error warning text string_tmp;
	    var2.position.put_position;
	    var.position.put_position;
	    POSITION.send_error;
	  };
	};
      };
    } else {
      stack_local.remove_since stack_top;
    };
  );
