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