mirror of https://github.com/python/cpython
gh-102033: Fix syntax error in `Tools/c-analyzer` (GH-102066)
The easiest way to format strings with `{}` meaningful chars is via `%`.
This commit is contained in:
parent
7559f5fda9
commit
1ca315538f
|
@ -18,10 +18,8 @@ from c_common.scriptutil import (
|
||||||
configure_logger,
|
configure_logger,
|
||||||
get_prog,
|
get_prog,
|
||||||
filter_filenames,
|
filter_filenames,
|
||||||
iter_marks,
|
|
||||||
)
|
)
|
||||||
from c_parser.info import KIND
|
from c_parser.info import KIND
|
||||||
from c_parser.match import is_type_decl
|
|
||||||
from .match import filter_forward
|
from .match import filter_forward
|
||||||
from . import (
|
from . import (
|
||||||
analyze as _analyze,
|
analyze as _analyze,
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
from collections import namedtuple
|
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
from c_common import fsutil
|
from c_common import fsutil
|
||||||
|
@ -13,9 +12,6 @@ from c_parser.info import (
|
||||||
from c_parser.match import (
|
from c_parser.match import (
|
||||||
is_type_decl,
|
is_type_decl,
|
||||||
)
|
)
|
||||||
from .match import (
|
|
||||||
is_process_global,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
IGNORED = _misc.Labeled('IGNORED')
|
IGNORED = _misc.Labeled('IGNORED')
|
||||||
|
|
|
@ -1,7 +1,3 @@
|
||||||
|
|
||||||
_NOT_SET = object()
|
|
||||||
|
|
||||||
|
|
||||||
def peek_and_iter(items):
|
def peek_and_iter(items):
|
||||||
if not items:
|
if not items:
|
||||||
return None, None
|
return None, None
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
import logging
|
import logging
|
||||||
import os.path
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from c_common import fsutil
|
|
||||||
from c_common.scriptutil import (
|
from c_common.scriptutil import (
|
||||||
CLIArgSpec as Arg,
|
|
||||||
add_verbosity_cli,
|
add_verbosity_cli,
|
||||||
add_traceback_cli,
|
add_traceback_cli,
|
||||||
add_kind_filtering_cli,
|
add_kind_filtering_cli,
|
||||||
|
@ -15,7 +12,6 @@ from c_common.scriptutil import (
|
||||||
get_prog,
|
get_prog,
|
||||||
main_for_filenames,
|
main_for_filenames,
|
||||||
)
|
)
|
||||||
from .preprocessor import get_preprocessor
|
|
||||||
from .preprocessor.__main__ import (
|
from .preprocessor.__main__ import (
|
||||||
add_common_cli as add_preprocessor_cli,
|
add_common_cli as add_preprocessor_cli,
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,244 +0,0 @@
|
||||||
|
|
||||||
f'''
|
|
||||||
struct {ANON_IDENTIFIER};
|
|
||||||
struct {{ ... }}
|
|
||||||
struct {IDENTIFIER} {{ ... }}
|
|
||||||
|
|
||||||
union {ANON_IDENTIFIER};
|
|
||||||
union {{ ... }}
|
|
||||||
union {IDENTIFIER} {{ ... }}
|
|
||||||
|
|
||||||
enum {ANON_IDENTIFIER};
|
|
||||||
enum {{ ... }}
|
|
||||||
enum {IDENTIFIER} {{ ... }}
|
|
||||||
|
|
||||||
typedef {VARTYPE} {IDENTIFIER};
|
|
||||||
typedef {IDENTIFIER};
|
|
||||||
typedef {IDENTIFIER};
|
|
||||||
typedef {IDENTIFIER};
|
|
||||||
'''
|
|
||||||
|
|
||||||
|
|
||||||
def parse(srclines):
|
|
||||||
if isinstance(srclines, str): # a filename
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# This only handles at most 10 nested levels.
|
|
||||||
#MATCHED_PARENS = textwrap.dedent(rf'''
|
|
||||||
# # matched parens
|
|
||||||
# (?:
|
|
||||||
# [(] # level 0
|
|
||||||
# (?:
|
|
||||||
# [^()]*
|
|
||||||
# [(] # level 1
|
|
||||||
# (?:
|
|
||||||
# [^()]*
|
|
||||||
# [(] # level 2
|
|
||||||
# (?:
|
|
||||||
# [^()]*
|
|
||||||
# [(] # level 3
|
|
||||||
# (?:
|
|
||||||
# [^()]*
|
|
||||||
# [(] # level 4
|
|
||||||
# (?:
|
|
||||||
# [^()]*
|
|
||||||
# [(] # level 5
|
|
||||||
# (?:
|
|
||||||
# [^()]*
|
|
||||||
# [(] # level 6
|
|
||||||
# (?:
|
|
||||||
# [^()]*
|
|
||||||
# [(] # level 7
|
|
||||||
# (?:
|
|
||||||
# [^()]*
|
|
||||||
# [(] # level 8
|
|
||||||
# (?:
|
|
||||||
# [^()]*
|
|
||||||
# [(] # level 9
|
|
||||||
# (?:
|
|
||||||
# [^()]*
|
|
||||||
# [(] # level 10
|
|
||||||
# [^()]*
|
|
||||||
# [)]
|
|
||||||
# )*
|
|
||||||
# [^()]*
|
|
||||||
# [)]
|
|
||||||
# )*
|
|
||||||
# [^()]*
|
|
||||||
# [)]
|
|
||||||
# )*
|
|
||||||
# [^()]*
|
|
||||||
# [)]
|
|
||||||
# )*
|
|
||||||
# [^()]*
|
|
||||||
# [)]
|
|
||||||
# )*
|
|
||||||
# [^()]*
|
|
||||||
# [)]
|
|
||||||
# )*
|
|
||||||
# [^()]*
|
|
||||||
# [)]
|
|
||||||
# )*
|
|
||||||
# [^()]*
|
|
||||||
# [)]
|
|
||||||
# )*
|
|
||||||
# [^()]*
|
|
||||||
# [)]
|
|
||||||
# )*
|
|
||||||
# [^()]*
|
|
||||||
# [)]
|
|
||||||
# )*
|
|
||||||
# [^()]*
|
|
||||||
# [)]
|
|
||||||
# )
|
|
||||||
# # end matched parens
|
|
||||||
# ''')
|
|
||||||
|
|
||||||
r'''
|
|
||||||
# for loop
|
|
||||||
(?:
|
|
||||||
\s* \b for
|
|
||||||
\s* [(]
|
|
||||||
(
|
|
||||||
[^;]* ;
|
|
||||||
[^;]* ;
|
|
||||||
.*?
|
|
||||||
) # <header>
|
|
||||||
[)]
|
|
||||||
\s*
|
|
||||||
(?:
|
|
||||||
(?:
|
|
||||||
(
|
|
||||||
{_ind(SIMPLE_STMT, 6)}
|
|
||||||
) # <stmt>
|
|
||||||
;
|
|
||||||
)
|
|
||||||
|
|
|
||||||
( {{ ) # <open>
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(
|
|
||||||
(?:
|
|
||||||
(?:
|
|
||||||
(?:
|
|
||||||
{_ind(SIMPLE_STMT, 6)}
|
|
||||||
)?
|
|
||||||
return \b \s*
|
|
||||||
{_ind(INITIALIZER, 5)}
|
|
||||||
)
|
|
||||||
|
|
|
||||||
(?:
|
|
||||||
(?:
|
|
||||||
{IDENTIFIER} \s*
|
|
||||||
(?: . | -> ) \s*
|
|
||||||
)*
|
|
||||||
{IDENTIFIER}
|
|
||||||
\s* = \s*
|
|
||||||
{_ind(INITIALIZER, 5)}
|
|
||||||
)
|
|
||||||
|
|
|
||||||
(?:
|
|
||||||
{_ind(SIMPLE_STMT, 5)}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
|
||||||
# cast compound literal
|
|
||||||
(?:
|
|
||||||
(?:
|
|
||||||
[^'"{{}};]*
|
|
||||||
{_ind(STRING_LITERAL, 5)}
|
|
||||||
)*
|
|
||||||
[^'"{{}};]*?
|
|
||||||
[^'"{{}};=]
|
|
||||||
=
|
|
||||||
\s* [(] [^)]* [)]
|
|
||||||
\s* {{ [^;]* }}
|
|
||||||
)
|
|
||||||
) # <stmt>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# compound statement
|
|
||||||
(?:
|
|
||||||
(
|
|
||||||
(?:
|
|
||||||
|
|
||||||
# "for" statements are handled separately above.
|
|
||||||
(?: (?: else \s+ )? if | switch | while ) \s*
|
|
||||||
{_ind(COMPOUND_HEAD, 5)}
|
|
||||||
)
|
|
||||||
|
|
|
||||||
(?: else | do )
|
|
||||||
# We do not worry about compound statements for labels,
|
|
||||||
# "case", or "default".
|
|
||||||
)? # <header>
|
|
||||||
\s*
|
|
||||||
( {{ ) # <open>
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(
|
|
||||||
(?:
|
|
||||||
[^'"{{}};]*
|
|
||||||
{_ind(STRING_LITERAL, 5)}
|
|
||||||
)*
|
|
||||||
[^'"{{}};]*
|
|
||||||
# Presumably we will not see "== {{".
|
|
||||||
[^\s='"{{}};]
|
|
||||||
)? # <header>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(
|
|
||||||
\b
|
|
||||||
(?:
|
|
||||||
# We don't worry about labels with a compound statement.
|
|
||||||
(?:
|
|
||||||
switch \s* [(] [^{{]* [)]
|
|
||||||
)
|
|
||||||
|
|
|
||||||
(?:
|
|
||||||
case \b \s* [^:]+ [:]
|
|
||||||
)
|
|
||||||
|
|
|
||||||
(?:
|
|
||||||
default \s* [:]
|
|
||||||
)
|
|
||||||
|
|
|
||||||
(?:
|
|
||||||
do
|
|
||||||
)
|
|
||||||
|
|
|
||||||
(?:
|
|
||||||
while \s* [(] [^{{]* [)]
|
|
||||||
)
|
|
||||||
|
|
|
||||||
#(?:
|
|
||||||
# for \s* [(] [^{{]* [)]
|
|
||||||
# )
|
|
||||||
#|
|
|
||||||
(?:
|
|
||||||
if \s* [(]
|
|
||||||
(?: [^{{]* [^)] \s* {{ )* [^{{]*
|
|
||||||
[)]
|
|
||||||
)
|
|
||||||
|
|
|
||||||
(?:
|
|
||||||
else
|
|
||||||
(?:
|
|
||||||
\s*
|
|
||||||
if \s* [(]
|
|
||||||
(?: [^{{]* [^)] \s* {{ )* [^{{]*
|
|
||||||
[)]
|
|
||||||
)?
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)? # <header>
|
|
||||||
'''
|
|
|
@ -1,6 +1,5 @@
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
import enum
|
import enum
|
||||||
import os.path
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from c_common import fsutil
|
from c_common import fsutil
|
||||||
|
@ -8,7 +7,7 @@ from c_common.clsutil import classonly
|
||||||
import c_common.misc as _misc
|
import c_common.misc as _misc
|
||||||
import c_common.strutil as _strutil
|
import c_common.strutil as _strutil
|
||||||
import c_common.tables as _tables
|
import c_common.tables as _tables
|
||||||
from .parser._regexes import SIMPLE_TYPE, _STORAGE
|
from .parser._regexes import _STORAGE
|
||||||
|
|
||||||
|
|
||||||
FIXED_TYPE = _misc.Labeled('FIXED_TYPE')
|
FIXED_TYPE = _misc.Labeled('FIXED_TYPE')
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
|
|
||||||
def _parse(srclines, anon_name):
|
|
||||||
text = ' '.join(l for _, l in srclines)
|
|
||||||
|
|
||||||
from ._delim import parse
|
|
||||||
yield from parse(text, anon_name)
|
|
|
@ -1,54 +0,0 @@
|
||||||
import re
|
|
||||||
import textwrap
|
|
||||||
|
|
||||||
from ._regexes import _ind, STRING_LITERAL
|
|
||||||
|
|
||||||
|
|
||||||
def parse(text, anon_name):
|
|
||||||
context = None
|
|
||||||
data = None
|
|
||||||
for m in DELIMITER_RE.find_iter(text):
|
|
||||||
before, opened, closed = m.groups()
|
|
||||||
delim = opened or closed
|
|
||||||
|
|
||||||
handle_segment = HANDLERS[context][delim]
|
|
||||||
result, context, data = handle_segment(before, delim, data)
|
|
||||||
if result:
|
|
||||||
yield result
|
|
||||||
|
|
||||||
|
|
||||||
DELIMITER = textwrap.dedent(rf'''
|
|
||||||
(
|
|
||||||
(?:
|
|
||||||
[^'"()\[\]{};]*
|
|
||||||
{_ind(STRING_LITERAL, 3)}
|
|
||||||
}*
|
|
||||||
[^'"()\[\]{};]+
|
|
||||||
)? # <before>
|
|
||||||
(?:
|
|
||||||
(
|
|
||||||
[(\[{]
|
|
||||||
) # <open>
|
|
||||||
|
|
|
||||||
(
|
|
||||||
[)\]};]
|
|
||||||
) # <close>
|
|
||||||
)?
|
|
||||||
''')
|
|
||||||
DELIMITER_RE = re.compile(DELIMITER, re.VERBOSE)
|
|
||||||
|
|
||||||
_HANDLERS = {
|
|
||||||
None: { # global
|
|
||||||
# opened
|
|
||||||
'{': ...,
|
|
||||||
'[': None,
|
|
||||||
'(': None,
|
|
||||||
# closed
|
|
||||||
'}': None,
|
|
||||||
']': None,
|
|
||||||
')': None,
|
|
||||||
';': ...,
|
|
||||||
},
|
|
||||||
'': {
|
|
||||||
},
|
|
||||||
}
|
|
|
@ -9,7 +9,6 @@ from ._common import (
|
||||||
set_capture_groups,
|
set_capture_groups,
|
||||||
)
|
)
|
||||||
from ._compound_decl_body import DECL_BODY_PARSERS
|
from ._compound_decl_body import DECL_BODY_PARSERS
|
||||||
#from ._func_body import parse_function_body
|
|
||||||
from ._func_body import parse_function_statics as parse_function_body
|
from ._func_body import parse_function_statics as parse_function_body
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ import logging
|
||||||
import sys
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
from c_common.fsutil import expand_filenames, iter_files_by_suffix
|
|
||||||
from c_common.scriptutil import (
|
from c_common.scriptutil import (
|
||||||
VERBOSITY,
|
VERBOSITY,
|
||||||
add_verbosity_cli,
|
add_verbosity_cli,
|
||||||
|
@ -11,7 +10,6 @@ from c_common.scriptutil import (
|
||||||
add_kind_filtering_cli,
|
add_kind_filtering_cli,
|
||||||
add_files_cli,
|
add_files_cli,
|
||||||
add_progress_cli,
|
add_progress_cli,
|
||||||
main_for_filenames,
|
|
||||||
process_args_by_key,
|
process_args_by_key,
|
||||||
configure_logger,
|
configure_logger,
|
||||||
get_prog,
|
get_prog,
|
||||||
|
|
|
@ -4,16 +4,12 @@ import re
|
||||||
from c_common.clsutil import classonly
|
from c_common.clsutil import classonly
|
||||||
from c_parser.info import (
|
from c_parser.info import (
|
||||||
KIND,
|
KIND,
|
||||||
DeclID,
|
|
||||||
Declaration,
|
Declaration,
|
||||||
TypeDeclaration,
|
TypeDeclaration,
|
||||||
TypeDef,
|
|
||||||
Struct,
|
|
||||||
Member,
|
Member,
|
||||||
FIXED_TYPE,
|
FIXED_TYPE,
|
||||||
)
|
)
|
||||||
from c_parser.match import (
|
from c_parser.match import (
|
||||||
is_type_decl,
|
|
||||||
is_pots,
|
is_pots,
|
||||||
is_funcptr,
|
is_funcptr,
|
||||||
)
|
)
|
||||||
|
|
|
@ -7,7 +7,7 @@ import textwrap
|
||||||
|
|
||||||
from c_common.tables import build_table, resolve_columns
|
from c_common.tables import build_table, resolve_columns
|
||||||
from c_parser.parser._regexes import _ind
|
from c_parser.parser._regexes import _ind
|
||||||
from ._files import iter_header_files, resolve_filename
|
from ._files import iter_header_files
|
||||||
from . import REPO_ROOT
|
from . import REPO_ROOT
|
||||||
|
|
||||||
|
|
||||||
|
@ -610,7 +610,6 @@ def _render_item_full(item, groupby, verbose):
|
||||||
yield item.name
|
yield item.name
|
||||||
yield f' {"filename:":10} {item.relfile}'
|
yield f' {"filename:":10} {item.relfile}'
|
||||||
for extra in ('kind', 'level'):
|
for extra in ('kind', 'level'):
|
||||||
#if groupby != extra:
|
|
||||||
yield f' {extra+":":10} {getattr(item, extra)}'
|
yield f' {extra+":":10} {getattr(item, extra)}'
|
||||||
if verbose:
|
if verbose:
|
||||||
print(' ---------------------------------------')
|
print(' ---------------------------------------')
|
||||||
|
@ -636,7 +635,6 @@ def render_summary(items, *,
|
||||||
|
|
||||||
subtotals = summary['totals']['subs']
|
subtotals = summary['totals']['subs']
|
||||||
bygroup = summary['totals']['bygroup']
|
bygroup = summary['totals']['bygroup']
|
||||||
lastempty = False
|
|
||||||
for outer, subtotal in subtotals.items():
|
for outer, subtotal in subtotals.items():
|
||||||
if bygroup:
|
if bygroup:
|
||||||
subtotal = f'({subtotal})'
|
subtotal = f'({subtotal})'
|
||||||
|
@ -646,10 +644,6 @@ def render_summary(items, *,
|
||||||
if outer in bygroup:
|
if outer in bygroup:
|
||||||
for inner, count in bygroup[outer].items():
|
for inner, count in bygroup[outer].items():
|
||||||
yield f' {inner + ":":9} {count}'
|
yield f' {inner + ":":9} {count}'
|
||||||
lastempty = False
|
|
||||||
else:
|
|
||||||
lastempty = True
|
|
||||||
|
|
||||||
total = f'*{summary["totals"]["all"]}*'
|
total = f'*{summary["totals"]["all"]}*'
|
||||||
label = '*total*:'
|
label = '*total*:'
|
||||||
if bygroup:
|
if bygroup:
|
||||||
|
|
Loading…
Reference in New Issue