mirror of
https://github.com/python/cpython.git
synced 2025-07-23 19:25:40 +00:00

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
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
from .parser import parse as _parse
|
|
from .preprocessor import get_preprocessor as _get_preprocessor
|
|
|
|
|
|
def parse_file(filename, *,
|
|
match_kind=None,
|
|
get_file_preprocessor=None,
|
|
):
|
|
if get_file_preprocessor is None:
|
|
get_file_preprocessor = _get_preprocessor()
|
|
yield from _parse_file(filename, match_kind, get_file_preprocessor)
|
|
|
|
|
|
def parse_files(filenames, *,
|
|
match_kind=None,
|
|
get_file_preprocessor=None,
|
|
):
|
|
if get_file_preprocessor is None:
|
|
get_file_preprocessor = _get_preprocessor()
|
|
for filename in filenames:
|
|
yield from _parse_file(filename, match_kind, get_file_preprocessor)
|
|
|
|
|
|
def _parse_file(filename, match_kind, get_file_preprocessor):
|
|
# Preprocess the file.
|
|
preprocess = get_file_preprocessor(filename)
|
|
preprocessed = preprocess()
|
|
if preprocessed is None:
|
|
return
|
|
|
|
# Parse the lines.
|
|
srclines = ((l.file, l.data) for l in preprocessed if l.kind == 'source')
|
|
for item in _parse(srclines):
|
|
if match_kind is not None and not match_kind(item.kind):
|
|
continue
|
|
if not item.filename:
|
|
raise NotImplementedError(repr(item))
|
|
yield item
|
|
|
|
|
|
def parse_signature(text):
|
|
raise NotImplementedError
|
|
|
|
|
|
# aliases
|
|
from .info import resolve_parsed
|