1 package org.simantics.scl.compiler.module;
\r
3 import org.simantics.scl.compiler.elaboration.expressions.EVar;
\r
4 import org.simantics.scl.compiler.internal.parsing.Symbol;
\r
5 import org.simantics.scl.compiler.internal.parsing.declarations.DeclarationAst;
\r
8 public class ImportDeclaration extends DeclarationAst {
\r
9 public static final ImportSpec DEFAULT_SPEC = new ImportSpec(true, new EVar[0]);
\r
11 public static final ImportDeclaration[] EMPTY_ARRAY = new ImportDeclaration[0];
\r
13 public static final ImportDeclaration[] ONLY_BUILTINS =
\r
14 new ImportDeclaration[] { new ImportDeclaration("Builtin", "") };
\r
17 public final String moduleName;
\r
18 public final String localName;
\r
19 public final boolean reexport;
\r
20 public final ImportSpec spec;
\r
22 public static class ImportSpec extends Symbol {
\r
23 public final boolean hiding;
\r
24 public final EVar[] values;
\r
26 public ImportSpec(boolean hiding, EVar[] values) {
\r
27 this.hiding = hiding;
\r
28 this.values = values;
\r
32 public String toString() {
\r
33 if(hiding && values.length == 0)
\r
35 StringBuilder b = new StringBuilder();
\r
37 b.append("hiding ");
\r
39 for(int i=0;i<values.length;++i) {
\r
42 b.append(values[i].name);
\r
45 return b.toString();
\r
49 public ImportDeclaration(String moduleName, String localName, boolean reexport) {
\r
50 this.moduleName = moduleName;
\r
51 this.localName = localName;
\r
52 this.reexport = reexport;
\r
53 this.spec = DEFAULT_SPEC;
\r
56 public ImportDeclaration(String moduleName, String localName, boolean reexport, ImportSpec spec) {
\r
58 throw new NullPointerException();
\r
59 this.moduleName = moduleName;
\r
60 this.localName = localName;
\r
61 this.reexport = reexport;
\r
65 public ImportDeclaration(String moduleName, String localName) {
\r
66 this(moduleName, localName, false);
\r
70 public void toString(int indentation, StringBuilder b) {
\r
71 for(int i=0;i<indentation;++i) b.append(" ");
\r
73 b.append("include \"");
\r
75 b.append("import \"");
\r
76 b.append(moduleName);
\r
78 b.append(localName);
\r
82 public String getSpecString() {
\r
83 return spec.toString();
\r
87 public int hashCode() {
\r
88 final int prime = 31;
\r
90 result = prime * result
\r
91 + ((localName == null) ? 0 : localName.hashCode());
\r
92 result = prime * result
\r
93 + ((moduleName == null) ? 0 : moduleName.hashCode());
\r
94 result = prime * result + (reexport ? 1231 : 1237);
\r
99 public boolean equals(Object obj) {
\r
104 if (getClass() != obj.getClass())
\r
106 ImportDeclaration other = (ImportDeclaration) obj;
\r
107 if (localName == null) {
\r
108 if (other.localName != null)
\r
110 } else if (!localName.equals(other.localName))
\r
112 if (moduleName == null) {
\r
113 if (other.moduleName != null)
\r
115 } else if (!moduleName.equals(other.moduleName))
\r
117 if (reexport != other.reexport)
\r