Add node_handle alias suffix _h
Signed-off-by: CHatingPython <chatingpython@gmail.com>
This commit is contained in:
@@ -27,22 +27,11 @@ protected:
|
||||
bool equal(const node& rhs) const override;
|
||||
};
|
||||
|
||||
struct function_body {
|
||||
location begin, end;
|
||||
std::vector<node_handle<statement_node>> statements;
|
||||
using declaration_node_h = node_handle<declaration_node>;
|
||||
|
||||
bool operator==(const function_body& rhs) const {
|
||||
return begin == rhs.begin && end == rhs.end && statements == rhs.statements;
|
||||
}
|
||||
|
||||
bool operator!=(const function_body& rhs) const { return !this->operator==(rhs); }
|
||||
};
|
||||
|
||||
using function_body_handle = handle<ast::function_body>;
|
||||
|
||||
class function_declarartion_node : public declaration_node {
|
||||
class function_declaration_node : public declaration_node {
|
||||
public:
|
||||
function_declarartion_node(front::token name)
|
||||
function_declaration_node(front::token name)
|
||||
: m_name(name) {}
|
||||
public:
|
||||
declaration_node_t declaration_type() const override { return declaration_node_t::FunctionDeclaration; }
|
||||
@@ -56,22 +45,39 @@ protected:
|
||||
front::token m_name;
|
||||
};
|
||||
|
||||
class function_definition_node : public function_declarartion_node {
|
||||
using function_declaration_node_h = node_handle<function_declaration_node>;
|
||||
|
||||
struct function_body {
|
||||
location begin, end;
|
||||
std::vector<node_handle<statement_node>> statements;
|
||||
|
||||
bool operator==(const function_body& rhs) const {
|
||||
return begin == rhs.begin && end == rhs.end && statements == rhs.statements;
|
||||
}
|
||||
|
||||
bool operator!=(const function_body& rhs) const { return !this->operator==(rhs); }
|
||||
};
|
||||
|
||||
using function_body_h = handle<ast::function_body>;
|
||||
|
||||
class function_definition_node : public function_declaration_node {
|
||||
public:
|
||||
function_definition_node(front::token name, function_body_handle&& body)
|
||||
: function_declarartion_node(name), m_body(std::move(body)) {}
|
||||
function_definition_node(front::token name, function_body_h&& body)
|
||||
: function_declaration_node(name), m_body(std::move(body)) {}
|
||||
public:
|
||||
declaration_node_t declaration_type() const override { return declaration_node_t::FunctionDefinition; }
|
||||
|
||||
const function_body_handle& body() const { return m_body; }
|
||||
const function_body_h& body() const { return m_body; }
|
||||
public:
|
||||
std::ostream& print(std::ostream& os) const override;
|
||||
protected:
|
||||
bool equal(const node& rhs) const override;
|
||||
private:
|
||||
function_body_handle m_body;
|
||||
function_body_h m_body;
|
||||
};
|
||||
|
||||
using function_definition_node_h = node_handle<function_definition_node>;
|
||||
|
||||
} // namespace ast
|
||||
} // namespace furc
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ protected:
|
||||
bool equal(const node& rhs) const override;
|
||||
};
|
||||
|
||||
using literal_node_h = node_handle<literal_node>;
|
||||
|
||||
class string_literal_node : public literal_node {
|
||||
public:
|
||||
string_literal_node(handle<std::string_view>&& value)
|
||||
@@ -40,6 +42,8 @@ private:
|
||||
handle<std::string_view> m_value;
|
||||
};
|
||||
|
||||
using string_literal_node_h = node_handle<string_literal_node>;
|
||||
|
||||
class integer_literal_node : public literal_node {
|
||||
public:
|
||||
integer_literal_node(handle<front::integer_token>&& value)
|
||||
@@ -58,6 +62,8 @@ private:
|
||||
handle<front::integer_token> m_value;
|
||||
};
|
||||
|
||||
using integer_literal_node_h = node_handle<integer_literal_node>;
|
||||
|
||||
} // namespace ast
|
||||
} // namespace furc
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@ private:
|
||||
std::vector<node_handle<declaration_node>> m_declarations;
|
||||
};
|
||||
|
||||
using program_node_h = node_handle<program_node>;
|
||||
|
||||
} // namespace ast
|
||||
} // namespace furc
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ protected:
|
||||
bool equal(const node& rhs) const override;
|
||||
};
|
||||
|
||||
using statement_node_h = node_handle<statement_node>;
|
||||
|
||||
class expression_node;
|
||||
class return_statement_node : public statement_node {
|
||||
public:
|
||||
@@ -40,6 +42,8 @@ private:
|
||||
node_handle<expression_node> m_value;
|
||||
};
|
||||
|
||||
using return_statement_node_h = node_handle<return_statement_node>;
|
||||
|
||||
} // namespace ast
|
||||
} // namespace furc
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include "furc/ast/declaration.hpp"
|
||||
#include "furc/ast/expression.hpp"
|
||||
#include "furc/ast/literal.hpp"
|
||||
#include "furc/ast/node.hpp"
|
||||
#include "furc/ast/program.hpp"
|
||||
#include "furc/front/lexer.hpp"
|
||||
#include "furlang/arena.hpp"
|
||||
@@ -26,17 +25,17 @@ public:
|
||||
parser& operator=(const parser&) = delete;
|
||||
public:
|
||||
// parser owns the arena :3c
|
||||
ast::node_handle<ast::program_node> parse() &;
|
||||
ast::program_node_h parse() &;
|
||||
private:
|
||||
ast::node_handle<ast::declaration_node> parse_declaration();
|
||||
ast::node_handle<ast::statement_node> parse_statement();
|
||||
ast::node_handle<ast::expression_node> parse_expression();
|
||||
ast::node_handle<ast::literal_node> parse_literal();
|
||||
ast::declaration_node_h parse_declaration();
|
||||
ast::statement_node_h parse_statement();
|
||||
ast::expression_node_h parse_expression();
|
||||
ast::literal_node_h parse_literal();
|
||||
|
||||
ast::expression_node_h parse_expression_primary();
|
||||
ast::expression_node_h parse_expression_rhs(const ast::expression_node_h& init, std::uint32_t precedence);
|
||||
|
||||
ast::function_body_handle parse_body();
|
||||
ast::function_body_h parse_body();
|
||||
private:
|
||||
token_handle<> next_token();
|
||||
const token_handle<>& peek_token();
|
||||
|
||||
Reference in New Issue
Block a user