From: Hannu Niemistö Date: Mon, 24 Apr 2017 05:58:38 +0000 (+0300) Subject: (refs #7105) Added defaultLocalName property to SCL modules X-Git-Tag: v1.29.0~89 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=c3945d04f5f0cff02b6d33d92d78325f53f121fa;p=simantics%2Fplatform.git (refs #7105) Added defaultLocalName property to SCL modules In textual modules defaultLocalName can be set in the module header. For ontology modules, use Ontology.defaultLocalName property. Change-Id: I2966c0b16e5d5f07c0e591a094f63908a7b492b3 --- diff --git a/bundles/org.simantics.layer0/graph.tg b/bundles/org.simantics.layer0/graph.tg index 053b27ddf..1d8b27562 100644 Binary files a/bundles/org.simantics.layer0/graph.tg and b/bundles/org.simantics.layer0/graph.tg differ diff --git a/bundles/org.simantics.layer0/graph/Layer0SCL.pgraph b/bundles/org.simantics.layer0/graph/Layer0SCL.pgraph index 88e081701..526139c0d 100644 --- a/bundles/org.simantics.layer0/graph/Layer0SCL.pgraph +++ b/bundles/org.simantics.layer0/graph/Layer0SCL.pgraph @@ -55,9 +55,11 @@ L0.Functions.clusterValidator : L0.Function L0.SCLModule -- L0.SCLModule.definition --> L0.String -- L0.SCLModule.alias --> L0.String -- L0.Ontology.defaultLocalName --> L0.String "Resource -> Resource -> ()" > childMaps = new THashMap>(); public OntologyModule(ReadGraph graph, String moduleName) throws DatabaseException { super(moduleName); ontology = graph.getResource(moduleName); + readDefaultLocalName(graph); childMaps.put(ontology, createLocalMap(graph, ontology)); } + + private void readDefaultLocalName(ReadGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + defaultLocalName = graph.getPossibleRelatedValue(ontology, L0.Ontology_defaultLocalName); + if(defaultLocalName == null) + defaultLocalName = ""; + } + + @Override + public String getDefaultLocalName() { + return defaultLocalName; + } @Override public List getDependencies() { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java index 898f6c0a5..c36564eda 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java @@ -159,6 +159,8 @@ public class Elaboration { module = new ConcreteModule(moduleName); compilationContext.module = module; + if(moduleHeader != null && moduleHeader.defaultLocalName != null) + module.setDefaultLocalName(moduleHeader.defaultLocalName); try { if(timer != null) timer.suspendTimer(); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/header/ModuleHeader.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/header/ModuleHeader.java index 9ca588779..7fec8f83c 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/header/ModuleHeader.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/header/ModuleHeader.java @@ -8,6 +8,7 @@ import org.simantics.scl.compiler.internal.parsing.declarations.DModuleHeader; public class ModuleHeader { public String classLoader; public long classLoaderLocation; + public String defaultLocalName; private void read(ErrorLog errorLog, DModuleHeader header) { for(FieldAssignment assignment : header.fields) @@ -23,6 +24,15 @@ public class ModuleHeader { classLoaderLocation = assignment.location; } break; + case "defaultLocalName": + if(assignment.value == null) + errorLog.log(assignment.location, "Property defaultLocalName needs to be given a string value."); + else { + defaultLocalName = AnnotationUtils.extractString(assignment.value); + if(defaultLocalName == null) + errorLog.log(assignment.value.location, "Expected string here."); + } + break; default: errorLog.logWarning(assignment.location, "Unknown module header field was skipped."); } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ConcreteModule.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ConcreteModule.java index 697e64ef8..55ee202f7 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ConcreteModule.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ConcreteModule.java @@ -31,6 +31,7 @@ import gnu.trove.procedure.TObjectProcedure; public class ConcreteModule implements Module { String moduleName; + String defaultLocalName; THashMap typeDescriptors = new THashMap(); THashMap effectConstructors = new THashMap(); THashMap typeClasses = new THashMap(); @@ -54,6 +55,15 @@ public class ConcreteModule implements Module { this.moduleName = moduleName; } + @Override + public String getDefaultLocalName() { + return defaultLocalName; + } + + public void setDefaultLocalName(String defaultLocalName) { + this.defaultLocalName = defaultLocalName; + } + public boolean addTypeDescriptor(String name, TypeDescriptor typeConstructor) { return typeDescriptors.put(name, typeConstructor) != null; } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/Module.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/Module.java index 6f13ed426..aff2e2d7f 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/Module.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/Module.java @@ -25,6 +25,7 @@ import gnu.trove.procedure.TObjectProcedure; public interface Module { String getName(); + String getDefaultLocalName(); SCLValue getValue(String name); SCLRelation getRelation(String name);