From 99553ddb951e5f35cd3e66872c23d257d8c5b4b4 Mon Sep 17 00:00:00 2001 From: paulklint Date: Sat, 9 Mar 2024 19:18:24 +0100 Subject: [PATCH] Robustness improvements - Incoming PathConfig is validated - More potentially exception triggering code is now inside a try catch - Simplification/improvement of several signatures --- .classpath | 2 +- pom.xml | 2 +- .../library/lang/rascalcore/check/Checker.rsc | 134 ++++++++++++------ .../lang/rascalcore/check/CheckerTesting.rsc | 18 +-- .../rascalcore/check/CollectDeclaration.rsc | 7 +- .../library/lang/rascalcore/check/Import.rsc | 7 +- .../lang/rascalcore/check/RascalConfig.rsc | 2 +- .../check/tests/StaticTestingUtils.rsc | 60 +------- .../lang/rascalcore/compile/Compile.rsc | 17 ++- .../lang/rascalcore/compile/Examples/Tst5.rsc | 11 +- 10 files changed, 140 insertions(+), 120 deletions(-) diff --git a/.classpath b/.classpath index ab8a66e3..97be03d0 100644 --- a/.classpath +++ b/.classpath @@ -38,8 +38,8 @@ - + diff --git a/pom.xml b/pom.xml index eb2bd5e7..6a30e236 100644 --- a/pom.xml +++ b/pom.xml @@ -219,7 +219,7 @@ org.rascalmpl rascal - 0.34.0 + 0.36.0-RC1 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 d4503ab8..e951248f 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/check/Checker.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/check/Checker.rsc @@ -38,14 +38,12 @@ extend lang::rascalcore::check::RascalConfig; import IO; import List; -import Map; import Message; import Node; import Relation; import Set; import String; -import util::Benchmark; import util::Reflective; import util::FileSystem; import util::Monitor; @@ -89,7 +87,7 @@ void rascalPreCollectInitialization(map[str, Tree] namedTrees, Collector c){ // } //} -// ---- Various check functions --------------------------------------------- +// ---- Various PathConfigs --------------------------------------------- private int npc = 0; @synopsis{PathConfig for testing generated modules in |memory://test-modules/| in memory file system.} @@ -98,17 +96,19 @@ private int npc = 0; * generates bin files in the in-memory file system * depends only on the pre-compiled standard library from the rascal project } -public PathConfig getDefaultPathConfig() { +public PathConfig getDefaultTestingPathConfig() { npc += 1; snpc = ""; return pathConfig( - srcs = [|memory://test-modules/|], - bin = |memory://test-modules/rascal-core-tests-bin-|, - libs = [|lib://rascal/|] + srcs = [ |memory:///test-modules/| ], + bin = |memory:///test-modules/rascal-core-tests-bin-|, + generatedSources = |memory:///test-modules/generated-test-sources-|, + resources = |memory:///test-modules/generated-test-resources-|, + libs = [ |std:///| ] ); } -@synopsis{for type-checking test modules in the rascal-core project; such as lang::rascalcore::check::Test1} +@synopsis{PathConfig for type-checking test modules in the rascal-core project; such as lang::rascalcore::check::Test1} @description{ * sources have to be in `|project://rascal-core/src/org/rascalmpl/core/library|` * binaries will be stored the target folder of the rascal-core project @@ -137,7 +137,7 @@ public PathConfig getRascalProjectPathConfig() { snpc = ""; return pathConfig( srcs = [|project://rascal/src/org/rascalmpl/library|], - bin = |memory://test-modules/rascal-lib-bin-|, + bin = |memory:///test-modules/rascal-lib-bin-|, libs = [] ); } @@ -145,6 +145,45 @@ public PathConfig getRascalProjectPathConfig() { CompilerConfig getRascalCompilerConfig() = cconfig(); +list[Message] validatePathConfigForCompiler(PathConfig pcfg, loc mloc){ + msgs = []; + + if(isEmpty(pcfg.srcs)) msgs += error("PathConfig: `srcs` is empty", mloc); + for(src <- pcfg.srcs){ + if(!exists(src)) msgs += error("PathConfig `srcs`: does not exist", src); + } + for(lb <- pcfg.libs){ + if(!exists(lb)) msgs += error("PathConfig `libs`: does not exist", lb); + } + + if(!exists(pcfg.bin)) { + try { + mkDirectory(pcfg.resources); + } catch _: { + msgs += error("PathConfig `bin`: does not exist", pcfg.bin); + } + } + + if(!exists(pcfg.resources)) { + try { + mkDirectory(pcfg.resources); + } catch _: { + msgs += error("PathConfig `resources`: does not exist", pcfg.resources); + } + } + + if(!exists(pcfg.generatedSources)) + try { + mkDirectory(pcfg.generatedSources); + } catch _: { + msgs += error("PathConfig `generatedSources`: does not exist", pcfg.generatedSources); + } + + return msgs; +} + +// ---- Various check functions --------------------------------------------- + // rascalTModelForLocs is the basic work horse ModuleStatus rascalTModelForLocs( @@ -153,14 +192,29 @@ ModuleStatus rascalTModelForLocs( CompilerConfig compilerConfig, list[Message](str qualifiedModuleName, lang::rascal::\syntax::Rascal::Module M, ModuleStatus ms, CompilerConfig compilerConfig) codgen ){ + bool forceCompilationTopModule = false; /***** for convenience, set to true during development of type checker *****/ pcfg = config.typepalPathConfig; if(compilerConfig.verbose) iprintln(pcfg); - - bool forceCompilationTopModule = false; /***** for convenience, set to true during development of type checker *****/ + + msgs = validatePathConfigForCompiler(pcfg, mlocs[0]); + if(!isEmpty(msgs)){ + throw msgs; + } + ModuleStatus ms = newModuleStatus(pcfg); - topModuleNames = { getModuleName(mloc, pcfg) | mloc <- mlocs }; - + topModuleNames = {}; + + for(mloc <- mlocs){ + //try { + m = getModuleName(mloc, pcfg); + topModuleNames += {m}; + //} catch str e: { + // ms.messages += [ error("Cannot get module name for , reason: ", mloc) ]; + // return ms; + //} + } + try { ms = getImportAndExtendGraph(topModuleNames, pcfg); @@ -179,7 +233,7 @@ ModuleStatus rascalTModelForLocs( if(isEmpty(sorted)){ ordered = toList(topModuleNames); - for(topModuleName <- topModuleNames){ + for(str topModuleName <- topModuleNames){ module2component[topModuleName] = {topModuleName}; } } else { @@ -211,7 +265,7 @@ ModuleStatus rascalTModelForLocs( } } if(!all(m <- component, tpl_uptodate() in ms.status[m] || checked() in ms.status[m])){ - = rascalTModelComponent(component, ms, config=config); + = rascalTModelComponent(component, ms, config); moduleScopes += getModuleScopes(tm); map[str,TModel] tmodels_for_component = (); map[str,set[str]] m_imports = (); @@ -252,6 +306,8 @@ ModuleStatus rascalTModelForLocs( } } tm.messages += msgs; + } else { + tm.messages += error("Cannot get parse tree for module ``", ms.moduleLocs[m]); } } if(ms.messages[m]?){ @@ -276,6 +332,8 @@ ModuleStatus rascalTModelForLocs( msgs = codgen(m, pt, ms, compilerConfig); ms.messages[m] = msgs; ms.status[m] += {code_generated()}; + } else { + ms.messages[m] += error("Cannot get parse tree for module ``", ms.moduleLocs[m]); } } ms = doSaveModule(component, m_imports, m_extends, ms, moduleScopes, compilerConfig); @@ -326,23 +384,20 @@ tuple[set[str], ModuleStatus] loadImportsAndExtends(str moduleName, ModuleStatus return ; } -tuple[TModel, ModuleStatus] rascalTModelComponent(set[str] moduleNames, ModuleStatus ms, - TypePalConfig config=rascalTypePalConfig(ms.pathConfig), bool inline=false){ +tuple[TModel, ModuleStatus] rascalTModelComponent(set[str] moduleNames, ModuleStatus ms, TypePalConfig config){ pcfg = ms.pathConfig; modelName = intercalate(" + ", toList(moduleNames)); map[str, Module] namedTrees = (); for(nm <- moduleNames){ - //if(checked() notin ms.status[nm]){ - = getModuleParseTree(nm, ms); - if(success){ - namedTrees[nm] = pt; - } - //} else { - // println("*** rascalTModelComponent: : reusing "); - //} + = getModuleParseTree(nm, ms); + if(success){ + namedTrees[nm] = pt; + } else { + ms.messages[nm] += error("Cannot get parse tree for module ``", ms.moduleLocs[nm]); + } } - + jobStart("RascalCompiler"); jobStep("RascalCompiler", "Type checking "); // TODO: monitor if(config.verbose) println("Type checking "); @@ -378,20 +433,19 @@ ModuleStatus rascalTModelForNames(list[str] moduleNames, list[Message] (str qualifiedModuleName, lang::rascal::\syntax::Rascal::Module M, ModuleStatus ms, CompilerConfig compilerConfig) codgen){ - - //try { - pcfg = config.typepalPathConfig; - mlocs = [ getModuleLocation(moduleName, pcfg) | moduleName <- moduleNames ]; - return rascalTModelForLocs(mlocs, config, compilerConfig, codgen); - //} catch value e: { - // mloc = |unknown:///|(0,0,<0,0>,<0,0>); - // ms = newModuleStatus(); - // for( moduleName <- moduleNames){ - // ms.messages[moduleName] = [ error("", mloc) ]; - // } - // return ms; - // //return <(moduleName : tmodel()[messages = [ error("", mloc) ]] | moduleName <- moduleNames), (), ()>; - //} + pcfg = config.typepalPathConfig; + mlocs = []; + for(moduleName <- moduleNames){ + try { + mlocs += [ getModuleLocation(moduleName, pcfg) ]; + } catch value e: { + mloc = |unknown:///|(0,0,<0,0>,<0,0>); + ms = newModuleStatus(pcfg); + ms.messages[moduleName] = [ error("", mloc) ]; + return ms; + } + } + return rascalTModelForLocs(mlocs, config, compilerConfig, codgen); } // ---- checker functions for IDE diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/check/CheckerTesting.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/check/CheckerTesting.rsc index ec2c2e00..4e1263c4 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/check/CheckerTesting.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/check/CheckerTesting.rsc @@ -13,23 +13,25 @@ start syntax Modules // ---- Testing --------------------------------------------------------------- TModel rascalTModelForTestModules(Tree pt, bool debug=false){ - ms = getInlineImportAndExtendGraph(pt, getDefaultPathConfig()); - TypePalConfig config=rascalTypePalConfig(getDefaultPathConfig()); - if(debug){ + ms = getInlineImportAndExtendGraph(pt, getDefaultTestingPathConfig()); + TypePalConfig config=rascalTypePalConfig(getDefaultTestingPathConfig()); + if(debug){ config = config[logImports = true]; - } + } if(start[Modules] mds := pt){ - return rascalTModelComponent( (unescape("") : md | md <- mds.top.modules ), ms, config=config, inline=true)[1]; + return rascalTModelComponent( {unescape("") | md <- mds.top.modules }, ms, config)[1]; } else if(Modules mds := pt){ - return rascalTModelComponent( (unescape("") : md | md <- mds.modules ), ms, config=config, inline=true)[1]; + return rascalTModelComponent( {unescape("") | md <- mds.modules }, ms, config)[1]; } else throw "Cannot handle Modules"; } void testModules(str names...) { if(isEmpty(names)) names = allTests; - runTests([|project://rascal-core/src/org/rascalmpl/core/library/lang/rascalcore/check/tests/.ttl| | str name <- names], #Modules, rascalTModelForTestModules, verbose=false); + runTests([|project://rascal-core/src/org/rascalmpl/core/library/lang/rascalcore/check/tests-ttl/.ttl| | str name <- names], #Modules, rascalTModelForTestModules, verbose=false); } list[str] allTests = ["adt", "adtparam", "alias", "assignment", "datadecl", "exp", "fields", "fundecl", - "imports", "operators", "pat", "scope", "splicepats", "stats"/*,"syntax1", "syntax2", "syntax3"*/]; \ No newline at end of file + "imports", "operators", "pat", "scope", "splicepats", "stats"/*,"syntax1", "syntax2", "syntax3"*/]; + +value main() = testModules(); \ No newline at end of file diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectDeclaration.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectDeclaration.rsc index b9ed56e9..95185532 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectDeclaration.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectDeclaration.rsc @@ -36,9 +36,8 @@ import util::Reflective; void collect(Module current: (Module) `
`, Collector c){ - //current = current.top; + mloc = getLoc(current); mname = prettyPrintName(header.name); - //println("Type checking module "); checkModuleName(getLoc(current), header.name, c); tagsMap = getTags(header.tags); @@ -68,8 +67,8 @@ void checkModuleName(loc mloc, QualifiedName qualifiedModuleName, Collector c){ if(mloc.scheme != mloc1.scheme || mloc.authority != mloc1.authority || mloc.path != mloc1.path){ c.report(error(qualifiedModuleName, "Module name %v is incompatible with its file location", mname)); } - } catch _: { - c.report(error(qualifiedModuleName, "Module name %v is not consistent with its file location", mname)); + } catch str e: { + c.report(error(qualifiedModuleName, e)); } } else if(isEmpty(pcfgVal)){ return; diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/check/Import.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/check/Import.rsc index 200071c2..aed16f4a 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/check/Import.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/check/Import.rsc @@ -354,6 +354,8 @@ ModuleStatus getImportAndExtendGraph(str qualifiedModuleName, ModuleStatus ms){ ms.strPaths += {}; ms = getImportAndExtendGraph(imp, ms); } + } else { + ms.messages[qualifiedModuleName] += error("Cannot get parse tree for module ``", ms.moduleLocs[qualifiedModuleName]); } return ms; @@ -462,7 +464,6 @@ ModuleStatus doSaveModule(set[str] component, map[str,set[str]] m_imports, map[s filteredModuleScopes = {getModuleScope(m, moduleScopes, pcfg) | str m <- (qualifiedModuleName + imports), checked() in ms.status[m]} + extendedModuleScopes; TModel m1 = tmodel(); - m1.modelName = qualifiedModuleName; m1.moduleLocs = (qualifiedModuleName : mscope); @@ -561,13 +562,13 @@ ModuleStatus doSaveModule(set[str] component, map[str,set[str]] m_imports, map[s writeBinaryValueFile(tplLoc, m1); if(compilerConfig.logWrittenFiles) println("Written: "); } catch value e: { - throw "Corrupt TPL file because of "; + throw "Cannot write TPL file , reason: "; } ms.tmodels[qualifiedModuleName] = m1; } catch value e: { - ms.tmodels[qualifiedModuleName] = tmodel(modelName=qualifiedModuleName, messages=tm.messages + [error("Could not save .tpl file for ``: ", |unknown:///|(0,0,<0,0>,<0,0>))]); + ms.tmodels[qualifiedModuleName] = tmodel(modelName=qualifiedModuleName, messages=tm.messages + [error("Could not save .tpl file for ``, reason: ", |unknown:///|(0,0,<0,0>,<0,0>))]); return ms; } } diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/check/RascalConfig.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/check/RascalConfig.rsc index effe4e02..bdd885a4 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/check/RascalConfig.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/check/RascalConfig.rsc @@ -408,7 +408,7 @@ void rascalPostSolver(map[str,Tree] namedTrees, Solver s){ } } -loc rascalCreateLogicalLoc(Define def, str _modelName, PathConfig pcfg){ +loc rascalCreateLogicalLoc(Define def, str modelName, PathConfig pcfg){ if(def.idRole in keepInTModelRoles){ moduleName = getModuleName(def.defined, pcfg); moduleNameSlashed = replaceAll(moduleName, "::", "/"); diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/check/tests/StaticTestingUtils.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/check/tests/StaticTestingUtils.rsc index 7833d92b..b420ec13 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/check/tests/StaticTestingUtils.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/check/tests/StaticTestingUtils.rsc @@ -21,7 +21,7 @@ import lang::rascal::\syntax::Rascal; import lang::rascalcore::check::Checker; PathConfig pathConfigForTesting() { - return getDefaultPathConfig(); + return getDefaultTestingPathConfig(); } str abbrev(str s) { return size(s) < 120 ? s : " ..."; } @@ -44,11 +44,10 @@ loc buildModule(str stmts, list[str] importedModules = [], list[str] initialDec } loc makeModule(str name, str body){ - mloc = |memory://test-modules/.rsc|; + mloc = |memory:///test-modules/.rsc|; writeFile(mloc, "@bootstrapParser 'module '"); - //println("module: \n"); return mloc; } @@ -61,7 +60,6 @@ set[Message] getWarningMessages(ModuleStatus r) set[Message] getAllMessages(ModuleStatus r) = { m | mname <- r.tmodels, m <- r.tmodels[mname].messages }; - ModuleStatus checkStatements(str stmts, list[str] importedModules = [], list[str] initialDecls = [], bool verbose=true){ mloc = buildModule(stmts, importedModules=importedModules, initialDecls=initialDecls); return rascalTModelForLocs([mloc], rascalTypePalConfig(pathConfigForTesting()), getRascalCompilerConfig(), dummy_compile1); @@ -89,12 +87,7 @@ bool checkOK(str stmts, list[str] importedModules = [], list[str] initialDecls = } bool checkModuleOK(loc moduleToCheck){ -<<<<<<< HEAD - //rascalTModelForLocs([moduleToCheck], testingConfig(), rascalTypePalConfig()); - errors = getErrorMessages(rascalTModelForLocs([moduleToCheck], rascalTypePalConfig(rascalPathConfig=testingConfig()), getRascalCompilerConfig(), dummy_compile1)); -======= errors = getErrorMessages(rascalTModelForLocs([moduleToCheck], rascalTypePalConfig(pathConfigForTesting()), getRascalCompilerConfig(), dummy_compile1)); ->>>>>>> e1f02a88 (Changed keyword parameter rascalPathConfig to positional parameter) if(size(errors) == 0) return true; throw abbrev(""); @@ -130,34 +123,6 @@ bool unexpectedType(str stmts, list[str] importedModules = [], list[str] initial "Types _ and _ do not match", "Cannot instantiate formal parameter type _", "Bounds _ and _ are not comparable" - //"_ not defined for _ and _", - //"not defined on _ and _", - //"not declared on", - //"Invalid type: expected _, found _", - //"Invalid type _, expected expression of type _", - //"Expected type _, found _", - //"Expected _, found _", - //"Unable to bind subject type _ to assignable", - //"Unable to bind result type _ to assignable", - //"not assignable to", - //"Cannot use type", - //"expected return type", - //"Expected subscript of type _, not _", - //"Cannot subscript assignable of type", - //"Unexpected type _, expected type _", - //"Unexpected type _, generator should be an expression of type bool", - //"Type of bound should be", - //"_ and _ incomparable", - //"must have an actual type", - //"Cannot assign value of type", - //"Cannot assign pattern of type", - //"does not allow fields", - //"Tuple index must be between", - //"out of range", - //"Cannot add append information, no valid surrounding context found", - //"Cannot match an expression of type: _ against a pattern of type _", - //"Cannot subscript map of type _ using subscript of type _", - //"Inserted type _ must be a subtype of case type _" ], importedModules=importedModules, initialDecls=initialDecls); // NOTE: type checker does not yet support analysis of uninitialized variables, therefore this check always succeeds, for now. @@ -181,7 +146,6 @@ bool undeclaredVariable(str stmts, list[str] importedModules = [], list[str] ini bool undeclaredType(str stmts, list[str] importedModules = [], list[str] initialDecls = []) = check(stmts, [ "Undefined _" - //"Type _ not declared" ], importedModules=importedModules, initialDecls=initialDecls); bool undefinedField(str stmts, list[str] importedModules = [], list[str] initialDecls = []) = @@ -195,22 +159,13 @@ bool argumentMismatch(str stmts, list[str] importedModules = [], list[str] initi "Expected _ argument(s),", "Argument _ should have type _ found _", "Return type _ expected, found _", - "Keyword argument _ has type _, expected _" - - //"Function of type _ cannot be called with argument types _", - //"Constructor of type _ cannot be built with argument types _", - //"Constructor accepts _ arguments but was given only _ arguments", - //"Keyword parameter of type _ cannot be assigned argument of type _", - //"Unknown keyword parameter passed: _" + "Keyword argument _ has type _, expected _" ], importedModules=importedModules, initialDecls=initialDecls); bool redeclaredVariable(str stmts, list[str] importedModules = [], list[str] initialDecls = []) = check(stmts, [ "Undefined _ due to double declaration", "Double declaration of _" - //"Cannot re-declare name that is already declared in the current function or closure", - //"redeclaration", - //"has already been declared" ], importedModules=importedModules, initialDecls=initialDecls); bool cannotMatch(str stmts, list[str] importedModules = [], list[str] initialDecls = []) = @@ -222,9 +177,6 @@ bool cannotMatch(str stmts, list[str] importedModules = [], list[str] initialDec "Pattern should be comparable with _, found _", "Expected tuple pattern with _ elements, found _", "Pattern variable _ has been introduced before, add explicit declaration of its type" - //"Cannot match an expression of type: _ against a pattern of type", - //"Cannot assign pattern of type", - //"is not enumerable" ], importedModules=importedModules, initialDecls=initialDecls); bool declarationError(str stmts, list[str] importedModules = [], list[str] initialDecls = []) = @@ -237,16 +189,11 @@ bool declarationError(str stmts, list[str] importedModules = [], list[str] initi "Unresolved type for _", "Constructor _ in formal parameter should be unique", "Type _ should have one type argument" - //"Constructor _ overlaps existing constructors in the same datatype", - //"Initializer type", - //"Errors present in constructor parameters, cannot add constructor to scope" ], importedModules=importedModules, initialDecls=initialDecls); bool missingModule(str stmts, list[str] importedModules = [], list[str] initialDecls = []) = check(stmts, [ "Reference to name _ cannot be resolved" - //"Cannot import module _", - //"Could not parse and prepare config for base module to check: IO" ], importedModules=importedModules, initialDecls=initialDecls); bool illegalUse(str stmts, list[str] importedModules = [], list[str] initialDecls = []) = @@ -257,7 +204,6 @@ bool illegalUse(str stmts, list[str] importedModules = [], list[str] initialDecl bool nonVoidType(str stmts, list[str] importedModules = [], list[str] initialDecls = []) = check(stmts, [ "Contribution to _ comprehension should not have type `void`" - //"Non-void type required" ], importedModules=importedModules, initialDecls=initialDecls); bool unsupported(str stmts, list[str] importedModules = [], list[str] initialDecls = []) = diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/compile/Compile.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/compile/Compile.rsc index 811e5136..bf38f978 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/compile/Compile.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/compile/Compile.rsc @@ -89,16 +89,27 @@ list[Message] compile1(str qualifiedModuleName, lang::rascal::\syntax::Rascal::M @doc{Compile a Rascal source module (given at a location) to Java} list[Message] compile(loc moduleLoc, PathConfig pcfg, CompilerConfig compilerConfig) { + + msgs = validatePathConfigForCompiler(pcfg, moduleLoc); + if(!isEmpty(msgs)){ + return msgs; + } + moduleName = "**unknown**"; try { moduleName = getModuleName(moduleLoc, pcfg); - return compile(moduleName, pcfg, compilerConfig); - } catch IO(msg): { - return [ error(msg, moduleLoc) ]; + } catch str e: { + return [ error("Cannot find name for location, reason: ", moduleLoc) ]; } + return compile(moduleName, pcfg, compilerConfig); } @doc{Compile a Rascal source module (given as qualifiedModuleName) to Java} list[Message] compile(str qualifiedModuleName, PathConfig pcfg, CompilerConfig compilerConfig){ + msgs = validatePathConfigForCompiler(pcfg, |unknown:///|); + if(!isEmpty(msgs)){ + return msgs; + } + jobStart("RascalCompiler");// TODO: monitor start_comp = cpuTime(); ms = rascalTModelForNames([qualifiedModuleName], rascalTypePalConfig(pcfg), compilerConfig, compile1); diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst5.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst5.rsc index 5d4f024d..1c3ed87b 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst5.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst5.rsc @@ -1,6 +1,13 @@ module lang::rascalcore::compile::Examples::Tst5 -import lang::rascalcore::compile::Examples::Tst4; +import lang::rascalcore::check::tests::StaticTestingUtils; -value main() = [S] "a"; \ No newline at end of file +value main() { + makeModule("RT", "import List; + 'int f(list[int] L) { + ' return size(L); + '} + '"); + return checkOK("f([1,2,3]);", importedModules=["RT"]); +} \ No newline at end of file