diff options
| author | Alex Rønne Petersen <alex@alexrp.com> | 2024-12-13 04:59:01 +0100 |
|---|---|---|
| committer | Alex Rønne Petersen <alex@alexrp.com> | 2024-12-13 05:05:36 +0100 |
| commit | b6ece854c93e3ff6d6f20cd31133174b34b02fb0 (patch) | |
| tree | 0f179ed04c610d23a093418710188b17b048cb79 /src | |
| parent | a68119f8f1d54b70e713e1e8ce07491ddba0f093 (diff) | |
| download | zig-b6ece854c93e3ff6d6f20cd31133174b34b02fb0.tar.gz zig-b6ece854c93e3ff6d6f20cd31133174b34b02fb0.zip | |
Compilation: Improve classification of various C/C++/Objective-C files.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Compilation.zig | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 947012e716..6f0952b9bf 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -5925,21 +5925,42 @@ pub fn hasCExt(filename: []const u8) bool { return mem.endsWith(u8, filename, ".c"); } +pub fn hasCHExt(filename: []const u8) bool { + return mem.endsWith(u8, filename, ".h"); +} + pub fn hasCppExt(filename: []const u8) bool { return mem.endsWith(u8, filename, ".C") or mem.endsWith(u8, filename, ".cc") or + mem.endsWith(u8, filename, ".cp") or + mem.endsWith(u8, filename, ".CPP") or mem.endsWith(u8, filename, ".cpp") or mem.endsWith(u8, filename, ".cxx") or mem.endsWith(u8, filename, ".c++") or mem.endsWith(u8, filename, ".stub"); } +pub fn hasCppHExt(filename: []const u8) bool { + return mem.endsWith(u8, filename, ".hh") or + mem.endsWith(u8, filename, ".hpp") or + mem.endsWith(u8, filename, ".hxx"); +} + pub fn hasObjCExt(filename: []const u8) bool { return mem.endsWith(u8, filename, ".m"); } +pub fn hasObjCHExt(filename: []const u8) bool { + return mem.endsWith(u8, filename, ".hm"); +} + pub fn hasObjCppExt(filename: []const u8) bool { - return mem.endsWith(u8, filename, ".mm"); + return mem.endsWith(u8, filename, ".M") or + mem.endsWith(u8, filename, ".mm"); +} + +pub fn hasObjCppHExt(filename: []const u8) bool { + return mem.endsWith(u8, filename, ".hmm"); } pub fn hasSharedLibraryExt(filename: []const u8) bool { @@ -5972,12 +5993,20 @@ pub fn hasSharedLibraryExt(filename: []const u8) bool { pub fn classifyFileExt(filename: []const u8) FileExt { if (hasCExt(filename)) { return .c; + } else if (hasCHExt(filename)) { + return .h; } else if (hasCppExt(filename)) { return .cpp; + } else if (hasCppHExt(filename)) { + return .hpp; } else if (hasObjCExt(filename)) { return .m; + } else if (hasObjCHExt(filename)) { + return .hm; } else if (hasObjCppExt(filename)) { return .mm; + } else if (hasObjCppHExt(filename)) { + return .hmm; } else if (mem.endsWith(u8, filename, ".ll")) { return .ll; } else if (mem.endsWith(u8, filename, ".bc")) { @@ -5986,8 +6015,6 @@ pub fn classifyFileExt(filename: []const u8) FileExt { return .assembly; } else if (mem.endsWith(u8, filename, ".S")) { return .assembly_with_cpp; - } else if (mem.endsWith(u8, filename, ".h")) { - return .h; } else if (mem.endsWith(u8, filename, ".zig")) { return .zig; } else if (hasSharedLibraryExt(filename)) { |
