| ... | ... | @@ -2400,25 +2400,40 @@ pub fn analyzeSlice(self: *Module, scope: *Scope, src: usize, array_ptr: *Inst, |
| 2400 | 2400 | } |
| 2401 | 2401 | |
| 2402 | 2402 | pub fn analyzeImport(self: *Module, scope: *Scope, src: usize, target_string: []const u8) !*Scope.File { |
| 2403 | | // TODO if (package_table.get(target_string)) |pkg| |
| 2404 | | if (self.import_table.get(target_string)) |some| { |
| 2403 | // TODO scope.getCurPkg(); |
| 2404 | const cur_pkg = self.root_pkg; |
| 2405 | const cur_pkg_dir_path = cur_pkg.root_src_directory.path orelse "."; |
| 2406 | const found_pkg = cur_pkg.table.get(target_string); |
| 2407 | |
| 2408 | const resolved_path = if (found_pkg) |pkg| |
| 2409 | try std.fs.path.resolve(self.gpa, &[_][]const u8{ pkg.root_src_directory.path orelse ".", pkg.root_src_path }) |
| 2410 | else |
| 2411 | try std.fs.path.resolve(self.gpa, &[_][]const u8{ cur_pkg_dir_path, target_string }); |
| 2412 | errdefer self.gpa.free(resolved_path); |
| 2413 | |
| 2414 | if (self.import_table.get(resolved_path)) |some| { |
| 2415 | self.gpa.free(resolved_path); |
| 2405 | 2416 | return some; |
| 2406 | 2417 | } |
| 2407 | 2418 | |
| 2408 | | // TODO check for imports outside of pkg path |
| 2409 | | if (false) return error.ImportOutsidePkgPath; |
| 2419 | if (found_pkg == null) { |
| 2420 | const resolved_root_path = try std.fs.path.resolve(self.gpa, &[_][]const u8{cur_pkg_dir_path}); |
| 2421 | defer self.gpa.free(resolved_root_path); |
| 2422 | |
| 2423 | if (!mem.startsWith(u8, resolved_path, resolved_root_path)) { |
| 2424 | return error.ImportOutsidePkgPath; |
| 2425 | } |
| 2426 | } |
| 2410 | 2427 | |
| 2411 | 2428 | // TODO Scope.Container arena for ty and sub_file_path |
| 2412 | 2429 | const struct_payload = try self.gpa.create(Type.Payload.EmptyStruct); |
| 2413 | 2430 | errdefer self.gpa.destroy(struct_payload); |
| 2414 | 2431 | const file_scope = try self.gpa.create(Scope.File); |
| 2415 | 2432 | errdefer self.gpa.destroy(file_scope); |
| 2416 | | const file_path = try self.gpa.dupe(u8, target_string); |
| 2417 | | errdefer self.gpa.free(file_path); |
| 2418 | 2433 | |
| 2419 | 2434 | struct_payload.* = .{ .scope = &file_scope.root_container }; |
| 2420 | 2435 | file_scope.* = .{ |
| 2421 | | .sub_file_path = file_path, |
| 2436 | .sub_file_path = resolved_path, |
| 2422 | 2437 | .source = .{ .unloaded = {} }, |
| 2423 | 2438 | .contents = .{ .not_available = {} }, |
| 2424 | 2439 | .status = .never_loaded, |