From 66ced93f835205135a84fea73b2fbb8e9d610f7e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Wed, 1 Feb 2017 16:40:11 +0200 Subject: [PATCH] Added module header feature to SCL language. Module header must be in the beginning of the module. However, comments are allowed before the header. Header has the following form: module { field = value, field = value } Currently field name classLoader is supported. It makes it possible to specify which classLoader is used to resolve importJava declarations. module { classLoader = "my.bundle.name.somewhere" } refs #6931 Change-Id: Ibca2152597a738d1e4641cf6262af06069b38af5 --- .../modeling/internal/Activator.java | 7 +- .../scl/GraphModuleSourceRepository.java | 10 + .../modeling/scl/OntologyModule.java | 5 + .../DeclarationClassification.java | 8 + .../scl/compiler/compilation/Elaboration.java | 28 +- .../scl/compiler/compilation/SCLCompiler.java | 16 +- .../annotations/AnnotationUtils.java | 22 ++ .../compiler/elaboration/java/Builtins.java | 2 + .../compiler/elaboration/java/JavaModule.java | 2 + .../elaboration/java/MinigraphModule.java | 1 + .../types/DummyJavaReferenceValidator.java | 5 + .../codegen/types/JavaReferenceValidator.java | 2 + .../types/JavaReferenceValidatorFactory.java | 6 + .../types/RuntimeJavaReferenceValidator.java | 5 + .../internal/header/ModuleHeader.java | 38 +++ .../parsing/declarations/DModuleHeader.java | 36 +++ .../internal/parsing/parser/SCL.grammar | 3 +- .../internal/parsing/parser/SCLParser.dat | Bin 23238 -> 23580 bytes .../internal/parsing/parser/SCLParser.java | 281 +++++++++--------- .../parsing/parser/SCLParserImpl.java | 17 +- .../parsing/parser/SCLParserOptions.java | 6 + .../internal/parsing/parser/SCLPostLexer.java | 12 +- .../internal/parsing/parser/SCLTerminals.java | 159 +++++----- .../scl/compiler/module/ConcreteModule.java | 12 + .../simantics/scl/compiler/module/Module.java | 2 +- .../module/repository/ModuleRepository.java | 2 +- .../scl/compiler/runtime/RuntimeModule.java | 2 + .../compiler/source/TextualModuleSource.java | 21 +- .../scl/osgi/internal/BundleModuleSource.java | 4 + .../OsgiJavaReferenceValidatorFactory.java | 58 ++++ 30 files changed, 530 insertions(+), 242 deletions(-) create mode 100644 bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/types/JavaReferenceValidatorFactory.java create mode 100644 bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/header/ModuleHeader.java create mode 100644 bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/declarations/DModuleHeader.java create mode 100644 bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/OsgiJavaReferenceValidatorFactory.java diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/internal/Activator.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/internal/Activator.java index f090be06c..3fc0d46fa 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/internal/Activator.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/internal/Activator.java @@ -10,9 +10,12 @@ import org.simantics.scl.compiler.source.repository.ModuleSourceRepository; public class Activator implements BundleActivator { + private static BundleContext context; + @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void start(BundleContext context) throws Exception { + Activator.context = context; Hashtable properties = new Hashtable(); context.registerService(ModuleSourceRepository.class, OntologyModuleSourceRepository.INSTANCE, properties); @@ -23,5 +26,7 @@ public class Activator implements BundleActivator { public void stop(BundleContext context) throws Exception { } - + public static BundleContext getContext() { + return context; + } } diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphModuleSourceRepository.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphModuleSourceRepository.java index 07af09e55..c75f7a941 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphModuleSourceRepository.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphModuleSourceRepository.java @@ -15,11 +15,14 @@ import org.simantics.db.procedure.SyncListener; import org.simantics.db.request.Read; import org.simantics.layer0.Layer0; import org.simantics.modeling.ModelingUtils; +import org.simantics.modeling.internal.Activator; +import org.simantics.scl.compiler.internal.codegen.types.JavaReferenceValidatorFactory; import org.simantics.scl.compiler.module.repository.UpdateListener; import org.simantics.scl.compiler.module.repository.UpdateListener.Observable; import org.simantics.scl.compiler.source.ModuleSource; import org.simantics.scl.compiler.source.StringModuleSource; import org.simantics.scl.compiler.source.repository.ModuleSourceRepository; +import org.simantics.scl.osgi.internal.OsgiJavaReferenceValidatorFactory; import org.simantics.scl.runtime.SCLContext; import org.simantics.scl.runtime.tuple.Tuple0; import org.simantics.structural2.utils.StructuralUtils; @@ -29,6 +32,8 @@ import gnu.trove.set.hash.THashSet; public enum GraphModuleSourceRepository implements ModuleSourceRepository { INSTANCE; + + private static final OsgiJavaReferenceValidatorFactory REFERENCE_VALIDATOR_FACTORY = new OsgiJavaReferenceValidatorFactory(Activator.getContext().getBundle()); @Override public ModuleSource getModuleSource(final String moduleName, UpdateListener listener) { @@ -123,6 +128,11 @@ public enum GraphModuleSourceRepository implements ModuleSourceRepository { e.printStackTrace(); } } + + @Override + public JavaReferenceValidatorFactory getJavaReferenceValidatorFactory() { + return REFERENCE_VALIDATOR_FACTORY; + } } static class ReadModuleSource extends UnaryRead { diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/OntologyModule.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/OntologyModule.java index 17aba97ea..1c8c91927 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/OntologyModule.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/OntologyModule.java @@ -312,4 +312,9 @@ public class OntologyModule extends LazyModule { public String toString() { return new StringBuilder().append("OntologyModule ").append(getName()).toString(); } + + @Override + public ClassLoader getParentClassLoader() { + return getClass().getClassLoader(); + } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/DeclarationClassification.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/DeclarationClassification.java index 7c6d53ac8..652adf93e 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/DeclarationClassification.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/DeclarationClassification.java @@ -23,6 +23,7 @@ import org.simantics.scl.compiler.internal.parsing.declarations.DFixityAst; import org.simantics.scl.compiler.internal.parsing.declarations.DImportJavaAst; import org.simantics.scl.compiler.internal.parsing.declarations.DInstanceAst; import org.simantics.scl.compiler.internal.parsing.declarations.DMappingRelationAst; +import org.simantics.scl.compiler.internal.parsing.declarations.DModuleHeader; import org.simantics.scl.compiler.internal.parsing.declarations.DRelationAst; import org.simantics.scl.compiler.internal.parsing.declarations.DRuleAst; import org.simantics.scl.compiler.internal.parsing.declarations.DTypeAst; @@ -38,6 +39,7 @@ import org.simantics.scl.compiler.module.ImportDeclaration; import gnu.trove.map.hash.THashMap; public class DeclarationClassification { + DModuleHeader moduleHeader; ArrayList importsAst = new ArrayList(); ArrayList dataTypesAst = new ArrayList(); ArrayList typeAliasesAst = new ArrayList(); @@ -106,6 +108,8 @@ public class DeclarationClassification { handle((DMappingRelationAst)declaration); else if(declaration instanceof DRelationAst) handle((DRelationAst)declaration); + else if(declaration instanceof DModuleHeader) + handle((DModuleHeader)declaration); else throw new InternalCompilerError("Unknown declaration " + declaration.getClass().getSimpleName()); } @@ -380,6 +384,10 @@ public class DeclarationClassification { mappingRelationsAst.add(declaration); } + public void handle(DModuleHeader declaration) { + moduleHeader = declaration; + } + public void addValueDocumentation(String valueName, DDocumentationAst documentation) { DDocumentationAst oldDoc = valueDocumentation.put(valueName, documentation); if(oldDoc != null) { 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 0971641e8..5461d7a29 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 @@ -59,6 +59,7 @@ import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.effects.EffectConstructor; import org.simantics.scl.compiler.internal.codegen.effects.ThreadLocalVariable; import org.simantics.scl.compiler.internal.codegen.types.JavaReferenceValidator; +import org.simantics.scl.compiler.internal.codegen.types.JavaReferenceValidatorFactory; import org.simantics.scl.compiler.internal.codegen.types.JavaTypeTranslator; import org.simantics.scl.compiler.internal.codegen.types.StandardTypeConstructor; import org.simantics.scl.compiler.internal.codegen.utils.Constants; @@ -68,6 +69,7 @@ import org.simantics.scl.compiler.internal.deriving.InstanceDeriver; import org.simantics.scl.compiler.internal.deriving.InstanceDerivers; import org.simantics.scl.compiler.internal.elaboration.profiling.BranchPointInjector; import org.simantics.scl.compiler.internal.elaboration.utils.StronglyConnectedComponents; +import org.simantics.scl.compiler.internal.header.ModuleHeader; import org.simantics.scl.compiler.internal.parsing.declarations.ConstructorAst; import org.simantics.scl.compiler.internal.parsing.declarations.DAnnotationAst; import org.simantics.scl.compiler.internal.parsing.declarations.DClassAst; @@ -116,7 +118,9 @@ public class Elaboration { private final CompilationContext compilationContext; private final ErrorLog errorLog; private final String moduleName; + private final ModuleHeader moduleHeader; private final ArrayList importsAst; + private final JavaReferenceValidatorFactory jrvFactory; final JavaReferenceValidator javaReferenceValidator; private final ValueRepository valueDefinitionsAst; private final RelationRepository relationDefinitionsAst; @@ -131,18 +135,23 @@ public class Elaboration { THashMap classRefs = new THashMap(); THashMap branchPoints; - @SuppressWarnings("unchecked") public Elaboration(CompilationContext compilationContext, CompilationTimer timer, EnvironmentFactory localEnvironmentFactory, - String moduleName, ArrayList importsAst, - JavaReferenceValidator javaReferenceValidator, + String moduleName, ModuleHeader moduleHeader, ArrayList importsAst, + JavaReferenceValidatorFactory jrvFactory, ValueRepository valueDefinitionsAst, RelationRepository relationDefinitionsAst) { this.compilationContext = compilationContext; this.errorLog = compilationContext.errorLog; this.moduleName = moduleName; + this.moduleHeader = moduleHeader; importsAst = processRelativeImports(importsAst); this.importsAst = importsAst; - this.javaReferenceValidator = (JavaReferenceValidator)javaReferenceValidator; + this.jrvFactory = jrvFactory; + this.javaReferenceValidator = moduleHeader == null || moduleHeader.classLoader == null + ? jrvFactory.getDefaultJavaReferenceValidator() + : jrvFactory.getJavaReferenceValidator(moduleHeader.classLoader); + if(javaReferenceValidator == null) + errorLog.log(moduleHeader.classLoaderLocation, "Didn't find the specified class loader."); this.valueDefinitionsAst = valueDefinitionsAst; this.relationDefinitionsAst = relationDefinitionsAst; @@ -653,15 +662,12 @@ public class Elaboration { if(annotations != null) { for(DAnnotationAst annotation : annotations) if(annotation.id.text.equals("@JavaName")) { - Expression p0 = annotation.parameters[0]; - if(p0 instanceof EVar) - javaName = ((EVar)p0).name; - else if(p0 instanceof ELiteral) { - ELiteral lit = (ELiteral)p0; - javaName = ((StringConstant)lit.getValue()).getValue(); - } + String temp = AnnotationUtils.processStringAnnotation(errorLog, annotation); + if(temp != null) + javaName = temp; } else if(annotation.id.text.equals("@private")) { + AnnotationUtils.processTagAnnotation(errorLog, annotation); isPrivate = true; } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/SCLCompiler.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/SCLCompiler.java index 29136b609..65e89edf1 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/SCLCompiler.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/SCLCompiler.java @@ -8,9 +8,12 @@ import java.util.Map; import org.simantics.scl.compiler.environment.EnvironmentFactory; import org.simantics.scl.compiler.errors.ErrorLog; import org.simantics.scl.compiler.internal.codegen.types.JavaReferenceValidator; +import org.simantics.scl.compiler.internal.codegen.types.JavaReferenceValidatorFactory; +import org.simantics.scl.compiler.internal.header.ModuleHeader; import org.simantics.scl.compiler.internal.parsing.declarations.DeclarationAst; import org.simantics.scl.compiler.internal.parsing.exceptions.SCLSyntaxErrorException; import org.simantics.scl.compiler.internal.parsing.parser.SCLParserImpl; +import org.simantics.scl.compiler.internal.parsing.parser.SCLParserOptions; import org.simantics.scl.compiler.module.ConcreteModule; import org.simantics.scl.compiler.module.options.ModuleCompilationOptions; import org.simantics.scl.compiler.top.ModuleInitializer; @@ -29,8 +32,11 @@ public class SCLCompiler { private CompilationTimer timer; private ModuleCompilationOptions options; - public SCLCompiler(ModuleCompilationOptions options) { + JavaReferenceValidatorFactory jrvFactory; + + public SCLCompiler(ModuleCompilationOptions options, JavaReferenceValidatorFactory jrvFactory) { this.options = options == null ? ModuleCompilationOptions.STANDARD_OPTIONS : options; + this.jrvFactory = jrvFactory; } @SuppressWarnings("unchecked") @@ -38,6 +44,7 @@ public class SCLCompiler { if(SCLCompilerConfiguration.ENABLE_TIMING) initializeTiming(); try { SCLParserImpl parser = new SCLParserImpl(sourceReader); + parser.setParserOptions(SCLParserOptions.MODULE_DEFAULT); if(!parser.isEmpty()) for(DeclarationAst declaration : (ArrayList)parser.parseModule()) declarations.handle(declaration); @@ -61,16 +68,16 @@ public class SCLCompiler { public void compile( EnvironmentFactory localEnvironmentFactory, - String moduleName, - JavaReferenceValidator javaReferenceValidator) { + String moduleName) { try { if(hasErrors()) return; Elaboration elaboration = new Elaboration(compilationContext, timer, localEnvironmentFactory, moduleName, + ModuleHeader.process(compilationContext.errorLog, declarations.moduleHeader), declarations.importsAst, - javaReferenceValidator, + jrvFactory, declarations.valueDefinitionsAst, declarations.relationDefinitionsAst); if(options.computeCoverage) @@ -159,6 +166,7 @@ public class SCLCompiler { codeGeneration.externalConstants); module.setClasses(classes); + module.setParentClassLoader(elaboration.javaReferenceValidator.getClassLoader()); module.setModuleInitializer(moduleInitializer); module.setBranchPoints(elaboration.branchPoints); if(compilationContext.errorLog.hasErrorsOrWarnings()) diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/annotations/AnnotationUtils.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/annotations/AnnotationUtils.java index fb7334cd2..8cc088b95 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/annotations/AnnotationUtils.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/annotations/AnnotationUtils.java @@ -5,8 +5,30 @@ import org.simantics.scl.compiler.elaboration.expressions.ELiteral; import org.simantics.scl.compiler.elaboration.expressions.EStringLiteral; import org.simantics.scl.compiler.elaboration.expressions.EVar; import org.simantics.scl.compiler.elaboration.expressions.Expression; +import org.simantics.scl.compiler.errors.ErrorLog; +import org.simantics.scl.compiler.internal.parsing.declarations.DAnnotationAst; public class AnnotationUtils { + /** + * Processes an annotation of form + *
@Annotation "text"
+ * or + *
@Annotation text
+ */ + public static String processStringAnnotation(ErrorLog errorLog, DAnnotationAst annotation) { + if(annotation.parameters.length != 1) + errorLog.log(annotation.location, "Expected one string parameter for " + annotation.id.text); + String result = extractString(annotation.parameters[0]); + if(result == null) + errorLog.log(annotation.location, "Expected a string parameter for " + annotation.id.text); + return result; + } + + public static void processTagAnnotation(ErrorLog errorLog, DAnnotationAst annotation) { + if(annotation.parameters.length != 0) + errorLog.log(annotation.location, "Expected no parameters for " + annotation.id.text); + } + public static String extractString(Expression expression) { if(expression instanceof EVar) return ((EVar)expression).name; diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/Builtins.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/Builtins.java index 7935257ac..14808c820 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/Builtins.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/Builtins.java @@ -348,6 +348,8 @@ public class Builtins extends ConcreteModule { addValue("visitBranchPoint", VisitBranchPoint.INSTANCE); } + + setParentClassLoader(getClass().getClassLoader()); } @Override diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/JavaModule.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/JavaModule.java index cb39346e4..e412a1168 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/JavaModule.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/JavaModule.java @@ -137,6 +137,8 @@ public class JavaModule extends ConcreteModule { "java/lang/Object", "hashCode", Types.NO_EFFECTS, Types.INTEGER, A)); addValue("toString", new JavaMethod(true, "java/lang/Object", "toString", Types.NO_EFFECTS, Types.STRING, A)); + + setParentClassLoader(getClass().getClassLoader()); } static Expression createLiteral(FunctionValue value) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/MinigraphModule.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/MinigraphModule.java index 6bdaaea7b..434f2da6e 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/MinigraphModule.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/MinigraphModule.java @@ -282,6 +282,7 @@ public class MinigraphModule extends ConcreteModule { return new ResourceAttribute(name); } }); + setParentClassLoader(getClass().getClassLoader()); } private static class ResourceAttribute implements SCLEntityType.Attribute { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/types/DummyJavaReferenceValidator.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/types/DummyJavaReferenceValidator.java index 84289af0d..994e2d63f 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/types/DummyJavaReferenceValidator.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/types/DummyJavaReferenceValidator.java @@ -76,5 +76,10 @@ public enum DummyJavaReferenceValidator implements JavaReferenceValidator { * class is not found. */ ClassRef getClassRef(String className); + + ClassLoader getClassLoader(); } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/types/JavaReferenceValidatorFactory.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/types/JavaReferenceValidatorFactory.java new file mode 100644 index 000000000..55d42c289 --- /dev/null +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/types/JavaReferenceValidatorFactory.java @@ -0,0 +1,6 @@ +package org.simantics.scl.compiler.internal.codegen.types; + +public interface JavaReferenceValidatorFactory { + JavaReferenceValidator getJavaReferenceValidator(String context); + JavaReferenceValidator getDefaultJavaReferenceValidator(); +} diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/types/RuntimeJavaReferenceValidator.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/types/RuntimeJavaReferenceValidator.java index 8b36a8148..4ee0ab4f8 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/types/RuntimeJavaReferenceValidator.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/types/RuntimeJavaReferenceValidator.java @@ -14,5 +14,10 @@ public class RuntimeJavaReferenceValidator extends AbstractRuntimeJavaReferenceV public Class findClass(TypeDesc name) { return name.toClass(classLoader); } + + @Override + public ClassLoader getClassLoader() { + return classLoader; + } } 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 new file mode 100644 index 000000000..c49b49abe --- /dev/null +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/header/ModuleHeader.java @@ -0,0 +1,38 @@ +package org.simantics.scl.compiler.internal.header; + +import org.simantics.scl.compiler.elaboration.expressions.annotations.AnnotationUtils; +import org.simantics.scl.compiler.elaboration.expressions.records.FieldAssignment; +import org.simantics.scl.compiler.errors.ErrorLog; +import org.simantics.scl.compiler.internal.parsing.declarations.DModuleHeader; + +public class ModuleHeader { + public String classLoader; + public long classLoaderLocation; + + private void read(ErrorLog errorLog, DModuleHeader header) { + for(FieldAssignment assignment : header.fields) + switch(assignment.name) { + case "classLoader": + if(assignment.value == null) + errorLog.log(assignment.location, "Property classLoader needs to be given a string value."); + else { + classLoader = AnnotationUtils.extractString(assignment.value); + if(classLoader == null) + errorLog.log(assignment.value.location, "Expected bundle name here."); + else + classLoaderLocation = assignment.location; + } + break; + default: + errorLog.logWarning(assignment.location, "Unknown module header field was skipped."); + } + } + + public static ModuleHeader process(ErrorLog errorLog, DModuleHeader header) { + if(header == null) + return null; + ModuleHeader result = new ModuleHeader(); + result.read(errorLog, header); + return result; + } +} diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/declarations/DModuleHeader.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/declarations/DModuleHeader.java new file mode 100644 index 000000000..25d14e2d2 --- /dev/null +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/declarations/DModuleHeader.java @@ -0,0 +1,36 @@ +package org.simantics.scl.compiler.internal.parsing.declarations; + +import org.simantics.scl.compiler.elaboration.expressions.printing.ExpressionToStringVisitor; +import org.simantics.scl.compiler.elaboration.expressions.records.FieldAssignment; + + + +public class DModuleHeader extends DeclarationAst { + public final FieldAssignment[] fields; + + public DModuleHeader(FieldAssignment[] fields) { + this.fields = fields; + } + + @Override + public void toString(int indentation, StringBuilder b) { + for(int i=0;iilo-2CUB{>iEYzrn^b8PE=|*FB4KT#T*9(@`v0FZ=g!RC2kyY0^ZTCX zdz{ytnYjxi;>y{;X}Ha+qaTQj-YY^n>KV_=6S3{9o{nA*3O;H8tOacG_I1r7b@Ku1 z08e>{=AkWyx?Ljm!w~mgud8o`j2!iEiZqP!K--2zzP({R_^%-s`qr>lq;agspyi;8 zK_B)ujn6{<5qR{sX(?<`n%))}yAKTe%>p`pC+OK825-tzNNx(oP@hhpZAAJjL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C;^TPeHv={&#@cZm*9FVG{m5_;Bq= zC<$z&%ykomTw`wL$+w1FBgQu$#zn*59n@QLZk^2-v%6bW$yb!N@o(MP;#}MKclWWi zodzb>pzWHd%&nnqgX-G86vy&4jH)*L--3}^+s}2RoqtCkTRZ=*KiAri%LyZ}?N<~B z+HWn&d8z&0yrg{l*CTx-daP!yS(pr!>?%*0KYy z?`$1-7h&t<|5ad%dt`eNbg|x@2L~xb`EwHEcH;kVMT0Bo(SI3b!$K)M2tAydsXv6ub`^FGmUmTJpD7v03 z=IDAZvon4i|A$3mi*pLz^*&9NPc8oMmtt2pWvD% zG`9Rbp>eD(=hhu^=kjo$3e9Yd+PxsoJ=nGbP@4tJ*~XC>$0+mQV|p32>y(HlPjyVE`69^$8zU+DhDpX>0= z21fB&=)MQru7uuGF#3b!e0PZdvHPi?=XZk~ykQZ3@33 zw{b__oOyC!=@ehzF~6jAMmF;u?-+Ip@1MyDpt!zm9vMxR?kKlA-Ykb-H=-76UVTWHh-T=V#f$v090-(L9!%C}R3y$SPe zxK-dAE`e{fBLUxd`KE2aH(|bY6Zm#a;2SvKnE4jo2-Bha{{X(d^X;F&H+sI=^9`SG z`h4T(w*vOf0KXkD;5P&OhJfD`3Jp&>sP|A*zo6 diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/parser/SCLParser.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/parser/SCLParser.java index 6c8ee5be9..362bc5142 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/parser/SCLParser.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/parser/SCLParser.java @@ -13,18 +13,18 @@ public abstract class SCLParser { public static final boolean TRACE = false; private static final int INITIAL_CAPACITY = 16; - private static final int STATE_COUNT = 344; - private static final int TERMINAL_COUNT = 82; + private static final int STATE_COUNT = 349; + private static final int TERMINAL_COUNT = 83; private static final int NONTERMINAL_COUNT = 51; - private static final int PRODUCT_COUNT = 132; + private static final int PRODUCT_COUNT = 133; private static final int[] ACTION_ROW_ID = new int[STATE_COUNT]; private static final int[] ACTION_COLUMN_ID = new int[TERMINAL_COUNT]; - private static final short[] ACTION_TABLE = new short[6120]; - private static final int[] ERROR_TABLE = new int[882]; + private static final short[] ACTION_TABLE = new short[6396]; + private static final int[] ERROR_TABLE = new int[906]; private static final int[] GOTO_ROW_ID = new int[STATE_COUNT]; private static final int[] GOTO_COLUMN_ID = new int[NONTERMINAL_COUNT]; - private static final short[] GOTO_TABLE = new short[1829]; + private static final short[] GOTO_TABLE = new short[1652]; private static final int[] PRODUCT_LHS = new int[PRODUCT_COUNT]; private static final short STATE_MASK = (short)0x0fff; @@ -38,6 +38,7 @@ public abstract class SCLParser { "SEMICOLON", "LBRACE", "RBRACE", + "MODULE", "COMMA", "HASTYPE", "DATA", @@ -130,6 +131,7 @@ public abstract class SCLParser { "command", "statement", "declarations", + "field", "var", "bexp", "rhs", @@ -156,7 +158,6 @@ public abstract class SCLParser { "stringLiteral", "symbolWithoutMinus", "listQualifier", - "field", "chrQuery", "verboseChrQuery", "caseRhs", @@ -392,19 +393,19 @@ public abstract class SCLParser { return parse(0); } public Object parseCommands() { - return parse(329); + return parse(334); } public Object parseImport() { - return parse(336); + return parse(341); } public Object parseType() { - return parse(338); + return parse(343); } public Object parseExp() { - return parse(340); + return parse(345); } public Object parseEquationBlock() { - return parse(342); + return parse(347); } @@ -428,240 +429,242 @@ public abstract class SCLParser { case 7: return reduceEquationBlock(); case 8: - return reduceTypeAnnotation(); + return reduceModuleHeader(); case 9: - return reduceValueDefinition(); + return reduceTypeAnnotation(); case 10: - return reduceDataDefinition(); + return reduceValueDefinition(); case 11: - return reduceTypeDefinition(); + return reduceDataDefinition(); case 12: - return reduceClassDefinition(); + return reduceTypeDefinition(); case 13: - return reduceInstanceDefinition(); + return reduceClassDefinition(); case 14: - return reduceDerivingInstanceDefinition(); + return reduceInstanceDefinition(); case 15: - return reduceDocumentationString(); + return reduceDerivingInstanceDefinition(); case 16: - return reduceAnnotation(); + return reduceDocumentationString(); case 17: - return reducePrecedenceDefinition(); + return reduceAnnotation(); case 18: - return reduceJustImport(); + return reducePrecedenceDefinition(); case 19: - return reduceImportJava(); + return reduceJustImport(); case 20: - return reduceEffectDefinition(); + return reduceImportJava(); case 21: - return reduceRuleDefinition(); + return reduceEffectDefinition(); case 22: - return reduceMappingRelationDefinition(); + return reduceRuleDefinition(); case 23: - return reduceRelationDefinition(); + return reduceMappingRelationDefinition(); case 24: - return reduceStatementCommand(); + return reduceRelationDefinition(); case 25: - return reduceImportCommand(); + return reduceStatementCommand(); case 26: - return reduceGuardStatement(); + return reduceImportCommand(); case 27: - return reduceLetStatement(); + return reduceGuardStatement(); case 28: - return reduceBindStatement(); + return reduceLetStatement(); case 29: - return reduceRuleStatement(); + return reduceBindStatement(); case 30: - return reduceCHRStatement(); + return reduceRuleStatement(); case 31: - return reduceVerboseCHRStatement(); + return reduceCHRStatement(); case 32: - return reduceConstraintStatement(); + return reduceVerboseCHRStatement(); case 33: - return reduceDeclarations(); + return reduceConstraintStatement(); case 34: - return reduceVarId(); + return reduceDeclarations(); case 35: - return reduceEscapedSymbol(); + return reduceField(); case 36: - return reduceTupleConstructor(); + return reduceFieldShorthand(); case 37: - return reduceBinary(); + return reduceVarId(); case 38: - return reduceSimpleRhs(); + return reduceEscapedSymbol(); case 39: - return reduceGuardedRhs(); + return reduceTupleConstructor(); case 40: - return reduceConstructor(); + return reduceBinary(); case 41: - return reduceRecordConstructor(); + return reduceSimpleRhs(); case 42: - return reduceContext(); + return reduceGuardedRhs(); case 43: - return reduceFundeps(); + return reduceConstructor(); case 44: - return reduceTypeVar(); + return reduceRecordConstructor(); case 45: - return reduceTupleType(); + return reduceContext(); case 46: - return reduceListType(); + return reduceFundeps(); case 47: - return reduceListTypeConstructor(); + return reduceTypeVar(); case 48: - return reduceTupleTypeConstructor(); + return reduceTupleType(); case 49: - return reduceLambda(); + return reduceListType(); case 50: - return reduceLambdaMatch(); + return reduceListTypeConstructor(); case 51: - return reduceLet(); + return reduceTupleTypeConstructor(); case 52: - return reduceIf(); + return reduceLambda(); case 53: - return reduceMatch(); + return reduceLambdaMatch(); case 54: - return reduceDo(); + return reduceLet(); case 55: - return reduceSelect(); + return reduceIf(); case 56: - return reduceEnforce(); + return reduceMatch(); case 57: - return reduceVar(); + return reduceDo(); case 58: - return reduceHashedId(); + return reduceSelect(); case 59: - return reduceBlank(); + return reduceEnforce(); case 60: - return reduceInteger(); + return reduceVar(); case 61: - return reduceFloat(); + return reduceHashedId(); case 62: - return reduceString(); + return reduceBlank(); case 63: - return reduceChar(); + return reduceInteger(); case 64: - return reduceTuple(); + return reduceFloat(); case 65: - return reduceViewPattern(); + return reduceString(); case 66: - return reduceRightSection(); + return reduceChar(); case 67: - return reduceLeftSection(); + return reduceTuple(); case 68: - return reduceListLiteral(); + return reduceViewPattern(); case 69: - return reduceRange(); + return reduceRightSection(); case 70: - return reduceListComprehension(); + return reduceLeftSection(); case 71: - return reduceAs(); + return reduceListLiteral(); case 72: - return reduceRecord(); + return reduceRange(); case 73: - return reduceTransformation(); + return reduceListComprehension(); case 74: - return reduceEq(); + return reduceAs(); case 75: - return reduceRuleDeclarations(); + return reduceRecord(); case 76: - return reduceImportShowing(); + return reduceTransformation(); case 77: - return reduceImportHiding(); + return reduceEq(); case 78: - return reduceImportValueItem(); + return reduceRuleDeclarations(); case 79: - return reduceFieldDescription(); + return reduceImportShowing(); case 80: - return reduceStatements(); + return reduceImportHiding(); case 81: - return reduceGuardedExpEq(); + return reduceImportValueItem(); case 82: - return reduceFundep(); + return reduceFieldDescription(); case 83: - return reduceQueryRuleDeclaration(); + return reduceStatements(); case 84: - return reduceAnnotation(); + return reduceGuardedExpEq(); case 85: - return reduceGuardQuery(); + return reduceFundep(); case 86: - return reduceEqualsQuery(); + return reduceQueryRuleDeclaration(); case 87: - return reduceBindQuery(); + return reduceAnnotation(); case 88: - return reduceCompositeQuery(); + return reduceGuardQuery(); case 89: - return reduceQueryBlock(); + return reduceEqualsQuery(); case 90: - return reduceApply(); + return reduceBindQuery(); case 91: - return reduceSymbol(); + return reduceCompositeQuery(); case 92: - return reduceEscapedId(); + return reduceQueryBlock(); case 93: - return reduceMinus(); + return reduceApply(); case 94: - return reduceLess(); + return reduceSymbol(); case 95: - return reduceGreater(); + return reduceEscapedId(); case 96: - return reduceDot(); + return reduceMinus(); case 97: - return reduceFieldAccess(); + return reduceLess(); case 98: - return reduceIdAccessor(); + return reduceGreater(); case 99: - return reduceStringAccessor(); + return reduceDot(); case 100: - return reduceExpAccessor(); + return reduceFieldAccess(); case 101: - return reduceCase(); + return reduceIdAccessor(); case 102: - return reduceStringLiteral(); + return reduceStringAccessor(); case 103: - return reduceSymbol(); + return reduceExpAccessor(); case 104: - return reduceEscapedId(); + return reduceCase(); case 105: - return reduceLess(); + return reduceStringLiteral(); case 106: - return reduceGreater(); + return reduceSymbol(); case 107: - return reduceDot(); + return reduceEscapedId(); case 108: - return reduceGuardQualifier(); + return reduceLess(); case 109: - return reduceLetQualifier(); + return reduceGreater(); case 110: - return reduceBindQualifier(); + return reduceDot(); case 111: - return reduceThenQualifier(); + return reduceGuardQualifier(); case 112: - return reduceField(); + return reduceLetQualifier(); case 113: - return reduceFieldShorthand(); + return reduceBindQualifier(); case 114: - return reduceCHRQuery(); + return reduceThenQualifier(); case 115: - return reduceVerboseCHRQuery(); + return reduceCHRQuery(); case 116: - return reduceSimpleCaseRhs(); + return reduceVerboseCHRQuery(); case 117: - return reduceGuardedCaseRhs(); + return reduceSimpleCaseRhs(); case 118: - return reduceGuardedExpArrow(); + return reduceGuardedCaseRhs(); case 119: - return reduceGuardEquation(); + return reduceGuardedExpArrow(); case 120: - return reduceBasicEquation(); + return reduceGuardEquation(); case 121: - return reduceEffect(); + return reduceBasicEquation(); case 122: - return reduceJustEtype(); + return reduceEffect(); case 123: - return reduceForAll(); + return reduceJustEtype(); case 124: - return reduceApplyType(); + return reduceForAll(); case 125: + return reduceApplyType(); + case 126: return reduceDummy(); default: @@ -714,6 +717,10 @@ public abstract class SCLParser { * equationBlock ::= (equation (SEMICOLON equation)*)? */ protected abstract Object reduceEquationBlock(); + /** + * declaration ::= MODULE LBRACE (field (COMMA field)*)? RBRACE + */ + protected abstract Object reduceModuleHeader(); /** * declaration ::= (var COMMA)* var HASTYPE type */ @@ -818,6 +825,14 @@ public abstract class SCLParser { * declarations ::= LBRACE (declaration (SEMICOLON (declaration SEMICOLON)* declaration)?)? RBRACE */ protected abstract Object reduceDeclarations(); + /** + * field ::= ID EQUALS exp + */ + protected abstract Object reduceField(); + /** + * field ::= ID + */ + protected abstract Object reduceFieldShorthand(); /** * var ::= ID */ @@ -1106,14 +1121,6 @@ public abstract class SCLParser { * listQualifier ::= THEN exp (BY exp)? */ protected abstract Object reduceThenQualifier(); - /** - * field ::= ID EQUALS exp - */ - protected abstract Object reduceField(); - /** - * field ::= ID - */ - protected abstract Object reduceFieldShorthand(); /** * chrQuery ::= (listQualifier COMMA)* listQualifier */ diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/parser/SCLParserImpl.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/parser/SCLParserImpl.java index 5498b16b5..90c801403 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/parser/SCLParserImpl.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/parser/SCLParserImpl.java @@ -87,6 +87,7 @@ import org.simantics.scl.compiler.internal.parsing.declarations.DFixityAst; import org.simantics.scl.compiler.internal.parsing.declarations.DImportJavaAst; import org.simantics.scl.compiler.internal.parsing.declarations.DInstanceAst; import org.simantics.scl.compiler.internal.parsing.declarations.DMappingRelationAst; +import org.simantics.scl.compiler.internal.parsing.declarations.DModuleHeader; import org.simantics.scl.compiler.internal.parsing.declarations.DRelationAst; import org.simantics.scl.compiler.internal.parsing.declarations.DRuleAst; import org.simantics.scl.compiler.internal.parsing.declarations.DTypeAst; @@ -155,10 +156,22 @@ public class SCLParserImpl extends SCLParser { @Override protected Object reduceModule() { ArrayList declarations = new ArrayList(length()/2+1); - for(int i=0;i classes = Collections.emptyMap(); + ClassLoader parentClassLoader; ModuleInitializer moduleInitializer; protected Documentation documentation; @@ -278,4 +279,15 @@ public class ConcreteModule implements Module { public CompilationError[] getWarnings() { return warnings; } + + @Override + public ClassLoader getParentClassLoader() { + return parentClassLoader; + } + + public void setParentClassLoader(ClassLoader parentClassLoader) { + if(parentClassLoader == null) + throw new NullPointerException(); + this.parentClassLoader = parentClassLoader; + } } 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 180509521..6f13ed426 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 @@ -54,5 +54,5 @@ public interface Module { void dispose(); CompilationError[] getWarnings(); - + ClassLoader getParentClassLoader(); } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/repository/ModuleRepository.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/repository/ModuleRepository.java index 7170b992b..40c69f434 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/repository/ModuleRepository.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/repository/ModuleRepository.java @@ -173,7 +173,7 @@ public class ModuleRepository { if(parentModule != null) parentModules.add(parentModule); }*/ - RuntimeModule rm = new RuntimeModule(module, parentModules, source.getClassLoader()); + RuntimeModule rm = new RuntimeModule(module, parentModules, module.getParentClassLoader()); ModuleInitializer initializer = module.getModuleInitializer(); if(initializer != null) try { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/runtime/RuntimeModule.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/runtime/RuntimeModule.java index 2415e6520..93ecb2f17 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/runtime/RuntimeModule.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/runtime/RuntimeModule.java @@ -209,6 +209,8 @@ public class RuntimeModule { public RuntimeModule(Module module, RuntimeModuleMap parentModuleMap, ClassLoader parentClassLoader) { + if(parentClassLoader == null) + throw new NullPointerException(); this.module = module; this.parentModuleMap = parentModuleMap; this.classLoader = new ModuleClassLoader(parentClassLoader); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/TextualModuleSource.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/TextualModuleSource.java index 4f22022e5..9a6f4c97f 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/TextualModuleSource.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/TextualModuleSource.java @@ -11,6 +11,7 @@ import org.simantics.scl.compiler.errors.Failable; import org.simantics.scl.compiler.errors.Failure; import org.simantics.scl.compiler.errors.Success; import org.simantics.scl.compiler.internal.codegen.types.JavaReferenceValidator; +import org.simantics.scl.compiler.internal.codegen.types.JavaReferenceValidatorFactory; import org.simantics.scl.compiler.internal.codegen.types.RuntimeJavaReferenceValidator; import org.simantics.scl.compiler.module.ImportDeclaration; import org.simantics.scl.compiler.module.Module; @@ -80,7 +81,7 @@ public abstract class TextualModuleSource implements ModuleSource { @SuppressWarnings("unchecked") @Override public Failable compileModule(final ModuleRepository environment, final UpdateListener listener, ModuleCompilationOptions options) { - SCLCompiler compiler = new SCLCompiler(options); + SCLCompiler compiler = new SCLCompiler(options, getJavaReferenceValidatorFactory()); try { compiler.addSource(getSourceReader(listener)); compiler.compile( @@ -88,8 +89,7 @@ public abstract class TextualModuleSource implements ModuleSource { environment, getBuiltinImports(listener), listener), - moduleName, - getJavaReferenceValidator()); + moduleName); if(compiler.getErrorLog().hasNoErrors()) return new Success(compiler.getModule()); else { @@ -102,6 +102,21 @@ public abstract class TextualModuleSource implements ModuleSource { } } + public JavaReferenceValidatorFactory getJavaReferenceValidatorFactory() { + return new JavaReferenceValidatorFactory() { + + @Override + public JavaReferenceValidator getJavaReferenceValidator(String context) { + return (JavaReferenceValidator)TextualModuleSource.this.getJavaReferenceValidator(); + } + + @Override + public JavaReferenceValidator getDefaultJavaReferenceValidator() { + return (JavaReferenceValidator)TextualModuleSource.this.getJavaReferenceValidator(); + } + }; + } + @Override public double getPriority() { return priority; diff --git a/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/BundleModuleSource.java b/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/BundleModuleSource.java index 244c7463f..3213cf9b5 100644 --- a/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/BundleModuleSource.java +++ b/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/BundleModuleSource.java @@ -15,6 +15,7 @@ import java.util.Arrays; import org.eclipse.core.runtime.FileLocator; import org.osgi.framework.Bundle; import org.osgi.framework.wiring.BundleWiring; +import org.simantics.scl.compiler.internal.codegen.types.JavaReferenceValidatorFactory; import org.simantics.scl.compiler.module.ImportDeclaration; import org.simantics.scl.compiler.module.repository.UpdateListener; import org.simantics.scl.compiler.source.EncodedTextualModuleSource; @@ -161,4 +162,7 @@ public class BundleModuleSource extends EncodedTextualModuleSource implements Up } } + public JavaReferenceValidatorFactory getJavaReferenceValidatorFactory() { + return new OsgiJavaReferenceValidatorFactory(bundle); + } } diff --git a/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/OsgiJavaReferenceValidatorFactory.java b/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/OsgiJavaReferenceValidatorFactory.java new file mode 100644 index 000000000..03524e883 --- /dev/null +++ b/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/OsgiJavaReferenceValidatorFactory.java @@ -0,0 +1,58 @@ +package org.simantics.scl.osgi.internal; + +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.wiring.BundleWiring; +import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; +import org.simantics.scl.compiler.internal.codegen.types.JavaReferenceValidator; +import org.simantics.scl.compiler.internal.codegen.types.JavaReferenceValidatorFactory; +import org.simantics.scl.compiler.internal.codegen.types.RuntimeJavaReferenceValidator; +import org.simantics.scl.compiler.types.Type; + +public class OsgiJavaReferenceValidatorFactory implements JavaReferenceValidatorFactory { + + private final Bundle bundle; + + public OsgiJavaReferenceValidatorFactory(Bundle bundle) { + this.bundle = bundle; + } + + private static ClassLoader getClassLoader(Bundle bundle) { + if(bundle.getSymbolicName().equals("org.simantics.scl.runtime")) + return Type.class.getClassLoader(); + else { + BundleWiring wiring = bundle.adapt(BundleWiring.class); + if(wiring != null) + return wiring.getClassLoader(); + throw new InternalCompilerError("Cannot get the class loader for bundle " + bundle.getSymbolicName() + "."); + } + } + + private static JavaReferenceValidator getJavaReferenceValidator(Bundle bundle) { + if(bundle == null) + return null; + return (JavaReferenceValidator) + (JavaReferenceValidator)new RuntimeJavaReferenceValidator(getClassLoader(bundle)); + } + + private static Bundle getBundle(BundleContext bundleContext, String symbolicName) { + Bundle result = null; + for (Bundle candidate : bundleContext.getBundles()) + if (candidate.getSymbolicName().equals(symbolicName)) + if (result == null || result.getVersion().compareTo(candidate.getVersion()) < 0) + result = candidate; + return result; + } + + @Override + public JavaReferenceValidator getJavaReferenceValidator(String bundleName) { + System.out.println("getJavaReferenceValidator(" + bundleName + ")"); + return getJavaReferenceValidator(getBundle(bundle.getBundleContext(), bundleName)); + } + + @Override + public JavaReferenceValidator getDefaultJavaReferenceValidator() { + return getJavaReferenceValidator(bundle); + } + +} -- 2.43.2