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