mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-07 23:48:43 +00:00
namespace storage fix, namespace enter fix, maybe other fixes
This commit is contained in:
parent
4882d458f8
commit
4b4756b657
11 changed files with 250 additions and 174 deletions
|
|
@ -29,7 +29,8 @@ bool AbstractType::operator>(const AbstractType& type) const {
|
|||
return type < *this;
|
||||
}
|
||||
|
||||
std::optional<utils::IdType> AbstractType::GetFieldType(const std::string& name) const {
|
||||
std::optional<utils::IdType> AbstractType::GetFieldType(const std::string& name,
|
||||
const std::unordered_set<utils::IdType>& type_namespaces) const {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
|
|
@ -59,8 +60,12 @@ bool DefinedType::operator>(const DefinedType& type) const {
|
|||
return type < *this;
|
||||
}
|
||||
|
||||
std::optional<utils::IdType> DefinedType::GetFieldType(const std::string& name) const {
|
||||
return type_manager_->GetAnyValue(type_)->GetFieldType(name);
|
||||
std::optional<utils::IdType> DefinedType::GetFieldType(const std::string& name,
|
||||
const std::unordered_set<utils::IdType>& type_namespaces) const {
|
||||
if (class_modifier_ == utils::ClassModifier::Struct || type_namespaces.count(type_id_) != 0) {
|
||||
return type_manager_->GetAnyValue(type_)->GetFieldType(name, type_namespaces);
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
//
|
||||
|
|
@ -109,7 +114,8 @@ bool TupleType::operator>(const TupleType& type) const {
|
|||
return type < *this;
|
||||
}
|
||||
|
||||
std::optional<utils::IdType> TupleType::GetFieldType(const std::string& name) const {
|
||||
std::optional<utils::IdType> TupleType::GetFieldType(const std::string& name,
|
||||
const std::unordered_set<utils::IdType>& type_namespaces) const {
|
||||
for (size_t i = 0; i < fields_.size(); ++i) { // TODO: optimize??
|
||||
if (fields_[i].first.has_value() && fields_[i].first.value() == name) {
|
||||
return fields_[i].second;
|
||||
|
|
@ -160,9 +166,10 @@ bool VariantType::operator>(const VariantType& type) const {
|
|||
return type < *this;
|
||||
}
|
||||
|
||||
std::optional<utils::IdType> VariantType::GetFieldType(const std::string& name) const {
|
||||
std::optional<utils::IdType> VariantType::GetFieldType(const std::string& name,
|
||||
const std::unordered_set<utils::IdType>& type_namespaces) const {
|
||||
if (current_constructor_.has_value()) {
|
||||
return constructors_.at(current_constructor_.value()).GetFieldType(name);
|
||||
return constructors_.at(current_constructor_.value()).GetFieldType(name, type_namespaces);
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
|
@ -191,7 +198,8 @@ bool OptionalType::operator>(const OptionalType& type) const {
|
|||
return type < *this;
|
||||
}
|
||||
|
||||
std::optional<utils::IdType> OptionalType::GetFieldType(const std::string& name) const {
|
||||
std::optional<utils::IdType> OptionalType::GetFieldType(const std::string& name,
|
||||
const std::unordered_set<utils::IdType>& type_namespaces) const {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
|
|
@ -219,8 +227,9 @@ bool ReferenceToType::operator>(const ReferenceToType& type) const {
|
|||
return type < *this;
|
||||
}
|
||||
|
||||
std::optional<utils::IdType> ReferenceToType::GetFieldType(const std::string& name) const {
|
||||
return type_manager_->GetAnyValue(type_)->GetFieldType(name);
|
||||
std::optional<utils::IdType> ReferenceToType::GetFieldType(const std::string& name,
|
||||
const std::unordered_set<utils::IdType>& type_namespaces) const {
|
||||
return type_manager_->GetAnyValue(type_)->GetFieldType(name, type_namespaces);
|
||||
}
|
||||
|
||||
//
|
||||
|
|
@ -270,7 +279,8 @@ bool FunctionType::operator>(const FunctionType& type) const {
|
|||
return type < *this;
|
||||
}
|
||||
|
||||
std::optional<utils::IdType> FunctionType::GetFieldType(const std::string& name) const {
|
||||
std::optional<utils::IdType> FunctionType::GetFieldType(const std::string& name,
|
||||
const std::unordered_set<utils::IdType>& type_namespaces) const {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
|
|
@ -299,7 +309,8 @@ bool ArrayType::operator>(const ArrayType& type) const {
|
|||
return type < *this;
|
||||
}
|
||||
|
||||
std::optional<utils::IdType> ArrayType::GetFieldType(const std::string& name) const {
|
||||
std::optional<utils::IdType> ArrayType::GetFieldType(const std::string& name,
|
||||
const std::unordered_set<utils::IdType>& type_namespaces) const {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
|
|
@ -405,28 +416,29 @@ bool Type::operator>(const Type& type) const {
|
|||
return type < *this;
|
||||
}
|
||||
|
||||
std::optional<utils::IdType> Type::GetFieldType(const std::string& name) const {
|
||||
std::optional<utils::IdType> Type::GetFieldType(const std::string& name,
|
||||
const std::unordered_set<utils::IdType>& type_namespaces) const {
|
||||
size_t index = type_.index();
|
||||
|
||||
switch (index) {
|
||||
case 0:
|
||||
return std::get<AbstractType>(type_).GetFieldType(name);
|
||||
return std::get<AbstractType>(type_).GetFieldType(name, type_namespaces);
|
||||
case 1:
|
||||
return std::get<DefinedType>(type_).GetFieldType(name);
|
||||
return std::get<DefinedType>(type_).GetFieldType(name, type_namespaces);
|
||||
case 2:
|
||||
return std::nullopt;
|
||||
case 3:
|
||||
return std::get<TupleType>(type_).GetFieldType(name);
|
||||
return std::get<TupleType>(type_).GetFieldType(name, type_namespaces);
|
||||
case 4:
|
||||
return std::get<VariantType>(type_).GetFieldType(name);
|
||||
return std::get<VariantType>(type_).GetFieldType(name, type_namespaces);
|
||||
case 5:
|
||||
return std::get<ReferenceToType>(type_).GetFieldType(name);
|
||||
return std::get<ReferenceToType>(type_).GetFieldType(name, type_namespaces);
|
||||
case 6:
|
||||
return std::get<FunctionType>(type_).GetFieldType(name);
|
||||
return std::get<FunctionType>(type_).GetFieldType(name, type_namespaces);
|
||||
case 7:
|
||||
return std::get<ArrayType>(type_).GetFieldType(name);
|
||||
return std::get<ArrayType>(type_).GetFieldType(name, type_namespaces);
|
||||
case 8:
|
||||
return std::get<OptionalType>(type_).GetFieldType(name);
|
||||
return std::get<OptionalType>(type_).GetFieldType(name, type_namespaces);
|
||||
default:
|
||||
// error
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue