mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-05 22:48:42 +00:00
119 lines
2.6 KiB
C++
119 lines
2.6 KiB
C++
|
|
#pragma once
|
||
|
|
|
||
|
|
#include "interpreter_tree.hpp"
|
||
|
|
#include <string>
|
||
|
|
#include <variant>
|
||
|
|
#include <vector>
|
||
|
|
#include <optional>
|
||
|
|
#include <unordered_map>
|
||
|
|
#include <memory>
|
||
|
|
|
||
|
|
// for clangd
|
||
|
|
#include "utils.hpp"
|
||
|
|
|
||
|
|
namespace interpreter {
|
||
|
|
class Node;
|
||
|
|
} // namespace interpreter
|
||
|
|
|
||
|
|
namespace info {
|
||
|
|
|
||
|
|
struct VariantTypeInfo;
|
||
|
|
struct TupleTypeInfo;
|
||
|
|
struct AliasTypeInfo;
|
||
|
|
|
||
|
|
struct TypeInfo;
|
||
|
|
|
||
|
|
struct TypeclassInfo;
|
||
|
|
|
||
|
|
enum class BuiltInTypeInfo {
|
||
|
|
StringT,
|
||
|
|
IntT,
|
||
|
|
FloatT,
|
||
|
|
UnitT,
|
||
|
|
};
|
||
|
|
|
||
|
|
struct TypeUsageInfo {
|
||
|
|
interpreter::tokens::TypeExpression* node;
|
||
|
|
TypeInfo* info = nullptr;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct ParameterInfo {
|
||
|
|
std::string type;
|
||
|
|
std::vector<interpreter::tokens::TypeclassExpression*> typeclass_nodes;
|
||
|
|
std::vector<TypeclassInfo*> typeclass_types;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct AbstractTypeInfo {
|
||
|
|
enum { Basic, Abstract } modifier;
|
||
|
|
ParameterInfo type;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct AliasTypeInfo {
|
||
|
|
enum {Alias, Type, Let} modifier;
|
||
|
|
std::vector<std::string> parameters;
|
||
|
|
TypeUsageInfo value;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct AnyTypeInfo {
|
||
|
|
ParameterInfo type;
|
||
|
|
std::vector<ParameterInfo> parameters;
|
||
|
|
interpreter::tokens::AnyType* value;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct TypeInfo {
|
||
|
|
std::variant<AbstractTypeInfo, AliasTypeInfo, AnyTypeInfo> type;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct ConstructorInfo {
|
||
|
|
std::string name;
|
||
|
|
size_t order;
|
||
|
|
utils::IdType type_id;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct FunctionDeclarationInfo {
|
||
|
|
std::vector<ParameterInfo> parameters;
|
||
|
|
std::vector<interpreter::tokens::AnyType*> argument_type_nodes;
|
||
|
|
std::vector<AnyTypeInfo*> argument_types;
|
||
|
|
interpreter::tokens::FunctionDeclaration* node = nullptr;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct FunctionDefinitionInfo {
|
||
|
|
std::vector<ParameterInfo> parameters;
|
||
|
|
std::vector<std::string> argument_names;
|
||
|
|
interpreter::tokens::FunctionDefinitionStatement* node = nullptr;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct FunctionInfo {
|
||
|
|
size_t argument_count = 0;
|
||
|
|
std::optional<FunctionDeclarationInfo> declaration;
|
||
|
|
std::optional<FunctionDefinitionInfo> definition;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct TypeclassInfo {
|
||
|
|
std::vector<ParameterInfo> parameters;
|
||
|
|
std::vector<FunctionDeclarationInfo> requirements;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct ImportInfo {
|
||
|
|
std::string module_name;
|
||
|
|
std::vector<std::string> symbols;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct NamespaceInfo {
|
||
|
|
enum Modifier { Const, Var };
|
||
|
|
|
||
|
|
std::unordered_map<std::string, utils::IdType> types;
|
||
|
|
std::unordered_map<std::string, utils::IdType> typeclasses;
|
||
|
|
std::unordered_map<std::string, utils::IdType> functions;
|
||
|
|
std::unordered_map<std::string, utils::IdType> constructors;
|
||
|
|
std::unordered_map<std::string, NamespaceInfo> namespaces;
|
||
|
|
std::unordered_map<std::string, std::vector<NamespaceInfo>> variable_namespaces;
|
||
|
|
|
||
|
|
std::optional<Modifier> modifier;
|
||
|
|
std::optional<std::string> variable;
|
||
|
|
std::string type_name;
|
||
|
|
TypeInfo* type_info = nullptr;
|
||
|
|
};
|
||
|
|
|
||
|
|
} // namespace info
|