Addition of "distinct" and "inline" as keywords. Removal of "alias" keyword.

This commit is contained in:
Christoffer Lerno
2023-05-04 08:48:17 +02:00
parent 6fc38bbcb9
commit db8c46d6c5
8 changed files with 30 additions and 36 deletions

View File

@@ -1872,12 +1872,10 @@ extern const char *kw_at_require;
extern const char *kw_at_return;
extern const char *kw_check_assign;
extern const char *kw_deprecated;
extern const char *kw_distinct;
extern const char *kw_finalize;
extern const char *kw_in;
extern const char *kw_incr;
extern const char *kw_initialize;
extern const char *kw_inline;
extern const char *kw_inout;
extern const char *kw_kind;
extern const char *kw_len;

View File

@@ -508,7 +508,6 @@ typedef enum
TOKEN_TYPEID,
// Keywords
TOKEN_ALIAS, // Reserved
TOKEN_ASSERT,
TOKEN_ASM,
TOKEN_BITSTRUCT,
@@ -521,6 +520,7 @@ typedef enum
TOKEN_DEFINE,
TOKEN_DEFAULT,
TOKEN_DEFER,
TOKEN_DISTINCT,
TOKEN_DO,
TOKEN_ELSE,
TOKEN_ENUM,
@@ -533,6 +533,7 @@ typedef enum
TOKEN_FN,
TOKEN_TLOCAL,
TOKEN_IF,
TOKEN_INLINE,
TOKEN_IMPORT,
TOKEN_MACRO,
TOKEN_MODULE,
@@ -548,6 +549,7 @@ typedef enum
TOKEN_UNION,
TOKEN_VAR,
TOKEN_WHILE,
TOKEN_LAST_NON_CT_KEYWORD = TOKEN_WHILE,
TOKEN_CT_ALIGNOF, // $alignof
TOKEN_CT_ASSERT, // $assert

View File

