@@ -529,6 +529,7 @@ pub fn addSourceFromReader(
529
529
path : []const u8 ,
530
530
contents : []u8 ,
531
531
included_automatically : bool ,
532
+ system_header_file : bool ,
532
533
) ! Source {
533
534
const duped_path = try comp .gpa .dupe (u8 , path );
534
535
errdefer comp .gpa .free (duped_path );
@@ -618,6 +619,7 @@ pub fn addSourceFromReader(
618
619
.id = source_id ,
619
620
.path = duped_path ,
620
621
.included_automatically = included_automatically ,
622
+ .system_header_file = system_header_file ,
621
623
.buf = if (i == contents .len ) contents else try comp .gpa .realloc (contents , i ),
622
624
.splice_locs = splice_locs ,
623
625
};
@@ -637,11 +639,11 @@ pub fn addSourceFromBuffer(comp: *Compilation, path: []const u8, buf: []const u8
637
639
const contents = try comp .gpa .alloc (u8 , buf .len );
638
640
errdefer comp .gpa .free (contents );
639
641
640
- return comp .addSourceFromReader (reader , path , contents , true );
642
+ return comp .addSourceFromReader (reader , path , contents , true , false );
641
643
}
642
644
643
645
/// Caller retains ownership of `path`
644
- pub fn addSourceFromPath (comp : * Compilation , path : []const u8 ) ! Source {
646
+ pub fn addSourceFromPath (comp : * Compilation , path : []const u8 , system_header_file : bool ) ! Source {
645
647
if (comp .sources .get (path )) | some | return some ;
646
648
647
649
if (mem .indexOfScalar (u8 , path , 0 ) != null ) {
@@ -657,7 +659,7 @@ pub fn addSourceFromPath(comp: *Compilation, path: []const u8) !Source {
657
659
const contents = try comp .gpa .alloc (u8 , size );
658
660
errdefer comp .gpa .free (contents );
659
661
660
- return comp .addSourceFromReader (reader , path , contents , false );
662
+ return comp .addSourceFromReader (reader , path , contents , false , system_header_file );
661
663
}
662
664
663
665
pub fn findInclude (comp : * Compilation , tok : Token , filename : []const u8 , search_cwd : bool ) ! ? Source {
@@ -669,7 +671,7 @@ pub fn findInclude(comp: *Compilation, tok: Token, filename: []const u8, search_
669
671
std .fs .path .join (fib .allocator (), &.{ some , filename }) catch break :blk
670
672
else
671
673
std .fs .path .join (fib .allocator (), &.{ "." , filename }) catch break :blk ;
672
- if (comp .addSourceFromPath (path )) | some |
674
+ if (comp .addSourceFromPath (path , false )) | some |
673
675
return some
674
676
else | err | switch (err ) {
675
677
error .OutOfMemory = > return error .OutOfMemory ,
@@ -679,7 +681,7 @@ pub fn findInclude(comp: *Compilation, tok: Token, filename: []const u8, search_
679
681
for (comp .include_dirs .items ) | dir | {
680
682
fib .end_index = 0 ;
681
683
const path = std .fs .path .join (fib .allocator (), &.{ dir , filename }) catch continue ;
682
- if (comp .addSourceFromPath (path )) | some |
684
+ if (comp .addSourceFromPath (path , false )) | some |
683
685
return some
684
686
else | err | switch (err ) {
685
687
error .OutOfMemory = > return error .OutOfMemory ,
@@ -689,7 +691,7 @@ pub fn findInclude(comp: *Compilation, tok: Token, filename: []const u8, search_
689
691
for (comp .system_include_dirs .items ) | dir | {
690
692
fib .end_index = 0 ;
691
693
const path = std .fs .path .join (fib .allocator (), &.{ dir , filename }) catch continue ;
692
- if (comp .addSourceFromPath (path )) | some |
694
+ if (comp .addSourceFromPath (path , true )) | some |
693
695
return some
694
696
else | err | switch (err ) {
695
697
error .OutOfMemory = > return error .OutOfMemory ,
@@ -785,7 +787,7 @@ test "addSourceFromReader" {
785
787
const contents = try comp .gpa .alloc (u8 , 1024 );
786
788
787
789
var reader = std .io .fixedBufferStream (str ).reader ();
788
- const source = try comp .addSourceFromReader (reader , "path" , contents , false );
790
+ const source = try comp .addSourceFromReader (reader , "path" , contents , false , false );
789
791
790
792
try std .testing .expectEqualStrings (expected , source .buf );
791
793
try std .testing .expectEqual (warning_count , @intCast (u32 , comp .diag .list .items .len ));
0 commit comments