void MMOModel::add (const FunctionDefinition &f) { string fname = f.getId (); MMOFunction *func = new MMOFunction (fname); int na = f.getNumArguments (); MMOMath d = MMOMath (_replace, &_functions, _prefix); list<string> funcArgs; for (int i = 0; i < na; i++) { d.parseEquation (f.getArgument (i)); string argExp = d.getExp (); MMODecl *adec = new MMODecl (argExp, function_input); func->add (adec); funcArgs.push_back (argExp); } string var = MMOUtils::getInstance ()->getVar (); d.parseEquation (f.getBody ()); _addAlgebraicReplacement (d); MMODecl *adec = new MMODecl (var, d.getExp (), function_definition); func->add (adec); _functions[fname] = pair<list<string>, ASTNode*> ( funcArgs, new ASTNode (*f.getBody ())); _add (func, external_functions); }
void FunctionDefinitionRecursion::addDependencies(const Model& m, const FunctionDefinition& object) { unsigned int ns; std::string thisId = object.getId(); /* loop thru the list of names in the Math * if they refer to a FunctionDefinition add to the map * with the variable as key */ List* variables = object.getMath()->getListOfNodes( ASTNode_isFunction ); for (ns = 0; ns < variables->getSize(); ns++) { ASTNode* node = static_cast<ASTNode*>( variables->get(ns) ); string name = node->getName() ? node->getName() : ""; if (m.getFunctionDefinition(name)) { mIdMap.insert(pair<const std::string, std::string>(thisId, name)); } } delete variables; }
/** * Logs a message about an undefined variable in the given * FunctionDefinition. */ void FunctionDefinitionVars::logUndefined ( const FunctionDefinition& fd, const string& varname ) { msg = msg = //"Inside the 'lambda' of a <functionDefinition>, if a 'ci' element is not " //"the first element within a MathML 'apply', then the 'ci''s value can " //"only be the value of a 'bvar' element declared in that 'lambda'. In " //"other words, all model entities referenced inside a function definition " //"must be passed arguments to that function. (References: L2V2 Section " //"4.3.2.)" "The variable '"; msg += varname; msg += "' is not listed as a <bvar> of FunctionDefinition '"; msg += fd.getId(); msg += "'."; logFailure(fd); }
void CompIdBase::checkId (const FunctionDefinition& x) { if (x.isSetId()) doCheckId(x.getId(), x); }