From 7a1a85d64088a9eaefaf30d6aa50711cb4ed8245 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Mon, 18 Jul 2022 19:03:57 -0600 Subject: gh-94673: [c-analyzer] Add a Script to Identify Static Types (#94989) issue: https://github.com/python/cpython/issues/94673 --- Objects/exceptions.c | 14 +- Tools/c-analyzer/c_common/tables.py | 285 ++++++++++++---------- Tools/c-analyzer/cpython/__main__.py | 48 +++- Tools/c-analyzer/cpython/_builtin_types.py | 365 ++++++++++++++++++++++++++++ Tools/c-analyzer/cpython/globals-to-fix.tsv | 54 ++-- 5 files changed, 614 insertions(+), 152 deletions(-) create mode 100644 Tools/c-analyzer/cpython/_builtin_types.py diff --git a/Objects/exceptions.c b/Objects/exceptions.c index e212e02..9aab683 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -600,17 +600,9 @@ StopIteration_traverse(PyStopIterationObject *self, visitproc visit, void *arg) return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg); } -ComplexExtendsException( - PyExc_Exception, /* base */ - StopIteration, /* name */ - StopIteration, /* prefix for *_init, etc */ - 0, /* new */ - 0, /* methods */ - StopIteration_members, /* members */ - 0, /* getset */ - 0, /* str */ - "Signal the end from iterator.__next__()." -); +ComplexExtendsException(PyExc_Exception, StopIteration, StopIteration, + 0, 0, StopIteration_members, 0, 0, + "Signal the end from iterator.__next__()."); /* diff --git a/Tools/c-analyzer/c_common/tables.py b/Tools/c-analyzer/c_common/tables.py index 130be6b..fe8e8cf 100644 --- a/Tools/c-analyzer/c_common/tables.py +++ b/Tools/c-analyzer/c_common/tables.py @@ -1,3 +1,4 @@ +from collections import namedtuple import csv import re import textwrap @@ -225,7 +226,11 @@ WIDTH = 20 def resolve_columns(specs): if isinstance(specs, str): specs = specs.replace(',', ' ').strip().split() - return _resolve_colspecs(specs) + resolved = [] + for raw in specs: + column = ColumnSpec.from_raw(raw) + resolved.append(column) + return resolved def build_table(specs, *, sep=' ', defaultwidth=None): @@ -233,37 +238,145 @@ def build_table(specs, *, sep=' ', defaultwidth=None): return _build_table(columns, sep=sep, defaultwidth=defaultwidth) -_COLSPEC_RE = re.compile(textwrap.dedent(r''' - ^ - (?: - \[ - ( - (?: [^\s\]] [^\]]* )? - [^\s\]] - ) #