Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi languages support other than C/C++ #254

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions data.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,22 @@
##################################################################################

defTypeR = {
'C': 'class',
'c': 'config',
'd': 'define',
'e': 'enum',
'E': 'enumerator',
'f': 'function',
'g': 'field',
'h': 'func',
'l': 'label',
'M': 'macro',
'm': 'member',
'N': 'module',
'n': 'method',
'P': 'package',
'p': 'prototype',
'S': 'subroutine',
's': 'struct',
't': 'typedef',
'u': 'union',
Expand Down
5 changes: 4 additions & 1 deletion lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def currentProject():
return os.path.basename(os.path.dirname(getDataDir()))

# List all families supported by Elixir
families = ['A', 'B', 'C', 'D', 'K', 'M']
families = ['A', 'B', 'C', 'D', 'E', 'K', 'M']

def validFamily(family):
return family in families
Expand All @@ -206,6 +206,8 @@ def getFileFamily(filename):

if ext.lower() in ['.c', '.cc', '.cpp', '.c++', '.cxx', '.h', '.s'] :
return 'C' # C file family and ASM
elif ext.lower() in ['.go', '.java', '.php', '.pl', '.py', '.rb', '.rs', '.sh'] :
return 'E' # Other than C family
elif ext.lower() in ['.dts', '.dtsi'] :
return 'D' # Devicetree files
elif name.lower()[:7] in ['kconfig'] and not ext.lower() in ['.rst']:
Expand All @@ -221,6 +223,7 @@ def getFileFamily(filename):
# 2 chars values with a M are macros families
compatibility_list = {
'C' : ['C', 'K'],
'E' : ['E'],
'K' : ['K'],
'D' : ['D', 'CM'],
'M' : ['K']
Expand Down
9 changes: 8 additions & 1 deletion query.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def get_idents_comps(version, ident):
# Used in DT files
# Documented in documentation files
symbol_c = []
symbol_others = []
symbol_dts = []
symbol_docs = []

Expand All @@ -261,6 +262,7 @@ def get_idents_comps(version, ident):
comps_idx, comps_lines, comps_family = next(comps)
comps_docs_idx, comps_docs_lines, comps_docs_family = next(comps_docs)
compsCBuf = [] # C/CPP/ASM files
compsEBuf = [] # Other than C files
compsDBuf = [] # DT files
compsBBuf = [] # DT bindings docs files

Expand All @@ -274,6 +276,8 @@ def get_idents_comps(version, ident):
if comps_idx == file_idx:
if comps_family == 'C':
compsCBuf.append((file_path, comps_lines))
elif comps_family == 'E':
compsEBuf.append((file_path, comps_lines))
elif comps_family == 'D':
compsDBuf.append((file_path, comps_lines))

Expand All @@ -283,13 +287,16 @@ def get_idents_comps(version, ident):
for path, cline in sorted(compsCBuf):
symbol_c.append(SymbolInstance(path, cline, 'compatible'))

for path, eline in sorted(compsEBuf):
symbol_others.append(SymbolInstance(path, eline))

for path, dlines in sorted(compsDBuf):
symbol_dts.append(SymbolInstance(path, dlines))

for path, blines in sorted(compsBBuf):
symbol_docs.append(SymbolInstance(path, blines))

return symbol_c, symbol_dts, symbol_docs
return symbol_c, symbol_others, symbol_dts, symbol_docs

def get_idents_defs(version, ident, family):

Expand Down
22 changes: 22 additions & 0 deletions script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ parse_defs()
"C")
parse_defs_C
;;
"E")
parse_defs_E
;;
"K")
parse_defs_K
;;
Expand Down Expand Up @@ -177,6 +180,25 @@ parse_defs_C()
rmdir $tmp
}

parse_defs_E()
{
tmp=`mktemp -d`
full_path=$tmp/$opt2
git cat-file blob "$opt1" > "$full_path"

# Use ctags to parse most of the defs
ctags -x --extras='-{anonymous}' "$full_path" |
grep -avE "^operator |CONFIG_" |
awk '{print $1" "$2" "$3}'

# Parse function macros, e.g., in .S files
perl -ne '/^\s*ENTRY\((\w+)\)/ and print "$1 function $.\n"' "$full_path"
perl -ne '/^SYSCALL_DEFINE[0-9]\(\s*(\w+)\W/ and print "sys_$1 function $.\n"' "$full_path"

rm "$full_path"
rmdir $tmp
}

parse_defs_K()
{
tmp=`mktemp -d`
Expand Down
1 change: 1 addition & 0 deletions templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<select name="f" title="Restricts search to specific file families">
<option value="A" {% if family=="A" %} selected="selected"{% endif %}>All symbols</option>
<option value="C" {% if family=="C" %} selected="selected"{% endif %}>C/CPP/ASM</option>
<option value="E" {% if family=="E" %} selected="selected"{% endif %}>non C/CPP/ASM</option>
Copy link

@tgross35 tgross35 Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth giving a separate option for all types that are found?

I think it would be useful to have a separate option at least for rust, since blended C+Rust projects are popping up more (including kernel). Maybe for perl and python too, but those are usually standalone scripts (vs. rust being more interconnected like c)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the comments!
Yes, I agree with the suggestions to provide a separate group for each types. The current bootlin/elixir provides searching "All symbols", so after the separations for each types, users can still choose to search within the specific file types or within the whole in the package.

<option value="K" {% if family=="K" %} selected="selected"{% endif %}>Kconfig</option>
<option value="D" {% if family=="D" %} selected="selected"{% endif %}>Devicetree</option>
<option value="B" {% if family=="B" %} selected="selected"{% endif %}>DT compatible</option>
Expand Down