part of type checker, type heck result type

This commit is contained in:
ProgramSnail 2023-08-12 14:36:00 +03:00
parent 48c9e200be
commit 17ff590048
13 changed files with 1022 additions and 321 deletions

View file

@ -1,5 +1,6 @@
#pragma once
#include "utils.hpp"
#include <optional>
#include <string>
#include <utility>
@ -24,29 +25,55 @@ enum class Modifier {
IN_OR_REF_OR_OUT, // <-|<>|-> x
IN_OR_CONST_OR_OUT, // <-|--|-> x
IN_OR_REF_OR_CONST, // <-|<>|-- x
REF_OR_CONST_OR_OUT, //<>|--|-> x
REF_OR_CONST_OR_OUT, // <>|--|-> x
//
IN_OR_REF_OR_CONST_OR_OUT, // <-|<>|--|-> x
//
OPTIONAL, // x?
RESULT, // x!
//
IN_OR_REF_OR_CONST_OR_OUT, //<-|<>|--|-> x
OPTIONAL, // x?
RESULT, // x!
NONE,
};
namespace utils {
inline bool is_suffix_modifier(nodes::Modifier modifier) {
return modifier == nodes::Modifier::OPTIONAL ||
modifier == nodes::Modifier::RESULT;
}
} // namespace utils
class Node {
public:
Node() : undefined_(true) {}
Node(std::pair<size_t, size_t> start_position,
std::pair<size_t, size_t> end_position)
: start_position_(start_position), end_position_(end_position) {}
: undefined_(false), start_position_(start_position),
end_position_(end_position) {}
std::pair<size_t, size_t> get_start_position() const {
if (undefined_) {
error_handling::handle_general_error(
"Get start position from undefined node");
}
return start_position_;
}
std::pair<size_t, size_t> get_end_position() const { return end_position_; }
std::pair<size_t, size_t> get_end_position() const {
if (undefined_) {
error_handling::handle_general_error(
"Get end position from undefined node");
}
return end_position_;
}
protected:
std::pair<size_t, size_t> start_position_;
std::pair<size_t, size_t> end_position_;
bool undefined_ = false;
std::pair<size_t, size_t> start_position_ = {0, 0};
std::pair<size_t, size_t> end_position_ = {0, 0};
};
struct unit {};
@ -125,6 +152,11 @@ public:
return !(*this == other_identifier);
}
bool operator<(const Identifier &other_identifier) const {
return type_ < other_identifier.type_ || (type_ == other_identifier.type_ &&
value_ < other_identifier.value_);
}
private:
IdentifierType type_;
std::string value_;