support unknown size arrays

This commit is contained in:
Andrew Kelley
2016-01-06 01:28:58 -07:00
parent 4ef062b9c8
commit 3c43bc9208
8 changed files with 137 additions and 83 deletions

View File

@@ -219,7 +219,7 @@ void ast_print(AstNode *node, int indent) {
}
case AstNodeTypeTypePointer:
{
const char *const_or_mut_str = node->data.type.is_const ? "const" : "mut";
const char *const_or_mut_str = node->data.type.is_const ? "const" : "var";
fprintf(stderr, "'%s' PointerType\n", const_or_mut_str);
ast_print(node->data.type.child_type, indent + 2);
@@ -227,9 +227,11 @@ void ast_print(AstNode *node, int indent) {
}
case AstNodeTypeTypeArray:
{
fprintf(stderr, "ArrayType\n");
const char *const_or_mut_str = node->data.type.is_const ? "const" : "var";
fprintf(stderr, "'%s' ArrayType\n", const_or_mut_str);
if (node->data.type.array_size)
ast_print(node->data.type.array_size, indent + 2);
ast_print(node->data.type.child_type, indent + 2);
ast_print(node->data.type.array_size, indent + 2);
break;
}
case AstNodeTypeTypeMaybe:
@@ -1107,6 +1109,12 @@ static AstNode *ast_parse_type(ParseContext *pc, int *token_index) {
ast_eat_token(pc, token_index, TokenIdRBracket);
Token *const_tok = &pc->tokens->at(*token_index);
if (const_tok->id == TokenIdKeywordConst) {
*token_index += 1;
node->data.type.is_const = true;
}
node->data.type.child_type = ast_parse_type(pc, token_index);
} else {
ast_invalid_token_error(pc, token);