Cleanup, FLAG32
This commit is contained in:
@@ -17,4 +17,4 @@ CONSTANT_VAL :: 10
|
||||
|
||||
global_thing: a_type = 10
|
||||
|
||||
arena: order2.Arena
|
||||
// arena: order2.Arena
|
||||
|
||||
@@ -513,14 +513,20 @@ _search_for_decl(Ast_Scope *scope, Intern_String name){
|
||||
return 0;
|
||||
}
|
||||
|
||||
FLAG32(Search_Flag) {
|
||||
SEARCH_ONLY_CURRENT_SCOPE = bit_flag(1),
|
||||
SEARCH_ALSO_FOR_PACKAGE = bit_flag(2),
|
||||
};
|
||||
|
||||
function Ast_Decl *
|
||||
search_for_decl(Ast_Scope *scope, Intern_String name){
|
||||
search_for_decl(Ast_Scope *scope, Intern_String name, Search_Flag flags = 0){
|
||||
Ast_Decl *result = 0;
|
||||
for(Ast_Scope *it = scope; it; it=it->parent_scope){
|
||||
result = _search_for_decl(it, name);
|
||||
if(result) break;
|
||||
if(is_flag_set(flags, SEARCH_ONLY_CURRENT_SCOPE)) break;
|
||||
}
|
||||
if(!result){
|
||||
if(!result && is_flag_set(flags, SEARCH_ALSO_FOR_PACKAGE)){
|
||||
For(pctx->packages){
|
||||
if(name == it->name){
|
||||
result = (Ast_Decl *)it;
|
||||
@@ -570,7 +576,7 @@ insert_builtin_types_into_package(Ast_Package *p){
|
||||
}
|
||||
|
||||
function Ast_Resolved_Type *
|
||||
resolve_typespec(Ast_Expr *ast, B32 flags){
|
||||
resolve_typespec(Ast_Expr *ast, Resolve_Flag flags){
|
||||
if(!ast && is_flag_set(flags, AST_CAN_BE_NULL))
|
||||
return 0;
|
||||
|
||||
@@ -583,7 +589,7 @@ resolve_typespec(Ast_Expr *ast, B32 flags){
|
||||
}
|
||||
|
||||
function Operand
|
||||
resolve_and_require_bool(const char *error, Ast_Expr *expr, B32 flags){
|
||||
resolve_and_require_bool(const char *error, Ast_Expr *expr, Resolve_Flag flags){
|
||||
if(!expr){
|
||||
if(flags == AST_CAN_BE_NULL)
|
||||
return {};
|
||||
@@ -599,7 +605,7 @@ resolve_and_require_bool(const char *error, Ast_Expr *expr, B32 flags){
|
||||
}
|
||||
|
||||
function Operand
|
||||
require_const_int(Ast_Expr *expr, B32 flags){
|
||||
require_const_int(Ast_Expr *expr, Resolve_Flag flags){
|
||||
Operand op = resolve_expr(expr, flags);
|
||||
|
||||
if(expr == 0 && flags)
|
||||
@@ -726,7 +732,7 @@ resolve_cast(Ast_Cast *node){
|
||||
}
|
||||
|
||||
function Operand
|
||||
resolve_expr(Ast_Expr *ast, B32 flags){
|
||||
resolve_expr(Ast_Expr *ast, Resolve_Flag flags){
|
||||
if(!ast && is_flag_set(flags, AST_CAN_BE_NULL)) return {};
|
||||
assert(is_flag_set(ast->flags, AST_EXPR));
|
||||
assert(ast->parent_scope->kind == AST_SCOPE || ast->parent_scope->kind == AST_PACKAGE);
|
||||
@@ -740,7 +746,6 @@ resolve_expr(Ast_Expr *ast, B32 flags){
|
||||
|
||||
// Typespec array [32]int
|
||||
CASE(ARRAY, Array){
|
||||
// @todo: Arrays of inferred size []
|
||||
Operand type = resolve_expr(node->base, AST_CANT_BE_NULL);
|
||||
Operand expr = require_const_int(node->expr, AST_CAN_BE_NULL);
|
||||
if(type.type != type_type) compiler_error(node->pos, "Prefix array operator is only allowed on types");
|
||||
@@ -923,13 +928,8 @@ resolve_expr(Ast_Expr *ast, B32 flags){
|
||||
invalid_return;
|
||||
}
|
||||
|
||||
// @todo: I hate this, package is a scope so it cant
|
||||
// be a DECL, I don't personally like this meme
|
||||
function void
|
||||
resolve_decl(Ast_Decl *ast){
|
||||
if(ast->kind == AST_PACKAGE){
|
||||
return;
|
||||
}
|
||||
if(ast->state == DECL_RESOLVED){
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -5,42 +5,18 @@ struct Operand{
|
||||
U8 is_lvalue: 1;
|
||||
};
|
||||
|
||||
enum{AST_CANT_BE_NULL = 0, AST_CAN_BE_NULL = 1, IS_NOT_PACKAGE_GLOBAL=2, RESOLVE_TYPESPEC_COMPLETE = bit_flag(3)};
|
||||
function Operand resolve_expr(Ast_Expr *ast, B32 flags);
|
||||
FLAG32(Resolve_Flag){
|
||||
AST_CANT_BE_NULL = bit_flag(0),
|
||||
AST_CAN_BE_NULL = bit_flag(1),
|
||||
RESOLVE_TYPESPEC_COMPLETE = bit_flag(2),
|
||||
};
|
||||
|
||||
function Operand resolve_expr(Ast_Expr *ast, Resolve_Flag flags);
|
||||
function void resolve_decl(Ast_Decl *ast);
|
||||
function Ast_Decl *resolve_name(Ast_Scope *parent_scope, Token *pos, Intern_String name);
|
||||
function Ast_Resolved_Type *resolve_typespec(Ast_Expr *ast, B32 ast_can_be_null);
|
||||
function Ast_Resolved_Type *resolve_typespec(Ast_Expr *ast, Resolve_Flag flags);
|
||||
|
||||
#if 0
|
||||
//-----------------------------------------------------------------------------
|
||||
// Symbols
|
||||
//-----------------------------------------------------------------------------
|
||||
enum Sym_Kind{
|
||||
SYM_NONE,
|
||||
SYM_CONST,
|
||||
SYM_VAR,
|
||||
};
|
||||
|
||||
enum Sym_State{
|
||||
SYM_NOT_RESOLVED,
|
||||
SYM_RESOLVING,
|
||||
SYM_RESOLVED,
|
||||
};
|
||||
|
||||
struct Sym{
|
||||
Intern_String name;
|
||||
Sym_Kind kind;
|
||||
Sym_State state;
|
||||
Ast *ast;
|
||||
INLINE_VALUE_FIELDS;
|
||||
};
|
||||
|
||||
|
||||
function Ast_Resolved_Type *resolve_typespec(Ast_Expr *ast, B32 ast_can_be_null = AST_CANT_BE_NULL);
|
||||
function Sym *resolve_name(Token *pos, Intern_String name);
|
||||
function Operand resolve_expr(Ast_Expr *ast, Ast_Resolved_Type *compound_required_type = 0, Sym *const_sym = 0);
|
||||
function Operand resolve_binding(Ast *ast, Sym *sym = 0);
|
||||
global Ast_Named empty_decl = {};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Symbol constructors and utils
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user