Example #1
0
void MMO_ToMicroModelica_::transform()
{
	/* Aca comienza todo el ciclo */
	checkStatement(_c->getStatements());
	checkStatement(_c->getIniStatements());
	
	initialFrame.push(_c->getIniStatements());
	
	
	transformEqList(_c->getIniEquations() , _c->getIniStatements(), NULL );
	transformEqList(_c->getEquations()    , _c->getStatements()   , NULL );
	
	/* Cambiamos los tipos y constantes Booleanas */ 
	for(int i = 0; i < _c->getVarSymbolTable()->count();i++) {
		VarInfo  v = _c->getVarSymbolTable()->varInfo(i);
		string n   = _c->getVarSymbolTable()->varName(i);
		//v->setComment(NULL);
		v->setModification( ChangeModifications(v->modification()));
		if (_pre->find(n) != _pre->end())
			v->setDiscrete();
		
		if ( ( !v->isConstant() ) || v->type()->getType() == TYBOOLEAN) v->setType(ChangeToReal(v->type()));
	}
	ChangePre(_c->getIniEquations());
	ChangePre(_c->getEquations());
}
Example #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);
	}
    }
}
Example #3
0
int
MMO_EvalInitExp_::foldTraverseElement (AST_Expression exp)
{
  int ret = 0;
  switch (exp->expressionType ())
    {
    case EXPCOMPREF:
      {
	AST_Expression_ComponentReference cr = exp->getAsComponentReference ();
	VarInfo vi = _vt->lookup (cr->name ());
	if (vi == NULL)
	  {
	    Error::getInstance ()->add (exp->lineNum (),
	    EM_IR | EM_VARIABLE_NOT_FOUND,
					ER_Error, "%s", cr->name ().c_str ());
	    return (ret);
	  }
	if (!vi->isConstant ())
	  {
	    Error::getInstance ()->add (
		exp->lineNum (), EM_IR | EM_INIT_EXP, ER_Error,
		"Only constants allowed inside initial expressions. %s",
		cr->name ().c_str ());
	    return (ret);
	  }
	return (vi->value ());
      }
    case EXPBOOLEAN:
      {
	AST_Expression_Boolean eb = exp->getAsBoolean ();
	if (eb->value ())
	  {
	    return (1);
	  }
	else
	  {
	    return (0);
	  }
      }
    case EXPBOOLEANNOT:
      {
	AST_Expression_BooleanNot ebn = exp->getAsBooleanNot ();
	int res = foldTraverse (ebn->exp ());
	if (res == 0)
	  {
	    return (1);
	  }
	else
	  {
	    return (0);
	  }
      }
    case EXPREAL:
      Error::getInstance ()->add (
	  0, EM_IR | EM_INIT_EXP, ER_Warning,
	  "Implicit conversion from Real to Integer, in initial expression.");
      return (exp->getAsReal ()->val ());
    case EXPINTEGER:
      return (exp->getAsInteger ()->val ());
    default:
      Error::getInstance ()->add (
	  0,
	  EM_IR | EM_INIT_EXP,
	  ER_Warning,
	  "Initial expression not recognized, returning zero as default value.");
      break;
    }
  return (ret);
}