lang_2023/include/types.hpp
2023-04-29 12:33:05 +03:00

71 lines
1.5 KiB
C++

#pragma once
#include <optional>
#include <string>
#include <variant>
#include <memory>
// for clangd
#include "utils.hpp"
namespace info::type {
// // Temporary frozen, TODO
// struct AbstractType {
// utils::IdType graph_id;
// std::vector<utils::IdType> paramaters;
// };
// 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
};
enum class InternalType {
Float,
Int,
String,
Char,
Bool,
Unit,
};
struct TupleType {
std::optional<std::string> type;
std::vector<std::pair<std::optional<std::string>, utils::IdType>> fields;
};
struct VariantType {
std::optional<std::string> type;
std::vector<TupleType> constructors;
};
struct OptionalType {
std::optional<utils::IdType> type; // Can be empty (Some or None)
};
struct ReferenceToType {
std::vector<utils::ReferenceType> references;
utils::IdType type;
};
struct FunctionType {
std::vector<utils::IdType> argument_types;
utils::IdType return_type;
};
struct ArrayType {
size_t size; // ?? = 0 for dynamic ??
std::optional<utils::IdType> elements_type;
};
using Type = std::variant<DefinedType,
InternalType,
TupleType,
VariantType,
ReferenceToType,
FunctionType,
ArrayType>;
} // namespace info::type