| ... | ... | @@ -3754,49 +3754,59 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) { |
| 3754 | 3754 | analyze_fn_ir(g, fn_table_entry, return_type_node); |
| 3755 | 3755 | } |
| 3756 | 3756 | |
| 3757 | | static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *dst_use_node, ScopeDecls* decls_scope) { |
| 3757 | static void add_symbols_from_struct(CodeGen *g, AstNode *src_use_node, AstNode *dst_use_node, ScopeDecls* decls_scope) { |
| 3758 | 3758 | if (src_use_node->data.use.resolution == TldResolutionUnresolved) { |
| 3759 | 3759 | preview_use_decl(g, src_use_node, decls_scope); |
| 3760 | 3760 | } |
| 3761 | 3761 | |
| 3762 | | ConstExprValue *use_target_value = src_use_node->data.use.using_namespace_value; |
| 3763 | | if (type_is_invalid(use_target_value->type)) { |
| 3762 | ConstExprValue *use_expr = src_use_node->data.use.using_namespace_value; |
| 3763 | if (type_is_invalid(use_expr->type)) { |
| 3764 | 3764 | decls_scope->any_imports_failed = true; |
| 3765 | 3765 | return; |
| 3766 | 3766 | } |
| 3767 | 3767 | |
| 3768 | 3768 | dst_use_node->data.use.resolution = TldResolutionOk; |
| 3769 | 3769 | |
| 3770 | | assert(use_target_value->special != ConstValSpecialRuntime); |
| 3770 | assert(use_expr->special != ConstValSpecialRuntime); |
| 3771 | 3771 | |
| 3772 | | ZigType *target_import = use_target_value->data.x_type; |
| 3773 | | assert(target_import); |
| 3772 | // The source struct for the imported symbols |
| 3773 | ZigType *src_ty = use_expr->data.x_type; |
| 3774 | assert(src_ty); |
| 3774 | 3775 | |
| 3775 | | if (target_import->id != ZigTypeIdStruct) { |
| 3776 | if (src_ty->id != ZigTypeIdStruct) { |
| 3776 | 3777 | add_node_error(g, dst_use_node, |
| 3777 | | buf_sprintf("expected struct, found '%s'", buf_ptr(&target_import->name))); |
| 3778 | buf_sprintf("expected struct, found '%s'", buf_ptr(&src_ty->name))); |
| 3778 | 3779 | decls_scope->any_imports_failed = true; |
| 3779 | 3780 | return; |
| 3780 | 3781 | } |
| 3781 | 3782 | |
| 3782 | | if (get_container_scope(target_import)->any_imports_failed) { |
| 3783 | // The source scope for the imported symbols |
| 3784 | ScopeDecls *src_scope = get_container_scope(src_ty); |
| 3785 | // The top-level container where the symbols are defined, it's used in the |
| 3786 | // loop below in order to exclude the ones coming from an import statement |
| 3787 | ZigType *src_import = get_scope_import(reinterpret_cast<Scope*>(src_scope)); |
| 3788 | assert(src_import && src_import->id == ZigTypeIdStruct); |
| 3789 | |
| 3790 | if (src_scope->any_imports_failed) { |
| 3783 | 3791 | decls_scope->any_imports_failed = true; |
| 3784 | 3792 | } |
| 3785 | 3793 | |
| 3786 | | auto it = get_container_scope(target_import)->decl_table.entry_iterator(); |
| 3794 | auto it = src_scope->decl_table.entry_iterator(); |
| 3787 | 3795 | for (;;) { |
| 3788 | 3796 | auto *entry = it.next(); |
| 3789 | 3797 | if (!entry) |
| 3790 | 3798 | break; |
| 3791 | 3799 | |
| 3800 | Buf *target_tld_name = entry->key; |
| 3792 | 3801 | Tld *target_tld = entry->value; |
| 3793 | | if (target_tld->import != target_import || |
| 3794 | | target_tld->visib_mod == VisibModPrivate) |
| 3795 | | { |
| 3802 | |
| 3803 | if (target_tld->visib_mod == VisibModPrivate) { |
| 3796 | 3804 | continue; |
| 3797 | 3805 | } |
| 3798 | 3806 | |
| 3799 | | Buf *target_tld_name = entry->key; |
| 3807 | if (target_tld->import != src_import) { |
| 3808 | continue; |
| 3809 | } |
| 3800 | 3810 | |
| 3801 | 3811 | auto existing_entry = decls_scope->decl_table.put_unique(target_tld_name, target_tld); |
| 3802 | 3812 | if (existing_entry) { |
| ... | ... | @@ -3811,10 +3821,10 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode * |
| 3811 | 3821 | } |
| 3812 | 3822 | } |
| 3813 | 3823 | |
| 3814 | | for (size_t i = 0; i < get_container_scope(target_import)->use_decls.length; i += 1) { |
| 3815 | | AstNode *use_decl_node = get_container_scope(target_import)->use_decls.at(i); |
| 3824 | for (size_t i = 0; i < src_scope->use_decls.length; i += 1) { |
| 3825 | AstNode *use_decl_node = src_scope->use_decls.at(i); |
| 3816 | 3826 | if (use_decl_node->data.use.visib_mod != VisibModPrivate) |
| 3817 | | add_symbols_from_import(g, use_decl_node, dst_use_node, decls_scope); |
| 3827 | add_symbols_from_struct(g, use_decl_node, dst_use_node, decls_scope); |
| 3818 | 3828 | } |
| 3819 | 3829 | } |
| 3820 | 3830 | |
| ... | ... | @@ -3826,7 +3836,7 @@ void resolve_use_decl(CodeGen *g, AstNode *node, ScopeDecls *decls_scope) { |
| 3826 | 3836 | { |
| 3827 | 3837 | return; |
| 3828 | 3838 | } |
| 3829 | | add_symbols_from_import(g, node, node, decls_scope); |
| 3839 | add_symbols_from_struct(g, node, node, decls_scope); |
| 3830 | 3840 | } |
| 3831 | 3841 | |
| 3832 | 3842 | void preview_use_decl(CodeGen *g, AstNode *node, ScopeDecls *decls_scope) { |