Add alias to ast
This commit is contained in:
+46
@@ -72,6 +72,52 @@ Module* parser_parse(TokenStream* ts) {
|
||||
}
|
||||
}
|
||||
|
||||
// Now t holds the first non-import token. If it's not TOKEN_ALIAS, return.
|
||||
// If it is, process it.
|
||||
while (t.token == TOKEN_ALIAS) {
|
||||
AliasDeclaration* new_aliases = realloc(module->aliases, (module->alias_count + 1) * sizeof(AliasDeclaration));
|
||||
if (!new_aliases) {
|
||||
fprintf(stderr, "Out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
module->aliases = new_aliases;
|
||||
|
||||
t = tokenstream_next(ts);
|
||||
if (t.token != TOKEN_IDENTIFIER) {
|
||||
log_on_line(&t.location, t.location.column_end, "expected alias name");
|
||||
parser_free(module);
|
||||
return NULL;
|
||||
}
|
||||
AliasDeclaration alias;
|
||||
alias.name = t;
|
||||
|
||||
t = tokenstream_next(ts);
|
||||
if (t.token != TOKEN_ASSIGN) {
|
||||
log_on_line(&t.location, t.location.column_end, "expected '='");
|
||||
parser_free(module);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
t = tokenstream_next(ts);
|
||||
if (t.token != TOKEN_IDENTIFIER || strncmp(t.text.data, "int32", t.text.length) != 0) {
|
||||
log_on_line(&t.location, t.location.column_end, "expected type");
|
||||
parser_free(module);
|
||||
return NULL;
|
||||
}
|
||||
alias.value = (TypeExpression){ .tag = TYPE_EXPRESSION_BUILTIN, .builtin = { .bitSize = 32, .isSigned = true } };
|
||||
|
||||
module->aliases[module->alias_count] = alias;
|
||||
module->alias_count++;
|
||||
|
||||
t = tokenstream_next(ts);
|
||||
if (t.token != TOKEN_SEMICOLON) {
|
||||
log_on_line(&t.location, t.location.column_end, "expected ';'");
|
||||
parser_free(module);
|
||||
return NULL;
|
||||
}
|
||||
t = tokenstream_next(ts);
|
||||
}
|
||||
|
||||
return module;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user