-package org.simantics.scl.compiler.elaboration.expressions;\r
-\r
-import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;\r
-import org.simantics.scl.compiler.internal.codegen.references.IVal;\r
-import org.simantics.scl.compiler.types.Type;\r
-import org.simantics.scl.compiler.types.Types;\r
-import org.simantics.scl.compiler.types.exceptions.UnificationException;\r
-import org.simantics.scl.compiler.types.util.Typed;\r
-\r
-public class Variable implements Typed {\r
- public static final Variable[] EMPTY_ARRAY = new Variable[0];\r
- \r
- String name;\r
- Type type;\r
- transient private IVal val;\r
-\r
- public Variable(String name) {\r
- this.name = name;\r
- }\r
-\r
- public Variable(String name, Type type) {\r
- this.name = name;\r
- this.type = type;\r
- }\r
-\r
- @Override\r
- public Type getType() {\r
- return type;\r
- }\r
-\r
- public String getName() {\r
- return name;\r
- }\r
- \r
- public void setType(Type type) {\r
- if(type == null)\r
- throw new NullPointerException();\r
- if(this.type != null)\r
- try {\r
- Types.unify(type, this.type);\r
- } catch(UnificationException e) {\r
- throw new InternalCompilerError(e.getMessage());\r
- }\r
- else\r
- this.type = type;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return name; // + "$" + hashCode();\r
- }\r
- \r
- public void setVal(IVal val) {\r
- this.val = val;\r
- val.setLabel(name);\r
- }\r
- \r
- public IVal getVal() {\r
- if(val == null)\r
- throw new InternalCompilerError("Variable " + name + " (with type " + type + ") is not given value anywhere.");\r
- return val;\r
- }\r
-\r
- public Variable copy() {\r
- return new Variable(name, type);\r
- }\r
-\r
- public void setName(String name) {\r
- this.name = name;\r
- }\r
-\r
- public static Variable[] concat(Variable[] a,\r
- Variable[] b) {\r
- Variable[] result = new Variable[a.length + b.length];\r
- System.arraycopy(a, 0, result, 0, a.length);\r
- System.arraycopy(b, 0, result, a.length, b.length);\r
- return result;\r
- }\r
-}\r
+package org.simantics.scl.compiler.elaboration.expressions;
+
+import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
+import org.simantics.scl.compiler.internal.codegen.references.IVal;
+import org.simantics.scl.compiler.types.Type;
+import org.simantics.scl.compiler.types.Types;
+import org.simantics.scl.compiler.types.exceptions.UnificationException;
+import org.simantics.scl.compiler.types.util.Typed;
+
+public class Variable implements Typed {
+ public static final Variable[] EMPTY_ARRAY = new Variable[0];
+
+ String name;
+ Type type;
+ transient private IVal val;
+
+ public Variable(String name) {
+ this.name = name;
+ }
+
+ public Variable(String name, Type type) {
+ this.name = name;
+ this.type = type;
+ }
+
+ @Override
+ public Type getType() {
+ return type;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setType(Type type) {
+ if(type == null)
+ throw new NullPointerException();
+ if(this.type != null)
+ try {
+ Types.unify(type, this.type);
+ } catch(UnificationException e) {
+ throw new InternalCompilerError(e.getMessage());
+ }
+ else
+ this.type = type;
+ }
+
+ @Override
+ public String toString() {
+ return name; // + "$" + hashCode();
+ }
+
+ public void setVal(IVal val) {
+ this.val = val;
+ val.setLabel(name);
+ }
+
+ public IVal getVal() {
+ if(val == null)
+ throw new InternalCompilerError("Variable " + name + " (with type " + type + ") is not given value anywhere.");
+ return val;
+ }
+
+ public Variable copy() {
+ return new Variable(name, type);
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public static Variable[] concat(Variable[] a,
+ Variable[] b) {
+ Variable[] result = new Variable[a.length + b.length];
+ System.arraycopy(a, 0, result, 0, a.length);
+ System.arraycopy(b, 0, result, a.length, b.length);
+ return result;
+ }
+}