]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/header/ModuleHeader.java
Merge "(refs #7508) Edo and modified mdo under edo feature"
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / internal / header / ModuleHeader.java
1 package org.simantics.scl.compiler.internal.header;
2
3 import java.util.List;
4
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;
9
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;
16     
17     // Features
18     public boolean chr;
19     public boolean fields;
20     public boolean edo;
21     
22     private void read(ErrorLog errorLog, FieldAssignment[] fields) {
23         for(FieldAssignment assignment : fields)
24             switch(assignment.name) {
25             case "bundle":
26                 if(assignment.value == null)
27                     errorLog.log(assignment.location, "Property classLoader needs to be given a string value.");
28                 else {
29                     classLoader = AnnotationUtils.extractString(assignment.value);
30                     if(classLoader == null)
31                         errorLog.log(assignment.value.location, "Expected bundle name here.");
32                     else 
33                         classLoaderLocation = assignment.location;
34                 }
35                 break;
36             case "export":
37                 if(assignment.value == null)
38                     errorLog.log(assignment.location, "Property export needs to be given a list of exported symbols.");
39                 else {
40                     export = AnnotationUtils.extractIdentifierList(assignment.value);
41                     if(export == null)
42                         errorLog.log(assignment.value.location, "Expected a list of exported symbols.");
43                 }
44                 break;
45             case "features":
46                 if(assignment.value == null)
47                     errorLog.log(assignment.location, "Property features needs to be given a list of features (identifiers).");
48                 else {
49                     List<EVar> features = AnnotationUtils.extractIdentifierList(assignment.value);
50                     if(features == null)
51                         errorLog.log(assignment.value.location, "Expected a list of features (identifiers).");
52                     for(EVar feature : features)
53                         handleFeature(errorLog, feature);
54                 }
55                 break;
56             case "defaultLocalName":
57                 if(assignment.value == null)
58                     errorLog.log(assignment.location, "Property defaultLocalName needs to be given a string value.");
59                 else {
60                     defaultLocalName = AnnotationUtils.extractString(assignment.value);
61                     if(defaultLocalName == null)
62                         errorLog.log(assignment.value.location, "Expected string here.");
63                 }
64                 break;
65             case "deprecated":
66                 if(assignment.value == null)
67                     deprecated = "";
68                 else {
69                     deprecated = AnnotationUtils.extractString(assignment.value);
70                     if(deprecated == null)
71                         errorLog.log(assignment.value.location, "Expected string here.");
72                 }
73                 break;
74             default:
75                 errorLog.logWarning(assignment.location, "Unknown module header field was skipped.");
76             }
77     }
78     
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;
84         default:
85             errorLog.log(feature.location, "Unknown feature " + feature.name + ".");
86         }
87     }
88
89     public static ModuleHeader process(ErrorLog errorLog, FieldAssignment[] fields) {
90         if(fields == null)
91             return null;
92         ModuleHeader result = new ModuleHeader();
93         result.read(errorLog, fields);
94         return result;
95     }
96 }