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 {...@@ -5925,21 +5925,42 @@ pub fn hasCExt(filename: []const u8) bool {
5925 return mem.endsWith(u8, filename, ".c");5925 return mem.endsWith(u8, filename, ".c");
5926}5926}
59275927
5928pub fn hasCHExt(filename: []const u8) bool {
5929 return mem.endsWith(u8, filename, ".h");
5930}
5931
5928pub fn hasCppExt(filename: []const u8) bool {5932pub fn hasCppExt(filename: []const u8) bool {
5929 return mem.endsWith(u8, filename, ".C") or5933 return mem.endsWith(u8, filename, ".C") or
5930 mem.endsWith(u8, filename, ".cc") or5934 mem.endsWith(u8, filename, ".cc") or
5935 mem.endsWith(u8, filename, ".cp") or
5936 mem.endsWith(u8, filename, ".CPP") or
5931 mem.endsWith(u8, filename, ".cpp") or5937 mem.endsWith(u8, filename, ".cpp") or
5932 mem.endsWith(u8, filename, ".cxx") or5938 mem.endsWith(u8, filename, ".cxx") or
5933 mem.endsWith(u8, filename, ".c++") or5939 mem.endsWith(u8, filename, ".c++") or
5934 mem.endsWith(u8, filename, ".stub");5940 mem.endsWith(u8, filename, ".stub");
5935}5941}
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
5937pub fn hasObjCExt(filename: []const u8) bool {5949pub fn hasObjCExt(filename: []const u8) bool {
5938 return mem.endsWith(u8, filename, ".m");5950 return mem.endsWith(u8, filename, ".m");
5939}5951}
59405952
5953pub fn hasObjCHExt(filename: []const u8) bool {
5954 return mem.endsWith(u8, filename, ".hm");
5955}
5956
5941pub fn hasObjCppExt(filename: []const u8) bool {5957pub 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");
5943}5964}
59445965
5945pub fn hasSharedLibraryExt(filename: []const u8) bool {5966pub fn hasSharedLibraryExt(filename: []const u8) bool {
...@@ -5972,12 +5993,20 @@ pub fn hasSharedLibraryExt(filename: []const u8) bool {...@@ -5972,12 +5993,20 @@ pub fn hasSharedLibraryExt(filename: []const u8) bool {
5972pub fn classifyFileExt(filename: []const u8) FileExt {5993pub fn classifyFileExt(filename: []const u8) FileExt {
5973 if (hasCExt(filename)) {5994 if (hasCExt(filename)) {
5974 return .c;5995 return .c;
5996 } else if (hasCHExt(filename)) {
5997 return .h;
5975 } else if (hasCppExt(filename)) {5998 } else if (hasCppExt(filename)) {
5976 return .cpp;5999 return .cpp;
6000 } else if (hasCppHExt(filename)) {
6001 return .hpp;
5977 } else if (hasObjCExt(filename)) {6002 } else if (hasObjCExt(filename)) {
5978 return .m;6003 return .m;
6004 } else if (hasObjCHExt(filename)) {
6005 return .hm;
5979 } else if (hasObjCppExt(filename)) {6006 } else if (hasObjCppExt(filename)) {
5980 return .mm;6007 return .mm;
6008 } else if (hasObjCppHExt(filename)) {
6009 return .hmm;
5981 } else if (mem.endsWith(u8, filename, ".ll")) {6010 } else if (mem.endsWith(u8, filename, ".ll")) {
5982 return .ll;6011 return .ll;
5983 } else if (mem.endsWith(u8, filename, ".bc")) {6012 } else if (mem.endsWith(u8, filename, ".bc")) {
...@@ -5986,8 +6015,6 @@ pub fn classifyFileExt(filename: []const u8) FileExt {...@@ -5986,8 +6015,6 @@ pub fn classifyFileExt(filename: []const u8) FileExt {
5986 return .assembly;6015 return .assembly;
5987 } else if (mem.endsWith(u8, filename, ".S")) {6016 } else if (mem.endsWith(u8, filename, ".S")) {
5988 return .assembly_with_cpp;6017 return .assembly_with_cpp;
5989 } else if (mem.endsWith(u8, filename, ".h")) {
5990 return .h;
5991 } else if (mem.endsWith(u8, filename, ".zig")) {6018 } else if (mem.endsWith(u8, filename, ".zig")) {
5992 return .zig;6019 return .zig;
5993 } else if (hasSharedLibraryExt(filename)) {6020 } else if (hasSharedLibraryExt(filename)) {