@@ -533,6 +533,8 @@ typedef enum {
533533 _UPF_TOK_TYPE_QUALIFIER ,
534534 _UPF_TOK_ATOMIC ,
535535 _UPF_TOK_GENERIC ,
536+ _UPF_TOK_SIZEOF ,
537+ _UPF_TOK_ALIGNOF ,
536538 _UPF_TOK_OPEN_PAREN ,
537539 _UPF_TOK_CLOSE_PAREN ,
538540 _UPF_TOK_OPEN_BRACKET ,
@@ -2356,6 +2358,9 @@ static void _upf_tokenize(const char *string) {
23562358 {_UPF_TOK_TYPE_QUALIFIER , "restrict" },
23572359 {_UPF_TOK_ATOMIC , "_Atomic" },
23582360 {_UPF_TOK_GENERIC , "_Generic" },
2361+ {_UPF_TOK_SIZEOF , "sizeof" },
2362+ {_UPF_TOK_ALIGNOF , "_Alignof" },
2363+ {_UPF_TOK_ALIGNOF , "alignof" },
23592364 };
23602365
23612366 const char * ch = string ;
@@ -2722,6 +2727,22 @@ static _upf_type *_upf_identifier(void) {
27222727
27232728static _upf_type * _upf_generic (void ) { _UPF_ERROR ("Generics are not supported at %s:%d." , _upf_state .file_path , _upf_state .line ); }
27242729
2730+ static _upf_type * _upf_sizeof (void ) {
2731+ _upf_consume_token ();
2732+ if (_upf_match_token (_UPF_TOK_OPEN_PAREN )) {
2733+ _upf_consume_parens (_UPF_TOK_OPEN_PAREN , _UPF_TOK_CLOSE_PAREN );
2734+ } else {
2735+ _upf_parse (_UPF_PREC_UNARY );
2736+ }
2737+ return _upf_get_number_type ();
2738+ }
2739+
2740+ static _upf_type * _upf_alignof (void ) {
2741+ _upf_consume_token ();
2742+ _upf_consume_parens (_UPF_TOK_OPEN_PAREN , _UPF_TOK_CLOSE_PAREN );
2743+ return _upf_get_number_type ();
2744+ }
2745+
27252746static _upf_type * _upf_unary (void ) {
27262747 _upf_token unop = _upf_consume_token ();
27272748 _upf_type * type = _upf_parse (_UPF_PREC_UNARY );
@@ -2849,6 +2870,8 @@ static const _upf_parse_rule _upf_parse_rules[_UPF_TOK_COUNT] = {
28492870 [_UPF_TOK_STRING ] = { _upf_string , NULL , _UPF_PREC_NONE },
28502871 [_UPF_TOK_IDENTIFIER ] = { _upf_identifier , NULL , _UPF_PREC_NONE },
28512872 [_UPF_TOK_GENERIC ] = { _upf_generic , NULL , _UPF_PREC_NONE },
2873+ [_UPF_TOK_SIZEOF ] = { _upf_sizeof , NULL , _UPF_PREC_NONE },
2874+ [_UPF_TOK_ALIGNOF ] = { _upf_alignof , NULL , _UPF_PREC_NONE },
28522875 [_UPF_TOK_UNARY ] = { _upf_unary , NULL , _UPF_PREC_NONE },
28532876 [_UPF_TOK_OPEN_PAREN ] = { _upf_paren , _upf_call , _UPF_PREC_POSTFIX },
28542877 [_UPF_TOK_OPEN_BRACKET ] = { NULL , _upf_index , _UPF_PREC_POSTFIX },
0 commit comments