Path: blob/main/Tools/c-analyzer/c_parser/__init__.py
12 views
from c_common.fsutil import match_glob as _match_glob1from .parser import parse as _parse2from .preprocessor import get_preprocessor as _get_preprocessor345def parse_file(filename, *,6match_kind=None,7get_file_preprocessor=None,8file_maxsizes=None,9):10if get_file_preprocessor is None:11get_file_preprocessor = _get_preprocessor()12yield from _parse_file(13filename, match_kind, get_file_preprocessor, file_maxsizes)141516def parse_files(filenames, *,17match_kind=None,18get_file_preprocessor=None,19file_maxsizes=None,20):21if get_file_preprocessor is None:22get_file_preprocessor = _get_preprocessor()23for filename in filenames:24try:25yield from _parse_file(26filename, match_kind, get_file_preprocessor, file_maxsizes)27except Exception:28print(f'# requested file: <{filename}>')29raise # re-raise303132def _parse_file(filename, match_kind, get_file_preprocessor, maxsizes):33srckwargs = {}34maxsize = _resolve_max_size(filename, maxsizes)35if maxsize:36srckwargs['maxtext'], srckwargs['maxlines'] = maxsize3738# Preprocess the file.39preprocess = get_file_preprocessor(filename)40preprocessed = preprocess()41if preprocessed is None:42return4344# Parse the lines.45srclines = ((l.file, l.data) for l in preprocessed if l.kind == 'source')46for item in _parse(srclines, **srckwargs):47if match_kind is not None and not match_kind(item.kind):48continue49if not item.filename:50raise NotImplementedError(repr(item))51yield item525354def _resolve_max_size(filename, maxsizes):55for pattern, maxsize in (maxsizes.items() if maxsizes else ()):56if _match_glob(filename, pattern):57break58else:59return None60if not maxsize:61return None, None62maxtext, maxlines = maxsize63if maxtext is not None:64maxtext = int(maxtext)65if maxlines is not None:66maxlines = int(maxlines)67return maxtext, maxlines686970def parse_signature(text):71raise NotImplementedError727374# aliases75from .info import resolve_parsed767778