]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/header/ModuleHeader.java
(refs #6924) Support for record field access syntax.
[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 org.simantics.scl.compiler.elaboration.expressions.annotations.AnnotationUtils;
4 import org.simantics.scl.compiler.elaboration.expressions.records.FieldAssignment;
5 import org.simantics.scl.compiler.errors.ErrorLog;
6 import org.simantics.scl.compiler.internal.parsing.declarations.DModuleHeader;
7
8 public class ModuleHeader {
9     public String classLoader;
10     public long classLoaderLocation;
11     public String defaultLocalName;
12     public boolean fields;
13     
14     private void read(ErrorLog errorLog, DModuleHeader header) {
15         for(FieldAssignment assignment : header.fields)
16             switch(assignment.name) {
17             case "bundle":
18                 if(assignment.value == null)
19                     errorLog.log(assignment.location, "Property classLoader needs to be given a string value.");
20                 else {
21                     classLoader = AnnotationUtils.extractString(assignment.value);
22                     if(classLoader == null)
23                         errorLog.log(assignment.value.location, "Expected bundle name here.");
24                     else 
25                         classLoaderLocation = assignment.location;
26                 }
27                 break;
28             case "defaultLocalName":
29                 if(assignment.value == null)
30                     errorLog.log(assignment.location, "Property defaultLocalName needs to be given a string value.");
31                 else {
32                         defaultLocalName = AnnotationUtils.extractString(assignment.value);
33                         if(defaultLocalName == null)
34                                 errorLog.log(assignment.value.location, "Expected string here.");
35                 }
36                 break;
37             case "fields":
38                 this.fields = true;
39                 break;
40             default:
41                 errorLog.logWarning(assignment.location, "Unknown module header field was skipped.");
42             }
43     }
44     
45     public static ModuleHeader process(ErrorLog errorLog, DModuleHeader header) {
46         if(header == null)
47             return null;
48         ModuleHeader result = new ModuleHeader();
49         result.read(errorLog, header);
50         return result;
51     }
52 }