| ... | ... | @@ -157,6 +157,19 @@ static void add_global_weak_alias(Context *c, Buf *new_name, Buf *canon_name) { |
| 157 | 157 | alias->canon_name = canon_name; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | static Buf *trans_lookup_zig_symbol(Context *c, TransScope *scope, Buf *c_symbol_name) { |
| 161 | while (scope != nullptr) { |
| 162 | if (scope->id == TransScopeIdVar) { |
| 163 | TransScopeVar *var_scope = (TransScopeVar *)scope; |
| 164 | if (buf_eql_buf(var_scope->c_name, c_symbol_name)) { |
| 165 | return var_scope->zig_name; |
| 166 | } |
| 167 | } |
| 168 | scope = scope->parent; |
| 169 | } |
| 170 | return c_symbol_name; |
| 171 | } |
| 172 | |
| 160 | 173 | static AstNode * trans_create_node(Context *c, NodeType id) { |
| 161 | 174 | AstNode *node = allocate<AstNode>(1); |
| 162 | 175 | node->type = id; |
| ... | ... | @@ -1650,13 +1663,14 @@ static AstNode *trans_implicit_cast_expr(Context *c, TransScope *scope, const Im |
| 1650 | 1663 | zig_unreachable(); |
| 1651 | 1664 | } |
| 1652 | 1665 | |
| 1653 | | static AstNode *trans_decl_ref_expr(Context *c, const DeclRefExpr *stmt, TransLRValue lrval) { |
| 1666 | static AstNode *trans_decl_ref_expr(Context *c, TransScope *scope, const DeclRefExpr *stmt, TransLRValue lrval) { |
| 1654 | 1667 | const ValueDecl *value_decl = stmt->getDecl(); |
| 1655 | | Buf *symbol_name = buf_create_from_str(decl_name(value_decl)); |
| 1668 | Buf *c_symbol_name = buf_create_from_str(decl_name(value_decl)); |
| 1669 | Buf *zig_symbol_name = trans_lookup_zig_symbol(c, scope, c_symbol_name); |
| 1656 | 1670 | if (lrval == TransLValue) { |
| 1657 | | c->ptr_params.put(symbol_name, true); |
| 1671 | c->ptr_params.put(zig_symbol_name, true); |
| 1658 | 1672 | } |
| 1659 | | return trans_create_node_symbol(c, symbol_name); |
| 1673 | return trans_create_node_symbol(c, zig_symbol_name); |
| 1660 | 1674 | } |
| 1661 | 1675 | |
| 1662 | 1676 | static AstNode *trans_create_post_crement(Context *c, ResultUsed result_used, TransScope *scope, |
| ... | ... | @@ -2562,7 +2576,7 @@ static int trans_stmt_extra(Context *c, TransScope *scope, const Stmt *stmt, |
| 2562 | 2576 | trans_implicit_cast_expr(c, scope, (const ImplicitCastExpr *)stmt)); |
| 2563 | 2577 | case Stmt::DeclRefExprClass: |
| 2564 | 2578 | return wrap_stmt(out_node, out_child_scope, scope, |
| 2565 | | trans_decl_ref_expr(c, (const DeclRefExpr *)stmt, lrvalue)); |
| 2579 | trans_decl_ref_expr(c, scope, (const DeclRefExpr *)stmt, lrvalue)); |
| 2566 | 2580 | case Stmt::UnaryOperatorClass: |
| 2567 | 2581 | return wrap_stmt(out_node, out_child_scope, scope, |
| 2568 | 2582 | trans_unary_operator(c, result_used, scope, (const UnaryOperator *)stmt)); |