1 package org.simantics.scl.compiler.module;
3 import org.simantics.scl.compiler.elaboration.expressions.EVar;
4 import org.simantics.scl.compiler.internal.parsing.Symbol;
5 import org.simantics.scl.compiler.internal.parsing.declarations.DeclarationAst;
8 public class ImportDeclaration extends DeclarationAst {
9 public static final ImportSpec DEFAULT_SPEC = new ImportSpec(true, new EVar[0]);
11 public static final ImportDeclaration[] EMPTY_ARRAY = new ImportDeclaration[0];
13 public static final ImportDeclaration[] ONLY_BUILTINS =
14 new ImportDeclaration[] { new ImportDeclaration("Builtin", "") };
17 public final String moduleName;
18 public final String localName;
19 public final boolean reexport;
20 public final ImportSpec spec;
22 public static class ImportSpec extends Symbol {
23 public final boolean hiding;
24 public final EVar[] values;
26 public ImportSpec(boolean hiding, EVar[] values) {
32 public String toString() {
33 if(hiding && values.length == 0)
35 StringBuilder b = new StringBuilder();
39 for(int i=0;i<values.length;++i) {
42 b.append(values[i].name);
49 public ImportDeclaration(String moduleName, String localName, boolean reexport) {
50 this.moduleName = moduleName;
51 this.localName = localName;
52 this.reexport = reexport;
53 this.spec = DEFAULT_SPEC;
56 public ImportDeclaration(long location, String moduleName, String localName, boolean reexport, ImportSpec spec) {
57 this(moduleName, localName, reexport);
58 this.location = location;
61 public ImportDeclaration(String moduleName, String localName, boolean reexport, ImportSpec spec) {
63 throw new NullPointerException();
64 this.moduleName = moduleName;
65 this.localName = localName;
66 this.reexport = reexport;
70 public ImportDeclaration(String moduleName, String localName) {
71 this(moduleName, localName, false);
75 public void toString(int indentation, StringBuilder b) {
76 for(int i=0;i<indentation;++i) b.append(" ");
78 b.append("include \"");
80 b.append("import \"");
87 public String getSpecString() {
88 return spec.toString();
92 public int hashCode() {
95 result = prime * result
96 + ((localName == null) ? 0 : localName.hashCode());
97 result = prime * result
98 + ((moduleName == null) ? 0 : moduleName.hashCode());
99 result = prime * result + (reexport ? 1231 : 1237);
104 public boolean equals(Object obj) {
109 if (getClass() != obj.getClass())
111 ImportDeclaration other = (ImportDeclaration) obj;
112 if (localName == null) {
113 if (other.localName != null)
115 } else if (!localName.equals(other.localName))
117 if (moduleName == null) {
118 if (other.moduleName != null)
120 } else if (!moduleName.equals(other.moduleName))
122 if (reexport != other.reexport)
127 public ImportDeclaration hidden() {
128 return new ImportDeclaration(moduleName, null);