execute_visitor value types fixed

This commit is contained in:
ProgramSnail 2023-05-22 18:33:56 +03:00
parent 9aaac90ef6
commit 6bf64acc4d
5 changed files with 146 additions and 128 deletions

View file

@ -49,11 +49,30 @@ public:
return value_manager_.GetValueType(value_id);
}
void ModifiyValue(utils::IdType value_id, utils::ValueType new_value_type) {
GetValueType(value_id) = new_value_type;
}
utils::IdType ToModifiedValue(utils::IdType value_id, utils::ValueType new_value_type) {
Value value = *GetAnyValue(value_id);
return AddAnyValue(std::move(value), new_value_type);
}
utils::IdType ToModifiedValueCopy(utils::IdType value_id,
utils::ValueType new_value_type) {
Value* value = GetAnyValue(value_id);
return value->DeepCopy(value_manager_, new_value_type);
}
// make deep copy if not temporary
utils::IdType ToTemporaryValue(utils::IdType value_id) {
if (GetValueType(value_id) == utils::ValueType::Tmp) {
return value_id;
}
return ToModifiedValueCopy(value_id, utils::ValueType::Tmp);
}
ValueManager* GetValueManager() {
return &value_manager_;
}

View file

@ -377,7 +377,7 @@ public:
return &types_.at(type_id).first;
}
utils::ValueType GetValueType(utils::IdType type_id) {
utils::ValueType& GetValueType(utils::IdType type_id) {
return types_.at(type_id).second;
}

View file

@ -34,7 +34,7 @@ public:
bool Same(const InternalValue& value) const;
std::optional<utils::IdType> GetFieldValue(const std::string& name) const;
utils::IdType DeepCopy(ValueManager* value_manager);
utils::IdType DeepCopy(ValueManager* value_manager, utils::ValueType new_value_type);
public:
std::variant<double,
@ -45,7 +45,7 @@ public:
Unit> value;
};
struct TupleValue { /// TODO: no need to store strings (only store associated type) ??
struct TupleValue { /// no need to store strings (only store associated type) ??
public:
TupleValue() = default;
@ -56,7 +56,7 @@ public:
bool Same(const TupleValue& other_value) const;
std::optional<utils::IdType> GetFieldValue(const std::string& name) const;
utils::IdType DeepCopy(ValueManager* value_manager); // TODO
utils::IdType DeepCopy(ValueManager* value_manager, utils::ValueType new_value_type); // TODO
public:
std::vector<std::pair<std::optional<std::string>, utils::IdType>> fields;
@ -75,7 +75,7 @@ public:
bool Same(const VariantValue& other_value) const;
std::optional<utils::IdType> GetFieldValue(const std::string& name) const;
utils::IdType DeepCopy(ValueManager* value_manager);
utils::IdType DeepCopy(ValueManager* value_manager, utils::ValueType new_value_type);
public:
TupleValue value;
@ -94,7 +94,7 @@ public:
bool Same(const ReferenceToValue& other_value) const;
std::optional<utils::IdType> GetFieldValue(const std::string& name) const;
utils::IdType DeepCopy(ValueManager* value_manager);
utils::IdType DeepCopy(ValueManager* value_manager, utils::ValueType new_value_type);
public:
std::vector<utils::ReferenceModifier> references;
@ -115,7 +115,7 @@ public:
bool Same(const FunctionValue& other_value) const;
std::optional<utils::IdType> GetFieldValue(const std::string& name) const;
utils::IdType DeepCopy(ValueManager* value_manager);
utils::IdType DeepCopy(ValueManager* value_manager, utils::ValueType new_value_type);
public:
std::variant<interpreter::tokens::FunctionDeclaration*,
@ -138,7 +138,7 @@ public:
bool Same(const ArrayValue& other_value) const;
std::optional<utils::IdType> GetFieldValue(const std::string& name) const;
utils::IdType DeepCopy(ValueManager* value_manager);
utils::IdType DeepCopy(ValueManager* value_manager, utils::ValueType new_value_type);
public:
std::vector<utils::IdType> elements;
@ -158,7 +158,7 @@ public:
bool Same(const OptionalValue& other_value) const;
std::optional<utils::IdType> GetFieldValue(const std::string& name) const;
utils::IdType DeepCopy(ValueManager* value_manager);
utils::IdType DeepCopy(ValueManager* value_manager, utils::ValueType new_value_type);
public:
std::optional<utils::IdType> value;
@ -177,7 +177,7 @@ public:
bool Same(const Value& other_value) const;
std::optional<utils::IdType> GetFieldValue(const std::string& name) const;
utils::IdType DeepCopy(ValueManager* value_manager);
utils::IdType DeepCopy(ValueManager* value_manager, utils::ValueType new_value_type);
public:
std::variant<InternalValue,
@ -223,7 +223,7 @@ public:
return &values_.at(value_id).first;
}
utils::ValueType GetValueType(utils::IdType value_id) {
utils::ValueType& GetValueType(utils::IdType value_id) {
return values_.at(value_id).second;
}