/*

    This file is part of the Maude 3 interpreter.

    Copyright 1997-2007 SRI International, Menlo Park, CA 94025, USA.

    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 2 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, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

*/

//
//      Implementation for class NarrowingVariableInfo.
//

#include "macros.hh"
#include "vector.hh"
//#include "graph.hh"

//      forward declarations
#include "interface.hh"
#include "core.hh"
#include "variable.hh"

//      core class definitions
#include "substitution.hh"
#include "narrowingVariableInfo.hh"

//      variable class definitions
#include "variableDagNode.hh"

int
NarrowingVariableInfo::variable2Index(VariableDagNode* variable)
{
  Assert(variable != 0, "null dagnode");
  int nrVariables = variables.length();
  for (int i = 0; i < nrVariables; i++)
    {
      if (variable->equal(variables[i]))
	return i;
    }
  variables.append(variable);
  return nrVariables;
}

int
NarrowingVariableInfo::variable2IndexNoAdd(VariableDagNode* variable) const
{
  Assert(variable != 0, "null dagnode");
  //cout << "looking at " << (DagNode*) variable << endl;
  int nrVariables = variables.length();
  for (int i = 0; i < nrVariables; i++)
    {
      if (variable->equal(variables[i]))
	return i;
      //cout << "not equal to " << (DagNode*) variables[i] << endl;
    }
  return NONE;
}
