lang_2023/include/types.hpp

72 lines
1.5 KiB
C++
Raw Normal View History

#pragma once
#include <optional>
#include <string>
#include <variant>
#include <memory>
2023-04-17 11:14:33 +03:00
// for clangd
#include "utils.hpp"
2023-04-17 11:14:33 +03:00
namespace info::type {
2023-04-17 11:14:33 +03:00
// // Temporary frozen, TODO
// struct AbstractType {
// utils::IdType graph_id;
// std::vector<utils::IdType> paramaters;
// };
2023-04-17 11:14:33 +03:00
2023-04-27 14:02:37 +03:00
// TODO: check, if defined type is variant, etc.
struct DefinedType {
utils::IdType type_id; // in defined types
utils::IdType type; // in types manager, created using context types
2023-04-17 11:14:33 +03:00
};
enum class InternalType {
Float,
Int,
String,
Char,
Bool,
Unit,
};
2023-04-17 11:14:33 +03:00
struct TupleType {
std::optional<std::string> type;
std::vector<std::pair<std::optional<std::string>, utils::IdType>> fields;
2023-04-17 11:14:33 +03:00
};
struct VariantType {
std::optional<std::string> type;
2023-04-27 14:02:37 +03:00
std::vector<TupleType> constructors;
2023-04-17 11:14:33 +03:00
};
2023-04-22 19:30:16 +03:00
struct OptionalType {
std::optional<utils::IdType> type; // Can be empty (Some or None)
};
struct ReferenceToType {
std::vector<utils::ReferenceType> references;
utils::IdType type;
};
2023-04-17 11:14:33 +03:00
struct FunctionType {
std::vector<utils::IdType> argument_types;
2023-04-22 19:30:16 +03:00
utils::IdType return_type;
2023-04-17 11:14:33 +03:00
};
struct ArrayType {
2023-04-22 19:30:16 +03:00
size_t size; // ?? = 0 for dynamic ??
std::optional<utils::IdType> elements_type;
2023-04-17 11:14:33 +03:00
};
using Type = std::variant<DefinedType,
InternalType,
TupleType,
VariantType,
ReferenceToType,
FunctionType,
ArrayType>;
} // namespace info::type