From: Hannu Niemistö Date: Thu, 15 Jun 2017 07:14:11 +0000 (+0300) Subject: (refs #7307) Added features field to SCL module header X-Git-Tag: v1.31.0~314^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=172abed5dbf73c1304a7a95bb8504ea293556948 (refs #7307) Added features field to SCL module header SCL language features are now enabled in the module header with syntax module { features = [chr, fields] } instead of module { chr, fields } Change-Id: Ibc533bc246efb29313e66576988913b09839b380 --- 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 80acf17c5..0ab17f834 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 @@ -12,6 +12,7 @@ public class ModuleHeader { public long classLoaderLocation; public String defaultLocalName; public List export; + // Features public boolean chr; public boolean fields; @@ -32,37 +33,47 @@ public class ModuleHeader { break; case "export": if(assignment.value == null) - errorLog.log(assignment.location, "Property export needs to be given a string list value."); + errorLog.log(assignment.location, "Property export needs to be given a list of exported symbols."); else { export = AnnotationUtils.extractIdentifierList(assignment.value); if(export == null) - errorLog.log(assignment.value.location, "Expected a list of exported items."); + errorLog.log(assignment.value.location, "Expected a list of exported symbols."); + } + break; + case "features": + if(assignment.value == null) + errorLog.log(assignment.location, "Property features needs to be given a list of features (identifiers)."); + else { + List features = AnnotationUtils.extractIdentifierList(assignment.value); + if(features == null) + errorLog.log(assignment.value.location, "Expected a list of features (identifiers)."); + for(EVar feature : features) + handleFeature(errorLog, feature); } break; case "defaultLocalName": - if(assignment.value == null) + 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; - case "fields": - if(assignment.value != null) - errorLog.log(assignment.location, "No value expected for property fields."); - this.fields = true; + else { + defaultLocalName = AnnotationUtils.extractString(assignment.value); + if(defaultLocalName == null) + errorLog.log(assignment.value.location, "Expected string here."); + } break; - case "chr": - if(assignment.value != null) - errorLog.log(assignment.location, "No value expected for property chr."); - this.chr = true; - break; default: errorLog.logWarning(assignment.location, "Unknown module header field was skipped."); } } + private void handleFeature(ErrorLog errorLog, EVar feature) { + switch(feature.name) { + case "chr": chr = true; break; + case "fields": fields = true; break; + default: + errorLog.log(feature.location, "Unknown feature " + feature.name + "."); + } + } + public static ModuleHeader process(ErrorLog errorLog, FieldAssignment[] fields) { if(fields == null) return null; diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR10.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR10.scl index 758074d32..8f587d508 100644 --- a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR10.scl +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR10.scl @@ -1,4 +1,4 @@ -module { export = [main], chr } +module { export = [main], features = [chr] } import "StandardLibrary" data V = V { x :: Double, y :: Double } @@ -17,7 +17,7 @@ main = () 4.0 () -- -module { export = [main], chr } +module { export = [main], features = [chr] } import "StandardLibrary" data V = V { x :: Double, y :: Double } diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR5.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR5.scl index c59c02dbb..6803c113e 100644 --- a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR5.scl +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR5.scl @@ -1,4 +1,4 @@ -module { export = [main], chr } +module { export = [main], features = [chr] } import "StandardLibrary" ruleset IntegerSet where diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR6.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR6.scl index f1e28d08a..76f0408a0 100644 --- a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR6.scl +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR6.scl @@ -1,4 +1,4 @@ -module { export = [main], chr } +module { export = [main], features = [chr] } import "StandardLibrary" ruleset RS where diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR7.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR7.scl index b10257ca8..6e878ebf4 100644 --- a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR7.scl +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR7.scl @@ -1,4 +1,4 @@ -module { export = [main], chr } +module { export = [main], features = [chr] } import "StandardLibrary" ruleset RS where diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR8.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR8.scl index c3a88f58a..dd915ebb5 100644 --- a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR8.scl +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR8.scl @@ -1,4 +1,4 @@ -module { export = [main], chr } +module { export = [main], features = [chr] } import "StandardLibrary" main = () diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR9.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR9.scl index 07514821a..427b8df6b 100644 --- a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR9.scl +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR9.scl @@ -1,4 +1,4 @@ -module { export = [main], chr } +module { export = [main], features = [chr] } import "StandardLibrary" main = () @@ -10,7 +10,7 @@ main = () 1.0 () -- -module { export = [main], chr } +module { export = [main], features = [chr] } import "StandardLibrary" main = () @@ -20,7 +20,7 @@ main = () -- 7:13-7:26: Field y not defined. -- -module { export = [main], chr } +module { export = [main], features = [chr] } import "StandardLibrary" @@ -31,7 +31,7 @@ main = () -- 8:13-8:35: Relation V does not define field names. -- -module { export = [main], chr } +module { export = [main], features = [chr] } import "StandardLibrary" diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/Record2.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/Record2.scl index de71cf487..352336ff3 100644 --- a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/Record2.scl +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/Record2.scl @@ -1,5 +1,5 @@ module { - fields + features = [fields] } import "Prelude"