Fix scope resolution

This commit is contained in:
Sam Vervaeck 2023-05-30 13:34:39 +02:00
parent 6bd8ecff39
commit 41aa820bca
Signed by: samvv
SSH key fingerprint: SHA256:dIg0ywU1OP+ZYifrYxy8c5esO72cIKB+4/9wkZj1VaY
2 changed files with 34 additions and 10 deletions

View file

@ -262,6 +262,7 @@ namespace bolt {
void addSymbol(ByteString Name, Node* Decl, SymbolKind Kind);
void scan(Node* X);
void scanChild(Node* X);
void visitPattern(Pattern* P, Node* ToInsert);

View file

@ -61,15 +61,41 @@ namespace bolt {
void Scope::scan(Node* X) {
switch (X->getKind()) {
case NodeKind::ExpressionStatement:
case NodeKind::ReturnStatement:
case NodeKind::IfStatement:
break;
case NodeKind::SourceFile:
{
auto File = static_cast<SourceFile*>(X);
for (auto Element: File->Elements) {
scan(Element);
scanChild(Element);
}
break;
}
case NodeKind::LetDeclaration:
{
auto Decl = static_cast<LetDeclaration*>(X);
for (auto Param: Decl->Params) {
visitPattern(Param->Pattern, Param);
}
if (Decl->Body) {
scanChild(Decl->Body);
}
break;
}
default:
ZEN_UNREACHABLE
}
}
void Scope::scanChild(Node* X) {
switch (X->getKind()) {
case NodeKind::LetExprBody:
case NodeKind::ExpressionStatement:
case NodeKind::ReturnStatement:
break;
case NodeKind::LetBlockBody:
{
auto Block = static_cast<LetBlockBody*>(X);
for (auto Element: Block->Elements) {
scanChild(Element);
}
break;
}
@ -78,13 +104,10 @@ namespace bolt {
auto Decl = static_cast<ClassDeclaration*>(X);
addSymbol(Decl->Name->getCanonicalText(), Decl, SymbolKind::Class);
for (auto Element: Decl->Elements) {
scan(Element);
scanChild(Element);
}
break;
}
case NodeKind::InstanceDeclaration:
// FIXME is this right?
break;
case NodeKind::LetDeclaration:
{
auto Decl = static_cast<LetDeclaration*>(X);