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) {
|
||||
if (root == NULL) {
|
||||
fprintf(stderr, "wraith: Attempted to call FindId on a null value.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
IdNode *result = NULL;
|
||||
IdNode **frontier = (IdNode**)malloc(sizeof(IdNode*));
|
||||
frontier[0] = root;
|
||||
|
|
10
src/main.c
10
src/main.c
|
@ -64,14 +64,22 @@ int main(int argc, char *argv[])
|
|||
exitCode = EXIT_FAILURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
IdNode *idTree = MakeIdTree(rootNode, NULL);
|
||||
PrintIdTree(idTree, /*tabCount=*/0);
|
||||
printf("\n");
|
||||
|
||||
{
|
||||
printf("Searching for a variable named 'lol' and printing its ancestors\n");
|
||||
IdNode *deepest = FindId(idTree, Variable, "lol");
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue