Fix scope resolution
This commit is contained in:
parent
6bd8ecff39
commit
41aa820bca
2 changed files with 34 additions and 10 deletions
|
@ -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);
|
||||
|
||||
|
|
41
src/CST.cc
41
src/CST.cc
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue