AST_STRICT for type aliases
This commit is contained in:
2
ast.cpp
2
ast.cpp
@@ -41,7 +41,7 @@ typedef U32 Ast_Flag;
|
|||||||
enum{
|
enum{
|
||||||
AST_EXPR = bit_flag(1),
|
AST_EXPR = bit_flag(1),
|
||||||
AST_STMT = bit_flag(2),
|
AST_STMT = bit_flag(2),
|
||||||
AST_BINDING = bit_flag(3),
|
AST_STRICT = bit_flag(3),
|
||||||
AST_AGGREGATE = bit_flag(4),
|
AST_AGGREGATE = bit_flag(4),
|
||||||
AST_AGGREGATE_CHILD = bit_flag(5),
|
AST_AGGREGATE_CHILD = bit_flag(5),
|
||||||
AST_ITEM_INCLUDED = bit_flag(6),
|
AST_ITEM_INCLUDED = bit_flag(6),
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ Intern_String keyword_enum;
|
|||||||
|
|
||||||
Intern_String intern_void;
|
Intern_String intern_void;
|
||||||
Intern_String intern_foreign;
|
Intern_String intern_foreign;
|
||||||
Intern_String intern_printf;
|
Intern_String intern_strict;
|
||||||
|
|
||||||
|
|
||||||
struct Ast_Scope;
|
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.first_keyword = keyword_struct.str;
|
||||||
l->interns.last_keyword = keyword_enum.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_void = intern_string(&l->interns, "void"_s);
|
||||||
intern_printf = intern_string(&l->interns, "printf"_s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function void
|
function void
|
||||||
|
|||||||
16
parsing.cpp
16
parsing.cpp
@@ -80,10 +80,10 @@ token_is_keyword(Intern_String keyword, S64 lookahead = 0){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Token *
|
function Token *
|
||||||
token_match_pound(String string){
|
token_match_pound(Intern_String string){
|
||||||
Token *token = token_get();
|
Token *token = token_get();
|
||||||
if(token->kind == TK_Pound){
|
if(token->kind == TK_Pound){
|
||||||
if(string_compare(token->intern_val.s, string)){
|
if(token->intern_val == string){
|
||||||
return token_next();
|
return token_next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -340,11 +340,8 @@ parse_lambda(Token *token){
|
|||||||
}
|
}
|
||||||
token_expect(TK_CloseParen);
|
token_expect(TK_CloseParen);
|
||||||
Ast_Expr *ret = parse_optional_type();
|
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_Scope *scope = token_is(OPEN_SCOPE) ? parse_stmt_scope() : 0;
|
||||||
Ast_Lambda *result = ast_lambda(token, params, ret, scope);
|
Ast_Lambda *result = ast_lambda(token, params, ret, scope);
|
||||||
if(foreign) set_flag(result->flags, AST_FOREIGN);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -598,8 +595,16 @@ parse_decl(B32 is_global){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ast_Flag flags = 0;
|
||||||
Token *tname = token_get();
|
Token *tname = token_get();
|
||||||
if(token_match(TK_Identifier, TK_DoubleColon)){
|
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
|
// @note parse struct binding
|
||||||
if(token_match_keyword(keyword_struct)){
|
if(token_match_keyword(keyword_struct)){
|
||||||
result = parse_struct(tname);
|
result = parse_struct(tname);
|
||||||
@@ -638,6 +643,7 @@ parse_decl(B32 is_global){
|
|||||||
|
|
||||||
if(result){
|
if(result){
|
||||||
result->name = tname->intern_val;
|
result->name = tname->intern_val;
|
||||||
|
set_flag(result->flags, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -965,7 +965,9 @@ resolve_decl(Ast_Decl *ast){
|
|||||||
node->value = op.value;
|
node->value = op.value;
|
||||||
if(op.value.type == type_type){
|
if(op.value.type == type_type){
|
||||||
node->kind = AST_TYPE;
|
node->kind = AST_TYPE;
|
||||||
node->type_val = type_copy(pctx->perm, node->type_val);
|
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)){
|
} else if(is_lambda(op.value.type)){
|
||||||
node->kind = AST_LAMBDA;
|
node->kind = AST_LAMBDA;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ struct Operand{
|
|||||||
INLINE_VALUE_FIELDS;
|
INLINE_VALUE_FIELDS;
|
||||||
U8 is_const : 1;
|
U8 is_const : 1;
|
||||||
U8 is_lvalue: 1;
|
U8 is_lvalue: 1;
|
||||||
|
U8 pound_strict: 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
FLAG32(Resolve_Flag){
|
FLAG32(Resolve_Flag){
|
||||||
|
|||||||
Reference in New Issue
Block a user