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 deprecated;
12 public String classLoader;
13 public long classLoaderLocation;
14 public String defaultLocalName;
15 public List<EVar> export;
19 public boolean fields;
22 private void read(ErrorLog errorLog, FieldAssignment[] fields) {
23 for(FieldAssignment assignment : fields)
24 switch(assignment.name) {
26 if(assignment.value == null)
27 errorLog.log(assignment.location, "Property classLoader needs to be given a string value.");
29 classLoader = AnnotationUtils.extractString(assignment.value);
30 if(classLoader == null)
31 errorLog.log(assignment.value.location, "Expected bundle name here.");
33 classLoaderLocation = assignment.location;
37 if(assignment.value == null)
38 errorLog.log(assignment.location, "Property export needs to be given a list of exported symbols.");
40 export = AnnotationUtils.extractIdentifierList(assignment.value);
42 errorLog.log(assignment.value.location, "Expected a list of exported symbols.");
46 if(assignment.value == null)
47 errorLog.log(assignment.location, "Property features needs to be given a list of features (identifiers).");
49 List<EVar> features = AnnotationUtils.extractIdentifierList(assignment.value);
51 errorLog.log(assignment.value.location, "Expected a list of features (identifiers).");
52 for(EVar feature : features)
53 handleFeature(errorLog, feature);
56 case "defaultLocalName":
57 if(assignment.value == null)
58 errorLog.log(assignment.location, "Property defaultLocalName needs to be given a string value.");
60 defaultLocalName = AnnotationUtils.extractString(assignment.value);
61 if(defaultLocalName == null)
62 errorLog.log(assignment.value.location, "Expected string here.");
66 if(assignment.value == null)
69 deprecated = AnnotationUtils.extractString(assignment.value);
70 if(deprecated == null)
71 errorLog.log(assignment.value.location, "Expected string here.");
75 errorLog.logWarning(assignment.location, "Unknown module header field was skipped.");
79 private void handleFeature(ErrorLog errorLog, EVar feature) {
80 switch(feature.name) {
81 case "chr": chr = true; break;
82 case "fields": fields = true; break;
83 case "edo": edo = true; break;
85 errorLog.log(feature.location, "Unknown feature " + feature.name + ".");
89 public static ModuleHeader process(ErrorLog errorLog, FieldAssignment[] fields) {
92 ModuleHeader result = new ModuleHeader();
93 result.read(errorLog, fields);