/*******************************************************************\

Module:

Author: Daniel Kroening, kroening@cs.cmu.edu

\*******************************************************************/

#include "language_util.h"
#include "mode.h"

/*******************************************************************\

Function: from_expr

  Inputs:

 Outputs:

 Purpose:

\*******************************************************************/

std::string from_expr(
  const namespacet &ns,
  const irep_idt &identifier,
  const exprt &expr)
{
  int mode;

  if(identifier=="")
    mode=0;
  else
  {
    const symbolt *symbol;
    
    if(ns.lookup(identifier, symbol))
      mode=0;
    else if(symbol->mode=="")
      mode=0;
    else
    {
      mode=get_mode(id2string(symbol->mode));
      if(mode<0)
        throw "symbol "+id2string(symbol->name)+" has unknown mode";
    }
  }

  std::auto_ptr<languaget> p(new_language(mode));
  std::string result;
  p->from_expr(expr, result, ns);
  return result;
}

/*******************************************************************\

Function: from_type

  Inputs:

 Outputs:

 Purpose:

\*******************************************************************/

std::string from_type(
  const namespacet &ns,
  const irep_idt &identifier,
  const typet &type)
{
  int mode;

  if(identifier=="")
    mode=0;
  else
  {
    const symbolt *symbol;
    
    if(ns.lookup(identifier, symbol))
      mode=0;
    else if(symbol->mode=="")
      mode=0;
    else
    {
      mode=get_mode(id2string(symbol->mode));
      if(mode<0)
        throw "symbol "+id2string(symbol->name)+" has unknown mode";
    }
  }

  std::auto_ptr<languaget> p(new_language(mode));
  std::string result;
  p->from_type(type, result, ns);
  return result;
}

