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 addSymbol(ByteString Name, Node* Decl, SymbolKind Kind);
|
||||||
|
|
||||||
void scan(Node* X);
|
void scan(Node* X);
|
||||||
|
void scanChild(Node* X);
|
||||||
|
|
||||||
void visitPattern(Pattern* P, Node* ToInsert);
|
void visitPattern(Pattern* P, Node* ToInsert);
|
||||||
|
|
||||||
|
|
43
src/CST.cc
43
src/CST.cc
|
@ -61,15 +61,41 @@ namespace bolt {
|
||||||
|
|
||||||
void Scope::scan(Node* X) {
|
void Scope::scan(Node* X) {
|
||||||
switch (X->getKind()) {
|
switch (X->getKind()) {
|
||||||
case NodeKind::ExpressionStatement:
|
|
||||||
case NodeKind::ReturnStatement:
|
|
||||||
case NodeKind::IfStatement:
|
|
||||||
break;
|
|
||||||
case NodeKind::SourceFile:
|
case NodeKind::SourceFile:
|
||||||
{
|
{
|
||||||
auto File = static_cast<SourceFile*>(X);
|
auto File = static_cast<SourceFile*>(X);
|
||||||
for (auto Element: File->Elements) {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -78,13 +104,10 @@ namespace bolt {
|
||||||
auto Decl = static_cast<ClassDeclaration*>(X);
|
auto Decl = static_cast<ClassDeclaration*>(X);
|
||||||
addSymbol(Decl->Name->getCanonicalText(), Decl, SymbolKind::Class);
|
addSymbol(Decl->Name->getCanonicalText(), Decl, SymbolKind::Class);
|
||||||
for (auto Element: Decl->Elements) {
|
for (auto Element: Decl->Elements) {
|
||||||
scan(Element);
|
scanChild(Element);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NodeKind::InstanceDeclaration:
|
|
||||||
// FIXME is this right?
|
|
||||||
break;
|
|
||||||
case NodeKind::LetDeclaration:
|
case NodeKind::LetDeclaration:
|
||||||
{
|
{
|
||||||
auto Decl = static_cast<LetDeclaration*>(X);
|
auto Decl = static_cast<LetDeclaration*>(X);
|
||||||
|
@ -150,7 +173,7 @@ namespace bolt {
|
||||||
ZEN_ASSERT(Path.Modules.empty());
|
ZEN_ASSERT(Path.Modules.empty());
|
||||||
auto Curr = this;
|
auto Curr = this;
|
||||||
do {
|
do {
|
||||||
auto Found= Curr->lookupDirect(Path, Kind);
|
auto Found = Curr->lookupDirect(Path, Kind);
|
||||||
if (Found) {
|
if (Found) {
|
||||||
return Found;
|
return Found;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue