aboutsummaryrefslogtreecommitdiff
path: root/include/type.hpp
blob: 9b25d2451e03ca0ed204452cb750e62470d09c44 (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
#pragma once

enum struct TypeKind {
    INT,
    CHAR,
    BOOL,
    STRING,
    FLOAT,
    DOUBLE,
    VOID,
    FUNCTION,
};

struct Type {
    TypeKind kind;

    Type* return_type = nullptr;
    std::vector<Type*> param_types;

    static Type makeInt() { return { TypeKind::INT }; }
    static Type makeChar() { return { TypeKind::CHAR }; }
    static Type makeBool() { return { TypeKind::BOOL }; }
    static Type makeString() { return { TypeKind::STRING }; }
    static Type makeFloat() { return { TypeKind::FLOAT }; }
    static Type makeDouble() { return { TypeKind::DOUBLE }; }
    static Type makeVoid() { return { TypeKind::VOID }; }

    static Type makeFunction(Type* return_type, std::vector<Type*> param_types) {
	Type t;
	t.kind = TypeKind::FUNCTION;
	t.return_type = return_type;
	t.param_types = std::move(param_types);
	return t;
    };
};