2023-03-26 15:20:53 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
2023-04-07 12:13:31 +03:00
|
|
|
#include "interpreter_tree.hpp"
|
2023-03-26 15:20:53 +03:00
|
|
|
#include <string>
|
|
|
|
|
#include <variant>
|
|
|
|
|
#include <vector>
|
2023-04-07 12:13:31 +03:00
|
|
|
#include <optional>
|
2023-03-26 15:20:53 +03:00
|
|
|
#include <unordered_map>
|
2023-04-07 12:13:31 +03:00
|
|
|
#include <memory>
|
2023-03-26 15:20:53 +03:00
|
|
|
|
|
|
|
|
// for clangd
|
2023-04-17 11:14:33 +03:00
|
|
|
#include "utils.hpp"
|
2023-03-26 15:20:53 +03:00
|
|
|
|
|
|
|
|
namespace interpreter {
|
|
|
|
|
class Node;
|
|
|
|
|
} // namespace interpreter
|
|
|
|
|
|
|
|
|
|
namespace info {
|
|
|
|
|
|
|
|
|
|
using NumberValue = long long;
|
|
|
|
|
using FloatNumberValue = float;
|
|
|
|
|
using StringValue = std::string;
|
|
|
|
|
|
|
|
|
|
struct SimpleValue {
|
|
|
|
|
std::variant<NumberValue, FloatNumberValue, StringValue> value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Value {
|
|
|
|
|
enum class ValueStructure {
|
|
|
|
|
Simple, // one value
|
|
|
|
|
Variant, // one value from list, can have arguments
|
|
|
|
|
// MultiVariant, // constructed variant // ??
|
|
|
|
|
Tuple, // tuple of values
|
|
|
|
|
};
|
|
|
|
|
ValueStructure structure;
|
|
|
|
|
std::vector<std::variant<SimpleValue, Value>> values;
|
|
|
|
|
};
|
|
|
|
|
// better variant value storage (then string) ??
|
|
|
|
|
|
|
|
|
|
struct VariantTypeInfo;
|
|
|
|
|
struct TupleTypeInfo;
|
|
|
|
|
struct AliasTypeInfo;
|
|
|
|
|
|
2023-04-07 12:13:31 +03:00
|
|
|
struct TypeInfo;
|
|
|
|
|
|
|
|
|
|
struct TypeclassInfo;
|
|
|
|
|
|
2023-03-26 15:20:53 +03:00
|
|
|
enum class BuiltInTypeInfo {
|
|
|
|
|
StringT,
|
|
|
|
|
IntT,
|
|
|
|
|
FloatT,
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-12 13:31:39 +03:00
|
|
|
struct TypeUsageInfo {
|
|
|
|
|
interpreter::tokens::ParametrizedType* node;
|
|
|
|
|
TypeInfo* info = nullptr;
|
2023-04-07 12:13:31 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ParameterInfo {
|
2023-04-12 13:31:39 +03:00
|
|
|
std::string type;
|
|
|
|
|
std::vector<interpreter::tokens::TypeclassUsage*> typeclass_nodes;
|
|
|
|
|
std::vector<TypeclassInfo*> typeclass_types;
|
2023-04-07 12:13:31 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-12 13:31:39 +03:00
|
|
|
struct AbstractTypeInfo {
|
|
|
|
|
enum { Basic, Abstract } modifier;
|
|
|
|
|
ParameterInfo type;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-07 12:13:31 +03:00
|
|
|
struct AliasTypeInfo {
|
2023-04-12 13:31:39 +03:00
|
|
|
enum {Alias, Type, Let} modifier;
|
|
|
|
|
std::vector<std::string> parameters;
|
2023-04-07 12:13:31 +03:00
|
|
|
TypeUsageInfo value;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-12 13:31:39 +03:00
|
|
|
struct AnyTypeInfo {
|
|
|
|
|
ParameterInfo type;
|
|
|
|
|
std::vector<ParameterInfo> parameters;
|
|
|
|
|
interpreter::tokens::AnyType* value;
|
|
|
|
|
};
|
2023-04-07 12:13:31 +03:00
|
|
|
|
2023-04-12 13:31:39 +03:00
|
|
|
struct TypeInfo { std::variant<AbstractTypeInfo, AliasTypeInfo, AnyTypeInfo> type; };
|
2023-04-07 12:13:31 +03:00
|
|
|
|
|
|
|
|
struct FunctionDeclarationInfo {
|
2023-04-12 13:31:39 +03:00
|
|
|
std::vector<ParameterInfo> parameters;
|
|
|
|
|
std::vector<interpreter::tokens::AnyType*> argument_type_nodes;
|
|
|
|
|
std::vector<AnyTypeInfo*> argument_types;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-12 13:31:39 +03:00
|
|
|
struct FunctionDefinitionInfo {
|
|
|
|
|
std::vector<ParameterInfo> parameters;
|
|
|
|
|
std::vector<std::string> argument_names;
|
|
|
|
|
interpreter::tokens::SuperExpression* expression = nullptr;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-07 12:13:31 +03:00
|
|
|
struct FunctionInfo {
|
|
|
|
|
FunctionDeclarationInfo declaration;
|
|
|
|
|
FunctionDefinitionInfo definition;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-12 13:31:39 +03:00
|
|
|
struct TypeclassInfo {
|
|
|
|
|
std::vector<ParameterInfo> parameters;
|
2023-04-07 12:13:31 +03:00
|
|
|
std::vector<FunctionDeclarationInfo> requirements;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ImportInfo {
|
|
|
|
|
std::string module_name;
|
|
|
|
|
std::vector<std::string> symbols;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct NamespaceInfo {
|
2023-04-12 13:31:39 +03:00
|
|
|
enum Modifier { Const, Var };
|
|
|
|
|
|
2023-04-17 11:14:33 +03:00
|
|
|
std::unordered_map<std::string, utils::IdType> types;
|
|
|
|
|
std::unordered_map<std::string, utils::IdType> typeclasses;
|
|
|
|
|
std::unordered_map<std::string, utils::IdType> functions;
|
2023-04-14 16:43:56 +03:00
|
|
|
std::unordered_map<std::string, NamespaceInfo> namespaces;
|
|
|
|
|
std::unordered_map<std::string, std::vector<NamespaceInfo>> variable_namespaces;
|
2023-04-12 13:31:39 +03:00
|
|
|
|
|
|
|
|
std::optional<Modifier> modifier;
|
|
|
|
|
std::optional<std::string> variable;
|
2023-04-07 12:13:31 +03:00
|
|
|
std::string type_name;
|
|
|
|
|
TypeInfo* type_info = nullptr;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace info
|