Skip to content

Commit

Permalink
fix (types): allow void pointers and correctly treat array pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
SantriptaSharma committed Dec 6, 2023
1 parent e8731c1 commit a75c394
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion 15_A5.y
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ declaration:
break;
}

if ($1 == VOID_T && $$.sym->type.kind != FUNC_T) {
if ($1 == VOID_T && $$.sym->type.kind != FUNC_T && $$.sym->type.kind != PRIMITIVE_PTR && $$.sym->type.kind != ARRAY_PTR) {
yyerror("void is zero-sized!");
YYABORT;
}
Expand Down
6 changes: 5 additions & 1 deletion 15_A5_translator.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,14 @@ int GetSize(Type type) {
break;

case PRIMITIVE_PTR:
case ARRAY_PTR:
return size_of_pointer;
break;

// semantically make more sense as pointer arrays and not array pointers, sorry
case ARRAY_PTR:
return size_of_pointer * type.array.size;
break;

case ARRAY_T:
return Sizes[type.array.base] * type.array.size;
break;
Expand Down

0 comments on commit a75c394

Please sign in to comment.