Merge "(refs #7307) Added features field to SCL module header"
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 15 Jun 2017 07:45:30 +0000 (10:45 +0300)
committerGerrit Code Review <gerrit2@www.simantics.org>
Thu, 15 Jun 2017 07:45:30 +0000 (10:45 +0300)
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/header/ModuleHeader.java
tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR10.scl
tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR5.scl
tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR6.scl
tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR7.scl
tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR8.scl
tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR9.scl
tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/Record2.scl

index 80acf17c571cb242e2db401233525006f118908d..0ab17f83478313ee3f5df5209850ce3178b198ef 100644 (file)
@@ -12,6 +12,7 @@ public class ModuleHeader {
     public long classLoaderLocation;
     public String defaultLocalName;
     public List<EVar> 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<EVar> 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;
index 758074d32dbfd0c6d83348ec3d3b49341264c8b1..8f587d508aeedb2a0beff3cb32ee7d77a7adb41f 100644 (file)
@@ -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 }
index c59c02dbb2b3a65cefd61c6266e5a3d94b71043d..6803c113ed039d418a2c0ce7f86df32c1b8de69c 100644 (file)
@@ -1,4 +1,4 @@
-module { export = [main], chr }
+module { export = [main], features = [chr] }
 import "StandardLibrary"
 
 ruleset IntegerSet where
index f1e28d08a157bfb9ca324cd7ef6ce58c1aee1d93..76f0408a0a5773001fd9b1f4168b52d5c8d62a53 100644 (file)
@@ -1,4 +1,4 @@
-module { export = [main], chr }
+module { export = [main], features = [chr] }
 import "StandardLibrary"
 
 ruleset RS where
index b10257ca89a4144dcfbb75fbf001c6e129d918b4..6e878ebf45ac8c32ae3c705ce9800019f29452ea 100644 (file)
@@ -1,4 +1,4 @@
-module { export = [main], chr }
+module { export = [main], features = [chr] }
 import "StandardLibrary"
 
 ruleset RS where
index c3a88f58a7199f59ccde3a512046d978ad3fe7bd..dd915ebb5d10b971f5ec7cccc8cc3d7440a16cca 100644 (file)
@@ -1,4 +1,4 @@
-module { export = [main], chr }
+module { export = [main], features = [chr] }
 import "StandardLibrary"
 
 main = ()
index 07514821a38342bc720b20a17aa6c58e2753794d..427b8df6b765032204c955f6bf405e359963c9db 100644 (file)
@@ -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"