mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-05 22:48:42 +00:00
values comparation (equality, using Same function)
This commit is contained in:
parent
b901078956
commit
e75652afc3
1 changed files with 27 additions and 4 deletions
|
|
@ -4,7 +4,30 @@
|
|||
namespace info::value {
|
||||
|
||||
bool InternalValue::Same(const InternalValue& other_value) const {
|
||||
size_t this_index = value.index();
|
||||
size_t other_index = other_value.value.index();
|
||||
|
||||
if (this_index == other_index) {
|
||||
switch (this_index) {
|
||||
case 0:
|
||||
return std::get<double>(value) == std::get<double>(other_value.value);
|
||||
case 1:
|
||||
return std::get<long long>(value) == std::get<long long>(other_value.value);
|
||||
case 2:
|
||||
return std::get<std::string>(value) == std::get<std::string>(other_value.value);
|
||||
case 3:
|
||||
return std::get<char>(value) == std::get<char>(other_value.value);
|
||||
case 4:
|
||||
return std::get<bool>(value) == std::get<bool>(other_value.value);
|
||||
case 5: // Unit
|
||||
return true;
|
||||
default:
|
||||
// error
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::optional<utils::IdType> InternalValue::GetFieldValue(const std::string& name) const {
|
||||
|
|
@ -14,12 +37,12 @@ std::optional<utils::IdType> InternalValue::GetFieldValue(const std::string& nam
|
|||
//
|
||||
|
||||
bool TupleValue::Same(const TupleValue& other_value) const {
|
||||
// TODO: check, that type is same
|
||||
// TODO: check, that type is same ?? (checked in typecheck ??)
|
||||
if (fields.size() != other_value.fields.size()) {
|
||||
return false;
|
||||
}
|
||||
for (size_t i = 0; i < fields.size(); ++i) {
|
||||
if (!) {
|
||||
for (size_t i = 0; i < fields.size(); ++i) { // compare field names ?? (checked in typecheck ??)
|
||||
if (!value_manager_->GetAnyValue(fields[i].second)->Same(*value_manager_->GetAnyValue(other_value.fields[i].second))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -38,7 +61,7 @@ std::optional<utils::IdType> TupleValue::GetFieldValue(const std::string& name)
|
|||
//
|
||||
|
||||
bool VariantValue::Same(const VariantValue& other_value) const {
|
||||
// TODO: check, that type is same
|
||||
// TODO: check, that type is same ?? (checked in typecheck ??)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue