Disambiguates scopes where ordering matters vs ones where it doesn't

pull/1/head
venko 2021-05-08 12:09:25 -07:00
parent 743828450c
commit 252dc9b87f
2 changed files with 15 additions and 10 deletions

View File

@ -43,7 +43,7 @@ IdNode* MakeIdTree(Node *astNode, IdNode *parent) {
case IfStatement: {
Node *stmtSeq = astNode->children[1];
IdNode *ifNode = MakeIdNode(LexicalScope, "if", parent);
IdNode *ifNode = MakeIdNode(OrderedScope, "if", parent);
for (i = 0; i < stmtSeq->childCount; i++) {
AddChildToNode(ifNode, MakeIdTree(stmtSeq->children[i], ifNode));
}
@ -53,9 +53,9 @@ IdNode* MakeIdTree(Node *astNode, IdNode *parent) {
case IfElseStatement: {
Node *ifNode = astNode->children[0];
Node *elseStmts = astNode->children[1];
IdNode *ifElseNode = MakeIdNode(LexicalScope, "if-else", parent);
IdNode *ifElseNode = MakeIdNode(OrderedScope, "if-else", parent);
IdNode *ifBranch = MakeIdTree(ifNode, ifElseNode);
IdNode *elseBranch = MakeIdNode(LexicalScope, "else", ifElseNode);
IdNode *elseBranch = MakeIdNode(OrderedScope, "else", ifElseNode);
AddChildToNode(ifElseNode, ifBranch);
AddChildToNode(ifElseNode, elseBranch);
@ -69,7 +69,7 @@ IdNode* MakeIdTree(Node *astNode, IdNode *parent) {
case ForLoop: {
Node *loopDecl = astNode->children[0];
Node *loopBody = astNode->children[3];
IdNode *loopNode = MakeIdNode(LexicalScope, "for-loop", parent);
IdNode *loopNode = MakeIdNode(OrderedScope, "for-loop", parent);
AddChildToNode(loopNode, MakeIdTree(loopDecl, loopNode));
for (i = 0; i < loopBody->childCount; i++) {
AddChildToNode(loopNode, MakeIdTree(loopBody->children[i], loopNode));
@ -111,7 +111,7 @@ IdNode* MakeIdTree(Node *astNode, IdNode *parent) {
}
case DeclarationSequence: {
IdNode *declSeqNode = MakeIdNode(LexicalScope, "", parent);
IdNode *declSeqNode = MakeIdNode(UnorderedScope, "", parent);
for (i = 0; i < astNode->childCount; i++) {
AddChildToNode(declSeqNode, MakeIdTree(astNode->children[i], declSeqNode));
}
@ -130,8 +130,11 @@ void PrintIdNode(IdNode *node) {
}
switch(node->type) {
case LexicalScope:
printf("Scope (%s)\n", node->name);
case OrderedScope:
printf("OrderedScope (%s)\n", node->name);
break;
case UnorderedScope:
printf("UnorderedScope (%s)\n", node->name);
break;
case Struct:
printf("%s : %s\n", node->name, TypeTagToString(node->typeTag));
@ -177,7 +180,7 @@ int PrintAncestors(IdNode *node) {
return indent;
}
IdNode* FindId(IdNode *root, NodeType targetType, char *targetName) {
IdNode* LookdownId(IdNode *root, NodeType targetType, char *targetName) {
if (root == NULL) {
fprintf(stderr, "wraith: Attempted to call FindId on a null value.\n");
return NULL;

View File

@ -7,7 +7,8 @@
#include "ast.h"
typedef enum NodeType {
LexicalScope,
UnorderedScope,
OrderedScope,
Struct,
Function,
Variable
@ -30,10 +31,11 @@ typedef struct IdStatus {
} IdStatus;
IdNode* FindId(IdNode *root, NodeType targetType, char *targetName);
IdNode* MakeIdTree(Node *astNode, IdNode *parent);
void PrintIdTree(IdNode *tree, uint32_t tabCount);
int PrintAncestors(IdNode *node);
IdNode* LookdownId(IdNode *root, NodeType targetType, char *targetName);
IdNode* LookupId(IdNode *node, IdNode *prev, char* target);
//IdStatus CheckIds(Node *root);