forked from cosmonaut/wraith-lang
Adds error message to FindId, extra test code in main
parent
8f86392cf3
commit
565d815deb
|
@ -0,0 +1,6 @@
|
||||||
|
struct Program {
|
||||||
|
// This triggers a parse error
|
||||||
|
static Main(): int {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -154,6 +154,11 @@ int PrintAncestors(IdNode *node) {
|
||||||
}
|
}
|
||||||
|
|
||||||
IdNode* FindId(IdNode *root, NodeType targetType, char *targetName) {
|
IdNode* FindId(IdNode *root, NodeType targetType, char *targetName) {
|
||||||
|
if (root == NULL) {
|
||||||
|
fprintf(stderr, "wraith: Attempted to call FindId on a null value.\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
IdNode *result = NULL;
|
IdNode *result = NULL;
|
||||||
IdNode **frontier = (IdNode**)malloc(sizeof(IdNode*));
|
IdNode **frontier = (IdNode**)malloc(sizeof(IdNode*));
|
||||||
frontier[0] = root;
|
frontier[0] = root;
|
||||||
|
|
14
src/main.c
14
src/main.c
|
@ -65,13 +65,21 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
IdNode *idTree = MakeIdTree(rootNode, NULL);
|
|
||||||
PrintIdTree(idTree, /*tabCount=*/0);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
|
IdNode *idTree = MakeIdTree(rootNode, NULL);
|
||||||
|
PrintIdTree(idTree, /*tabCount=*/0);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
printf("Searching for a variable named 'lol' and printing its ancestors\n");
|
printf("Searching for a variable named 'lol' and printing its ancestors\n");
|
||||||
IdNode *deepest = FindId(idTree, Variable, "lol");
|
IdNode *deepest = FindId(idTree, Variable, "lol");
|
||||||
PrintAncestors(deepest);
|
PrintAncestors(deepest);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
printf("Now searching for the same variable but with the caveat that it"
|
||||||
|
" must be inside an if-block, and printing its ancestors\n");
|
||||||
|
deepest = FindId(idTree, LexicalScope, "if");
|
||||||
|
deepest = FindId(deepest, Variable, "lol");
|
||||||
|
PrintAncestors(deepest);
|
||||||
}
|
}
|
||||||
exitCode = Codegen(rootNode, optimizationLevel);
|
exitCode = Codegen(rootNode, optimizationLevel);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue