diff options
| author | Mustafa Quraish <[email protected]> | 2022-02-05 00:58:16 -0500 |
|---|---|---|
| committer | Mustafa Quraish <[email protected]> | 2022-02-05 08:56:15 -0500 |
| commit | 3da421417167d30ef6291342b19b08419049faae (patch) | |
| tree | 0b7e685b25f8d4cf64db32e09d6c52b3951006fa /src/parser.c | |
| parent | Add ability to initialize global variables (diff) | |
| download | cup-3da421417167d30ef6291342b19b08419049faae.tar.xz cup-3da421417167d30ef6291342b19b08419049faae.zip | |
Add `sizeof(<type>)` operator that can return the size of a type.
Diffstat (limited to 'src/parser.c')
| -rw-r--r-- | src/parser.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/parser.c b/src/parser.c index 81c90da..99926d0 100644 --- a/src/parser.c +++ b/src/parser.c @@ -541,6 +541,14 @@ Node *parse_factor(Lexer *lexer) Lexer_next(lexer); expr = parse_expression(lexer); assert_token(Lexer_next(lexer), TOKEN_CLOSE_PAREN); + + // FIXME: This should probably go somewhere else more appropriate + } else if (token.type == TOKEN_SIZEOF) { + Lexer_next(lexer); + assert_token(Lexer_next(lexer), TOKEN_OPEN_PAREN); + Type *type = parse_type(lexer); + assert_token(Lexer_next(lexer), TOKEN_CLOSE_PAREN); + expr = Node_from_int_literal(size_for_type(type)); } else if (is_literal_token(token.type)) { expr = parse_literal(lexer); } else if (token.type == TOKEN_IDENTIFIER) { |