mirror of
https://codeberg.org/ProgramSnail/lang.git
synced 2025-12-13 02:18:44 +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
|
|
@ -5,36 +5,51 @@
|
|||
|
||||
namespace names {
|
||||
|
||||
// --- AnyStatementProxy
|
||||
|
||||
nodes::Statement *AnyStatementProxy::get() {
|
||||
return name_tree_->nodes_.at(id_).get_statement().value();
|
||||
}
|
||||
|
||||
const nodes::Statement *AnyStatementProxy::get() const {
|
||||
return name_tree_->nodes_.at(id_).get_statement().value();
|
||||
}
|
||||
|
||||
// --- NameTree
|
||||
|
||||
// --- public
|
||||
|
||||
bool NameTree::insert(const std::string &path, nodes::Statement &&statement) {
|
||||
std::optional<AnyStatementProxy>
|
||||
NameTree::insert(const std::string &path, nodes::Statement &&statement) {
|
||||
auto name_ids = slice_path_to_name_ids(path);
|
||||
|
||||
size_t node_id = add_node(get_root(), name_ids);
|
||||
|
||||
if (nodes_[node_id].get_statement().has_value()) {
|
||||
return false;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
nodes_[node_id].set_statement(std::move(statement));
|
||||
return true;
|
||||
return AnyStatementProxy(*this, node_id);
|
||||
}
|
||||
|
||||
nodes::CombineResult NameTree::insert_combine(const std::string &path,
|
||||
nodes::Statement &&statement) {
|
||||
std::pair<std::optional<AnyStatementProxy>, nodes::CombineResult>
|
||||
NameTree::insert_combine(const std::string &path,
|
||||
nodes::Statement &&statement) {
|
||||
auto name_ids = slice_path_to_name_ids(path);
|
||||
|
||||
size_t node_id = add_node(get_root(), name_ids);
|
||||
|
||||
if (!nodes_[node_id].get_statement().has_value()) {
|
||||
nodes_[node_id].set_statement(std::move(statement));
|
||||
return nodes::CombineResult::OK;
|
||||
return {AnyStatementProxy(*this, node_id), nodes::CombineResult::OK};
|
||||
}
|
||||
|
||||
return nodes_[node_id].get_statement().value()->combine(std::move(statement));
|
||||
return {std::nullopt, nodes_[node_id].get_statement().value()->combine(
|
||||
std::move(statement))};
|
||||
}
|
||||
|
||||
std::optional<nodes::Statement *> NameTree::find(const std::string &path) {
|
||||
std::optional<AnyStatementProxy> NameTree::find(const std::string &path) {
|
||||
auto name_ids = slice_path_to_existing_name_ids(path);
|
||||
|
||||
if (!name_ids.has_value()) {
|
||||
|
|
@ -44,24 +59,7 @@ std::optional<nodes::Statement *> NameTree::find(const std::string &path) {
|
|||
auto node_id = find_node(get_root(), name_ids.value());
|
||||
|
||||
if (node_id.has_value()) {
|
||||
return nodes_[node_id.value()].get_statement();
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<const nodes::Statement *>
|
||||
NameTree::find(const std::string &path) const {
|
||||
auto name_ids = slice_path_to_existing_name_ids(path);
|
||||
|
||||
if (!name_ids.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto node_id = find_node(get_root(), name_ids.value());
|
||||
|
||||
if (node_id.has_value()) {
|
||||
return nodes_[node_id.value()].get_statement();
|
||||
return AnyStatementProxy(*this, node_id.value());
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
|
|
@ -71,33 +69,34 @@ void NameTree::print(printers::Printer &printer) const {
|
|||
nodes_[get_root()].print(nodes_, printer);
|
||||
}
|
||||
|
||||
// TODO
|
||||
void NameTree::add_statement_children_to_tree() {
|
||||
for (auto &node : nodes_) {
|
||||
if (!node.get_statement().has_value()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (node.get_statement().value()->get_any()->index()) {
|
||||
case 0: // Import
|
||||
// TODO: link imported symbols, if named import, otherwise link imported
|
||||
// symbols to root
|
||||
break;
|
||||
case 1: // FunctionDefinition
|
||||
// TODO: link to result type
|
||||
break;
|
||||
case 2: // TypeDefinition
|
||||
// TODO: link methods + link children to types + connect to typeclasses
|
||||
break;
|
||||
case 3: // EmptyLines
|
||||
break;
|
||||
default:
|
||||
error_handling::handle_general_error(
|
||||
"Unexpected statement type in name tree");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// // TODO
|
||||
// void NameTree::add_statement_children_to_tree() {
|
||||
// for (auto &node : nodes_) {
|
||||
// if (!node.get_statement().has_value()) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// switch (node.get_statement().value()->get_any()->index()) {
|
||||
// case 0: // Import
|
||||
// // TODO: link imported symbols, if named import, otherwise link
|
||||
// imported
|
||||
// // symbols to root
|
||||
// break;
|
||||
// case 1: // FunctionDefinition
|
||||
// // TODO: link to result type
|
||||
// break;
|
||||
// case 2: // TypeDefinition
|
||||
// // TODO: link methods + link children to types + connect to typeclasses
|
||||
// break;
|
||||
// case 3: // EmptyLines
|
||||
// break;
|
||||
// default:
|
||||
// error_handling::handle_general_error(
|
||||
// "Unexpected statement type in name tree");
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// --- private
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue