diff --git a/commenttest.w b/commenttest.w new file mode 100644 index 0000000..70cd73e --- /dev/null +++ b/commenttest.w @@ -0,0 +1,6 @@ +struct Program { + // This triggers a parse error + static Main(): int { + return 0; + } +} \ No newline at end of file diff --git a/src/identcheck.c b/src/identcheck.c index 1796ca6..a05543d 100644 --- a/src/identcheck.c +++ b/src/identcheck.c @@ -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; diff --git a/src/main.c b/src/main.c index ab08167..03985fc 100644 --- a/src/main.c +++ b/src/main.c @@ -65,13 +65,21 @@ int main(int argc, char *argv[]) } 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"); 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); }