-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e576fb
commit 21e5983
Showing
17 changed files
with
231 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include "ValueUtils.h" | ||
|
||
namespace em::utils::values { | ||
namespace { | ||
const auto TRUE = std::make_shared<em::values::LiteralValue<bool>>(true); | ||
const auto FALSE = std::make_shared<em::values::LiteralValue<bool>>(false); | ||
} // namespace | ||
|
||
const std::shared_ptr<em::values::LiteralValue<bool>>& toValue(bool val) { | ||
return val ? TRUE : FALSE; | ||
} | ||
} // namespace em::utils::values |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include "../Token.h" | ||
#include "../values/LiteralValue.h" | ||
#include "../values/Value.h" | ||
|
||
namespace em::utils::values { | ||
|
||
const std::shared_ptr<em::values::LiteralValue<bool>>& toValue(bool val); | ||
|
||
template <typename T> | ||
std::shared_ptr<T> requireType(const std::shared_ptr<em::values::Value>& value, | ||
const std::string& errorMessage) { | ||
if (auto castedPtr = std::dynamic_pointer_cast<T>(value)) { | ||
return castedPtr; | ||
} | ||
throw std::logic_error(errorMessage); | ||
} | ||
|
||
template <typename T> | ||
std::shared_ptr<T> requireType(const std::shared_ptr<em::values::Value>& value, | ||
const Token& token) { | ||
return requireType<T>(value, "Operation " + TokenTypeToString(token.type()) + | ||
" is not supported for operand " + | ||
value->str() + " at " + | ||
token.location().str()); | ||
} | ||
|
||
} // namespace em::utils::values |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,16 @@ | ||
#pragma once | ||
#include <memory> | ||
|
||
namespace em::values { | ||
class Value : public std::enable_shared_from_this<Value> { | ||
public: | ||
virtual ~Value() = default; | ||
class Value { | ||
public: | ||
virtual ~Value() = default; | ||
|
||
virtual bool operator==(const Value& other) = 0; | ||
virtual bool operator==(const Value& other) = 0; | ||
|
||
virtual bool operator!=(const Value& other) = 0; | ||
virtual bool operator!=(const Value& other) = 0; | ||
|
||
virtual explicit operator bool() const = 0; | ||
[[nodiscard]] virtual size_t hash() const = 0; | ||
|
||
[[nodiscard]] virtual size_t hash() const = 0; | ||
|
||
[[nodiscard]] bool isTruthy() const; | ||
|
||
[[nodiscard]] std::unique_ptr<Value> isEqualTo(const std::shared_ptr<Value>& other); | ||
|
||
[[nodiscard]] std::unique_ptr<Value> isDifferentTo(const std::shared_ptr<Value>& other); | ||
|
||
[[nodiscard]] virtual std::unique_ptr<Value> isSubsetOf(const std::shared_ptr<Value>& other) const = 0; | ||
|
||
[[nodiscard]] virtual std::unique_ptr<Value> hasElement(const std::shared_ptr<Value>& other) const = 0; | ||
|
||
[[nodiscard]] std::unique_ptr<Value> isElementOf(const std::shared_ptr<Value>& other); | ||
|
||
[[nodiscard]] std::unique_ptr<Value> isNotSubsetOf(const std::shared_ptr<Value>& other) const; | ||
|
||
[[nodiscard]] virtual std::unique_ptr<Value> negation() const = 0; | ||
|
||
[[nodiscard]] virtual std::unique_ptr<Value> unionOp(const std::shared_ptr<Value>& other) const = 0; | ||
|
||
[[nodiscard]] virtual std::unique_ptr<Value> intersection(const std::shared_ptr<Value>& other) const = 0; | ||
|
||
[[nodiscard]] virtual std::string str() const = 0; | ||
}; | ||
[[nodiscard]] virtual std::string str() const = 0; | ||
}; | ||
} // namespace em::values |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.