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(String moduleName, String localName, boolean reexport, ImportSpec spec) {
58 throw new NullPointerException();
59 this.moduleName = moduleName;
60 this.localName = localName;
61 this.reexport = reexport;
65 public ImportDeclaration(String moduleName, String localName) {
66 this(moduleName, localName, false);
70 public void toString(int indentation, StringBuilder b) {
71 for(int i=0;i<indentation;++i) b.append(" ");
73 b.append("include \"");
75 b.append("import \"");
82 public String getSpecString() {
83 return spec.toString();
87 public int hashCode() {
90 result = prime * result
91 + ((localName == null) ? 0 : localName.hashCode());
92 result = prime * result
93 + ((moduleName == null) ? 0 : moduleName.hashCode());
94 result = prime * result + (reexport ? 1231 : 1237);
99 public boolean equals(Object obj) {
104 if (getClass() != obj.getClass())
106 ImportDeclaration other = (ImportDeclaration) obj;
107 if (localName == null) {
108 if (other.localName != null)
110 } else if (!localName.equals(other.localName))
112 if (moduleName == null) {
113 if (other.moduleName != null)
115 } else if (!moduleName.equals(other.moduleName))
117 if (reexport != other.reexport)