@@ -203,7 +203,7 @@ static inline Path *parse_module_path(ParseContext *c)
const char *string = symstr(c);
if (!try_consume(c, TOKEN_IDENT))
{
if (token_is_keyword(c->tok))
if (token_is_keyword_ident(c->tok))
{
SEMA_ERROR_HERE("The module path cannot contain a reserved keyword, try another name.");
return NULL;
@@ -290,7 +290,7 @@ bool parse_module(ParseContext *c, AstId contracts)
if (!tok_is(c, TOKEN_IDENT))
{
if (token_is_keyword(c->tok))
if (token_is_keyword_ident(c->tok))
{
RETURN_SEMA_ERROR_HERE("The module name cannot contain a reserved keyword, try another name.");
}
@@ -400,7 +400,7 @@ bool parse_module(ParseContext *c, AstId contracts)
static bool consume_type_name(ParseContext *c, const char* type)
{
if (tok_is(c, TOKEN_IDENT) || token_is_keyword(c->tok))
if (tok_is(c, TOKEN_IDENT) || token_is_keyword_ident(c->tok))
{
RETURN_SEMA_ERROR_HERE("Names of %ss must start with an uppercase letter.", type);
}
@@ -413,7 +413,7 @@ static bool consume_type_name(ParseContext *c, const char* type)
bool consume_const_name(ParseContext *c, const char* type)
{
if (tok_is(c, TOKEN_IDENT) || tok_is(c, TOKEN_TYPE_IDENT) || token_is_keyword(c->tok))
if (tok_is(c, TOKEN_IDENT) || tok_is(c, TOKEN_TYPE_IDENT) || token_is_keyword_ident(c->tok))
{
RETURN_SEMA_ERROR_HERE("Names of %ss must be all uppercase.", type);
}
@@ -1164,7 +1164,7 @@ static inline bool parse_enum_param_decl(ParseContext *c, Decl*** parameters)
Decl *param = decl_new_var_current(c, type, VARDECL_PARAM);
if (!try_consume(c, TOKEN_IDENT))
{
if (token_is_keyword(c->tok)) RETURN_SEMA_ERROR_HERE("Keywords cannot be used as member names.");
if (token_is_keyword_ident(c->tok)) RETURN_SEMA_ERROR_HERE("Keywords cannot be used as member names.");
if (token_is_some_ident(c->tok)) RETURN_SEMA_ERROR_HERE("Expected a name starting with a lower-case letter.");
RETURN_SEMA_ERROR_HERE("Expected a member name here.");
}
@@ -1501,7 +1501,7 @@ bool parse_struct_body(ParseContext *c, Decl *parent)
continue;
}
bool was_inline = false;
if (token_type == TOKEN_IDENT && symstr(c) == kw_inline)
if (tok_is(c, TOKEN_INLINE))
{
if (parent->decl_kind != DECL_STRUCT)
{
@@ -1761,23 +1761,15 @@ static inline Decl *parse_typedef_declaration(ParseContext *c)
CONSUME_OR_RET(TOKEN_EQ, poisoned_decl);
bool distinct = false;
bool is_inline = false;
if (tok_is(c, TOKEN_IDENT))
if (tok_is(c, TOKEN_INLINE))
{
if (symstr(c) == kw_inline)
{
SEMA_ERROR_HERE("'inline' must always follow 'distinct'.");
return poisoned_decl;
}
if (symstr(c) == kw_distinct)
{
distinct = true;
advance(c);
if (tok_is(c, TOKEN_IDENT) && symstr(c) == kw_inline)
{
is_inline = true;
advance(c);
}
}
SEMA_ERROR_HERE("'inline' must always follow 'distinct'.");
return poisoned_decl;
}
if (try_consume(c, TOKEN_DISTINCT))
{
distinct = true;
is_inline = try_consume(c, TOKEN_INLINE);
}
// 1. Did we have `fn`? In that case it's a function pointer.

View File

@@ -1290,7 +1290,6 @@ Ast *parse_stmt(ParseContext *c)
case TOKEN_SHL:
case TOKEN_SHR_ASSIGN:
case TOKEN_SHL_ASSIGN:
case TOKEN_ALIAS:
case TOKEN_ELSE:
case TOKEN_QUESTQUEST:
case TOKEN_ENUM:
@@ -1323,6 +1322,8 @@ Ast *parse_stmt(ParseContext *c)
case TOKEN_CT_ENDFOREACH:
case TOKEN_CT_VASPLAT:
case TOKEN_IMPLIES:
case TOKEN_INLINE:
case TOKEN_DISTINCT:
case TOKEN_CT_INCLUDE:
SEMA_ERROR_HERE("Unexpected '%s' found when expecting a statement.",
token_type_to_string(c->tok));

View File

@@ -130,9 +130,12 @@ INLINE bool token_is_some_ident(TokenType token_type)
INLINE bool token_is_keyword(TokenType token_type)
{
if (token_type >= TOKEN_VOID && token_type <= TOKEN_TYPEID) return true;
if (token_type >= TOKEN_ALIAS && token_type <= TOKEN_WHILE) return true;
return false;
return token_type >= TOKEN_FIRST_KEYWORD && token_type <= TOKEN_LAST_KEYWORD;
}
INLINE bool token_is_keyword_ident(TokenType token_type)
{
return token_type >= TOKEN_FIRST_KEYWORD && token_type <= TOKEN_LAST_NON_CT_KEYWORD;
}
static inline bool expect_ident(ParseContext *c, const char* name)

View File

@@ -51,12 +51,10 @@ const char *kw_at_require;
const char *kw_at_return;
const char *kw_check_assign;
const char *kw_deprecated;
const char *kw_distinct;
const char *kw_finalize;
const char *kw_in;
const char *kw_incr;
const char *kw_initialize;
const char *kw_inline;
const char *kw_inout;
const char *kw_kind;
const char *kw_len;
@@ -141,12 +139,10 @@ void symtab_init(uint32_t capacity)
kw_argv = KW_DEF("_$argv");
kw_check_assign = KW_DEF("check_assign");
kw_deprecated = KW_DEF("deprecated");
kw_distinct = KW_DEF("distinct");
kw_finalize = KW_DEF("finalize");
kw_in = KW_DEF("in");
kw_initialize = KW_DEF("initialize");
kw_incr = KW_DEF("incr");
kw_inline = KW_DEF("inline");
kw_inout = KW_DEF("inout");
kw_libc = KW_DEF("libc");
kw_mainstub = KW_DEF("_$start");

View File

@@ -183,8 +183,6 @@ const char *token_type_to_string(TokenType type)
return "DOC_COMMENT";
// Keywords
case TOKEN_ALIAS:
return "alias";
case TOKEN_ANYFAULT:
return "anyfault";
case TOKEN_ASM:
@@ -211,6 +209,8 @@ const char *token_type_to_string(TokenType type)
return "defer";
case TOKEN_DEFINE:
return "define";
case TOKEN_DISTINCT:
return "distinct";
case TOKEN_DO:
return "do";
case TOKEN_ELSE:
@@ -233,6 +233,8 @@ const char *token_type_to_string(TokenType type)
return "fn";
case TOKEN_IF:
return "if";
case TOKEN_INLINE:
return "inline";
case TOKEN_IMPORT:
return "import";
case TOKEN_MACRO:

View File

@@ -1 +1 @@
#define COMPILER_VERSION "0.4.502"
#define COMPILER_VERSION "0.4.503"