From 9068b2476496b7836f4adb26c4cca3a6029b391d Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Tue, 3 Oct 2023 13:32:52 +0330 Subject: [PATCH] cpp_import/clang: Resolve class bases' namespaces before resolving them --- selfhost/cpp_import/clang.jakt | 46 +++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/selfhost/cpp_import/clang.jakt b/selfhost/cpp_import/clang.jakt index 36a87cb27..0ed04ad76 100644 --- a/selfhost/cpp_import/clang.jakt +++ b/selfhost/cpp_import/clang.jakt @@ -203,6 +203,13 @@ fn function_names_from(cursor: CXCursor) throws -> (String, ExternalName?) { return (name, extern_name) } +enum ScopeSemanticParent { + name: String + + Namespace + Record +} + struct TemplateParameters { params: [CheckedGenericParameter] defaults: [TypeId?] @@ -1779,14 +1786,45 @@ class CppImportProcessor { mut super_struct_ids: [StructId] = [] for base in bases { - match program.get_type(.cached_type_of_cursor( + mut base_scope_id = parent_scope_id + visit( + base + fn[&mut base_scope_id, &mut program]( + anon cursor: CXCursor + anon parent: CXCursor + ) throws -> CXChildVisitResult { + match clang_getCursorKind(cursor) { + CXCursor_NamespaceRef => { + let name = name_from(cursor) + let scope = program.get_scope(base_scope_id) + let result = program.find_namespace_in_scope( + scope_id: base_scope_id + name + ) + if result.has_value() { + base_scope_id = result!.0 + } else { + // :shrug: + return CXChildVisitResult::CXChildVisit_Break + } + } + else => {} + } + return CXChildVisitResult::CXChildVisit_Continue + } + ) + + let type = program.get_type(.cached_type_of_cursor( cursor: base &mut program - scope_id: parent_scope_id + scope_id: base_scope_id module_id - )) { + )) + match type { GenericInstance(id) | Struct(id) => { super_struct_ids.push(id) } - else => {} + else => { + eprintln("[ICE] Base type of {} is not a struct or generic instance: {}", specialized_name, type) + } } }