]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/header/ModuleHeader.java
Added module header feature to SCL language.
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / internal / header / ModuleHeader.java
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 (file)
index 0000000..c49b49a
--- /dev/null
@@ -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;
+    }
+}