X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Fcommands%2FCommandSession.java;h=06853c898a7fe30895cfce8d4e3f0ff5abfb0f21;hp=d7f1aa11e568c2d5e1351c973e5022cb9a49eb5d;hb=6a8b529bc5ceff5f1455968c03e65d140ffb6e39;hpb=1941a8f086ccdc3017c84dd149418114a499aee4 diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/commands/CommandSession.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/commands/CommandSession.java index d7f1aa11e..06853c898 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/commands/CommandSession.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/commands/CommandSession.java @@ -17,6 +17,7 @@ import java.util.Set; import org.simantics.scl.compiler.common.names.Names; import org.simantics.scl.compiler.constants.StringConstant; +import org.simantics.scl.compiler.dynamic.SafeDynamic; import org.simantics.scl.compiler.elaboration.expressions.EApply; import org.simantics.scl.compiler.elaboration.expressions.EBlock; import org.simantics.scl.compiler.elaboration.expressions.EConstant; @@ -32,6 +33,7 @@ import org.simantics.scl.compiler.environment.Environment; import org.simantics.scl.compiler.environment.LocalEnvironment; import org.simantics.scl.compiler.environment.specification.EnvironmentSpecification; import org.simantics.scl.compiler.errors.CompilationError; +import org.simantics.scl.compiler.errors.ErrorSeverity; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.utils.NameMangling; import org.simantics.scl.compiler.internal.parsing.exceptions.SCLSyntaxErrorException; @@ -56,6 +58,8 @@ import org.simantics.scl.runtime.reporting.DelegatingSCLReportingHandler; import org.simantics.scl.runtime.reporting.SCLReporting; import org.simantics.scl.runtime.reporting.SCLReportingHandler; import org.simantics.scl.runtime.tuple.Tuple0; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import gnu.trove.map.hash.THashMap; import gnu.trove.procedure.TObjectProcedure; @@ -64,6 +68,8 @@ import gnu.trove.set.hash.THashSet; public class CommandSession { + private static final Logger LOGGER = LoggerFactory.getLogger(CommandSession.class); + ModuleRepository moduleRepository; SCLReportingHandler defaultHandler; @@ -83,6 +89,10 @@ public class CommandSession { */ private boolean validateOnly; + public CommandSession(ModuleRepository moduleRepository) { + this(moduleRepository, SCLReporting.getCurrentReportingHandler()); + } + public CommandSession(ModuleRepository moduleRepository, SCLReportingHandler handler) { this.moduleRepository = moduleRepository; this.defaultHandler = new PrintDecorator( @@ -123,7 +133,8 @@ public class CommandSession { defaultHandler.printError(failure.toString()); if(failure.reason instanceof CompilationError[]) for(CompilationError error : (CompilationError[])failure.reason) { - defaultHandler.printError(" " + error.description); + if(error.severity != ErrorSeverity.WARNING) + defaultHandler.printError(" " + error.description); } } for(CommandSessionImportEntry entry : importEntries) @@ -140,7 +151,7 @@ public class CommandSession { } } } catch(RuntimeException e) { - e.printStackTrace(); + LOGGER.error("updateRuntimeEnvironment(clearErrorsFlags={}) failed", clearErrorsFlags, e); throw e; } valueToStringConverter = new ValueToStringConverter(runtimeEnvironment); @@ -511,7 +522,7 @@ public class CommandSession { if(e.location != Locations.NO_LOCATION) handler.printError(parser.reader.locationUnderlining(e.location)); handler.printError(e.getMessage()); - } catch(Exception e) { + } catch (Exception | AssertionError e) { if(e instanceof InterruptedException) handler.printError("Execution interrupted."); else @@ -598,7 +609,9 @@ public class CommandSession { b.append("\tat "); if("_SCL_Module".equals(fileName) || "_SCL_TypeClassInstance".equals(fileName)) - b.append(NameMangling.demangle(methodName)) + b.append(className) + .append('.') + .append(NameMangling.demangle(methodName)) .append('(').append(element.getLineNumber()).append(')'); else b.append(element); @@ -611,6 +624,11 @@ public class CommandSession { variableTypes.put(name, type); } + public void setVariable(String name, SafeDynamic typeAndValue) { + variableValues.put(name, typeAndValue.value); + variableTypes.put(name, typeAndValue.type_); + } + public Object getVariableValue(String name) { return variableValues.get(name); } @@ -619,6 +637,14 @@ public class CommandSession { return variableTypes.get(name); } + public SafeDynamic getVariableValueAndType(String name) { + Type type = variableTypes.get(name); + if(type == null) + return null; + Object value = variableValues.get(name); + return new SafeDynamic(type, value); + } + public void removeVariable(String name) { variableValues.remove(name); variableTypes.remove(name); @@ -655,7 +681,7 @@ public class CommandSession { formatException(handler, e); } } - + public static CompilationError[] validate(ModuleRepository moduleRepository,StringReader commandReader) { CommandSession session = new CommandSession(moduleRepository, null); return session.validate(commandReader);