1 package org.simantics.scl.compiler.elaboration.expressions;
3 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
4 import org.simantics.scl.compiler.internal.codegen.references.IVal;
5 import org.simantics.scl.compiler.types.Type;
6 import org.simantics.scl.compiler.types.Types;
7 import org.simantics.scl.compiler.types.exceptions.UnificationException;
8 import org.simantics.scl.compiler.types.util.Typed;
10 public class Variable implements Typed {
11 public static final Variable[] EMPTY_ARRAY = new Variable[0];
15 transient private IVal val;
17 public Variable(String name) {
21 public Variable(String name, Type type) {
27 public Type getType() {
31 public String getName() {
35 public void setType(Type type) {
37 throw new NullPointerException();
40 Types.unify(type, this.type);
41 } catch(UnificationException e) {
42 throw new InternalCompilerError(e.getMessage());
49 public String toString() {
50 return name; // + "$" + hashCode();
53 public void setVal(IVal val) {
58 public IVal getVal() {
60 throw new InternalCompilerError("Variable " + name + " (with type " + type + ") is not given value anywhere.");
64 public Variable copy() {
65 return new Variable(name, type);
68 public void setName(String name) {
72 public static Variable[] concat(Variable[] a,
74 Variable[] result = new Variable[a.length + b.length];
75 System.arraycopy(a, 0, result, 0, a.length);
76 System.arraycopy(b, 0, result, a.length, b.length);