More work on binder type registration, support in REPL to show registered types.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -54,13 +54,23 @@ namespace MalachScript::Binder {
|
||||
case Parser::ParsedStatementKind::Class: {
|
||||
const auto* s = static_cast<const ParsedClassStatement*>(statement);
|
||||
auto identifier = s->GetIdentifier();
|
||||
if (activeType.has_value()) {
|
||||
auto type = ns->ResolveType(s->GetIdentifier());
|
||||
if (!type.has_value()) {
|
||||
if (activeType.has_value()) {
|
||||
type = activeType.value()->ResolveType(s->GetIdentifier());
|
||||
}
|
||||
}
|
||||
auto* type = new BoundType(s->GetClassAttr());
|
||||
if (type.has_value()) {
|
||||
log(DiagnosticLevel::Error, DiagnosticType::TypeAlreadyDefined, s->GetSpan(),
|
||||
{identifier.GetStdString()});
|
||||
break;
|
||||
}
|
||||
|
||||
type = new BoundType(identifier, s->GetClassAttr());
|
||||
if (activeType.has_value()) {
|
||||
activeType.value()->RegisterType(identifier, type);
|
||||
activeType.value()->RegisterType(identifier, type.value());
|
||||
} else {
|
||||
ns->RegisterType(identifier, type);
|
||||
ns->RegisterType(identifier, type.value());
|
||||
}
|
||||
for (const auto& child : s->GetBody()) {
|
||||
TypeRegistrationFirstPass(ns, child.get(), type, log);
|
||||
@@ -92,7 +102,12 @@ namespace MalachScript::Binder {
|
||||
const auto* s = static_cast<const ParsedClassStatement*>(statement);
|
||||
auto type = ns->ResolveType(s->GetIdentifier());
|
||||
if (!type.has_value()) {
|
||||
throw std::logic_error("Shouldn't be reached");
|
||||
if (activeType.has_value()) {
|
||||
type = activeType.value()->ResolveType(s->GetIdentifier());
|
||||
}
|
||||
if (!type.has_value()) {
|
||||
throw std::logic_error("Shouldn't be reached");
|
||||
}
|
||||
}
|
||||
for (const auto& inherits : s->GetInherits()) {
|
||||
auto inheritType = ResolveType(ns, inherits);
|
||||
@@ -152,7 +167,12 @@ namespace MalachScript::Binder {
|
||||
const auto* s = static_cast<const ParsedClassStatement*>(statement);
|
||||
auto type = ns->ResolveType(s->GetIdentifier());
|
||||
if (!type.has_value()) {
|
||||
throw std::logic_error("Shouldn't be reached");
|
||||
if (activeType.has_value()) {
|
||||
type = activeType.value()->ResolveType(s->GetIdentifier());
|
||||
}
|
||||
if (!type.has_value()) {
|
||||
throw std::logic_error("Shouldn't be reached");
|
||||
}
|
||||
}
|
||||
for (const auto& child : s->GetBody()) {
|
||||
TypeRegistrationThirdPass(ns, child.get(), type.value(), log);
|
||||
|
||||
Reference in New Issue
Block a user