mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-17 12:28:45 +00:00
changes for new grammar, fixes
This commit is contained in:
parent
91f9affadc
commit
3106a64949
35 changed files with 605 additions and 550 deletions
|
|
@ -144,7 +144,9 @@ std::string TupleType::ToString() const {
|
|||
|
||||
std::optional<utils::IdType> VariantType::InContext(const std::unordered_map<std::string, utils::IdType>& context) {
|
||||
for (size_t i = 0; i < constructors_.size(); ++i) {
|
||||
constructors_[i].InContext(context);
|
||||
if (constructors_[i].second.has_value()) {
|
||||
constructors_[i].second.value().InContext(context);
|
||||
}
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
|
|
@ -156,9 +158,20 @@ bool VariantType::Same(const VariantType& type) const {
|
|||
}
|
||||
|
||||
for (size_t i = 0; i < constructors_.size(); ++i) {
|
||||
if (!constructors_[i].Same(constructors_[i])) {
|
||||
|
||||
if (constructors_[i].first != type.constructors_[i].first) { // TODO: decide
|
||||
return false;
|
||||
}
|
||||
|
||||
if (constructors_[i].second.has_value() != type.constructors_[i].second.has_value()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (constructors_[i].second.has_value()) {
|
||||
if (!constructors_[i].second.value().Same(type.constructors_[i].second.value())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
@ -184,8 +197,8 @@ bool VariantType::operator>(const VariantType& type) 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, type_namespaces);
|
||||
if (current_constructor_.has_value() && constructors_.at(current_constructor_.value()).second.has_value()) {
|
||||
return constructors_[current_constructor_.value()].second.value().GetFieldType(name, type_namespaces);
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
|
@ -197,7 +210,10 @@ std::string VariantType::ToString() const {
|
|||
|
||||
for (auto& constructor : constructors_) {
|
||||
result += "& ";
|
||||
result += constructor.ToString();
|
||||
result += constructor.first;
|
||||
if (constructor.second.has_value()) {
|
||||
result += " " + constructor.second.value().ToString();
|
||||
}
|
||||
}
|
||||
|
||||
result += ")";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue