// file: mm_new_2.cc
//
 
// isip include files
//
#include "memory_manager.h"
#include "memory_manager_constants.h"

#include <lex_node.h>

// method: new_lex_cc
//
// arguments: none
//
// return: a Lex* pointer to a new lex node
//
// this method outputs a new empty lex node, and creates them whenever
// necessary
//
Lex_node* Memory_manager::new_lex_cc() {

  // if there are no free lex nodes available, create a few
  //
  if (lex_count_d == (int_4)0) {
    grow_lex_cc();
  }

  // get a lex node off the list
  //
  Link_node* lnd = lex_list_d;
  lex_list_d = lex_list_d->get_next_cc();

  // adjust params
  //
  lnd->set_next_cc((Link_node*)NULL);
  if (lex_list_d != (Link_node*)NULL) {
    lex_list_d->set_prev_cc((Link_node*)NULL);
  }

  // get the lexical node here
  //
  Lex_node* lxn = (Lex_node*)(lnd->get_item_cc());
  
  // return the link node to the free node list
  //
  delete_cc(lnd);

  // decrement free lex node count
  //
  lex_count_d --;
  
  // return the lex node and exit gracefully
  //
  return lxn;
}
