part of name expession type check plan

This commit is contained in:
programsnail 2024-04-06 14:04:15 +03:00
parent d6a3ce1946
commit f688dd99a2
3 changed files with 57 additions and 12 deletions

View file

@ -282,7 +282,7 @@ public:
value_ += NAME_DELIMITER + *identifier.get();
}
std::vector<Identifier> git_fragments() const {
std::vector<Identifier> get_fragments() const {
std::vector<Identifier> fragments;
for (auto &&fragment_name :
std::ranges::views::split(value_, NAME_DELIMITER)) {

View file

@ -15,6 +15,12 @@ class ContextHolder;
class State {
friend ContextHolder;
public:
struct VariableInfo {
nodes::TypeProxy type;
nodes::NameDefinition::Modifier modifier;
};
public:
bool insert_variable(const std::string &name, nodes::TypeProxy type,
nodes::NameDefinition::Modifier modifier) {
@ -23,10 +29,10 @@ public:
"Insert variable into contexts_ with zero elements in State");
}
return contexts_.back().variables.insert({name, {type, modifier}}).second;
return contexts_.back().variables.insert({name, VariableInfo{type, modifier}}).second;
}
std::optional<std::pair<nodes::TypeProxy, nodes::NameDefinition::Modifier>>
std::optional<VariableInfo>
find_variable(const std::string &name) {
for (ssize_t i = contexts_.size(); i >= 0; --i) {
auto iter = contexts_[i].variables.find(name);
@ -128,8 +134,7 @@ public:
public:
nodes::MaybeTypeProxy brought_type;
nodes::MaybeTypeProxy returned_type;
std::unordered_map<std::string, std::pair<nodes::TypeProxy,
nodes::NameDefinition::Modifier>>
std::unordered_map<std::string, VariableInfo>
variables;
private:
@ -168,7 +173,8 @@ public:
Arguments expect(nodes::MaybeTypeProxy type) const {
Arguments copy(*this);
copy.expected_types_ = (type.has_value() ? nodes::TypeProxies{type.value()} : nodes::TypeProxies{});
copy.expected_types_ = (type.has_value() ? nodes::TypeProxies{type.value()}
: nodes::TypeProxies{});
return copy;
}
@ -241,13 +247,14 @@ nodes::TypeProxy check_same_to_pass_type_in_arguments(
// const std::string &message = "Type can't be passed to this node");
nodes::TypeCheckResult type_same_to_expected(
nodes::TypeProxy type, const Arguments& argumensr,
const nodes::Node &node, SourcesManager &sources_manager,
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);
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,