@@ -31,6 +31,7 @@ const clangMain = @import("main.zig").clangMain;
3131const Module = @import ("Module.zig" );
3232const Cache = @import ("Cache.zig" );
3333const translate_c = @import ("translate_c.zig" );
34+ const clang = @import ("clang.zig" );
3435const c_codegen = @import ("codegen/c.zig" );
3536const ThreadPool = @import ("ThreadPool.zig" );
3637const WaitGroup = @import ("WaitGroup.zig" );
@@ -2749,6 +2750,9 @@ pub fn totalErrorCount(self: *Compilation) usize {
27492750 const decl = module .declPtr (key );
27502751 if (decl .getFileScope ().okToReportErrors ()) {
27512752 total += 1 ;
2753+ if (module .cimport_errors .get (key )) | errors | {
2754+ total += errors .len ;
2755+ }
27522756 }
27532757 }
27542758 if (module .emit_h ) | emit_h | {
@@ -2858,6 +2862,23 @@ pub fn getAllErrorsAlloc(self: *Compilation) !AllErrors {
28582862 // We'll try again once parsing succeeds.
28592863 if (decl .getFileScope ().okToReportErrors ()) {
28602864 try AllErrors .add (module , & arena , & errors , entry .value_ptr .*.* );
2865+ if (module .cimport_errors .get (entry .key_ptr .* )) | cimport_errors | for (cimport_errors ) | c_error | {
2866+ if (c_error .path ) | some |
2867+ try errors .append (.{
2868+ .src = .{
2869+ .src_path = try arena_allocator .dupe (u8 , std .mem .span (some )),
2870+ .span = .{ .start = c_error .offset , .end = c_error .offset + 1 , .main = c_error .offset },
2871+ .msg = try arena_allocator .dupe (u8 , std .mem .span (c_error .msg )),
2872+ .line = c_error .line ,
2873+ .column = c_error .column ,
2874+ .source_line = if (c_error .source_line ) | line | try arena_allocator .dupe (u8 , std .mem .span (line )) else null ,
2875+ },
2876+ })
2877+ else
2878+ try errors .append (.{
2879+ .plain = .{ .msg = try arena_allocator .dupe (u8 , std .mem .span (c_error .msg )) },
2880+ });
2881+ };
28612882 }
28622883 }
28632884 }
@@ -3524,7 +3545,7 @@ test "cImport" {
35243545
35253546const CImportResult = struct {
35263547 out_zig_path : []u8 ,
3527- errors : []translate_c.ClangErrMsg ,
3548+ errors : []clang.ErrorMsg ,
35283549};
35293550
35303551/// Caller owns returned memory.
@@ -3599,7 +3620,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
35993620
36003621 const c_headers_dir_path = try comp .zig_lib_directory .join (arena , &[_ ][]const u8 {"include" });
36013622 const c_headers_dir_path_z = try arena .dupeZ (u8 , c_headers_dir_path );
3602- var clang_errors : []translate_c.ClangErrMsg = &[0 ]translate_c.ClangErrMsg {};
3623+ var clang_errors : []clang.ErrorMsg = &[0 ]clang.ErrorMsg {};
36033624 var tree = translate_c .translate (
36043625 comp .gpa ,
36053626 new_argv .ptr ,
@@ -3665,7 +3686,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
36653686 }
36663687 return CImportResult {
36673688 .out_zig_path = out_zig_path ,
3668- .errors = &[0 ]translate_c.ClangErrMsg {},
3689+ .errors = &[0 ]clang.ErrorMsg {},
36693690 };
36703691}
36713692
0 commit comments