From: Hannu Niemistö Date: Mon, 30 Oct 2017 17:41:45 +0000 (+0200) Subject: Merge "Change universal type variables to existential in requested value types" X-Git-Tag: v1.31.0~79 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=331406ad9dfcb7332a645ddc7029a863ef064d2f;hp=41d461afeab1da2a4e10b726c5f2b14996706dcd Merge "Change universal type variables to existential in requested value types" --- diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/LoggingModule.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/LoggingModule.java index dadc13aa7..552c93f64 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/LoggingModule.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/LoggingModule.java @@ -4,6 +4,7 @@ import org.cojen.classfile.TypeDesc; import org.osgi.service.component.annotations.Component; import org.simantics.scl.compiler.commands.CommandSession; import org.simantics.scl.compiler.common.names.Name; +import org.simantics.scl.compiler.compilation.CompilationContext; import org.simantics.scl.compiler.constants.JavaMethod; import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext; import org.simantics.scl.compiler.elaboration.expressions.EApply; @@ -63,12 +64,7 @@ public class LoggingModule extends ConcreteModule { value.setMacroRule(new MacroRule() { @Override public Expression apply(SimplificationContext context, Type[] typeParameters, EApply apply) { - ConcreteModule module = context.getCompilationContext().module; - String identifier; - if (module != null) - identifier = module.getName().replaceAll("/", "."); - else - identifier = CommandSession.class.getName(); + String identifier = resolveModuleIdentifier(context.getCompilationContext()); apply.set(new ELiteral(javaMethod), new Expression[] { new EExternalConstant(LoggerFactory.getLogger(identifier), Logger) }); @@ -84,12 +80,7 @@ public class LoggingModule extends ConcreteModule { value.setMacroRule(new MacroRule() { @Override public Expression apply(SimplificationContext context, Type[] typeParameters, EApply apply) { - ConcreteModule module = context.getCompilationContext().module; - String identifier; - if (module != null) - identifier = module.getName().replaceAll("/", "."); - else - identifier = CommandSession.class.getName(); + String identifier = resolveModuleIdentifier(context.getCompilationContext()); apply.set(new ELiteral(javaMethod), new Expression[] { new EExternalConstant(LoggerFactory.getLogger(identifier), Logger), apply.parameters[0] @@ -106,12 +97,7 @@ public class LoggingModule extends ConcreteModule { value.setMacroRule(new MacroRule() { @Override public Expression apply(SimplificationContext context, Type[] typeParameters, EApply apply) { - ConcreteModule module = context.getCompilationContext().module; - String identifier; - if (module != null) - identifier = module.getName().replaceAll("/", "."); - else - identifier = CommandSession.class.getName(); + String identifier = resolveModuleIdentifier(context.getCompilationContext()); apply.set(new ELiteral(javaMethod), new Expression[] { new EExternalConstant(LoggerFactory.getLogger(identifier), Logger), apply.parameters[0], @@ -129,12 +115,7 @@ public class LoggingModule extends ConcreteModule { value.setMacroRule(new MacroRule() { @Override public Expression apply(SimplificationContext context, Type[] typeParameters, EApply apply) { - ConcreteModule module = context.getCompilationContext().module; - String identifier; - if (module != null) - identifier = module.getName().replaceAll("/", "."); - else - identifier = CommandSession.class.getName(); + String identifier = resolveModuleIdentifier(context.getCompilationContext()); apply.set(new ELiteral(javaMethod), new Expression[] { new EExternalConstant(LoggerFactory.getLogger(identifier), Logger), apply.parameters[0], @@ -152,12 +133,7 @@ public class LoggingModule extends ConcreteModule { value.setMacroRule(new MacroRule() { @Override public Expression apply(SimplificationContext context, Type[] typeParameters, EApply apply) { - ConcreteModule module = context.getCompilationContext().module; - String identifier; - if (module != null) - identifier = module.getName().replaceAll("/", "."); - else - identifier = CommandSession.class.getName(); + String identifier = resolveModuleIdentifier(context.getCompilationContext()); apply.set(new ELiteral(javaMethod), new Expression[] { new EExternalConstant(LoggerFactory.getLogger(identifier), Logger), apply.parameters[0], @@ -181,4 +157,19 @@ public class LoggingModule extends ConcreteModule { private static String capitalizeFirstCharacter(String input) { return input.substring(0, 1).toUpperCase() + input.substring(1); } + + private static String resolveModuleIdentifier(CompilationContext context) { + ConcreteModule module = context.module; + String identifier; + if (module != null) { + String moduleName = module.getName(); + if (moduleName.startsWith("http://")) { + moduleName = moduleName.substring("http://".length()); + } + identifier = moduleName.replaceAll("/", "."); + } else { + identifier = CommandSession.class.getName(); + } + return identifier; + } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/repository/ProceduralModuleSourceRepository.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/repository/ProceduralModuleSourceRepository.java index 4899f88ba..8d0d2e42e 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/repository/ProceduralModuleSourceRepository.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/repository/ProceduralModuleSourceRepository.java @@ -16,9 +16,13 @@ import org.simantics.scl.compiler.source.ModuleSource; import org.simantics.scl.compiler.source.PrecompiledModuleSource; import org.simantics.scl.compiler.source.repository.procedural.ProceduralValueDefinition; import org.simantics.scl.compiler.top.ValueNotFound; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public abstract class ProceduralModuleSourceRepository implements ModuleSourceRepository { + private static final Logger LOGGER = LoggerFactory.getLogger(ProceduralModuleSourceRepository.class); + public static final String PREFIX = "procedural:"; protected abstract ModuleRepository getModuleRepository(UpdateListener listener); @@ -44,6 +48,10 @@ public abstract class ProceduralModuleSourceRepository implements ModuleSourceRe try { values = sourceModule.getValue("values"); } catch (ValueNotFound e) { + return null; // normal + } catch (Throwable e) { + // abnormal exception + LOGGER.error("Failed to find value " + moduleName + "/values", e); return null; } diff --git a/bundles/org.simantics.scl.runtime/scl/MList.scl b/bundles/org.simantics.scl.runtime/scl/MList.scl index 6cafe6bf4..fc4f94114 100644 --- a/bundles/org.simantics.scl.runtime/scl/MList.scl +++ b/bundles/org.simantics.scl.runtime/scl/MList.scl @@ -9,6 +9,7 @@ importJava "java.util.List" where size :: T a -> Integer isEmpty :: T a -> Boolean get :: T a -> Integer -> a + set :: T a -> Integer -> a -> Maybe a add :: T a -> a -> () addAll :: T a -> [a] -> ()