From 66f40e1a28beb914c329e94c347bae718a895b36 Mon Sep 17 00:00:00 2001 From: paulklint Date: Sun, 1 Dec 2024 14:23:39 +0100 Subject: [PATCH] Made uses of getModuleName more robust --- .../library/lang/rascalcore/check/Checker.rsc | 64 +++++++++++-------- .../lang/rascalcore/check/CheckerCommon.rsc | 18 +----- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/check/Checker.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/check/Checker.rsc index c07144eb..37d77fd6 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/check/Checker.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/check/Checker.rsc @@ -127,37 +127,48 @@ ModuleStatus rascalTModelForLocs( msgs = validatePathConfigForChecker(pcfg, mlocs[0]); ModuleStatus ms = newModuleStatus(compilerConfig); - topModuleNames = {}; + + mnames = + for(mloc <- mlocs){ + if(!exists(mloc)){ + msgs += error(" does not exist", mloc); + append "LocationDoesNotExist: "; + } else { + try { + append getModuleName(mloc, pcfg); + } catch e: { + append "NoModuleNameFound: "; + msgs += error("No module name found for ", mloc); + } + } + }; if(!otherModulesWithOutdatedTpls(mlocs, pcfg)){ - if(uptodateTPls(mlocs, pcfg)){ - for (mloc <- mlocs) { - m = getModuleName(mloc, pcfg); - = getTModelForModule(m, ms); + if(uptodateTPls(mlocs, mnames, pcfg)){ + for (i <- index(mlocs)) { + = getTModelForModule(mnames[i], ms); if(!found){ - throw "TModel for not found (no changes)"; + throw "TModel for not found (no changes)"; } } return ms; } } - for (mloc <- mlocs) { - try { - m = getModuleName(mloc, pcfg); - if(isModuleLocationInLibs(m, mloc, pcfg)){ - ms.status[m] ? {} += {rsc_not_found()}; - } - topModuleNames += {m}; - ms.moduleLocs[m] = mloc; - msgs += toList(ms.messages[m] ? {}); - } catch e:{ - msgs += error(e, mloc); + for (int i <- index(mlocs)) { + mloc = mlocs[i]; + mname = mnames[i]; + if(isModuleLocationInLibs(mname, mloc, pcfg)){ + ms.status[mname] ? {} += {rsc_not_found()}; } + + ms.moduleLocs[mname] = mloc; + msgs += toList(ms.messages[mname] ? {}); } str jobName = ""; + topModuleNames = toSet(mnames); try { ms = getImportAndExtendGraph(topModuleNames, ms); @@ -168,7 +179,6 @@ ModuleStatus rascalTModelForLocs( imports_and_extends = ms.strPaths<0,2>; = stronglyConnectedComponentsAndTopSort(imports_and_extends); - //println("strong: , Ambiguity: "); map[str, set[str]] module2component = (m : c | c <- components, m <- c); list[str] ordered = []; @@ -489,10 +499,10 @@ ModuleStatus rascalTModelForNames(list[str] moduleNames, return rascalTModelForLocs(mlocs, compilerConfig, codgen); } -bool uptodateTPls(list[loc] candidates, PathConfig pcfg){ - for(mloc <- candidates){ - mname = getModuleName(mloc, pcfg); - = getTPLReadLoc(mname, pcfg); +bool uptodateTPls(list[loc] candidates, list[str] mnames, PathConfig pcfg){ + for(int i <- index(candidates)){ + mloc = candidates[i]; + = getTPLReadLoc(mnames[i], pcfg); if(!found || lastModified(mloc) > lastModified(tpl)){ return false; } @@ -503,9 +513,13 @@ bool uptodateTPls(list[loc] candidates, PathConfig pcfg){ bool otherModulesWithOutdatedTpls(list[loc] candidates, PathConfig pcfg){ for(srcdir <- pcfg.srcs){ for(loc mloc <- find(srcdir, "rsc")){ - mname = getModuleName(mloc, pcfg); - = getTPLReadLoc(mname, pcfg); - if(found && (mloc notin candidates) && (lastModified(mloc) > lastModified(tpl))){ + try { + mname = getModuleName(mloc, pcfg); + = getTPLReadLoc(mname, pcfg); + if(found && (mloc notin candidates) && (lastModified(mloc) > lastModified(tpl))){ + return true; + } + } catch e:{ return true; } } diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/check/CheckerCommon.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/check/CheckerCommon.rsc index 9dc943b0..787b4ace 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/check/CheckerCommon.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/check/CheckerCommon.rsc @@ -258,10 +258,6 @@ ModuleStatus updateBOM(str qualifiedModuleName, ModuleStatus ms){ } ModuleStatus removeTModel(str candidate, ModuleStatus ms, bool updateBOMneeded = false){ - // if(candidate == "analysis::grammar::Ambiguity"){ - // println("removeTModel: , "); - // } - messages = []; if(ms.status[candidate]? && tpl_saved() notin ms.status[candidate] && rsc_not_found() notin ms.status[candidate]){ pcfg = ms.pathConfig; if(updateBOMneeded){ @@ -272,27 +268,17 @@ ModuleStatus removeTModel(str candidate, ModuleStatus ms, bool updateBOMneeded = = getTPLWriteLoc(candidate, pcfg); tm = ms.tmodels[candidate]; tm = convertTModel2LogicalLocs(tm, ms.tmodels); - messages = tm.messages; ms.status[candidate] += tpl_saved(); if(ms.compilerConfig.verbose) println("Save before removing from cache "); try { writeBinaryValueFile(tplLoc, tm); - // if(candidate == "analysis::grammar::Ambiguity"){ - // println("removeTModel : , tpl: "); - // } if(traceTPL) println("Written "); } catch value e: { - throw "Cannot write TPL file , reason: "; + mloc = ms.moduleLocs[candidate] ? |unknown:///|; + ms.messages[candidate] += { error("Cannot write TPL file , reason: ", mloc) }; } } - // if(!isEmpty(messages)){ - // ms.messages[candidate] = messages; - // println(":"); iprintln(messages); - // } ms.tmodels = delete(ms.tmodels, candidate); - //if(candidate == "analysis::grammar::Ambiguity"){ - // println("removeTModel, end: , "); - //} return ms; }