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); }
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()); }
Type TypeCheck_::check_expression(AST_Expression e) { Type ct,t1,t2,t; switch (e->expressionType()) { case EXPBINOP: { AST_Expression_BinOp b = e->getAsBinOp(); return check_binop(b->left() , b->right() , b->binopType()); } case EXPUMINUS: { AST_Expression_UMinus b = e->getAsUMinus(); t = check_expression(b->exp()); if ( check_equal(t , T("Integer")) or check_equal(t , T("Real")) ) return t; throw "Type Error (3)"; } case EXPOUTPUT : { AST_Expression_Output b = e->getAsOutput(); return check_expression(b->expressionList()->front() ); } case EXPIF: { AST_Expression_If b = e->getAsIf(); ct = check_expression(b->condition() ); t1 = check_expression(b->then() ); t2 = check_expression(b->else_exp()); // Falta el elseIF if ( !check_equal(ct, T("Boolean")) ) throw "Type Error (4)"; if ( !check_equal(t1,t2) ) throw "Type Error (5)"; return t1; } case EXPCALL: { // Añadir las funciones en la listaaaa de variables AST_Expression_Call c = e->getAsCall(); if ( toStr(c->name()) == "sample" ) return T("Boolean"); if ( toStr(c->name()) == "pre" ) return check_expression(c->arguments()->front()); return T("Real"); } case EXPCOMPREF: { AST_Expression_ComponentReference b = e->getAsComponentReference(); VarInfo tt = varEnv->lookup( toStr(b->names()->front()) ); if (tt == NULL) { cerr << "Var:" << b->names()->front() << ":"; throw "Variable no existe (8)"; } if (b->indexes()->front()->size() == 0) return tt->type(); else { Type t = tt->type(); AST_ExpressionListIterator exit; foreach(exit , b->indexes()->front() ) if (t->getType() == TYARRAY) t = t->getAsArray()->arrayOf(); else throw "Type Error (7)"; return t; } break; } case EXPDERIVATIVE: return T("Real"); case EXPBOOLEAN: return T("Boolean"); case EXPSTRING: return T("String"); case EXPREAL: return T("Real"); case EXPINTEGER: return T("Integer"); case EXPBOOLEANNOT: { AST_Expression_BooleanNot b = e->getAsBooleanNot(); t = check_expression(b->exp()); if ( !check_equal(t, T("Boolean")) ) throw "Type Error (6)"; return t; } default: throw "No implrementado aun! (check_expression)"; } }