import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
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;
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;
import org.simantics.scl.compiler.module.repository.ImportFailure;
import org.simantics.scl.compiler.module.repository.ImportFailureException;
import org.simantics.scl.compiler.module.repository.ModuleRepository;
+import org.simantics.scl.compiler.module.repository.UpdateListener;
import org.simantics.scl.compiler.runtime.RuntimeEnvironment;
import org.simantics.scl.compiler.top.ExpressionEvaluator;
import org.simantics.scl.compiler.top.LocalStorage;
THashMap<String,Type> variableTypes = new THashMap<String,Type>();
PrintStream fileOutput;
+ private UpdateListener dependenciesListener;
/**
* Only checks the commands for compilation errors but does not run them.
*/
private boolean validateOnly;
+ public CommandSession(ModuleRepository moduleRepository) {
+ this(moduleRepository, SCLReporting.getCurrentReportingHandler());
+ }
+
public CommandSession(ModuleRepository moduleRepository, SCLReportingHandler handler) {
this.moduleRepository = moduleRepository;
this.defaultHandler = new PrintDecorator(
runtimeEnvironment = null;
try {
+ if(dependenciesListener != null)
+ dependenciesListener.stopListening();
try {
runtimeEnvironment = moduleRepository.createRuntimeEnvironment(
environmentSpecification,
- getClass().getClassLoader());
+ getClass().getClassLoader(),
+ dependenciesListener);
} catch(ImportFailureException e) {
THashSet<String> failedModules = new THashSet<String>();
for(ImportFailure failure : e.failures) {
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)
try {
runtimeEnvironment = moduleRepository.createRuntimeEnvironment(
environmentSpecification,
- getClass().getClassLoader());
+ getClass().getClassLoader()); // no listener here, because should listen also failed modules
} catch (ImportFailureException e1) {
for(ImportFailure failure : e1.failures)
defaultHandler.printError(failure.toString());
void finishBlock() {
if(currentBlock != null) {
checkInterrupted();
- LinkedList<Statement> statements = currentBlock.getStatements();
currentBlock.location = Locations.combine(
- statements.getFirst().location,
- statements.getLast().location);
+ currentBlock.getFirst().location,
+ currentBlock.getLast().location);
execute(reader, currentBlock, handler);
currentBlock = null;
}
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
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);
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);
}
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);
formatException(handler, e);
}
}
-
+
public static CompilationError[] validate(ModuleRepository moduleRepository,StringReader commandReader) {
CommandSession session = new CommandSession(moduleRepository, null);
return session.validate(commandReader);
return validate(new StringReader(command));
}
+ public void setDependenciesListener(UpdateListener dependenciesListener) {
+ this.dependenciesListener = dependenciesListener;
+ }
}