Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion compiledb/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def __init__(self, name="gcc"):
"c++": {
"extensions": ["cpp", "cc", "cx", "cxx"],
},
"fortran": {
"extensions": [".f", ".for", ".ftn", ".f77", ".f90", ".f95", ".f03", ".f08", ".f15"],
},
}

# Keep a list of macros for each language since, for example, gcc can be used both for C and C++ sources.
Expand Down Expand Up @@ -52,15 +55,21 @@ def _get_language(self, arguments, source_file):
return arguments[arg_idx + 1]

if "-std=" in arg:
if "++" in arg:
std_value = arg.split("=", 1)[1].lower() # get what's after "-std="
if "++" in std_value:
return "c++"
elif std_value.startswith("f"): # e.g. f95, f2003, f2018
# doesn't catch some Fortran cases (e.g. gnu)
return "fortran"
else:
return default

_, extension = os.path.splitext(source_file)

if extension in self._languages["c++"]["extensions"]:
return "c++"
elif extension.lower() in self._languages["fortran"]["extensions"]:
return "fortran"
else:
return default

Expand Down
7 changes: 5 additions & 2 deletions compiledb/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
# Internal variables used to parse build log entries
cc_compile_regex = re.compile(r"^.*-?g?cc-?[0-9.]*$|^.*-?clang-?[0-9.]*$")
cpp_compile_regex = re.compile(r"^.*-?[gc]\+\+-?[0-9.]*$|^.*-?clang\+\+-?[0-9.]*$")
fortran_compile_regex = re.compile(r"^.*-?(gfortran|flang|ifort|nvfortran)-?[0-9.]*$")
file_regex = re.compile(r"^.+\.c$|^.+\.cc$|^.+\.cpp$|^.+\.cxx$|^.+\.s$", re.IGNORECASE)
fortran_file_regex = re.compile(r"^.+\.(f|for|ftn|f77|f90|f95|f03|f08|f15)$", re.IGNORECASE)
compiler_wrappers = {"ccache", "icecc", "sccache"}

# Leverage `make --print-directory` option
Expand Down Expand Up @@ -235,12 +237,13 @@ def visitword(self, node, word):
# Check if it looks like an entry of interest and
# and try to determine the compiler
if self.compiler is None:
if ((cc_compile_regex.match(word) or cpp_compile_regex.match(word)) and
if ((cc_compile_regex.match(word) or cpp_compile_regex.match(word)
or fortran_compile_regex.match(word)) and
word not in compiler_wrappers):
self.compiler = word
else:
self.wrappers.append(word)
elif (file_regex.match(word)):
elif (file_regex.match(word) or fortran_file_regex.match(word)):
self.filepath = word

self.tokens.append(word)
Expand Down