patterns: Fixed recursive types

This commit is contained in:
WerWolv
2022-03-17 00:10:16 +01:00
parent 844845223f
commit 2d87d29fa0
7 changed files with 46 additions and 43 deletions

View File

@@ -19,12 +19,12 @@ namespace hex::pl {
class ASTNodeArrayVariableDecl : public ASTNode,
public Attributable {
public:
ASTNodeArrayVariableDecl(std::string name, std::unique_ptr<ASTNode> &&type, std::unique_ptr<ASTNode> &&size, std::unique_ptr<ASTNode> &&placementOffset = {})
ASTNodeArrayVariableDecl(std::string name, std::shared_ptr<ASTNodeTypeDecl> type, std::unique_ptr<ASTNode> &&size, std::unique_ptr<ASTNode> &&placementOffset = {})
: ASTNode(), m_name(std::move(name)), m_type(std::move(type)), m_size(std::move(size)), m_placementOffset(std::move(placementOffset)) { }
ASTNodeArrayVariableDecl(const ASTNodeArrayVariableDecl &other) : ASTNode(other), Attributable(other) {
this->m_name = other.m_name;
this->m_type = other.m_type->clone();
this->m_type = other.m_type;
if (other.m_size != nullptr)
this->m_size = other.m_size->clone();
else
@@ -81,7 +81,7 @@ namespace hex::pl {
private:
std::string m_name;
std::unique_ptr<ASTNode> m_type;
std::shared_ptr<ASTNodeTypeDecl> m_type;
std::unique_ptr<ASTNode> m_size;
std::unique_ptr<ASTNode> m_placementOffset;

View File

@@ -10,13 +10,13 @@ namespace hex::pl {
class ASTNodePointerVariableDecl : public ASTNode,
public Attributable {
public:
ASTNodePointerVariableDecl(std::string name, std::shared_ptr<ASTNode> &&type, std::shared_ptr<ASTNode> &&sizeType, std::unique_ptr<ASTNode> &&placementOffset = nullptr)
ASTNodePointerVariableDecl(std::string name, std::shared_ptr<ASTNodeTypeDecl> type, std::shared_ptr<ASTNodeTypeDecl> sizeType, std::unique_ptr<ASTNode> &&placementOffset = nullptr)
: ASTNode(), m_name(std::move(name)), m_type(std::move(type)), m_sizeType(std::move(sizeType)), m_placementOffset(std::move(placementOffset)) { }
ASTNodePointerVariableDecl(const ASTNodePointerVariableDecl &other) : ASTNode(other), Attributable(other) {
this->m_name = other.m_name;
this->m_type = other.m_type->clone();
this->m_sizeType = other.m_sizeType->clone();
this->m_type = other.m_type;
this->m_sizeType = other.m_sizeType;
if (other.m_placementOffset != nullptr)
this->m_placementOffset = other.m_placementOffset->clone();
@@ -29,8 +29,8 @@ namespace hex::pl {
}
[[nodiscard]] const std::string &getName() const { return this->m_name; }
[[nodiscard]] constexpr const std::shared_ptr<ASTNode> &getType() const { return this->m_type; }
[[nodiscard]] constexpr const std::shared_ptr<ASTNode> &getSizeType() const { return this->m_sizeType; }
[[nodiscard]] constexpr const std::shared_ptr<ASTNodeTypeDecl> &getType() const { return this->m_type; }
[[nodiscard]] constexpr const std::shared_ptr<ASTNodeTypeDecl> &getSizeType() const { return this->m_sizeType; }
[[nodiscard]] constexpr const std::unique_ptr<ASTNode> &getPlacementOffset() const { return this->m_placementOffset; }
[[nodiscard]] std::vector<std::unique_ptr<Pattern>> createPatterns(Evaluator *evaluator) const override {
@@ -87,8 +87,8 @@ namespace hex::pl {
private:
std::string m_name;
std::shared_ptr<ASTNode> m_type;
std::shared_ptr<ASTNode> m_sizeType;
std::shared_ptr<ASTNodeTypeDecl> m_type;
std::shared_ptr<ASTNodeTypeDecl> m_sizeType;
std::unique_ptr<ASTNode> m_placementOffset;
};

View File

@@ -8,7 +8,7 @@ namespace hex::pl {
class ASTNodeTypeDecl : public ASTNode,
public Attributable {
public:
ASTNodeTypeDecl(std::string name, std::shared_ptr<ASTNode> &&type, std::optional<std::endian> endian = std::nullopt)
ASTNodeTypeDecl(std::string name, std::shared_ptr<ASTNode> type, std::optional<std::endian> endian = std::nullopt)
: ASTNode(), m_name(std::move(name)), m_type(std::move(type)), m_endian(endian) { }
ASTNodeTypeDecl(const ASTNodeTypeDecl &other) : ASTNode(other), Attributable(other) {

View File

@@ -3,18 +3,19 @@
#include <hex/pattern_language/ast/ast_node.hpp>
#include <hex/pattern_language/ast/ast_node_attribute.hpp>
#include <hex/pattern_language/ast/ast_node_literal.hpp>
#include <hex/pattern_language/ast/ast_node_type_decl.hpp>
namespace hex::pl {
class ASTNodeVariableDecl : public ASTNode,
public Attributable {
public:
ASTNodeVariableDecl(std::string name, std::unique_ptr<ASTNode> &&type, std::unique_ptr<ASTNode> &&placementOffset = nullptr, bool inVariable = false, bool outVariable = false)
ASTNodeVariableDecl(std::string name, std::shared_ptr<ASTNodeTypeDecl> type, std::unique_ptr<ASTNode> &&placementOffset = nullptr, bool inVariable = false, bool outVariable = false)
: ASTNode(), m_name(std::move(name)), m_type(std::move(type)), m_placementOffset(std::move(placementOffset)), m_inVariable(inVariable), m_outVariable(outVariable) { }
ASTNodeVariableDecl(const ASTNodeVariableDecl &other) : ASTNode(other), Attributable(other) {
this->m_name = other.m_name;
this->m_type = other.m_type->clone();
this->m_type = other.m_type;
if (other.m_placementOffset != nullptr)
this->m_placementOffset = other.m_placementOffset->clone();
@@ -30,7 +31,7 @@ namespace hex::pl {
}
[[nodiscard]] const std::string &getName() const { return this->m_name; }
[[nodiscard]] constexpr const std::unique_ptr<ASTNode> &getType() const { return this->m_type; }
[[nodiscard]] constexpr const std::shared_ptr<ASTNodeTypeDecl> &getType() const { return this->m_type; }
[[nodiscard]] constexpr const std::unique_ptr<ASTNode> &getPlacementOffset() const { return this->m_placementOffset; }
[[nodiscard]] constexpr bool isInVariable() const { return this->m_inVariable; }
@@ -71,7 +72,7 @@ namespace hex::pl {
private:
std::string m_name;
std::unique_ptr<ASTNode> m_type;
std::shared_ptr<ASTNodeTypeDecl> m_type;
std::unique_ptr<ASTNode> m_placementOffset;
bool m_inVariable = false, m_outVariable = false;

View File

@@ -112,17 +112,17 @@ namespace hex::pl {
std::unique_ptr<ASTNodeTypeDecl> parseType(bool allowFunctionTypes = false);
std::shared_ptr<ASTNodeTypeDecl> parseUsingDeclaration();
std::unique_ptr<ASTNode> parsePadding();
std::unique_ptr<ASTNode> parseMemberVariable(std::unique_ptr<ASTNodeTypeDecl> &&type);
std::unique_ptr<ASTNode> parseMemberArrayVariable(std::unique_ptr<ASTNodeTypeDecl> &&type);
std::unique_ptr<ASTNode> parseMemberPointerVariable(std::unique_ptr<ASTNodeTypeDecl> &&type);
std::unique_ptr<ASTNode> parseMemberVariable(const std::shared_ptr<ASTNodeTypeDecl> &type);
std::unique_ptr<ASTNode> parseMemberArrayVariable(const std::shared_ptr<ASTNodeTypeDecl> &type);
std::unique_ptr<ASTNode> parseMemberPointerVariable(const std::shared_ptr<ASTNodeTypeDecl> &type);
std::unique_ptr<ASTNode> parseMember();
std::shared_ptr<ASTNodeTypeDecl> parseStruct();
std::shared_ptr<ASTNodeTypeDecl> parseUnion();
std::shared_ptr<ASTNodeTypeDecl> parseEnum();
std::shared_ptr<ASTNodeTypeDecl> parseBitfield();
std::unique_ptr<ASTNode> parseVariablePlacement(std::unique_ptr<ASTNodeTypeDecl> &&type);
std::unique_ptr<ASTNode> parseArrayVariablePlacement(std::unique_ptr<ASTNodeTypeDecl> &&type);
std::unique_ptr<ASTNode> parsePointerVariablePlacement(std::unique_ptr<ASTNodeTypeDecl> &&type);
std::unique_ptr<ASTNode> parseVariablePlacement(const std::shared_ptr<ASTNodeTypeDecl> &type);
std::unique_ptr<ASTNode> parseArrayVariablePlacement(const std::shared_ptr<ASTNodeTypeDecl> &type);
std::unique_ptr<ASTNode> parsePointerVariablePlacement(const std::shared_ptr<ASTNodeTypeDecl> &type);
std::unique_ptr<ASTNode> parsePlacement();
std::vector<std::shared_ptr<ASTNode>> parseNamespace();
std::vector<std::shared_ptr<ASTNode>> parseStatements();