Deleting more code poggers
This commit is contained in:
105
typechecking.cpp
105
typechecking.cpp
@@ -312,106 +312,6 @@ _rewrite_into_const(Ast *node, U64 ast_size, Value value){
|
||||
ast->value = value;
|
||||
}
|
||||
|
||||
#if 0
|
||||
function Operand
|
||||
resolve_expr(Ast_Expr *ast, Ast_Resolved_Type *expected_type, Sym *lambda_to_resolve){
|
||||
if(!ast) return {}; // @todo: add option for better error prevention
|
||||
assert(is_flag_set(ast->flags, AST_EXPR));
|
||||
|
||||
switch(ast->kind){
|
||||
|
||||
|
||||
CASE(BINARY, Binary){
|
||||
Operand result = {};
|
||||
//-----------------------------------------------------------------------------
|
||||
else if(node->op == TK_Dot){
|
||||
B32 required_to_be_const = false;
|
||||
// @note: resolve first chunk which involves querying global map
|
||||
// second part requires searching through a struct
|
||||
// resolve.x.y
|
||||
Operand resolved_ident = resolve_expr(node->left);
|
||||
Ast_Resolved_Type *type = resolved_ident.type;
|
||||
if(type == type_type){
|
||||
type = resolved_ident.type_val;
|
||||
required_to_be_const = true;
|
||||
}
|
||||
// @copy_paste
|
||||
if(is_pointer(type)) type = type->base;
|
||||
|
||||
sym_var({}, resolved_ident.type, node->left);
|
||||
if(is_string(type) && !required_to_be_const){
|
||||
result = field_access_builtin_string(node->right);
|
||||
}
|
||||
else if(is_array(type) && !required_to_be_const){
|
||||
result = field_access_builtin_array(node->right);
|
||||
}
|
||||
else{
|
||||
type_complete(type);
|
||||
if(!(is_struct(type) || is_enum(type))) compiler_error(node->pos, "Trying to access inside a value that is not a struct or enum");
|
||||
|
||||
// This happens only on binary nodes which further chain with dots and require lookups
|
||||
// This part cant happen on enums
|
||||
// x.resolve.y
|
||||
Ast_Binary *binary = (Ast_Binary *)node->right;
|
||||
for(;!is_ident(binary); binary=(Ast_Binary *)binary->right){
|
||||
assert(is_ident(binary->left));
|
||||
Ast_Atom *ident = (Ast_Atom *)binary->left;
|
||||
assert(is_binary(binary));
|
||||
|
||||
Ast_Struct *agg = (Ast_Struct *)type->ast;
|
||||
Ast *query = query_struct(agg, ident->intern_val);
|
||||
if(query){
|
||||
Sym *sym = resolved_get(query);
|
||||
if(required_to_be_const && sym->kind != SYM_CONST) compiler_error(ident->pos, "Required to be constant");
|
||||
type = sym->type;
|
||||
// @copy_paste
|
||||
if(type == type_type){
|
||||
required_to_be_const = true;
|
||||
type = sym->type_val;
|
||||
}
|
||||
if(is_pointer(type)) type = type->base;
|
||||
type_complete(type);
|
||||
if(!(is_struct(type) || is_enum(type))) compiler_error(node->pos, "Trying to access inside a value that is not a struct or enum");
|
||||
sym_associate(ident, sym);
|
||||
|
||||
} else compiler_error(ident->pos, "No such member in struct");
|
||||
}
|
||||
|
||||
// Here we can resolve the last part, this doesnt need to be a struct
|
||||
// x.y.resolve
|
||||
// @copy_paste
|
||||
Ast_Atom *ident = (Ast_Atom *)binary;
|
||||
if(is_enum(type)){
|
||||
Ast_Enum *enu = (Ast_Enum *)type->ast;
|
||||
Ast_Enum_Member *query = query_enum(enu, ident->intern_val);
|
||||
if(query){
|
||||
Sym *resolved = resolved_get(query);
|
||||
assert(resolved);
|
||||
rewrite_into_const(node, Ast_Binary, resolved);
|
||||
result = operand(resolved);
|
||||
}
|
||||
}
|
||||
else if(is_struct(type)){
|
||||
Ast_Struct *agg = (Ast_Struct *)type->ast;
|
||||
Ast *query = query_struct(agg, ident->intern_val);
|
||||
if(query){
|
||||
Sym *sym = resolved_get(query);
|
||||
result = operand(sym);
|
||||
assert(sym);
|
||||
if(sym->kind == SYM_CONST) rewrite_into_const(node, Ast_Binary, sym);
|
||||
else sym_associate(ident, sym);
|
||||
|
||||
} else compiler_error(ident->pos, "No such member in struct");
|
||||
}
|
||||
else compiler_error(ident->pos, "Trying to [.] access a value that is not [Enum] or [Struct]");
|
||||
|
||||
if(result.is_const == false && required_to_be_const){
|
||||
invalid_codepath;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
function Ast_Decl *
|
||||
_search_for_decl(Ast_Scope *scope, Intern_String name){
|
||||
For(scope->decls){
|
||||
@@ -973,8 +873,11 @@ resolve_decl(Ast_Decl *ast){
|
||||
}
|
||||
|
||||
CASE(ENUM, Decl){
|
||||
Ast_Resolved_Type *type_of_enum = resolve_typespec(node->typespec, AST_CAN_BE_NULL);
|
||||
|
||||
node->type = type_type;
|
||||
node->type_val = type_enum(node);
|
||||
node->type_val = type_enum(node, type_of_enum);
|
||||
|
||||
S64 value = 0;
|
||||
For(node->scope->decls){
|
||||
Operand op = {};
|
||||
|
||||
@@ -19,7 +19,6 @@ FLAG32(Search_Flag){
|
||||
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, Search_Flag search_flags = 0);
|
||||
function Ast_Resolved_Type *resolve_typespec(Ast_Expr *ast, Resolve_Flag flags);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Operands
|
||||
@@ -178,8 +177,7 @@ type_lambda(Ast *ast, Ast_Resolved_Type *ret, Array<Ast_Resolved_Type *> args){
|
||||
|
||||
|
||||
function Ast_Resolved_Type *
|
||||
type_enum(Ast_Decl *ast){
|
||||
Ast_Resolved_Type *type = resolve_typespec(ast->typespec, AST_CAN_BE_NULL);
|
||||
type_enum(Ast_Decl *ast, Ast_Resolved_Type *type){
|
||||
if(!type){
|
||||
type = type_s64;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user