1 package org.simantics.scl.compiler.internal.header;
5 import org.simantics.scl.compiler.elaboration.expressions.EVar;
6 import org.simantics.scl.compiler.elaboration.expressions.annotations.AnnotationUtils;
7 import org.simantics.scl.compiler.elaboration.expressions.records.FieldAssignment;
8 import org.simantics.scl.compiler.errors.ErrorLog;
10 public class ModuleHeader {
11 public String classLoader;
12 public long classLoaderLocation;
13 public String defaultLocalName;
14 public List<EVar> export;
18 public boolean fields;
20 private void read(ErrorLog errorLog, FieldAssignment[] fields) {
21 for(FieldAssignment assignment : fields)
22 switch(assignment.name) {
24 if(assignment.value == null)
25 errorLog.log(assignment.location, "Property classLoader needs to be given a string value.");
27 classLoader = AnnotationUtils.extractString(assignment.value);
28 if(classLoader == null)
29 errorLog.log(assignment.value.location, "Expected bundle name here.");
31 classLoaderLocation = assignment.location;
35 if(assignment.value == null)
36 errorLog.log(assignment.location, "Property export needs to be given a list of exported symbols.");
38 export = AnnotationUtils.extractIdentifierList(assignment.value);
40 errorLog.log(assignment.value.location, "Expected a list of exported symbols.");
44 if(assignment.value == null)
45 errorLog.log(assignment.location, "Property features needs to be given a list of features (identifiers).");
47 List<EVar> features = AnnotationUtils.extractIdentifierList(assignment.value);
49 errorLog.log(assignment.value.location, "Expected a list of features (identifiers).");
50 for(EVar feature : features)
51 handleFeature(errorLog, feature);
54 case "defaultLocalName":
55 if(assignment.value == null)
56 errorLog.log(assignment.location, "Property defaultLocalName needs to be given a string value.");
58 defaultLocalName = AnnotationUtils.extractString(assignment.value);
59 if(defaultLocalName == null)
60 errorLog.log(assignment.value.location, "Expected string here.");
64 errorLog.logWarning(assignment.location, "Unknown module header field was skipped.");
68 private void handleFeature(ErrorLog errorLog, EVar feature) {
69 switch(feature.name) {
70 case "chr": chr = true; break;
71 case "fields": fields = true; break;
73 errorLog.log(feature.location, "Unknown feature " + feature.name + ".");
77 public static ModuleHeader process(ErrorLog errorLog, FieldAssignment[] fields) {
80 ModuleHeader result = new ModuleHeader();
81 result.read(errorLog, fields);