summaryrefslogtreecommitdiff
path: root/Tools/c-analyzer/cpython/find.py
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2020-10-22 18:42:51 -0600
committerGitHub <noreply@github.com>2020-10-22 18:42:51 -0600
commit345cd37abe324ad4f60f80e2c3133b8849e54e9b (patch)
tree5d965e662dca9dcac19e7eddd63a3d9d0b816fed /Tools/c-analyzer/cpython/find.py
parentec388cfb4ede56dace2bb78851ff6f38fa2a6abe (diff)
downloadcpython-git-345cd37abe324ad4f60f80e2c3133b8849e54e9b.tar.gz
bpo-36876: Fix the C analyzer tool. (GH-22841)
The original tool wasn't working right and it was simpler to create a new one, partially re-using some of the old code. At this point the tool runs properly on the master. (Try: ./python Tools/c-analyzer/c-analyzer.py analyze.) It take ~40 seconds on my machine to analyze the full CPython code base. Note that we'll need to iron out some OS-specific stuff (e.g. preprocessor). We're okay though since this tool isn't used yet in our workflow. We will also need to verify the analysis results in detail before activating the check in CI, though I'm pretty sure it's close. https://bugs.python.org/issue36876
Diffstat (limited to 'Tools/c-analyzer/cpython/find.py')
-rw-r--r--Tools/c-analyzer/cpython/find.py101
1 files changed, 0 insertions, 101 deletions
diff --git a/Tools/c-analyzer/cpython/find.py b/Tools/c-analyzer/cpython/find.py
deleted file mode 100644
index a7bc0b477b..0000000000
--- a/Tools/c-analyzer/cpython/find.py
+++ /dev/null
@@ -1,101 +0,0 @@
-import os.path
-
-from c_analyzer.common import files
-from c_analyzer.common.info import UNKNOWN, ID
-from c_analyzer.variables import find as _common
-
-from . import SOURCE_DIRS, PYTHON, REPO_ROOT
-from .known import (
- from_file as known_from_file,
- DATA_FILE as KNOWN_FILE,
- )
-from .supported import (
- ignored_from_file, IGNORED_FILE, is_supported, _is_object,
- )
-
-# XXX need tests:
-# * vars_from_binary()
-# * vars_from_source()
-# * supported_vars()
-
-
-def _handle_id(filename, funcname, name, *,
- _relpath=os.path.relpath,
- ):
- filename = _relpath(filename, REPO_ROOT)
- return ID(filename, funcname, name)
-
-
-def vars_from_binary(*,
- known=KNOWN_FILE,
- _known_from_file=known_from_file,
- _iter_files=files.iter_files_by_suffix,
- _iter_vars=_common.vars_from_binary,
- ):
- """Yield a Variable for each found Symbol.
-
- Details are filled in from the given "known" variables and types.
- """
- if isinstance(known, str):
- known = _known_from_file(known)
- dirnames = SOURCE_DIRS
- suffixes = ('.c',)
- filenames = _iter_files(dirnames, suffixes)
- # XXX For now we only use known variables (no source lookup).
- filenames = None
- yield from _iter_vars(PYTHON,
- known=known,
- filenames=filenames,
- handle_id=_handle_id,
- check_filename=(lambda n: True),
- )
-
-
-def vars_from_source(*,
- preprocessed=None,
- known=KNOWN_FILE,
- _known_from_file=known_from_file,
- _iter_files=files.iter_files_by_suffix,
- _iter_vars=_common.vars_from_source,
- ):
- """Yield a Variable for each declaration in the raw source code.
-
- Details are filled in from the given "known" variables and types.
- """
- if isinstance(known, str):
- known = _known_from_file(known)
- dirnames = SOURCE_DIRS
- suffixes = ('.c',)
- filenames = _iter_files(dirnames, suffixes)
- yield from _iter_vars(filenames,
- preprocessed=preprocessed,
- known=known,
- handle_id=_handle_id,
- )
-
-
-def supported_vars(*,
- known=KNOWN_FILE,
- ignored=IGNORED_FILE,
- skip_objects=False,
- _known_from_file=known_from_file,
- _ignored_from_file=ignored_from_file,
- _iter_vars=vars_from_binary,
- _is_supported=is_supported,
- ):
- """Yield (var, is supported) for each found variable."""
- if isinstance(known, str):
- known = _known_from_file(known)
- if isinstance(ignored, str):
- ignored = _ignored_from_file(ignored)
-
- for var in _iter_vars(known=known):
- if not var.isglobal:
- continue
- elif var.vartype == UNKNOWN:
- yield var, None
- # XXX Support proper filters instead.
- elif skip_objects and _is_object(found.vartype):
- continue
- else:
- yield var, _is_supported(var, ignored, known)