예제 #1
0
void
MMO_Generator_::_variables ()
{
  stringstream buffer;
  VarSymbolTable vt = _model->varTable ();
  vt->setPrintEnvironment (VST_INIT);
  if (_model->annotation ()->solver () == ANT_DASSL
      || _model->annotation ()->solver () == ANT_DOPRI)
    {
      vt->setPrintEnvironment (VST_CLASSIC_INIT);
    }
  string indent = _writer->indent (1);
  list<VarInfo>::iterator it;
  list<VarInfo> parameters = vt->parameters ();
  for (it = parameters.begin (); it != parameters.end (); it++)
    {
      VarInfo vi = *it;
      Index idx = vi->index ();
      stringstream reverse;
      if (vi->type ()->getType () == TYREAL)
	{
	  buffer << "double " << vt->print (vi);
	}
      else if (vi->type ()->getType () == TYINTEGER)
	{
	  buffer << "int " << vt->print (vi);
	  reverse << "int __reverse" << vt->print (vi);
	}
      if (vi->isArray ())
	{
	  buffer << "[" << vi->size () << "]";
	  reverse << "[" << vi->size () << "]";
	}
      else
	{
	  buffer << " = 0";
	  reverse << " = 0";
	}
      buffer << ";";
      if (vi->type ()->getType () == TYINTEGER)
	{
	  reverse << ";";
	  _writer->write (&reverse, WR_GLOBAL_VARS);
	}
      _writer->write (&buffer, WR_GLOBAL_VARS);
      if (vi->hasAssignment () || vi->hasStartModifier ()
	  || vi->hasEachModifier ())
	{
	  buffer << _model->printInitialAssignment (vi, indent);
	  _writer->write (&buffer, WR_START_CODE);
	}
    }
  _writer->newLine (WR_GLOBAL_VARS);
}
예제 #2
0
void
MMO_Generator_::_variablesInitCode ()
{
  stringstream buffer;
  VarSymbolTable vt = _model->varTable ();
  vt->setPrintEnvironment (VST_INIT);
  if (_model->annotation ()->solver () == ANT_DASSL
      || _model->annotation ()->solver () == ANT_DOPRI)
    {
      vt->setPrintEnvironment (VST_CLASSIC_INIT);
    }
  string indent = _writer->indent (1);
  for (VarInfo vi = vt->begin (); !vt->end (); vi = vt->next ())
    {
      Index idx = vi->index ();
      if (!vi->isConstant () && !vi->isParameter ()
	  && (vi->hasAssignment () || vi->hasStartModifier ()
	      || vi->hasEachModifier ()))
	{
	  buffer << _model->printInitialAssignment (vi, indent);
	  _writer->write (&buffer, WR_START_CODE);
	}
    }
}