From e971b8b91e178cb30641c15dd7fd8c295390d59b Mon Sep 17 00:00:00 2001 From: nitrix Date: Tue, 4 Feb 2020 19:15:59 +0100 Subject: [PATCH] create a new type class that represents the type of a struct --- .../hsrm/compiler/Klang/types/StructType.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/main/java/de/hsrm/compiler/Klang/types/StructType.java diff --git a/src/main/java/de/hsrm/compiler/Klang/types/StructType.java b/src/main/java/de/hsrm/compiler/Klang/types/StructType.java new file mode 100644 index 0000000..9fac760 --- /dev/null +++ b/src/main/java/de/hsrm/compiler/Klang/types/StructType.java @@ -0,0 +1,43 @@ +package de.hsrm.compiler.Klang.types; + +public class StructType extends Type { + + public String name; + + public StructType(String name) { + this.name = name; + } + + @Override + public String getName() { + return this.name; + } + + @Override + public Type combine(Type that) { + if (that.equals(this)) { + return this; + } + + throw new RuntimeException("Type missmatch: cannot combine " + this.getName() + " and " + that.getName()); + } + + @Override + public boolean isPrimitiveType() { + return false; + } + + @Override + public boolean equals(Object that) { + if (this == that) { + return true; + } + + if (that instanceof StructType) { + StructType thatType = (StructType) that; + return this.getName().equals(thatType.getName()); + } + + return false; + } +} \ No newline at end of file