diff options
| author | Cori Barker <coribarker2@gmail.com> | 2026-03-10 15:13:23 +0000 |
|---|---|---|
| committer | Cori Barker <coribarker2@gmail.com> | 2026-03-10 15:13:23 +0000 |
| commit | 85918e5c3ef2f109583c7f414e7d604df0272c03 (patch) | |
| tree | 829aaa3df8847585d05b7e00ec308cbab8ca75bf | |
| parent | 50a51df0404ee4f057fbc19657672d1c7d3eef68 (diff) | |
refactored types
| -rw-r--r-- | include/type.hpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/include/type.hpp b/include/type.hpp index c46ff34..9b25d24 100644 --- a/include/type.hpp +++ b/include/type.hpp @@ -1,6 +1,6 @@ #pragma once -enum struct Type { +enum struct TypeKind { INT, CHAR, BOOL, @@ -8,4 +8,28 @@ enum struct Type { 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; + }; }; |
