mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-03 05:57:40 -05:00
patterns: Added array index syntax to rvalues and turned addressof/sizeof into operators
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <bit>
|
||||
#include <optional>
|
||||
#include <unordered_map>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
namespace hex::lang {
|
||||
@@ -394,20 +395,29 @@ namespace hex::lang {
|
||||
|
||||
class ASTNodeRValue : public ASTNode {
|
||||
public:
|
||||
explicit ASTNodeRValue(std::vector<std::string> path) : ASTNode(), m_path(std::move(path)) { }
|
||||
using Path = std::vector<std::variant<std::string, ASTNode*>>;
|
||||
|
||||
explicit ASTNodeRValue(Path path) : ASTNode(), m_path(std::move(path)) { }
|
||||
|
||||
ASTNodeRValue(const ASTNodeRValue&) = default;
|
||||
|
||||
~ASTNodeRValue() override {
|
||||
for (auto &part : this->m_path) {
|
||||
if (auto node = std::get_if<ASTNode*>(&part); node != nullptr)
|
||||
delete *node;
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] ASTNode* clone() const override {
|
||||
return new ASTNodeRValue(*this);
|
||||
}
|
||||
|
||||
const std::vector<std::string>& getPath() {
|
||||
const Path& getPath() {
|
||||
return this->m_path;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::string> m_path;
|
||||
Path m_path;
|
||||
};
|
||||
|
||||
class ASTNodeScopeResolution : public ASTNode {
|
||||
@@ -557,4 +567,35 @@ namespace hex::lang {
|
||||
std::optional<std::string> m_value;
|
||||
};
|
||||
|
||||
class ASTNodeTypeOperator : public ASTNode {
|
||||
public:
|
||||
ASTNodeTypeOperator(Token::Operator op, ASTNode *expression) : m_op(op), m_expression(expression) {
|
||||
|
||||
}
|
||||
|
||||
ASTNodeTypeOperator(const ASTNodeTypeOperator &other) : ASTNode(other) {
|
||||
this->m_op = other.m_op;
|
||||
this->m_expression = other.m_expression->clone();
|
||||
}
|
||||
|
||||
[[nodiscard]] ASTNode* clone() const override {
|
||||
return new ASTNodeTypeOperator(*this);
|
||||
}
|
||||
|
||||
~ASTNodeTypeOperator() override {
|
||||
delete this->m_expression;
|
||||
}
|
||||
|
||||
Token::Operator getOperator() const {
|
||||
return this->m_op;
|
||||
}
|
||||
|
||||
ASTNode* getExpression() const {
|
||||
return this->m_expression;
|
||||
}
|
||||
|
||||
private:
|
||||
Token::Operator m_op;
|
||||
ASTNode *m_expression;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user