Adds handling for generic AST nodes in PrintNode and SyntaxKindString

traversal
venko 2021-05-23 16:58:59 -07:00
parent d641f713de
commit d48995716e
2 changed files with 32 additions and 0 deletions

13
generic.w Normal file
View File

@ -0,0 +1,13 @@
struct Foo {
static Func<T>(t: T): T {
return t;
}
}
struct Program {
static main(): int {
x: int = 4;
y: int = Foo.Func(x);
return x;
}
}

View File

@ -39,6 +39,10 @@ const char *SyntaxKindString(SyntaxKind syntaxKind)
return "FunctionSignature"; return "FunctionSignature";
case FunctionSignatureArguments: case FunctionSignatureArguments:
return "FunctionSignatureArguments"; return "FunctionSignatureArguments";
case GenericArgument:
return "GenericArgument";
case GenericArguments:
return "GenericArguments";
case Identifier: case Identifier:
return "Identifier"; return "Identifier";
case IfStatement: case IfStatement:
@ -599,6 +603,7 @@ void PrintNode(Node *node, uint32_t tabCount)
case FunctionSignature: case FunctionSignature:
printf("\n"); printf("\n");
PrintNode(node->functionSignature.identifier, tabCount + 1); PrintNode(node->functionSignature.identifier, tabCount + 1);
PrintNode(node->functionSignature.genericArguments, tabCount + 1);
PrintNode(node->functionSignature.arguments, tabCount + 1); PrintNode(node->functionSignature.arguments, tabCount + 1);
PrintNode(node->functionSignature.type, tabCount + 1); PrintNode(node->functionSignature.type, tabCount + 1);
PrintNode(node->functionSignature.modifiers, tabCount + 1); PrintNode(node->functionSignature.modifiers, tabCount + 1);
@ -614,6 +619,20 @@ void PrintNode(Node *node, uint32_t tabCount)
} }
return; return;
case GenericArgument:
printf("\n");
PrintNode(node->genericArgument.identifier, tabCount + 1);
/* Constraint nodes are not implemented. */
/* PrintNode(node->genericArgument.constraint, tabCount + 1); */
return;
case GenericArguments:
printf("\n");
for (i = 0; i < node->genericArguments.count; i += 1) {
PrintNode(node->genericArguments.arguments[i], tabCount + 1);
}
return;
case Identifier: case Identifier:
if (node->typeTag == NULL) if (node->typeTag == NULL)
{ {