name tree mostly finished

This commit is contained in:
ProgramSnail 2023-07-28 19:42:09 +03:00
parent 263b58a17c
commit fc114ff959
14 changed files with 116 additions and 38 deletions

View file

@ -8,11 +8,11 @@
namespace nodes {
enum class Modifier {
OUT, // -> x
IN, // <- x
REF, // <> x
OR_FALSE, // x?
OR_RETURN, // x!
OUT, // -> x
IN, // <- x
REF, // <> x
OPTIONAL, // x?
RESULT, // x!
NONE,
};

View file

@ -19,6 +19,8 @@ public:
bool insert(const std::string &path, nodes::Statement &&statement);
bool insert(const std::string &path, const nodes::Statement &statement);
std::optional<nodes::Statement *> find(const std::string &path);
std::optional<const nodes::Statement *> find(const std::string &path) const;
@ -48,6 +50,14 @@ private:
return true;
}
bool set_statement(const nodes::Statement &statement) {
if (statement_.has_value()) {
return false;
}
statement_ = statement;
return true;
}
std::optional<size_t> find(size_t name_id) const {
auto name_iter = children_.find(name_id);

View file

@ -1,5 +1,6 @@
#pragma once
#include "name_tree.hpp"
#include "statement_nodes.hpp"
#include "tree_sitter_wrapper.hpp"
@ -7,14 +8,18 @@
namespace builders {
// statements (copies of statements are in name_tree) returned to print /
// translate them in required order
std::vector<nodes::Statement>
build_source_file(parser::ParseTree::Node parser_node,
nodes::ExpressionStorage &expression_storage,
nodes::TypeStorage &type_storage);
nodes::TypeStorage &type_storage, names::NameTree &name_tree);
// copy of statement inserted into name_tree
nodes::Statement build_statement(parser::ParseTree::Node parser_node,
nodes::ExpressionStorage &expression_storage,
nodes::TypeStorage &type_storage);
nodes::TypeStorage &type_storage,
names::NameTree &name_tree);
nodes::Import build_import(parser::ParseTree::Node parser_node);

View file

@ -464,6 +464,10 @@ private:
class Statement {
public:
Statement(const Statement &) = default;
Statement(Statement &&) = default;
Statement &operator=(const Statement &) = default;
template <typename T>
Statement(T &&statement) : expression_(std::forward<T>(statement)) {}

View file

@ -1,6 +1,7 @@
#pragma once
#include "basic_printers.hpp"
#include "name_tree.hpp"
#include "statement_nodes.hpp"
#include <vector>