mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
bpo-36876: [c-analyzer tool] Tighten up the results and output. (GH-23431)
We also update the "ignored" file with a temporary list of all known globals.
This commit is contained in:
parent
a993e901eb
commit
9f02b479e6
13 changed files with 3203 additions and 110 deletions
|
|
@ -1,3 +1,6 @@
|
|||
import os.path
|
||||
|
||||
from c_common import fsutil
|
||||
import c_common.tables as _tables
|
||||
import c_parser.info as _info
|
||||
import c_parser.match as _match
|
||||
|
|
@ -13,6 +16,30 @@ EXTRA_COLUMNS = [
|
|||
]
|
||||
|
||||
|
||||
def get_known(known, extracolumns=None, *,
|
||||
analyze_resolved=None,
|
||||
handle_unresolved=True,
|
||||
relroot=fsutil.USE_CWD,
|
||||
):
|
||||
if isinstance(known, str):
|
||||
known = read_known(known, extracolumns, relroot)
|
||||
return analyze_known(
|
||||
known,
|
||||
handle_unresolved=handle_unresolved,
|
||||
analyze_resolved=analyze_resolved,
|
||||
)
|
||||
|
||||
|
||||
def read_known(infile, extracolumns=None, relroot=fsutil.USE_CWD):
|
||||
extracolumns = EXTRA_COLUMNS + (
|
||||
list(extracolumns) if extracolumns else []
|
||||
)
|
||||
known = {}
|
||||
for decl, extra in _parser.iter_decls_tsv(infile, extracolumns, relroot):
|
||||
known[decl] = extra
|
||||
return known
|
||||
|
||||
|
||||
def analyze_known(known, *,
|
||||
analyze_resolved=None,
|
||||
handle_unresolved=True,
|
||||
|
|
@ -34,32 +61,8 @@ def analyze_known(known, *,
|
|||
return types, typespecs
|
||||
|
||||
|
||||
def get_known(known, extracolumns=None, *,
|
||||
analyze_resolved=None,
|
||||
handle_unresolved=True,
|
||||
relroot=None,
|
||||
):
|
||||
if isinstance(known, str):
|
||||
known = read_known(known, extracolumns, relroot)
|
||||
return analyze_known(
|
||||
known,
|
||||
handle_unresolved=handle_unresolved,
|
||||
analyze_resolved=analyze_resolved,
|
||||
)
|
||||
|
||||
|
||||
def read_known(infile, extracolumns=None, relroot=None):
|
||||
extracolumns = EXTRA_COLUMNS + (
|
||||
list(extracolumns) if extracolumns else []
|
||||
)
|
||||
known = {}
|
||||
for decl, extra in _parser.iter_decls_tsv(infile, extracolumns, relroot):
|
||||
known[decl] = extra
|
||||
return known
|
||||
|
||||
|
||||
def write_known(rows, outfile, extracolumns=None, *,
|
||||
relroot=None,
|
||||
relroot=fsutil.USE_CWD,
|
||||
backup=True,
|
||||
):
|
||||
extracolumns = EXTRA_COLUMNS + (
|
||||
|
|
@ -86,22 +89,34 @@ IGNORED_COLUMNS = [
|
|||
IGNORED_HEADER = '\t'.join(IGNORED_COLUMNS)
|
||||
|
||||
|
||||
def read_ignored(infile):
|
||||
return dict(_iter_ignored(infile))
|
||||
def read_ignored(infile, relroot=fsutil.USE_CWD):
|
||||
return dict(_iter_ignored(infile, relroot))
|
||||
|
||||
|
||||
def _iter_ignored(infile):
|
||||
def _iter_ignored(infile, relroot):
|
||||
if relroot and relroot is not fsutil.USE_CWD:
|
||||
relroot = os.path.abspath(relroot)
|
||||
bogus = {_tables.EMPTY, _tables.UNKNOWN}
|
||||
for row in _tables.read_table(infile, IGNORED_HEADER, sep='\t'):
|
||||
*varidinfo, reason = row
|
||||
if _tables.EMPTY in varidinfo or _tables.UNKNOWN in varidinfo:
|
||||
varidinfo = tuple(None if v in bogus else v
|
||||
for v in varidinfo)
|
||||
if reason in bogus:
|
||||
reason = None
|
||||
varid = _info.DeclID.from_row(varidinfo)
|
||||
varid = varid.fix_filename(relroot, formatted=False, fixroot=False)
|
||||
yield varid, reason
|
||||
|
||||
|
||||
def write_ignored(variables, outfile):
|
||||
def write_ignored(variables, outfile, relroot=fsutil.USE_CWD):
|
||||
raise NotImplementedError
|
||||
if relroot and relroot is not fsutil.USE_CWD:
|
||||
relroot = os.path.abspath(relroot)
|
||||
reason = '???'
|
||||
#if not isinstance(varid, DeclID):
|
||||
# varid = getattr(varid, 'parsed', varid).id
|
||||
decls = (d.fix_filename(relroot, fixroot=False) for d in decls)
|
||||
_tables.write_table(
|
||||
outfile,
|
||||
IGNORED_HEADER,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue