summaryrefslogtreecommitdiff
path: root/minijava/TypeInstance.java
blob: f7d6329883a6a34bddb1acc35b38da82cfc7ea9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package minijava;

public class TypeInstance {
    TypeEnum type;
    String type_name;

    public String toString() {
        return "name:" + type_name + "|type:" + type;
    }

    public TypeInstance(String type_name, TypeEnum type) {
        this.type = type;
        this.type_name = type_name;
    }

    public boolean equal_type(TypeInstance other) {
        /**
         * Given a TypeInstance object other,
         * returns true if other object
         * is the same type as this one.
         *
         * We can say two types are equal, as
         * long as they are not equal on a
         * type error!
         */

        return this.type != TypeEnum.ERROR &&
            this.type == other.type;
    }

    public boolean has_checked() {
        return type != TypeEnum.ERROR;
    }

    public TypeEnum get_type() {
        return this.type;
    }

    public String get_type_name() {
        return this.type_name;
    }

}