From 6861ff47bc35438adc1d5c6c8bf698ee78b41591 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 12 May 2020 16:28:22 +0100 Subject: [PATCH] Replace `entity_of_ident` with `entity_of_node` --- src/check_expr.cpp | 8 ++++---- src/check_stmt.cpp | 2 +- src/checker.cpp | 21 +++++---------------- src/checker.hpp | 1 - src/ir.cpp | 18 +++++++++--------- src/llvm_backend.cpp | 28 ++++++++++++++-------------- 6 files changed, 33 insertions(+), 45 deletions(-) diff --git a/src/check_expr.cpp b/src/check_expr.cpp index c998c6dc2..ab8a7ab63 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -422,7 +422,7 @@ bool find_or_generate_polymorphic_procedure(CheckerContext *c, Entity *base_enti bool check_polymorphic_procedure_assignment(CheckerContext *c, Operand *operand, Type *type, Ast *poly_def_node, PolyProcData *poly_proc_data) { if (operand->expr == nullptr) return false; - Entity *base_entity = entity_of_ident(operand->expr); + Entity *base_entity = entity_of_node(operand->expr); if (base_entity == nullptr) return false; return find_or_generate_polymorphic_procedure(c, base_entity, type, nullptr, poly_def_node, poly_proc_data); } @@ -1692,7 +1692,7 @@ void check_unary_expr(CheckerContext *c, Operand *o, Token op, Ast *node) { gbString str = expr_to_string(ue->expr); defer (gb_string_free(str)); - Entity *e = entity_of_ident(o->expr); + Entity *e = entity_of_node(o->expr); if (e != nullptr && (e->flags & EntityFlag_Param) != 0) { error(op, "Cannot take the pointer address of '%s' which is a procedure parameter", str); } else { @@ -6885,7 +6885,7 @@ CallArgumentData check_call_arguments(CheckerContext *c, Operand *operand, Type ident = s; } - Entity *e = entity_of_ident(ident); + Entity *e = entity_of_node(ident); CallArgumentData data = {}; CallArgumentError err = call_checker(c, call, proc_type, e, operands, CallArgumentMode_ShowErrors, &data); @@ -7296,7 +7296,7 @@ ExprKind check_call_expr(CheckerContext *c, Operand *operand, Ast *call, Type *t return builtin_procs[id].kind; } - Entity *e = entity_of_ident(operand->expr); + Entity *e = entity_of_node(operand->expr); if (e != nullptr && e->kind == Entity_Procedure) { if (e->Procedure.deferred_procedure.entity != nullptr) { diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 3266bd780..df6d3685c 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -310,7 +310,7 @@ Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, Operand *rhs) } } - Entity *e = entity_of_ident(lhs->expr); + Entity *e = entity_of_node(lhs->expr); gbString str = expr_to_string(lhs->expr); if (e != nullptr && e->flags & EntityFlag_Param) { diff --git a/src/checker.cpp b/src/checker.cpp index eba30e737..9dfa75443 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -904,15 +904,6 @@ void destroy_checker(Checker *c) { } -Entity *entity_of_ident(Ast *identifier) { - identifier = unparen_expr(identifier); - if (identifier->kind == Ast_Ident) { - return identifier->Ident.entity; - } - return nullptr; -} - - TypeAndValue type_and_value_of_expr(Ast *expr) { TypeAndValue tav = {}; if (expr != nullptr) { @@ -926,8 +917,8 @@ Type *type_of_expr(Ast *expr) { if (tav.mode != Addressing_Invalid) { return tav.type; } - if (expr->kind == Ast_Ident) { - Entity *entity = entity_of_ident(expr); + { + Entity *entity = entity_of_node(expr); if (entity) { return entity->type; } @@ -947,13 +938,11 @@ Entity *entity_of_node(Ast *expr) { expr = unparen_expr(expr); switch (expr->kind) { case_ast_node(ident, Ident, expr); - return entity_of_ident(expr); + return ident->entity; case_end; case_ast_node(se, SelectorExpr, expr); Ast *s = unselector_expr(se->selector); - if (s->kind == Ast_Ident) { - return entity_of_ident(s); - } + return entity_of_node(s); case_end; case_ast_node(cc, CaseClause, expr); return cc->implicit_entity; @@ -971,7 +960,7 @@ DeclInfo *decl_info_of_entity(Entity *e) { } DeclInfo *decl_info_of_ident(Ast *ident) { - return decl_info_of_entity(entity_of_ident(ident)); + return decl_info_of_entity(entity_of_node(ident)); } AstFile *ast_file_of_filename(CheckerInfo *i, String filename) { diff --git a/src/checker.hpp b/src/checker.hpp index 546dba478..af45fa249 100644 --- a/src/checker.hpp +++ b/src/checker.hpp @@ -344,7 +344,6 @@ HashKey hash_decl_info(DeclInfo *decl) { return hash_pointer(decl); } // CheckerInfo API TypeAndValue type_and_value_of_expr (Ast *expr); Type * type_of_expr (Ast *expr); -Entity * entity_of_ident (Ast *identifier); Entity * implicit_entity_of_node(Ast *clause); Scope * scope_of_node (Ast *node); DeclInfo * decl_info_of_ident (Ast *ident); diff --git a/src/ir.cpp b/src/ir.cpp index 40be67623..531f3a62c 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -1751,7 +1751,7 @@ irValue *ir_add_local(irProcedure *proc, Entity *e, Ast *expr, bool zero_initial } irValue *ir_add_local_for_identifier(irProcedure *proc, Ast *ident, bool zero_initialized) { - Entity *e = entity_of_ident(ident); + Entity *e = entity_of_node(ident); if (e != nullptr) { String name = e->token.string; ir_emit_comment(proc, name); @@ -6271,7 +6271,7 @@ void ir_mangle_add_sub_type_name(irModule *m, Entity *field, String parent) { irBranchBlocks ir_lookup_branch_blocks(irProcedure *proc, Ast *ident) { GB_ASSERT(ident->kind == Ast_Ident); - Entity *e = entity_of_ident(ident); + Entity *e = entity_of_node(ident); GB_ASSERT(e->kind == Entity_Label); for_array(i, proc->branch_blocks) { irBranchBlocks *b = &proc->branch_blocks[i]; @@ -6586,7 +6586,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, Ast *expr, TypeAndValue tv, Bu if (ce->args.count > 0) { Ast *ident = unselector_expr(ce->args[0]); GB_ASSERT(ident->kind == Ast_Ident); - Entity *e = entity_of_ident(ident); + Entity *e = entity_of_node(ident); GB_ASSERT(e != nullptr); if (e->parent_proc_decl != nullptr && e->parent_proc_decl->entity != nullptr) { @@ -7474,7 +7474,7 @@ irValue *ir_build_expr_internal(irProcedure *proc, Ast *expr) { case_end; case_ast_node(i, Ident, expr); - Entity *e = entity_of_ident(expr); + Entity *e = entity_of_node(expr); e = strip_entity_wrapping(e); GB_ASSERT_MSG(e != nullptr, "%s", expr_to_string(expr)); @@ -7968,7 +7968,7 @@ irAddr ir_build_addr(irProcedure *proc, Ast *expr) { return val; } String name = i->token.string; - Entity *e = entity_of_ident(expr); + Entity *e = entity_of_node(expr); // GB_ASSERT(name == e->token.string); return ir_build_addr_from_entity(proc, e, expr); case_end; @@ -7986,7 +7986,7 @@ irAddr ir_build_addr(irProcedure *proc, Ast *expr) { if (tav.mode == Addressing_Invalid) { // NOTE(bill): Imports - Entity *imp = entity_of_ident(se->expr); + Entity *imp = entity_of_node(se->expr); if (imp != nullptr) { GB_ASSERT(imp->kind == Entity_ImportName); } @@ -9171,7 +9171,7 @@ void ir_build_constant_value_decl(irProcedure *proc, AstValueDecl *vd) { for_array(i, vd->names) { Ast *ident = vd->names[i]; GB_ASSERT(ident->kind == Ast_Ident); - Entity *e = entity_of_ident(ident); + Entity *e = entity_of_node(ident); GB_ASSERT(e != nullptr); switch (e->kind) { case Entity_TypeName: @@ -9733,7 +9733,7 @@ void ir_build_stmt_internal(irProcedure *proc, Ast *node) { bool is_static = false; if (vd->names.count > 0) { - Entity *e = entity_of_ident(vd->names[0]); + Entity *e = entity_of_node(vd->names[0]); if (e->flags & EntityFlag_Static) { // NOTE(bill): If one of the entities is static, they all are is_static = true; @@ -9754,7 +9754,7 @@ void ir_build_stmt_internal(irProcedure *proc, Ast *node) { Ast *ident = vd->names[i]; GB_ASSERT(!is_blank_ident(ident)); - Entity *e = entity_of_ident(ident); + Entity *e = entity_of_node(ident); GB_ASSERT(e->flags & EntityFlag_Static); String name = e->token.string; diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index ead835531..40ba1bcd5 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -2502,7 +2502,7 @@ void lb_build_constant_value_decl(lbProcedure *p, AstValueDecl *vd) { for_array(i, vd->names) { Ast *ident = vd->names[i]; GB_ASSERT(ident->kind == Ast_Ident); - Entity *e = entity_of_ident(ident); + Entity *e = entity_of_node(ident); GB_ASSERT(e != nullptr); if (e->kind != Entity_TypeName) { continue; @@ -2531,7 +2531,7 @@ void lb_build_constant_value_decl(lbProcedure *p, AstValueDecl *vd) { for_array(i, vd->names) { Ast *ident = vd->names[i]; GB_ASSERT(ident->kind == Ast_Ident); - Entity *e = entity_of_ident(ident); + Entity *e = entity_of_node(ident); GB_ASSERT(e != nullptr); if (e->kind != Entity_Procedure) { continue; @@ -2615,7 +2615,7 @@ void lb_build_stmt_list(lbProcedure *p, Array const &stmts) { lbBranchBlocks lb_lookup_branch_blocks(lbProcedure *p, Ast *ident) { GB_ASSERT(ident->kind == Ast_Ident); - Entity *e = entity_of_ident(ident); + Entity *e = entity_of_node(ident); GB_ASSERT(e->kind == Entity_Label); for_array(i, p->branch_blocks) { lbBranchBlocks *b = &p->branch_blocks[i]; @@ -3031,11 +3031,11 @@ void lb_build_range_stmt(lbProcedure *p, AstRangeStmt *rs) { } if (val0_type != nullptr) { - Entity *e = entity_of_ident(rs->val0); + Entity *e = entity_of_node(rs->val0); lb_add_local(p, e->type, e, true); } if (val1_type != nullptr) { - Entity *e = entity_of_ident(rs->val1); + Entity *e = entity_of_node(rs->val1); lb_add_local(p, e->type, e, true); } @@ -3168,11 +3168,11 @@ void lb_build_inline_range_stmt(lbProcedure *p, AstInlineRangeStmt *rs) { } if (val0_type != nullptr) { - Entity *e = entity_of_ident(rs->val0); + Entity *e = entity_of_node(rs->val0); lb_add_local(p, e->type, e, true); } if (val1_type != nullptr) { - Entity *e = entity_of_ident(rs->val1); + Entity *e = entity_of_node(rs->val1); lb_add_local(p, e->type, e, true); } @@ -3679,7 +3679,7 @@ void lb_build_stmt(lbProcedure *p, Ast *node) { bool is_static = false; if (vd->names.count > 0) { - Entity *e = entity_of_ident(vd->names[0]); + Entity *e = entity_of_node(vd->names[0]); if (e->flags & EntityFlag_Static) { // NOTE(bill): If one of the entities is static, they all are is_static = true; @@ -3700,7 +3700,7 @@ void lb_build_stmt(lbProcedure *p, Ast *node) { Ast *ident = vd->names[i]; GB_ASSERT(!is_blank_ident(ident)); - Entity *e = entity_of_ident(ident); + Entity *e = entity_of_node(ident); GB_ASSERT(e->flags & EntityFlag_Static); String name = e->token.string; @@ -3755,7 +3755,7 @@ void lb_build_stmt(lbProcedure *p, Ast *node) { for_array(i, vd->names) { Ast *name = vd->names[i]; if (!is_blank_ident(name)) { - Entity *e = entity_of_ident(name); + Entity *e = entity_of_node(name); lb_add_local(p, e->type, e, true); } } @@ -3767,7 +3767,7 @@ void lb_build_stmt(lbProcedure *p, Ast *node) { Ast *name = vd->names[i]; lbAddr lval = {}; if (!is_blank_ident(name)) { - Entity *e = entity_of_ident(name); + Entity *e = entity_of_node(name); lval = lb_add_local(p, e->type, e, false); } array_add(&lvals, lval); @@ -6957,7 +6957,7 @@ lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv, if (ce->args.count > 0) { Ast *ident = unselector_expr(ce->args[0]); GB_ASSERT(ident->kind == Ast_Ident); - Entity *e = entity_of_ident(ident); + Entity *e = entity_of_node(ident); GB_ASSERT(e != nullptr); if (e->parent_proc_decl != nullptr && e->parent_proc_decl->entity != nullptr) { @@ -9162,7 +9162,7 @@ lbAddr lb_build_addr(lbProcedure *p, Ast *expr) { return val; } String name = i->token.string; - Entity *e = entity_of_ident(expr); + Entity *e = entity_of_node(expr); return lb_build_addr_from_entity(p, e, expr); case_end; @@ -9174,7 +9174,7 @@ lbAddr lb_build_addr(lbProcedure *p, Ast *expr) { if (tav.mode == Addressing_Invalid) { // NOTE(bill): Imports - Entity *imp = entity_of_ident(se->expr); + Entity *imp = entity_of_node(se->expr); if (imp != nullptr) { GB_ASSERT(imp->kind == Entity_ImportName); }