mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2026-01-25 13:07:13 +00:00
part of find_symbols_visitor done
This commit is contained in:
parent
f88a23194f
commit
18e85f794f
6 changed files with 827 additions and 57 deletions
|
|
@ -8,18 +8,95 @@
|
|||
|
||||
namespace info {
|
||||
|
||||
// TODO: partitions
|
||||
class GlobalInfo {
|
||||
public:
|
||||
GlobalInfo();
|
||||
GlobalInfo() {
|
||||
namespace_stack.push_back(&global_namespace_);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void AddImport(T&& import_info) {
|
||||
if (waiting_usage.has_value()) {
|
||||
usages_[waiting_usage.value()] = std::forward(import_info);
|
||||
waiting_usage = std::nullopt;
|
||||
} else {
|
||||
imports_.push_back(std::forward(import_info));
|
||||
}
|
||||
}
|
||||
|
||||
void AddUsageForNextImport(const std::string& name) {
|
||||
if (waiting_usage.has_value()) {
|
||||
// error
|
||||
}
|
||||
waiting_usage = name;
|
||||
}
|
||||
|
||||
void AddEnterNamespace(const std::optional<std::string>& var,
|
||||
const std::string& type) {
|
||||
NamespaceInfo* namespace_info = &namespace_stack.back()->namespaces[type].emplace_back();
|
||||
namespace_stack.push_back(namespace_info);
|
||||
|
||||
namespace_info->var = var;
|
||||
namespace_info->type_name = type;
|
||||
}
|
||||
|
||||
void ExitNamespace() {
|
||||
if (namespace_stack.size() <= 1) {
|
||||
// error
|
||||
return;
|
||||
}
|
||||
|
||||
namespace_stack.pop_back();
|
||||
}
|
||||
|
||||
void ToGlobalNamespace() {
|
||||
namespace_stack.clear();
|
||||
namespace_stack.push_back(&global_namespace_);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void AddFunctionDeclaration(const std::string& name,
|
||||
T&& function_declaration_info) {
|
||||
FunctionInfo* function_info = &namespace_stack.back()->functions[name];
|
||||
|
||||
function_info->declaration = std::forward(function_declaration_info);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void AddFunctionDefinition(const std::string& name,
|
||||
T&& function_definition_info) {
|
||||
FunctionInfo* function_info = &namespace_stack.back()->functions[name];
|
||||
|
||||
function_info->definition = std::forward(function_definition_info);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void AddType(const std::string& type,
|
||||
T&& type_info) {
|
||||
&namespace_stack.back()->types[type] = std::forward(type_info);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void AddTypeclass(const std::string& typeclass,
|
||||
T&& typeclass_info) {
|
||||
namespace_stack.back()->typeclasses[typeclass] = std::forward(typeclass_info);
|
||||
}
|
||||
|
||||
// AddVar ?? // TODO: decide
|
||||
|
||||
// FindFunction
|
||||
// FindType
|
||||
|
||||
// FindVar ??
|
||||
|
||||
// ?? EnterNamespace / ExitNamespace ??
|
||||
// concurrent work ??
|
||||
// AddType, AddFunction
|
||||
// TODO
|
||||
private:
|
||||
std::unordered_map<std::string, NamespaceInfo> namespaces_;
|
||||
std::vector<NamespaceInfo*> namespace_stack;
|
||||
std::optional<std::string> waiting_usage;
|
||||
|
||||
NamespaceInfo global_namespace_;
|
||||
// lock for concurrency ??
|
||||
std::vector<ImportInfo> imports_;
|
||||
std::unordered_map<std::string, ImportInfo> usages_;
|
||||
};
|
||||
|
||||
} // namespace info
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue