mirror of
https://github.com/python/cpython.git
synced 2025-11-25 12:44:13 +00:00
bpo-36876: Small adjustments to the C-analyzer tool. (GH-23045)
This is a little bit of clean-up, small fixes, and additional helpers prior to building an updated & accurate list of globals to eliminate.
This commit is contained in:
parent
b9ee4af4c6
commit
4fe72090de
16 changed files with 632 additions and 217 deletions
|
|
@ -163,6 +163,8 @@ def _parse(srclines, anon_name):
|
|||
|
||||
|
||||
def _iter_source(lines, *, maxtext=20_000, maxlines=700, showtext=False):
|
||||
maxtext = maxtext if maxtext and maxtext > 0 else None
|
||||
maxlines = maxlines if maxlines and maxlines > 0 else None
|
||||
filestack = []
|
||||
allinfo = {}
|
||||
# "lines" should be (fileinfo, data), as produced by the preprocessor code.
|
||||
|
|
@ -181,9 +183,7 @@ def _iter_source(lines, *, maxtext=20_000, maxlines=700, showtext=False):
|
|||
|
||||
_logger.debug(f'-> {line}')
|
||||
srcinfo._add_line(line, fileinfo.lno)
|
||||
if len(srcinfo.text) > maxtext:
|
||||
break
|
||||
if srcinfo.end - srcinfo.start > maxlines:
|
||||
if srcinfo.too_much(maxtext, maxlines):
|
||||
break
|
||||
while srcinfo._used():
|
||||
yield srcinfo
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import re
|
||||
|
||||
from ..info import KIND, ParsedItem, FileInfo
|
||||
|
||||
|
||||
|
|
@ -121,6 +123,19 @@ class SourceInfo:
|
|||
def done(self):
|
||||
self._set_ready()
|
||||
|
||||
def too_much(self, maxtext, maxlines):
|
||||
if maxtext and len(self.text) > maxtext:
|
||||
pass
|
||||
elif maxlines and self.end - self.start > maxlines:
|
||||
pass
|
||||
else:
|
||||
return False
|
||||
|
||||
#if re.fullmatch(r'[^;]+\[\][ ]*=[ ]*[{]([ ]*\d+,)*([ ]*\d+,?)\s*',
|
||||
# self._current.text):
|
||||
# return False
|
||||
return True
|
||||
|
||||
def _set_ready(self):
|
||||
if self._current is None:
|
||||
self._ready = False
|
||||
|
|
|
|||
|
|
@ -137,7 +137,8 @@ COMPOUND_TYPE_KIND = r'(?: \b (?: struct | union | enum ) \b )'
|
|||
#######################################
|
||||
# variable declarations
|
||||
|
||||
STORAGE_CLASS = r'(?: \b (?: auto | register | static | extern ) \b )'
|
||||
_STORAGE = 'auto register static extern'.split()
|
||||
STORAGE_CLASS = rf'(?: \b (?: {" | ".join(_STORAGE)} ) \b )'
|
||||
TYPE_QUALIFIER = r'(?: \b (?: const | volatile ) \b )'
|
||||
PTR_QUALIFIER = rf'(?: [*] (?: \s* {TYPE_QUALIFIER} )? )'
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue