authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-12-13 04:59:01+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-12-13 05:05:36+01:00
logb6ece854c93e3ff6d6f20cd31133174b34b02fb0
tree0f179ed04c610d23a093418710188b17b048cb79
parenta68119f8f1d54b70e713e1e8ce07491ddba0f093
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

Compilation: Improve classification of various C/C++/Objective-C files.


1 files changed, 30 insertions(+), 3 deletions(-)

src/Compilation.zig+30-3
......@@ -5925,21 +5925,42 @@ pub fn hasCExt(filename: []const u8) bool {
59255925 return mem.endsWith(u8, filename, ".c");
59265926}
59275927
5928pub fn hasCHExt(filename: []const u8) bool {
5929 return mem.endsWith(u8, filename, ".h");
5930}
5931
59285932pub fn hasCppExt(filename: []const u8) bool {
59295933 return mem.endsWith(u8, filename, ".C") or
59305934 mem.endsWith(u8, filename, ".cc") or
5935 mem.endsWith(u8, filename, ".cp") or
5936 mem.endsWith(u8, filename, ".CPP") or
59315937 mem.endsWith(u8, filename, ".cpp") or
59325938 mem.endsWith(u8, filename, ".cxx") or
59335939 mem.endsWith(u8, filename, ".c++") or
59345940 mem.endsWith(u8, filename, ".stub");
59355941}
59365942
5943pub fn hasCppHExt(filename: []const u8) bool {
5944 return mem.endsWith(u8, filename, ".hh") or
5945 mem.endsWith(u8, filename, ".hpp") or
5946 mem.endsWith(u8, filename, ".hxx");
5947}
5948
59375949pub fn hasObjCExt(filename: []const u8) bool {
59385950 return mem.endsWith(u8, filename, ".m");
59395951}
59405952
5953pub fn hasObjCHExt(filename: []const u8) bool {
5954 return mem.endsWith(u8, filename, ".hm");
5955}
5956
59415957pub fn hasObjCppExt(filename: []const u8) bool {
5942 return mem.endsWith(u8, filename, ".mm");
5958 return mem.endsWith(u8, filename, ".M") or
5959 mem.endsWith(u8, filename, ".mm");
5960}
5961
5962pub fn hasObjCppHExt(filename: []const u8) bool {
5963 return mem.endsWith(u8, filename, ".hmm");
59435964}
59445965
59455966pub fn hasSharedLibraryExt(filename: []const u8) bool {
......@@ -5972,12 +5993,20 @@ pub fn hasSharedLibraryExt(filename: []const u8) bool {
59725993pub fn classifyFileExt(filename: []const u8) FileExt {
59735994 if (hasCExt(filename)) {
59745995 return .c;
5996 } else if (hasCHExt(filename)) {
5997 return .h;
59755998 } else if (hasCppExt(filename)) {
59765999 return .cpp;
6000 } else if (hasCppHExt(filename)) {
6001 return .hpp;
59776002 } else if (hasObjCExt(filename)) {
59786003 return .m;
6004 } else if (hasObjCHExt(filename)) {
6005 return .hm;
59796006 } else if (hasObjCppExt(filename)) {
59806007 return .mm;
6008 } else if (hasObjCppHExt(filename)) {
6009 return .hmm;
59816010 } else if (mem.endsWith(u8, filename, ".ll")) {
59826011 return .ll;
59836012 } else if (mem.endsWith(u8, filename, ".bc")) {
......@@ -5986,8 +6015,6 @@ pub fn classifyFileExt(filename: []const u8) FileExt {
59866015 return .assembly;
59876016 } else if (mem.endsWith(u8, filename, ".S")) {
59886017 return .assembly_with_cpp;
5989 } else if (mem.endsWith(u8, filename, ".h")) {
5990 return .h;
59916018 } else if (mem.endsWith(u8, filename, ".zig")) {
59926019 return .zig;
59936020 } else if (hasSharedLibraryExt(filename)) {