mirror of
https://codeberg.org/ProgramSnail/lang.git
synced 2025-12-17 20:38:45 +00:00
fixes, refactoring (shorter names, visitor)
This commit is contained in:
parent
57b1172a4f
commit
f58bfd938c
20 changed files with 564 additions and 764 deletions
|
|
@ -217,7 +217,7 @@ public:
|
|||
bool operator>=(const Type &other) const { return !operator<(other); }
|
||||
|
||||
// is parameters count check necessary ??
|
||||
builtin::types::Type to_builtin() const {
|
||||
builtin::Type to_builtin() const {
|
||||
auto builtin_type = builtin::types::to_type(*name_.get());
|
||||
|
||||
auto builtin_type_parameters_count =
|
||||
|
|
@ -226,15 +226,13 @@ public:
|
|||
// for fixed parameter counts
|
||||
if (builtin_type_parameters_count.has_value() &&
|
||||
builtin_type_parameters_count.value() != parameters_.size()) {
|
||||
return builtin::types::Type::NONE;
|
||||
return builtin::Type::NONE;
|
||||
}
|
||||
|
||||
return builtin_type;
|
||||
}
|
||||
|
||||
bool is_builtin(builtin::types::Type type) const {
|
||||
return to_builtin() == type;
|
||||
}
|
||||
bool is_builtin(builtin::Type type) const { return to_builtin() == type; }
|
||||
|
||||
private:
|
||||
Identifier name_;
|
||||
|
|
@ -247,7 +245,7 @@ class TypeStorage {
|
|||
friend TypeProxy;
|
||||
|
||||
public:
|
||||
TypeProxy primitive_type(builtin::types::Type type) {
|
||||
TypeProxy primitive(builtin::Type type) {
|
||||
auto iter = primitive_type_ids_.find(type);
|
||||
if (iter != primitive_type_ids_.end()) {
|
||||
return TypeProxy(*this, iter->second);
|
||||
|
|
@ -289,7 +287,7 @@ public:
|
|||
}
|
||||
|
||||
nodes::TypeProxy add_container_of(std::vector<TypeProxy> &¶meters,
|
||||
builtin::types::Type container,
|
||||
builtin::Type container,
|
||||
Node node = Node()) {
|
||||
for (auto ¶meter : parameters) {
|
||||
if (parameter.type_storage_ != this) {
|
||||
|
|
@ -343,7 +341,7 @@ public:
|
|||
if (type.is_generic()) {
|
||||
auto iter = resolved_generic_names_.find(*type.get_name()->get());
|
||||
|
||||
// because of undefined order sone types can became resolved earlir
|
||||
// because of undefined order some types can became resolved earlir
|
||||
// wirking correctly because each generic type has <= 1 successor, no
|
||||
// cyclic deps allowed (do check ??)
|
||||
if (iter != resolved_generic_names_.end()) {
|
||||
|
|
@ -471,7 +469,7 @@ private:
|
|||
|
||||
private:
|
||||
// check is builtin type instaniated
|
||||
std::unordered_map<builtin::types::Type, size_t> primitive_type_ids_;
|
||||
std::unordered_map<builtin::Type, size_t> primitive_type_ids_;
|
||||
|
||||
// deal with generic types and generic names
|
||||
std::unordered_map<std::string, size_t> resolved_generic_names_;
|
||||
|
|
@ -485,46 +483,4 @@ private:
|
|||
std::vector<Type> storage_;
|
||||
};
|
||||
|
||||
class TypeCheckResult {
|
||||
public:
|
||||
// for invalid type
|
||||
static TypeCheckResult construct_invalid_result() {
|
||||
return TypeCheckResult();
|
||||
}
|
||||
|
||||
explicit TypeCheckResult(nodes::TypeProxy type) : type_(type) {}
|
||||
|
||||
//
|
||||
|
||||
TypeProxy &get() {
|
||||
if (!type_.has_value()) {
|
||||
error_handling::handle_general_error(
|
||||
"Access to invalid type in TypeCheckResult");
|
||||
}
|
||||
|
||||
return type_.value();
|
||||
}
|
||||
|
||||
const TypeProxy &get() const {
|
||||
if (!type_.has_value()) {
|
||||
error_handling::handle_general_error(
|
||||
"Access to invalid type in TypeCheckResult");
|
||||
}
|
||||
|
||||
return type_.value();
|
||||
}
|
||||
|
||||
void set(TypeProxy type) { type_ = type; }
|
||||
|
||||
//
|
||||
|
||||
bool is_invalid() const { return !type_.has_value(); }
|
||||
|
||||
private:
|
||||
TypeCheckResult() = default;
|
||||
|
||||
private:
|
||||
nodes::MaybeTypeProxy type_;
|
||||
};
|
||||
|
||||
} // namespace nodes
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue