mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2026-01-25 13:07:13 +00:00
namespace storage fix, namespace enter fix, maybe other fixes
This commit is contained in:
parent
4882d458f8
commit
4b4756b657
11 changed files with 250 additions and 174 deletions
|
|
@ -17,6 +17,10 @@ namespace info {
|
|||
class GlobalInfo {
|
||||
friend class NamespaceVisitor;
|
||||
public:
|
||||
GlobalInfo() {
|
||||
namespaces_.emplace_back(); // global namespace
|
||||
}
|
||||
|
||||
struct PartitionInfo {
|
||||
std::vector<std::string> path;
|
||||
std::string name;
|
||||
|
|
@ -39,7 +43,8 @@ public:
|
|||
std::optional<utils::IsConstModifier> modifier,
|
||||
const interpreter::tokens::BaseNode& base_node);
|
||||
|
||||
void EnterNamespace(const std::string& name);
|
||||
void EnterNamespace(const std::string& name,
|
||||
std::optional<utils::IsConstModifier> modifier);
|
||||
|
||||
void ExitNamespace();
|
||||
|
||||
|
|
@ -70,7 +75,7 @@ public:
|
|||
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);
|
||||
std::optional<utils::IdType> FindNamespace(const std::optional<std::vector<std::string>>& path);
|
||||
|
||||
std::optional<utils::IdType> FindFunction(const std::optional<std::vector<std::string>>& path,
|
||||
const std::string& name);
|
||||
|
|
@ -104,25 +109,25 @@ public:
|
|||
return current_path_;
|
||||
}
|
||||
|
||||
definition::Namespace* GetCurrentNamespace() {
|
||||
utils::IdType GetCurrentNamespace() {
|
||||
return namespace_stack_.back();
|
||||
}
|
||||
private:
|
||||
NamespaceVisitor(GlobalInfo& global_info) : global_info_(global_info),
|
||||
namespace_stack_({&global_info.global_namespace_}) {}
|
||||
namespace_stack_ {global_info.GlobalNamespaceId} {}
|
||||
|
||||
template<typename T>
|
||||
std::optional<T> FindSomething(
|
||||
const std::optional<std::vector<std::string>>& path,
|
||||
std::function<std::optional<T>(definition::Namespace*)> search_func);
|
||||
std::function<std::optional<T>(utils::IdType)> search_func);
|
||||
|
||||
std::optional<definition::Namespace*> FindNamespaceIn(
|
||||
definition::Namespace* current_namespace,
|
||||
std::optional<utils::IdType> FindNamespaceIn(
|
||||
utils::IdType current_namespace,
|
||||
const std::vector<std::string>& path);
|
||||
private:
|
||||
GlobalInfo& global_info_;
|
||||
|
||||
std::vector<definition::Namespace*> namespace_stack_;
|
||||
std::vector<utils::IdType> namespace_stack_;
|
||||
std::vector<std::string> current_path_;
|
||||
};
|
||||
|
||||
|
|
@ -131,7 +136,7 @@ public:
|
|||
}
|
||||
|
||||
// remember about vector realloc
|
||||
const definition::Function& GetFunctionInfo(utils::IdType id) {
|
||||
definition::Function& GetFunctionInfo(utils::IdType id) {
|
||||
return functions_.at(id);
|
||||
}
|
||||
|
||||
|
|
@ -144,22 +149,27 @@ public:
|
|||
}
|
||||
|
||||
// remember about vector realloc
|
||||
const definition::Type& GetAnyTypeInfo(utils::IdType id) {
|
||||
definition::Type& GetAnyTypeInfo(utils::IdType id) {
|
||||
return types_.at(id);
|
||||
}
|
||||
|
||||
// remember about vector realloc
|
||||
const definition::Typeclass& GetTypeclassInfo(utils::IdType id) {
|
||||
definition::Typeclass& GetTypeclassInfo(utils::IdType id) {
|
||||
return typeclasses_.at(id);
|
||||
}
|
||||
|
||||
// remember about vector realloc
|
||||
const definition::Constructor& GetConstructorInfo(utils::IdType id) {
|
||||
definition::Constructor& GetConstructorInfo(utils::IdType id) {
|
||||
return constructors_.at(id);
|
||||
}
|
||||
|
||||
// remember about vector realloc
|
||||
const PartitionInfo& GetPartitionInfo(utils::IdType id) {
|
||||
definition::Namespace& GetNamespaceInfo(utils::IdType id) {
|
||||
return namespaces_.at(id);
|
||||
}
|
||||
|
||||
// remember about vector realloc
|
||||
PartitionInfo& GetPartitionInfo(utils::IdType id) {
|
||||
return partitions_.at(id);
|
||||
}
|
||||
|
||||
|
|
@ -181,6 +191,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
const utils::IdType GlobalNamespaceId = 0;
|
||||
|
||||
std::vector<definition::Function> functions_;
|
||||
std::vector<definition::Type> types_;
|
||||
|
|
@ -188,13 +199,14 @@ private:
|
|||
std::vector<definition::Typeclass> typeclasses_;
|
||||
std::vector<definition::Constructor> constructors_;
|
||||
|
||||
std::vector<definition::Namespace> namespaces_;
|
||||
|
||||
std::unordered_map<std::string, utils::IdType> name_to_typeclass_;
|
||||
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_;
|
||||
std::unordered_map<std::string, definition::Import> usages_;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue