mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-13 18:38:44 +00:00
bug fixes
This commit is contained in:
parent
bb8b32a7c8
commit
8647918f37
6 changed files with 87 additions and 102 deletions
|
|
@ -16,7 +16,8 @@ template<typename Value, typename ValueManager>
|
|||
class ContextManager {
|
||||
public:
|
||||
ContextManager() {
|
||||
contexts_.emplace_back(true); // no difference ??
|
||||
contexts_.emplace_back(false); // global context
|
||||
contexts_.emplace_back(true); // first context
|
||||
}
|
||||
|
||||
size_t ContextCount() {
|
||||
|
|
@ -86,8 +87,8 @@ public:
|
|||
}
|
||||
|
||||
void ExitContext() {
|
||||
if (contexts_.empty()) {
|
||||
error_handling::HandleInternalError("contexts_ is empty",
|
||||
if (contexts_.size() <= 2) {
|
||||
error_handling::HandleInternalError("only global context & first context in contexts_",
|
||||
"ContextManager.ExitContext",
|
||||
std::nullopt);
|
||||
}
|
||||
|
|
@ -103,6 +104,10 @@ public:
|
|||
return contexts_.back().DefineVariable(name, value_id);
|
||||
}
|
||||
|
||||
bool DefineGlobalType(const std::string& name, utils::IdType type_id) {
|
||||
return contexts_.front().DefineLocalType(name, type_id);
|
||||
}
|
||||
|
||||
bool DefineLocalType(const std::string& name, utils::IdType type_id) {
|
||||
return contexts_.back().DefineLocalType(name, type_id);
|
||||
}
|
||||
|
|
@ -113,8 +118,8 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
if (contexts_[i].IsHidingPrevious()) {
|
||||
break;
|
||||
if (contexts_[i].IsHidingPrevious() && i > 0) { // not for global context
|
||||
i = 1; // go to global context after --i
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
@ -126,8 +131,8 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
if (contexts_[i].IsHidingPrevious()) {
|
||||
break;
|
||||
if (contexts_[i].IsHidingPrevious() && i > 0) { // not for global context
|
||||
i = 1; // go to global context after --i
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
@ -139,8 +144,8 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
if (contexts_[i].IsHidingPrevious()) {
|
||||
break;
|
||||
if (contexts_[i].IsHidingPrevious() && i > 0) { // not for global context
|
||||
i = 1; // go to global context after --i
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
@ -161,8 +166,8 @@ public:
|
|||
return maybe_variable.value();
|
||||
}
|
||||
|
||||
if (contexts_[i].IsHidingPrevious()) {
|
||||
break;
|
||||
if (contexts_[i].IsHidingPrevious() && i > 0) { // not for global context
|
||||
i = 1; // go to global context after --i
|
||||
}
|
||||
}
|
||||
return std::nullopt;
|
||||
|
|
@ -175,9 +180,9 @@ public:
|
|||
return maybe_type.value();
|
||||
}
|
||||
|
||||
// if (contexts_[i].IsHidingPrevious()) { // TODO: old types automatically shadowed by new ??
|
||||
// break;
|
||||
// }
|
||||
if (contexts_[i].IsHidingPrevious() && i > 0) { // not for global context
|
||||
i = 1; // go to global context after --i
|
||||
}
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue