mirror of
https://codeberg.org/ProgramSnail/lang.git
synced 2025-12-15 11:28:46 +00:00
types for typecheck, sources manager
This commit is contained in:
parent
4714a05467
commit
ef88e6af86
9 changed files with 353 additions and 104 deletions
|
|
@ -11,28 +11,78 @@
|
|||
|
||||
namespace names {
|
||||
|
||||
// IN PROGRESS
|
||||
class NameTree;
|
||||
|
||||
class AnyStatementProxy {
|
||||
friend NameTree;
|
||||
|
||||
public:
|
||||
nodes::Statement *get();
|
||||
|
||||
const nodes::Statement *get() const;
|
||||
|
||||
//
|
||||
|
||||
bool operator==(const AnyStatementProxy &other_any_statement_proxy) const {
|
||||
return name_tree_ == other_any_statement_proxy.name_tree_ &&
|
||||
id_ == other_any_statement_proxy.id_;
|
||||
}
|
||||
|
||||
bool operator!=(const AnyStatementProxy &other_any_statement_proxy) const {
|
||||
return !(*this == other_any_statement_proxy);
|
||||
}
|
||||
|
||||
private:
|
||||
AnyStatementProxy(NameTree &name_tree, size_t id)
|
||||
: name_tree_(&name_tree), id_(id) {}
|
||||
|
||||
private:
|
||||
NameTree *name_tree_;
|
||||
size_t id_;
|
||||
};
|
||||
|
||||
template <typename T> class StatementProxy {
|
||||
public:
|
||||
StatementProxy(AnyStatementProxy proxy) : proxy_(proxy) {}
|
||||
|
||||
T *get() { proxy_.get()->get<T>().value(); }
|
||||
|
||||
const T *get() const { proxy_.get()->get<T>().value(); }
|
||||
|
||||
//
|
||||
|
||||
bool operator==(const StatementProxy &other_statement_proxy) const {
|
||||
return proxy_ == other_statement_proxy.proxy_;
|
||||
}
|
||||
|
||||
bool operator!=(const StatementProxy &other_statement_proxy) const {
|
||||
return !(*this == other_statement_proxy);
|
||||
}
|
||||
|
||||
private:
|
||||
AnyStatementProxy proxy_;
|
||||
};
|
||||
|
||||
class NameTree {
|
||||
friend AnyStatementProxy;
|
||||
|
||||
public:
|
||||
NameTree() {
|
||||
nodes_.emplace_back(); // root
|
||||
}
|
||||
|
||||
bool insert(const std::string &path, nodes::Statement &&statement);
|
||||
std::optional<AnyStatementProxy> insert(const std::string &path,
|
||||
nodes::Statement &&statement);
|
||||
|
||||
// bool insert(const std::string &path, const nodes::Statement &statement);
|
||||
std::pair<std::optional<AnyStatementProxy>, nodes::CombineResult>
|
||||
insert_combine(const std::string &path, nodes::Statement &&statement);
|
||||
|
||||
nodes::CombineResult insert_combine(const std::string &path,
|
||||
nodes::Statement &&statement);
|
||||
|
||||
std::optional<nodes::Statement *> find(const std::string &path);
|
||||
|
||||
std::optional<const nodes::Statement *> find(const std::string &path) const;
|
||||
std::optional<AnyStatementProxy> find(const std::string &path);
|
||||
|
||||
void print(printers::Printer &printer) const;
|
||||
|
||||
// TODO
|
||||
void add_statement_children_to_tree();
|
||||
// // TODO
|
||||
// void add_statement_children_to_tree();
|
||||
|
||||
private:
|
||||
struct Node {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue