commit 58642b848d97cf227d1811c8c7d4c9bdf2d7fa02
parent 9c9fa65864337e6a313be023e4266ee38b0ac389
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Sat, 1 Oct 2022 07:57:26 -0400
cc: add "typedef" keyword
Diffstat:
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/fs/cc/ast.fs b/fs/cc/ast.fs
@@ -418,8 +418,6 @@ current to parseFactor
( node tok ) to nexttputback ;
current to parseExpression
-: expectType ( tok -- type ) parseType not if _err then ( type ) ;
-
\ Parse a variable declaration from within a function
: parseDeclare ( type parentnode -- dnode )
swap parseVariable ( pnode ctype )
@@ -437,7 +435,7 @@ current to parseExpression
FuncSig :new nextt ( snode tok )
dup S" )" s= if drop exit then
begin ( snode tok )
- expectType over parseDeclare STORAGE_PS swap to Declare storage
+ parseType _assert over parseDeclare STORAGE_PS swap to Declare storage
nextt dup S" )" s= not while
',' expectChar nextt repeat ( snode tok ) drop ;
@@ -523,6 +521,9 @@ current to parseStatement
dup S" #[" s= if drop #[0 drop exit then
0 to curstatic
dup S" static" s= if drop nextt 1 to curstatic then
+ dup S" typedef" s= if
+ drop nextt parseType _assert
+ nextt expectIdent read; addTypedef drop exit then
parseType _assert ( unode type )
nextt dup ';' isChar? if \ Only a type on a line is fine, carry on
2drop drop exit then
diff --git a/fs/tests/cc/test.c b/fs/tests/cc/test.c
@@ -205,13 +205,14 @@ int unaryopmut(int n) {
return n;
}
+typedef short MyType;
struct MyStruct {
int foo;
- short bar;
+ MyType bar;
char baz[2];
};
-short structget(MyStruct *s) {
+MyType structget(MyStruct *s) {
return s->bar;
}
void structset(MyStruct *s, char val) {