mirror of
https://codeberg.org/ProgramSnail/lang.git
synced 2025-12-24 15:58:45 +00:00
ERROR type, check of passed type, many expected types in Arguments
This commit is contained in:
parent
a5fc0c7ee7
commit
005fb6aaf3
7 changed files with 200 additions and 112 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "basic_nodes.hpp"
|
||||
#include "sources_manager.hpp"
|
||||
#include "type_check_utils.hpp"
|
||||
|
||||
namespace type_check {
|
||||
|
||||
|
|
@ -9,6 +10,6 @@ namespace type_check {
|
|||
nodes::TypeCheckResult
|
||||
type_check_literal(const nodes::Literal &literal,
|
||||
SourcesManager &sources_manager,
|
||||
nodes::MaybeTypeProxy expected_type);
|
||||
const Arguments& arguments);
|
||||
|
||||
} // namespace type_check
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ const static std::string OPTIONAL_IDENTIFIER = "Optional";
|
|||
|
||||
const static std::string RESULT_IDENTIFIER = "Result";
|
||||
|
||||
const static std::string ERROR_IDENTIFIER = "Error";
|
||||
|
||||
// -- basic types
|
||||
|
||||
const static std::string FLOAT_IDENTIFIER = "Float";
|
||||
|
|
@ -56,6 +58,7 @@ enum class Type {
|
|||
ARRAY,
|
||||
OPTIONAL,
|
||||
RESULT,
|
||||
ERROR,
|
||||
// -- basic types
|
||||
FLOAT,
|
||||
DOUBLE,
|
||||
|
|
@ -86,6 +89,8 @@ inline std::string to_string(Type type) {
|
|||
return OPTIONAL_IDENTIFIER;
|
||||
case Type::RESULT:
|
||||
return RESULT_IDENTIFIER;
|
||||
case Type::ERROR:
|
||||
return ERROR_IDENTIFIER;
|
||||
// -- basic types
|
||||
case Type::FLOAT:
|
||||
return FLOAT_IDENTIFIER;
|
||||
|
|
@ -127,6 +132,7 @@ inline Type to_type(const std::string &str) {
|
|||
builtin_types[ARRAY_IDENTIFIER] = Type::ARRAY;
|
||||
builtin_types[OPTIONAL_IDENTIFIER] = Type::OPTIONAL;
|
||||
builtin_types[RESULT_IDENTIFIER] = Type::RESULT;
|
||||
builtin_types[ERROR_IDENTIFIER] = Type::ERROR;
|
||||
|
||||
// -- basic types
|
||||
builtin_types[FLOAT_IDENTIFIER] = Type::FLOAT;
|
||||
|
|
@ -172,6 +178,7 @@ inline std::optional<size_t> get_parameters_count(Type type) {
|
|||
case Type::ARRAY:
|
||||
case Type::OPTIONAL:
|
||||
case Type::RESULT:
|
||||
case Type::ERROR:
|
||||
return 1;
|
||||
// -- basic types
|
||||
case Type::FLOAT:
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ private:
|
|||
};
|
||||
|
||||
using MaybeTypeProxy = std::optional<TypeProxy>;
|
||||
using TypeProxies = std::vector<TypeProxy>;
|
||||
|
||||
class Type {
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -147,8 +147,9 @@ public:
|
|||
Arguments expect_builtin(builtin::types::Type type,
|
||||
SourcesManager &sources_manager) const {
|
||||
Arguments copy(*this);
|
||||
copy.expected_type_ =
|
||||
sources_manager.get_type_storage()->primitive_type(type);
|
||||
copy.expected_types_ = {
|
||||
sources_manager.get_type_storage()->primitive_type(type)};
|
||||
return copy;
|
||||
}
|
||||
|
||||
Arguments pass_builtin(builtin::types::Type type,
|
||||
|
|
@ -159,9 +160,15 @@ public:
|
|||
return copy;
|
||||
}
|
||||
|
||||
Arguments expect(nodes::TypeProxies types) const {
|
||||
Arguments copy(*this);
|
||||
copy.expected_types_ = types;
|
||||
return copy;
|
||||
}
|
||||
|
||||
Arguments expect(nodes::MaybeTypeProxy type) const {
|
||||
Arguments copy(*this);
|
||||
copy.expected_type_ = type;
|
||||
copy.expected_types_ = (type.has_value() ? nodes::TypeProxies{type.value()} : nodes::TypeProxies{});
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
|
@ -171,7 +178,19 @@ public:
|
|||
return copy;
|
||||
}
|
||||
|
||||
nodes::MaybeTypeProxy get_expected() const { return expected_type_; };
|
||||
Arguments without_expect() const {
|
||||
Arguments copy(*this);
|
||||
copy.expected_types_ = {};
|
||||
return copy;
|
||||
}
|
||||
|
||||
Arguments without_pass() const {
|
||||
Arguments copy(*this);
|
||||
copy.passed_type_ = {};
|
||||
return copy;
|
||||
}
|
||||
|
||||
nodes::TypeProxies get_expected() const { return expected_types_; };
|
||||
|
||||
nodes::MaybeTypeProxy get_passed() const { return passed_type_; };
|
||||
|
||||
|
|
@ -179,8 +198,8 @@ public:
|
|||
// TODO: arguments builder ??
|
||||
|
||||
private:
|
||||
nodes::MaybeTypeProxy expected_type_ = {};
|
||||
nodes::MaybeTypeProxy passed_type_ = {};
|
||||
nodes::TypeProxies expected_types_;
|
||||
nodes::MaybeTypeProxy passed_type_;
|
||||
};
|
||||
|
||||
class ContextHolder {
|
||||
|
|
@ -211,11 +230,25 @@ private:
|
|||
nodes::MaybeTypeProxy *context_exit_type_;
|
||||
};
|
||||
|
||||
nodes::TypeProxy check_same_to_pass_type_in_arguments(
|
||||
nodes::TypeProxy type, const Arguments &arguments, const nodes::Node &node,
|
||||
SourcesManager &sources_manager,
|
||||
const std::string &message = "Different type with passed one");
|
||||
|
||||
// bool check_no_pass_type_in_arguments(
|
||||
// const Arguments &arguments, const nodes::Node &node,
|
||||
// SourcesManager &sources_manager,
|
||||
// const std::string &message = "Type can't be passed to this node");
|
||||
|
||||
nodes::TypeCheckResult type_same_to_expected(
|
||||
nodes::TypeProxy type, nodes::MaybeTypeProxy expected_type,
|
||||
const nodes::Node &node, error_handling::ErrorLog &error_log,
|
||||
nodes::TypeProxy type, const Arguments& argumensr,
|
||||
const nodes::Node &node, SourcesManager &sources_manager,
|
||||
const std::string &message = "Different type with expected one");
|
||||
|
||||
nodes::TypeCheckResult type_check_from_arguments(
|
||||
nodes::TypeProxy type, const Arguments& arguments,
|
||||
const nodes::Node &node, SourcesManager &sources_manager);
|
||||
|
||||
std::optional<const nodes::TypeDefinition *>
|
||||
find_type_definition_handle_errors(const std::string &name,
|
||||
const nodes::Node &node,
|
||||
|
|
@ -229,8 +262,4 @@ find_name_definition_handle_errors(const std::string &name,
|
|||
void type_check_error(const std::string &message, const nodes::Node &node,
|
||||
SourcesManager &sources_manager);
|
||||
|
||||
bool check_no_pass_type_in_arguments(const Arguments &arguments,
|
||||
const nodes::Node &node,
|
||||
SourcesManager &sources_manager);
|
||||
|
||||
} // namespace type_check
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue