Path: blob/main/Tools/c-analyzer/c_analyzer/datafiles.py
12 views
import os.path12from c_common import fsutil3import c_common.tables as _tables4import c_parser.info as _info5import c_parser.match as _match6import c_parser.datafiles as _parser7from . import analyze as _analyze8910#############################11# "known" decls1213EXTRA_COLUMNS = [14#'typedecl',15]161718def get_known(known, extracolumns=None, *,19analyze_resolved=None,20handle_unresolved=True,21relroot=fsutil.USE_CWD,22):23if isinstance(known, str):24known = read_known(known, extracolumns, relroot)25return analyze_known(26known,27handle_unresolved=handle_unresolved,28analyze_resolved=analyze_resolved,29)303132def read_known(infile, extracolumns=None, relroot=fsutil.USE_CWD):33extracolumns = EXTRA_COLUMNS + (34list(extracolumns) if extracolumns else []35)36known = {}37for decl, extra in _parser.iter_decls_tsv(infile, extracolumns, relroot):38known[decl] = extra39return known404142def analyze_known(known, *,43analyze_resolved=None,44handle_unresolved=True,45):46knowntypes = knowntypespecs = {}47collated = _match.group_by_kinds(known)48types = {decl: None for decl in collated['type']}49typespecs = _analyze.get_typespecs(types)50def analyze_decl(decl):51return _analyze.analyze_decl(52decl,53typespecs,54knowntypespecs,55types,56knowntypes,57analyze_resolved=analyze_resolved,58)59_analyze.analyze_type_decls(types, analyze_decl, handle_unresolved)60return types, typespecs616263def write_known(rows, outfile, extracolumns=None, *,64relroot=fsutil.USE_CWD,65backup=True,66):67extracolumns = EXTRA_COLUMNS + (68list(extracolumns) if extracolumns else []69)70_parser.write_decls_tsv(71rows,72outfile,73extracolumns,74relroot=relroot,75backup=backup,76)777879#############################80# ignored vars8182IGNORED_COLUMNS = [83'filename',84'funcname',85'name',86'reason',87]88IGNORED_HEADER = '\t'.join(IGNORED_COLUMNS)899091def read_ignored(infile, relroot=fsutil.USE_CWD):92return dict(_iter_ignored(infile, relroot))939495def _iter_ignored(infile, relroot):96if relroot and relroot is not fsutil.USE_CWD:97relroot = os.path.abspath(relroot)98bogus = {_tables.EMPTY, _tables.UNKNOWN}99for row in _tables.read_table(infile, IGNORED_HEADER, sep='\t'):100*varidinfo, reason = row101if _tables.EMPTY in varidinfo or _tables.UNKNOWN in varidinfo:102varidinfo = tuple(None if v in bogus else v103for v in varidinfo)104if reason in bogus:105reason = None106varid = _info.DeclID.from_row(varidinfo)107varid = varid.fix_filename(relroot, formatted=False, fixroot=False)108yield varid, reason109110111def write_ignored(variables, outfile, relroot=fsutil.USE_CWD):112raise NotImplementedError113if relroot and relroot is not fsutil.USE_CWD:114relroot = os.path.abspath(relroot)115reason = '???'116#if not isinstance(varid, DeclID):117# varid = getattr(varid, 'parsed', varid).id118decls = (d.fix_filename(relroot, fixroot=False) for d in decls)119_tables.write_table(120outfile,121IGNORED_HEADER,122sep='\t',123rows=(r.render_rowdata() + (reason,) for r in decls),124)125126127