some minor style revisions

pull/1/head
cosmonaut 2021-05-14 11:53:09 -07:00
parent f441e5bede
commit 41bf2bece8
3 changed files with 33 additions and 32 deletions

View File

@ -83,11 +83,11 @@ typedef struct TypeTag
} type;
union
{
// Valid when type = Primitive.
/* Valid when type = Primitive. */
PrimitiveType primitiveType;
// Valid when type = Reference.
/* Valid when type = Reference. */
struct TypeTag *referenceType;
// Valid when type = Custom.
/* Valid when type = Custom. */
char *customType;
} value;
} TypeTag;

View File

@ -24,10 +24,10 @@ void AddChildToNode(IdNode *node, IdNode *child) {
if (node->children == NULL) {
node->childCapacity = 2;
node->children = (IdNode**)malloc(sizeof(IdNode*) * node->childCapacity);
node->children = (IdNode**) malloc(sizeof(IdNode*) * node->childCapacity);
} else if (node->childCount == node->childCapacity) {
node->childCapacity *= 2;
node->children = realloc(node->children, sizeof(IdNode*) * node->childCapacity);
node->children = (IdNode**) realloc(node->children, sizeof(IdNode*) * node->childCapacity);
}
node->children[node->childCount] = child;
@ -242,7 +242,7 @@ IdNode* LookdownId(IdNode *root, NodeType targetType, char *targetName) {
}
size_t newSize = frontierCount + current->childCount - 1;
if (frontierCount != newSize) {
frontier = realloc(frontier, sizeof(IdNode*) * newSize);
frontier = (IdNode**) realloc(frontier, sizeof(IdNode*) * newSize);
}
for (i = 0; i < current->childCount; i++) {
frontier[frontierCount + i - 1] = current->children[i];
@ -258,7 +258,7 @@ bool ScopeHasOrdering(IdNode *node) {
switch (node->type) {
case OrderedScope:
case Function:
case Variable: // this is only technically true
case Variable: /* this is only technically true */
return true;
default:
return false;
@ -274,20 +274,22 @@ IdNode* LookupId(IdNode *node, IdNode *prev, char *target) {
return node;
}
// If this is the start of our search, we should not attempt to look at child nodes. Only
// looking up the scope tree is valid at this point.
//
// This has the notable side-effect that this function will return NULL if you attempt to look
// up a struct's internals starting from the node representing the struct itself. This is
// because an IdNode corresponds to the location *where an identifier is first declared.* Thus,
// an identifier has no knowledge of identifiers declared "inside" of it.
/* If this is the start of our search, we should not attempt to look at child nodes. Only
* looking up the scope tree is valid at this point.
*
* This has the notable side-effect that this function will return NULL if you attempt to look
* up a struct's internals starting from the node representing the struct itself. This is
* because an IdNode corresponds to the location *where an identifier is first declared.* Thus,
* an identifier has no knowledge of identifiers declared "inside" of it.
*/
if (prev == NULL) {
return LookupId(node->parent, node, target);
}
/* If the current node forms an ordered scope then we want to prevent ourselves from looking
* up identifiers declared after the scope we have just come from.
*/
uint32_t idxLimit;
// If the current node forms an ordered scope then we want to prevent ourselves from looking
// up identifiers declared after the scope we have just come from.
if (ScopeHasOrdering(node)) {
uint32_t i;
for (i = 0, idxLimit = 0; i < node->childCount; i++, idxLimit++) {
@ -303,7 +305,7 @@ IdNode* LookupId(IdNode *node, IdNode *prev, char *target) {
for (i = 0; i < idxLimit; i++) {
IdNode *child = node->children[i];
if (child == prev || child->type == Placeholder) {
// Do not inspect the node we just came from or placeholders.
/* Do not inspect the node we just came from or placeholders. */
continue;
}

View File

@ -1,4 +1,5 @@
// Validates identifier usage in an AST.
/* Validates identifier usage in an AST. */
#ifndef WRAITH_IDENTCHECK_H
#define WRAITH_IDENTCHECK_H
@ -42,6 +43,4 @@ int PrintAncestors(IdNode *node);
IdNode* LookdownId(IdNode *root, NodeType targetType, char *targetName);
IdNode* LookupId(IdNode *node, IdNode *prev, char* target);
//IdStatus CheckIds(Node *root);
#endif /* WRAITH_IDENTCHECK_H */