AST_STRICT for type aliases

This commit is contained in:
Krzosa Karol
2022-06-12 13:09:37 +02:00
parent beb10d6e2d
commit cd29798c1d
5 changed files with 19 additions and 10 deletions

View File

@@ -41,7 +41,7 @@ typedef U32 Ast_Flag;
enum{
AST_EXPR = bit_flag(1),
AST_STMT = bit_flag(2),
AST_BINDING = bit_flag(3),
AST_STRICT = bit_flag(3),
AST_AGGREGATE = bit_flag(4),
AST_AGGREGATE_CHILD = bit_flag(5),
AST_ITEM_INCLUDED = bit_flag(6),

View File

@@ -161,7 +161,7 @@ Intern_String keyword_enum;
Intern_String intern_void;
Intern_String intern_foreign;
Intern_String intern_printf;
Intern_String intern_strict;
struct Ast_Scope;
@@ -209,9 +209,9 @@ lex_init(Allocator *token_string_arena, Allocator *map_allocator, Lexer *l){
l->interns.first_keyword = keyword_struct.str;
l->interns.last_keyword = keyword_enum.str;
intern_foreign = intern_string(&l->interns, "#foreign"_s);
intern_foreign = intern_string(&l->interns, "foreign"_s);
intern_strict = intern_string(&l->interns, "strict"_s);
intern_void = intern_string(&l->interns, "void"_s);
intern_printf = intern_string(&l->interns, "printf"_s);
}
function void

View File

@@ -80,10 +80,10 @@ token_is_keyword(Intern_String keyword, S64 lookahead = 0){
}
function Token *
token_match_pound(String string){
token_match_pound(Intern_String string){
Token *token = token_get();
if(token->kind == TK_Pound){
if(string_compare(token->intern_val.s, string)){
if(token->intern_val == string){
return token_next();
}
}
@@ -340,11 +340,8 @@ parse_lambda(Token *token){
}
token_expect(TK_CloseParen);
Ast_Expr *ret = parse_optional_type();
Token *foreign = token_match_pound("foreign"_s);
Ast_Scope *scope = token_is(OPEN_SCOPE) ? parse_stmt_scope() : 0;
Ast_Lambda *result = ast_lambda(token, params, ret, scope);
if(foreign) set_flag(result->flags, AST_FOREIGN);
return result;
}
@@ -598,8 +595,16 @@ parse_decl(B32 is_global){
}
}
Ast_Flag flags = 0;
Token *tname = token_get();
if(token_match(TK_Identifier, TK_DoubleColon)){
if(token_match_pound(intern_strict)){
set_flag(flags, AST_STRICT);
} else if(token_match_pound(intern_foreign)){
set_flag(flags, AST_FOREIGN);
}
// @note parse struct binding
if(token_match_keyword(keyword_struct)){
result = parse_struct(tname);
@@ -638,6 +643,7 @@ parse_decl(B32 is_global){
if(result){
result->name = tname->intern_val;
set_flag(result->flags, flags);
}
return result;

View File

@@ -965,7 +965,9 @@ resolve_decl(Ast_Decl *ast){
node->value = op.value;
if(op.value.type == type_type){
node->kind = AST_TYPE;
if(is_flag_set(node->flags, AST_STRICT)){
node->type_val = type_copy(pctx->perm, node->type_val);
}
} else if(is_lambda(op.value.type)){
node->kind = AST_LAMBDA;
}

View File

@@ -3,6 +3,7 @@ struct Operand{
INLINE_VALUE_FIELDS;
U8 is_const : 1;
U8 is_lvalue: 1;
U8 pound_strict: 1;
};
FLAG32(Resolve_Flag){