aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Spartan322 <Megacake1234@gmail.com>2023-11-04 02:41:33 +0100
committer Spartan322 <Megacake1234@gmail.com>2023-11-04 02:41:33 +0100
commit3a0f4872bf77578f5c53cb054a64e4d73c1a00f7 (patch)
tree1369794c1a0fced9dc01b4e90b4f0f4f2e6c646d
parentefc11f571794acd64884680834c6636a03e8322b (diff)
Change nodes to support list checks:
EventNode DecisionNode EventMtthModifierNode ExecutionListNode
-rw-r--r--include/openvic-dataloader/v2script/AbstractSyntaxTree.hpp47
-rw-r--r--src/openvic-dataloader/v2script/AbstractSyntaxTree.cpp6
2 files changed, 25 insertions, 28 deletions
diff --git a/include/openvic-dataloader/v2script/AbstractSyntaxTree.hpp b/include/openvic-dataloader/v2script/AbstractSyntaxTree.hpp
index 32e7e42..689ab6e 100644
--- a/include/openvic-dataloader/v2script/AbstractSyntaxTree.hpp
+++ b/include/openvic-dataloader/v2script/AbstractSyntaxTree.hpp
@@ -30,9 +30,9 @@ namespace ovdl::v2script {
constexpr std::string_view get_type() const override { return ::ovdl::detail::type_name<std::decay_t<decltype(*this)>>(); }
// defines type for self-class referencing
-#define OVDL_TYPE_DEFINE_SELF \
- struct _self_type_tag {}; \
- constexpr auto _self_type_helper()->decltype(::ovdl::detail::Writer<_self_type_tag, decltype(this)> {}); \
+#define OVDL_TYPE_DEFINE_SELF \
+ struct _self_type_tag {}; \
+ constexpr auto _self_type_helper() -> decltype(::ovdl::detail::Writer<_self_type_tag, decltype(this)> {}); \
using type = ::ovdl::detail::Read<_self_type_tag>;
namespace ovdl::v2script::ast {
@@ -248,37 +248,35 @@ namespace ovdl::v2script::ast {
#undef OVDL_AST_LIST_NODE
- struct EventNode final : public Node {
+#define OVDL_AST_LIST_EXTEND(NAME) \
+ NAME(lexy::nullopt); \
+ NAME(NodeLocation location, lexy::nullopt); \
+ OVDL_TYPE_DEFINE_SELF; \
+ OVDL_RT_TYPE_DEF; \
+ OVDL_PRINT_FUNC_DEF
+
+ struct EventNode final : public AbstractListNode {
+ OVDL_AST_LIST_EXTEND(EventNode);
enum class Type {
Country,
Province
} _type;
- std::vector<NodeUPtr> _statements;
EventNode(Type type, const std::vector<NodePtr>& statements = {});
EventNode(NodeLocation location, Type type, const std::vector<NodePtr>& statements = {});
- OVDL_TYPE_DEFINE_SELF;
- OVDL_RT_TYPE_DEF;
- OVDL_PRINT_FUNC_DEF;
};
- struct DecisionNode final : public Node {
+ struct DecisionNode final : public AbstractListNode {
+ OVDL_AST_LIST_EXTEND(DecisionNode);
NodeUPtr _name;
- std::vector<NodeUPtr> _statements;
DecisionNode(NodePtr name, const std::vector<NodePtr>& statements = {});
DecisionNode(NodeLocation location, NodePtr name, const std::vector<NodePtr>& statements = {});
- OVDL_TYPE_DEFINE_SELF;
- OVDL_RT_TYPE_DEF;
- OVDL_PRINT_FUNC_DEF;
};
- struct EventMtthModifierNode final : public Node {
+ struct EventMtthModifierNode final : public AbstractListNode {
+ OVDL_AST_LIST_EXTEND(EventMtthModifierNode);
NodeUPtr _factor_value;
- std::vector<NodeUPtr> _statements;
- EventMtthModifierNode() : Node({}) {}
- EventMtthModifierNode(NodeLocation location) : Node(location) {}
- OVDL_TYPE_DEFINE_SELF;
- OVDL_RT_TYPE_DEF;
- OVDL_PRINT_FUNC_DEF;
+ EventMtthModifierNode() : AbstractListNode() {}
+ EventMtthModifierNode(NodeLocation location) : AbstractListNode(location) {}
};
// Packed single case
@@ -296,16 +294,15 @@ namespace ovdl::v2script::ast {
OVDL_PRINT_FUNC_DEF;
};
- struct ExecutionListNode final : public Node {
+ struct ExecutionListNode final : public AbstractListNode {
+ OVDL_AST_LIST_EXTEND(ExecutionListNode);
ExecutionNode::Type _type;
- std::vector<NodeUPtr> _statements;
ExecutionListNode(ExecutionNode::Type type, const std::vector<NodePtr>& statements);
ExecutionListNode(NodeLocation location, ExecutionNode::Type type, const std::vector<NodePtr>& statements);
- OVDL_TYPE_DEFINE_SELF;
- OVDL_RT_TYPE_DEF;
- OVDL_PRINT_FUNC_DEF;
};
+#undef OVDL_AST_LIST_EXTEND
+
}
#undef OVDL_PRINT_FUNC_DECL
diff --git a/src/openvic-dataloader/v2script/AbstractSyntaxTree.cpp b/src/openvic-dataloader/v2script/AbstractSyntaxTree.cpp
index 5518e5d..45150cb 100644
--- a/src/openvic-dataloader/v2script/AbstractSyntaxTree.cpp
+++ b/src/openvic-dataloader/v2script/AbstractSyntaxTree.cpp
@@ -215,7 +215,7 @@ OVDL_AST_LIST_NODE_DEF(DecisionListNode, {
#undef OVDL_AST_LIST_NODE_DEF
-EventNode::EventNode(NodeLocation location, Type type, const std::vector<NodePtr>& statements) : Node(location),
+EventNode::EventNode(NodeLocation location, Type type, const std::vector<NodePtr>& statements) : AbstractListNode(location),
_type(type) {
copy_into_node_ptr_vector(statements, _statements);
}
@@ -233,7 +233,7 @@ std::ostream& EventNode::print(std::ostream& stream, size_t indent) const {
return stream << '}';
}
-DecisionNode::DecisionNode(NodeLocation location, NodePtr name, const std::vector<NodePtr>& statements) : Node(location),
+DecisionNode::DecisionNode(NodeLocation location, NodePtr name, const std::vector<NodePtr>& statements) : AbstractListNode(location),
_name(std::move(name)) {
copy_into_node_ptr_vector(statements, _statements);
}
@@ -261,7 +261,7 @@ std::ostream& ExecutionNode::print(std::ostream& stream, size_t indent) const {
return stream;
}
-ExecutionListNode::ExecutionListNode(NodeLocation location, ExecutionNode::Type type, const std::vector<NodePtr>& statements) : Node(location),
+ExecutionListNode::ExecutionListNode(NodeLocation location, ExecutionNode::Type type, const std::vector<NodePtr>& statements) : AbstractListNode(location),
_type(type) {
copy_into_node_ptr_vector(statements, _statements);
}