This allows testing optnum, optenum, errnum and resnum as alternatives to errtype.

This commit is contained in:
Christoffer Lerno
2022-01-19 23:21:17 +01:00
parent e6ad9c324d
commit ec291d4a9d
5 changed files with 30 additions and 2 deletions

View File

@@ -216,7 +216,7 @@ extern fn int strcoll(char* str1, char* str2);
extern fn char* strcpy(char* dst, char* src);
extern fn char* strncpy(char* dst, char* src, usize n);
extern fn usize strcspn(char* str1, char* str2);
extern fn char* strerror(int errnum);
extern fn char* strerror(int errn);
extern fn usize strlen(char* str);
extern fn char* strpbrk(char* str1, char* str2);
extern fn usize strspn(char* str1, char* str2);

View File

@@ -464,6 +464,11 @@ typedef enum
TOKEN_VAR,
TOKEN_WHILE,
TOKEN_ERRNUM,
TOKEN_OPTNUM,
TOKEN_OPTENUM,
TOKEN_RESNUM,
TOKEN_CT_ALIGNOF, // $alignof
TOKEN_CT_ASSERT, // $assert
TOKEN_CT_CASE, // $case

View File

@@ -79,6 +79,10 @@ void recover_top_level(ParseContext *context)
case TOKEN_GENERIC:
case TOKEN_DEFINE:
case TOKEN_ERRTYPE:
case TOKEN_OPTENUM:
case TOKEN_OPTNUM:
case TOKEN_ERRNUM:
case TOKEN_RESNUM:
return;
case TOKEN_IDENT: // Incr arrays only
case TOKEN_CONST:
@@ -1774,7 +1778,8 @@ static inline Decl *parse_macro_declaration(ParseContext *context, Visibility vi
*/
static inline Decl *parse_error_declaration(ParseContext *context, Visibility visibility)
{
advance_and_verify(context, TOKEN_ERRTYPE);
advance(context);
// advance_and_verify(context, TOKEN_ERRTYPE);
Decl *decl = decl_new_with_type(context->tok.id, DECL_ERRTYPE, visibility);
@@ -2317,6 +2322,10 @@ Decl *parse_top_level_statement(ParseContext *context)
ASSIGN_DECL_ELSE(decl, parse_enum_declaration(context, visibility), poisoned_decl);
break;
}
case TOKEN_OPTENUM:
case TOKEN_OPTNUM:
case TOKEN_ERRNUM:
case TOKEN_RESNUM:
case TOKEN_ERRTYPE:
{
ASSIGN_DECL_ELSE(decl, parse_error_declaration(context, visibility), poisoned_decl);

View File

@@ -947,6 +947,10 @@ Ast *parse_stmt(ParseContext *context)
case TOKEN_EXTERN:
case TOKEN_STRUCT:
case TOKEN_ERRTYPE:
case TOKEN_OPTENUM:
case TOKEN_OPTNUM:
case TOKEN_ERRNUM:
case TOKEN_RESNUM:
case TOKEN_UNION:
case TOKEN_DEFINE:
case TOKEN_DOCS_START:

View File

@@ -270,6 +270,16 @@ const char *token_type_to_string(TokenType type)
return "var";
case TOKEN_WHILE:
return "while";
// Aliases to test out
case TOKEN_OPTENUM:
return "optenum";
case TOKEN_OPTNUM:
return "optnum";
case TOKEN_ERRNUM:
return "errnum";
case TOKEN_RESNUM:
return "resnum";
// Named types
case TOKEN_VOID: