@@ -62,6 +62,7 @@ public import Env;
6262public import Dependency ;
6363public import Interactive ;
6464public import HashTableExpToIndex ;
65+ public import HashTableStringToPath ;
6566public import Absyn ;
6667public import Ceval ;
6768public import Tpl ;
@@ -7634,92 +7635,85 @@ protected function getCalledFunctionsInFunctions
76347635 Goes through the given DAE, finds the given functions and collects
76357636 the names of the functions called from within those functions"
76367637 input list< Absyn . Path > paths;
7637- input list < Absyn . Path > accumulated ;
7638+ input HashTableStringToPath . HashTable ht ;
76387639 input DAE . FunctionTree funcs;
7639- output list< Absyn . Path > res;
7640- protected
7641- list< list< Absyn . Path >> pathslist;
7640+ output HashTableStringToPath . HashTable outHt;
76427641algorithm
7643- res := matchcontinue (paths,accumulated ,funcs)
7642+ outHt := match (paths,ht ,funcs)
76447643 local
7645- list< Absyn . Path > acc, rest;
7644+ list< Absyn . Path > rest;
76467645 Absyn . Path path;
7647- case ({},accumulated ,funcs) then accumulated ;
7648- case (path::rest,accumulated ,funcs)
7646+ case ({},ht ,funcs) then ht ;
7647+ case (path::rest,ht ,funcs)
76497648 equation
7650- acc = getCalledFunctionsInFunction (path, accumulated , funcs);
7651- res = getCalledFunctionsInFunctions(rest, acc , funcs);
7652- then res ;
7653- end matchcontinue ;
7649+ ht = getCalledFunctionsInFunction2 (path, Absyn . pathString(path), ht , funcs);
7650+ ht = getCalledFunctionsInFunctions(rest, ht , funcs);
7651+ then ht ;
7652+ end match ;
76547653end getCalledFunctionsInFunctions;
76557654
76567655public function getCalledFunctionsInFunction
7656+ "function: getCalledFunctionsInFunction
7657+ Goes through the given DAE, finds the given function and collects
7658+ the names of the functions called from within those functions"
7659+ input Absyn . Path path;
7660+ input DAE . FunctionTree funcs;
7661+ output list< Absyn . Path > outPaths;
7662+ protected
7663+ HashTableStringToPath . HashTable ht;
7664+ algorithm
7665+ ht := HashTableStringToPath . emptyHashTable();
7666+ ht := getCalledFunctionsInFunction2(path,Absyn . pathString(path),ht,funcs);
7667+ outPaths := BaseHashTable . hashTableValueList(ht);
7668+ end getCalledFunctionsInFunction;
7669+
7670+ protected function getCalledFunctionsInFunction2
76577671"function: getCalledFunctionsInFunction
76587672 Goes through the given DAE, finds the given function and collects
76597673 the names of the functions called from within those functions"
76607674 input Absyn . Path inPath;
7661- input list< Absyn . Path > accumulated;
7675+ input String pathstr;
7676+ input HashTableStringToPath . HashTable ht "paths to not add" ;
76627677 input DAE . FunctionTree funcs;
7663- output list < Absyn . Path > outAbsynPathLst ;
7678+ output HashTableStringToPath . HashTable outHt "paths to not add" ;
76647679algorithm
7665- outAbsynPathLst := matchcontinue (inPath,accumulated ,funcs)
7680+ outHt := matchcontinue (inPath,pathstr,ht ,funcs)
76667681 local
7667- String pathstr, debugpathstr;
7682+ String debugpathstr,str ;
76687683 Absyn . Path path;
76697684 DAE . Function funcelem;
7670- list< DAE . Function > funcelems;
7671- list< DAE . Function > elements;
7672- list< DAE . Exp > explist,fcallexps,fcallexps_1, fnrefs;
7673- list< Absyn . ComponentRef > crefs;
7674- list< Absyn . Path > calledfuncs, res1, res2, res, acc, varfuncs, fnpaths, fns, referencedFuncs, reffuncs;
7685+ list< DAE . Function > funcelems,elements;
7686+ list< Absyn . Path > calledfuncs, varfuncs, fnpaths, fns;
76757687 list< String > debugpathstrs;
76767688 DAE . DAElist dae;
76777689 list< DAE . Element > els;
7678- String str;
7679- list< DAE . Element > varlist;
7680- list< list< DAE . Element >> varlistlist;
76817690
7682- case (path,acc ,_)
7691+ case (path,pathstr,ht ,_)
76837692 equation
7684- true = listMember( path,acc );
7685- then acc ;
7693+ _ = BaseHashTable . get( Absyn . pathString( path), ht );
7694+ then ht ;
76867695
7687- case (path,acc ,funcs)
7696+ case (path,pathstr,ht ,funcs)
76887697 equation
7689- false = listMember(path,acc);
76907698 funcelem = DAEUtil . getNamedFunction(path, funcs);
76917699 els = DAEUtil . getFunctionElements(funcelem);
76927700 // Function reference variables are filtered out
76937701 varfuncs = Util . listFold(els, DAEUtil . collectFunctionRefVarPaths, {});
76947702 (_,(_,varfuncs)) = DAEUtil . traverseDAE2(Util . if_(RTOpts . acceptMetaModelicaGrammar(), els, {}),Expression . traverseSubexpressionsHelper,(DAEUtil . collectValueblockFunctionRefVars,varfuncs));
7695- // print("varfuncs: " +& Util.stringDelimitList(Util.listMap(varfuncs,Absyn.pathString),",") +& "\n");
7696- // print("Got expressions in " +& Absyn.pathString(path) +& ": " +& ExpressionDump.printExpStr(DAE.TUPLE(explist)) +& "\n");
76977703 (_,(_,(calledfuncs,_))) = DAEUtil . traverseDAE2(els,Expression . traverseSubexpressionsHelper,(matchNonBuiltinCallsAndFnRefPaths,({},varfuncs)));
7698- // print("calledfuncs: " +& Util.stringDelimitList(Util.listMap(calledfuncs,Absyn.pathString),",") +& "\n");
7699- res = getCalledFunctionsInFunctions(calledfuncs, path::acc, funcs);
7700- /* Debug.fprintln("info", "getCalledFunctionsInFunction: " +& Absyn.pathString(path)) "debug" ;
7701- Debug.fprint("info", "Found variable function refs to ignore: ") "debug" ;
7702- debugpathstrs = Util.listMap(varfuncs, Absyn.pathString) "debug" ;
7703- debugpathstr = Util.stringDelimitList(debugpathstrs, ", ") "debug" ;
7704- Debug.fprintln("info", debugpathstr) "debug" ;
7705- Debug.fprint("info", "Found called functions: ") "debug" ;
7706- debugpathstrs = Util.listMap(res, Absyn.pathString) "debug" ;
7707- debugpathstr = Util.stringDelimitList(debugpathstrs, ", ") "debug" ;
7708- Debug.fprintln("info", debugpathstr) "debug" ;*/
7709- then
7710- res;
7704+ ht = BaseHashTable . add((pathstr,path),ht);
7705+ ht = getCalledFunctionsInFunctions(calledfuncs, ht, funcs);
7706+ then ht;
77117707
7712- case (path,acc ,funcs)
7708+ case (path,pathstr,ht ,funcs)
77137709 equation
7714- false = listMember(path,acc);
77157710 failure(_ = DAEUtil . getNamedFunction(path, funcs));
7716- pathstr = Absyn . pathString(path);
7717- str = "SimCode.getCalledFunctionsInFunction: Class " +& pathstr +& " not found in global scope." ;
7711+ str = "SimCode.getCalledFunctionsInFunction2: Class " +& pathstr +& " not found in global scope." ;
77187712 Error . addMessage(Error . INTERNAL_ERROR ,{str});
77197713 then
77207714 fail();
77217715 end matchcontinue;
7722- end getCalledFunctionsInFunction ;
7716+ end getCalledFunctionsInFunction2 ;
77237717
77247718protected function getCallPath
77257719"function: getCallPath
0 commit comments