github.com/atrn/dcc@v0.0.0-20220806184050-4470d2553272/classify.go (about) 1 // dcc - dependency-driven C/C++ compiler front end 2 // 3 // Copyright © A.Newman 2015. 4 // 5 // This source code is released under version 2 of the GNU Public License. 6 // See the file LICENSE for details. 7 // 8 9 package main 10 11 import ( 12 "path/filepath" 13 ) 14 15 var cppSet = MakeStringSet( 16 ".c++", 17 ".cc", 18 ".cpp", 19 ".cxx", 20 ".h++", 21 ".hh", 22 ".hpp", 23 ".hxx", 24 ) 25 26 var sourceFileSet = MakeStringSet( 27 ".c", 28 ".c++", 29 ".cc", 30 ".cpp", 31 ".cxx", 32 ".m", 33 ".mm", 34 ) 35 36 var headerFileSet = MakeStringSet( 37 ".h", 38 ".h++", 39 ".hh", 40 ".hpp", 41 ".hxx", 42 ) 43 44 // IsCPlusPlusFile returns true if the supplied pathname is that 45 // of a C++ source file. 46 // 47 func IsCPlusPlusFile(path string) bool { 48 return cppSet.Contains(LowercaseFilenameExtension(path)) 49 } 50 51 // IsSourceFile returns true if the supplied pathname is that 52 // of a C, C++ or Objective-C source file. 53 // 54 func IsSourceFile(path string) bool { 55 return sourceFileSet.Contains(LowercaseFilenameExtension(path)) 56 } 57 58 // IsHeaderFile returns true if the supplied pathname is that 59 // of a C/C++ header file. 60 // 61 func IsHeaderFile(path string) bool { 62 return headerFileSet.Contains(LowercaseFilenameExtension(path)) 63 } 64 65 // IsLibraryFile returns true if the supplied pathname is 66 // that of a library of some kind? 67 // 68 func IsLibraryFile(path string) bool { 69 ext := filepath.Ext(path) 70 if ext == platform.StaticLibSuffix { 71 return true 72 } 73 if ext == platform.DynamicLibSuffix { 74 return true 75 } 76 return false 77 } 78 79 // FileWillBeCompiled returns true if the supplied pathname is the 80 // name of a some source file that the compiler would compile. 81 // Header files are considered source files to accomodate pre- 82 // compiling header files. 83 // 84 func FileWillBeCompiled(path string) bool { 85 return IsSourceFile(path) || IsHeaderFile(path) 86 }