void check
This commit is contained in:
parent
e97820d7ef
commit
fb54211c71
2 changed files with 22 additions and 1 deletions
22
boot.c
22
boot.c
|
@ -1080,6 +1080,10 @@ int parse_expr() {
|
|||
}
|
||||
|
||||
void parse_local_variable(int type) {
|
||||
if (type == TYPE_VOID) {
|
||||
eprintf("local variable of void type is not supported\n");
|
||||
exit(1);
|
||||
}
|
||||
expect_token(TOKEN_ID);
|
||||
int id = token_data;
|
||||
next_token();
|
||||
|
@ -1252,7 +1256,19 @@ void parse_function(const char* name) {
|
|||
expect_token(TOKEN_PAREN_RIGHT);
|
||||
break;
|
||||
}
|
||||
if (token_type == TOKEN_VOID) {
|
||||
if (arg != 0) {
|
||||
eprintf("void should be the only argument\n");
|
||||
exit(1);
|
||||
}
|
||||
expect_token(TOKEN_PAREN_RIGHT);
|
||||
break;
|
||||
}
|
||||
int arg_type = parse_type();
|
||||
if (arg_type < 0 || arg_type == TYPE_VOID) {
|
||||
eprintf("unexpected a non-void argument type");
|
||||
exit(1);
|
||||
}
|
||||
expect_token(TOKEN_ID);
|
||||
int arg_name = token_data;
|
||||
next_token();
|
||||
|
@ -1322,6 +1338,10 @@ void parse_function(const char* name) {
|
|||
}
|
||||
|
||||
void parse_global_variable(int id, const char* name, int type) {
|
||||
if (type == TYPE_VOID) {
|
||||
eprintf("global variable of void type is not supported\n");
|
||||
exit(1);
|
||||
}
|
||||
if (type & TYPE_PTR_MASK) {
|
||||
eprintf("global variable of pointer is not supported\n");
|
||||
exit(1);
|
||||
|
@ -1353,7 +1373,7 @@ void parse_global_variable(int id, const char* name, int type) {
|
|||
void parse_global_declaration() {
|
||||
int type = parse_type();
|
||||
if (type < 0) {
|
||||
eprintf("unexpected token: %d\n", token_type);
|
||||
eprintf("expecting type for global declaration\n");
|
||||
exit(1);
|
||||
}
|
||||
expect_token(TOKEN_ID);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue