From 81a8b75e622cd246b371f09b7292aaac0b324648 Mon Sep 17 00:00:00 2001 From: Vasilii Rogin Date: Sun, 14 May 2023 22:44:32 +0300 Subject: [PATCH] Removing TODOs --- src/sfall_arrays.cc | 100 ++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 65 deletions(-) diff --git a/src/sfall_arrays.cc b/src/sfall_arrays.cc index f135130..6fb0fc6 100644 --- a/src/sfall_arrays.cc +++ b/src/sfall_arrays.cc @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -24,7 +25,6 @@ static ArrayId stackArrayId = 0; #define ARRAY_ACTION_REVERSE (-4) #define ARRAY_ACTION_SHUFFLE (-5) -// TODO: Move me into separate file "sfall_arrays_utils" template static void ListSort(std::vector& arr, int type, Compare cmp) { @@ -70,14 +70,16 @@ private: union { int integerValue; float floatValue; - unsigned char* stringValue; + char* stringValue; void* pointerValue; }; public: - ArrayElement() { - // todo - }; + ArrayElement() + : type(ArrayElementType::INT) + , integerValue(0) { + // nothing here + }; ArrayElement(const ArrayElement& other) = delete; ArrayElement& operator=(const ArrayElement& rhs) = delete; @@ -90,8 +92,6 @@ public: return *this; } - // TODO: Remove all other constructors - ArrayElement(ProgramValue programValue, Program* program) { // todo @@ -104,27 +104,39 @@ public: bool operator<(ArrayElement const& other) const { - // todo - return false; + if (type != other.type) { + return type < other.type; + }; + switch (type) { + case ArrayElementType::INT: + return integerValue < other.integerValue; + case ArrayElementType::FLOAT: + return floatValue < other.floatValue; + case ArrayElementType::POINTER: + return pointerValue < other.pointerValue; + case ArrayElementType::STRING: + return strcmp(stringValue, other.stringValue) < 0; + default: + throw(std::exception()); + } } bool operator==(ArrayElement const& other) const { - // todo - /* - if (!a.isString()) { - return a == b; - }; - if (!b.isString()) { + if (type != other.type) { return false; }; - auto str1 = programGetString(program, a.opcode, a.integerValue); - auto str2 = programGetString(program, a.opcode, a.integerValue); - if (!str1 || !str2) { - return false; - }; - return strcmp(str1, str2) == 0; - */ - return false; + switch (type) { + case ArrayElementType::INT: + return integerValue == other.integerValue; + case ArrayElementType::FLOAT: + return floatValue == other.floatValue; + case ArrayElementType::POINTER: + return pointerValue == other.pointerValue; + case ArrayElementType::STRING: + return strcmp(stringValue, other.stringValue) == 0; + default: + throw(std::exception()); + } } }; @@ -143,48 +155,6 @@ public: virtual ~SFallArray() = default; }; -/* -bool ProgramValue::operator<(ProgramValue const& other) const -{ - if (opcode != other.opcode) { - return opcode < other.opcode; - } - - switch (opcode) { - case VALUE_TYPE_INT: - case VALUE_TYPE_STRING: - case VALUE_TYPE_DYNAMIC_STRING: - return integerValue < other.integerValue; - case VALUE_TYPE_PTR: - return pointerValue < other.pointerValue; - case VALUE_TYPE_FLOAT: - return floatValue < other.floatValue; - default: - throw(std::exception()); - } -} - -bool ProgramValue::operator==(ProgramValue const& other) const -{ - if (opcode != other.opcode) { - return false; - } - - switch (opcode) { - case VALUE_TYPE_INT: - case VALUE_TYPE_STRING: - case VALUE_TYPE_DYNAMIC_STRING: - return integerValue == other.integerValue; - case VALUE_TYPE_PTR: - return pointerValue == other.pointerValue; - case VALUE_TYPE_FLOAT: - return floatValue == other.floatValue; - default: - throw(std::exception()); - } -} -*/ - class SFallArrayList : public SFallArray { private: std::vector values;