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

Add a list of tokens that are always indexed #288

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
106 changes: 106 additions & 0 deletions lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,112 @@ def decode(byte_object):
b'x'
)

# list of tokens, that are indexed as references even if no definitions are known

always_indexed_tokens = [
b'_Alignas',
b'_Alignof',
b'_Atomic',
b'_BitInt',
b'_Bool',
b'_Complex',
b'_Imaginary',
b'_Float16',
b'_Float32',
b'_Float64',
b'_Float128',
b'_Float32x',
b'_Float64x',
b'_Float128x',
b'_Decimal32',
b'_Decimal64',
b'_Decimal128',
b'_Fract',
b'_Accum',
b'_Sat',
b'_Static_assert',
b'_Noreturn',
b'_Generic',
b'_Thread_local',
b'__FUNCTION__',
b'__PRETTY_FUNCTION__',
b'__alignof',
b'__alignof__',
b'__asm',
b'__asm__',
b'__attribute',
b'__attribute__',
b'__auto_type',
b'__builtin_addressof',
b'__builtin_assoc_barrier',
b'__builtin_bit_cast',
b'__builtin_call_with_static_chain',
b'__builtin_choose_expr',
b'__builtin_complex',
b'__builtin_convertvector',
b'__builtin_has_attribute',
b'__builtin_launder',
b'__builtin_shuffle',
b'__builtin_shufflevector',
b'__builtin_stdc_bit_ceil',
b'__builtin_stdc_bit_floor',
b'__builtin_stdc_bit_width',
b'__builtin_stdc_count_ones',
b'__builtin_stdc_count_zeros',
b'__builtin_stdc_first_leading_one',
b'__builtin_stdc_first_leading_zero',
b'__builtin_stdc_first_trailing_one',
b'__builtin_stdc_first_trailing_zero',
b'__builtin_stdc_has_single_bit',
b'__builtin_stdc_leading_ones',
b'__builtin_stdc_leading_zeros',
b'__builtin_stdc_trailing_ones',
b'__builtin_stdc_trailing_zeros',
b'__builtin_tgmath',
b'__builtin_offsetof',
b'__builtin_types_compatible_p',
b'__builtin_va_arg',
b'__complex',
b'__complex__',
b'__const',
b'__const__',
b'__constinit',
b'__decltype',
b'__extension__',
b'__func__',
b'__imag',
b'__imag__',
b'__inline',
b'__inline__',
b'__label__',
b'__null',
b'__real',
b'__real__',
b'__restrict',
b'__restrict__',
b'__signed',
b'__signed__',
b'__thread',
b'__transaction_atomic',
b'__transaction_relaxed',
b'__transaction_cancel',
b'__typeof',
b'__typeof__',
b'__typeof_unqual',
b'__typeof_unqual__',
b'__volatile',
b'__volatile__',
b'__GIMPLE',
b'__PHI',
b'__RTL',
b'alignas',
b'alignof',
b'asm',
b'auto',
b'thread_local',
b'sizeof',
]

def isIdent(bstr):
if (len(bstr) < 2 or
bstr in blacklist or
Expand Down
13 changes: 7 additions & 6 deletions update.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from threading import Thread, Lock, Event, Condition

import lib
from lib import script, scriptLines
from lib import script, scriptLines, always_indexed_tokens
Copy link
Member

Choose a reason for hiding this comment

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

Maybe use lib.always_indexed_tokens instead and avoid a manual import.

import data
from data import PathList
from find_compatible_dts import FindCompatibleDTS
Expand Down Expand Up @@ -315,11 +315,12 @@ def update_references(self, idxes):
if even:
tok = prefix + tok

if (db.defs.exists(tok) and
not ( (idx*idx_key_mod + line_num) in defs_idxes and
defs_idxes[idx*idx_key_mod + line_num] == tok ) and
(family != 'M' or tok.startswith(b'CONFIG_'))):
# We only index CONFIG_??? in makefiles
ref_allowed = db.defs.exists(tok) or (tok in always_indexed_tokens)
# We only index CONFIG_??? in makefiles
config_or_not_makefile = tok.startswith(b'CONFIG_') or family != 'M'
Copy link
Member

Choose a reason for hiding this comment

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

Any reason to reverse the conditional order from family != 'M' or tok.startswith(b'CONFIG') to tok.startswith(b'CONFIG') or family != 'M'?

Copy link
Collaborator Author

@fstachura fstachura Jun 18, 2024

Choose a reason for hiding this comment

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

IIRC I called the variable config_or_not_makefile and decided to reverse order to make it match the name. Assuming that expression will be evaluated left to right, old order is probably a bit better, I will fix that.

i = idx*idx_key_mod + line_num

if ref_allowed and defs_idxes.get(i) != tok and config_or_not_makefile:
if tok in idents:
idents[tok] += ',' + str(line_num)
else:
Expand Down