]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/header/ModuleHeader.java
80acf17c571cb242e2db401233525006f118908d
[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 classLoader;
12     public long classLoaderLocation;
13     public String defaultLocalName;
14     public List<EVar> export;
15     // Features
16     public boolean chr;
17     public boolean fields;
18     
19     private void read(ErrorLog errorLog, FieldAssignment[] fields) {
20         for(FieldAssignment assignment : fields)
21             switch(assignment.name) {
22             case "bundle":
23                 if(assignment.value == null)
24                     errorLog.log(assignment.location, "Property classLoader needs to be given a string value.");
25                 else {
26                     classLoader = AnnotationUtils.extractString(assignment.value);
27                     if(classLoader == null)
28                         errorLog.log(assignment.value.location, "Expected bundle name here.");
29                     else 
30                         classLoaderLocation = assignment.location;
31                 }
32                 break;
33             case "export":
34                 if(assignment.value == null)
35                     errorLog.log(assignment.location, "Property export needs to be given a string list value.");
36                 else {
37                     export = AnnotationUtils.extractIdentifierList(assignment.value);
38                     if(export == null)
39                         errorLog.log(assignment.value.location, "Expected a list of exported items.");
40                 }
41                 break;
42             case "defaultLocalName":
43                 if(assignment.value == null)
44                     errorLog.log(assignment.location, "Property defaultLocalName needs to be given a string value.");
45                 else {
46                         defaultLocalName = AnnotationUtils.extractString(assignment.value);
47                         if(defaultLocalName == null)
48                                 errorLog.log(assignment.value.location, "Expected string here.");
49                 }
50                 break;
51             case "fields":
52                 if(assignment.value != null)
53                     errorLog.log(assignment.location, "No value expected for property fields.");
54                 this.fields = true;
55                 break;
56             case "chr":
57                 if(assignment.value != null)
58                     errorLog.log(assignment.location, "No value expected for property chr.");
59                 this.chr = true;
60                 break;                
61             default:
62                 errorLog.logWarning(assignment.location, "Unknown module header field was skipped.");
63             }
64     }
65     
66     public static ModuleHeader process(ErrorLog errorLog, FieldAssignment[] fields) {
67         if(fields == null)
68             return null;
69         ModuleHeader result = new ModuleHeader();
70         result.read(errorLog, fields);
71         return result;
72     }
73 }