mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2026-01-25 13:07:13 +00:00
better partitions system in global_info, trie in utils
This commit is contained in:
parent
6e487c8fd9
commit
a97a6125de
3 changed files with 130 additions and 8 deletions
|
|
@ -67,8 +67,7 @@ public:
|
|||
definition::Constructor&& constructor_info,
|
||||
const interpreter::tokens::BaseNode& base_node);
|
||||
|
||||
utils::IdType AddPartition(const std::vector<std::string>& path,
|
||||
const std::string& name,
|
||||
utils::IdType AddPartition(const std::vector<std::string>& path, // including name
|
||||
interpreter::tokens::PartitionStatement* node);
|
||||
|
||||
std::optional<definition::Namespace*> FindNamespace(const std::optional<std::vector<std::string>>& path);
|
||||
|
|
@ -164,6 +163,23 @@ public:
|
|||
return partitions_.at(id);
|
||||
}
|
||||
|
||||
std::optional<utils::IdType> FindPartition(const std::vector<std::string>& path) {
|
||||
auto trie_ans = partitions_trie_.Find(path);
|
||||
return trie_ans.has_value() ? std::optional<utils::IdType>(*trie_ans.value()) : std::nullopt;
|
||||
}
|
||||
|
||||
std::vector<utils::IdType> FindPartitionsByPrefix(const std::vector<std::string>& path) { // optimize ??
|
||||
auto trie_ans = partitions_trie_.FindByPrefix(path);
|
||||
|
||||
std::vector<utils::IdType> ans(trie_ans.size());
|
||||
|
||||
for (size_t i = 0; i < ans.size(); ++i) {
|
||||
ans[i] = *trie_ans[i];
|
||||
}
|
||||
|
||||
return ans;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::vector<definition::Function> functions_;
|
||||
|
|
@ -176,6 +192,7 @@ private:
|
|||
std::unordered_map<std::string, utils::IdType> name_to_abstract_type_;
|
||||
|
||||
std::vector<PartitionInfo> partitions_;
|
||||
utils::Trie<std::string, utils::IdType> partitions_trie_;
|
||||
|
||||
definition::Namespace global_namespace_;
|
||||
std::vector<definition::Import> imports_;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue