8000 bpo-36876: Re-organize the c-analyzer tool code. by ericsnowcurrently · Pull Request #16841 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-36876: Re-organize the c-analyzer tool code. #16841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Oct 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8ce7d62
Move show.py to c_analyzer_common.
ericsnowcurrently Sep 27, 2019
c40c247
Small cleanups around _check_results().
ericsnowcurrently Sep 27, 2019
bf3bd21
Merge c_parser.info into c_analyzer_common.info.
ericsnowcurrently Sep 27, 2019
52113ae
c_symbols.binary -> c_symbols.find.
ericsnowcurrently Sep 27, 2019
dc8333f
Add ID.match().
ericsnowcurrently Sep 30, 2019
9b47596
Add known.look_up_variable().
ericsnowcurrently Sep 30, 2019
67eea78
Add c_parser.find module.
ericsnowcurrently Sep 30, 2019
b61b704
Add c_symbols.find module.
ericsnowcurrently Sep 30, 2019
a041e4a
Avoid variable resolution in _nm.iter_symbols().
ericsnowcurrently Sep 30, 2019
b9b0499
Add c_analyzer_common.find module.
ericsnowcurrently Sep 30, 2019
15b60db
Use the new modules in __main__.
ericsnowcurrently Sep 30, 2019
2f9958f
Drop the old code.
ericsnowcurrently Sep 30, 2019
b05272c
Specify "preprocessed" option as an arg.
ericsnowcurrently Sep 30, 2019
80d299c
Add a TODO.
ericsnowcurrently Sep 30, 2019
15c1226
Use declarations.iter_all() instead of iter_variables().
ericsnowcurrently Sep 30, 2019
e08bad5
Make sure "resolve()" is used properly.
ericsnowcurrently Oct 1, 2019
fa6f1b5
Move extract_storage() to c_parser.declarations.
ericsnowcurrently Oct 4, 2019
6531014
Move the generic code under a top-level c_analyzer package.
ericsnowcurrently Oct 4, 2019
15f010b
Move some code to a new c_analyzer.variables package.
ericsnowcurrently Oct 4, 2019
c399dc0
c_global -> cpython.
ericsnowcurrently Oct 4, 2019
025e8c3
Do not use Variable in symbols or parser packages.
ericsnowcurrently Oct 15, 2019
f60551e
Drop "INCLUDES" from SOURCE_DIRS.
ericsnowcurrently Oct 18, 2019
4beba49
Process files more cleanly.
ericsnowcurrently Oct 18, 2019
9e5c09b
Fix a typo.
ericsnowcurrently Oct 18, 2019
6e14276
Call check_filename() properly.
ericsnowcurrently Oct 18, 2019
0ce0cd1
Fix one last import.
ericsnowcurrently Oct 18, 2019
264d698
Fix whitespace.
ericsnowcurrently Oct 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move extract_storage() to c_parser.declarations.
  • Loading branch information
ericsnowcurrently committed Oct 4, 2019
commit fa6f1b50deffc81f6482b914a8dccaee4f2d8118
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
with tool_imports_for_tests():
from c_parser.declarations import (
iter_global_declarations, iter_local_statements,
parse_func, parse_var, parse_compound,
parse_func, _parse_var, parse_compound,
iter_variables,
)

Expand Down Expand Up @@ -515,7 +515,7 @@ def test_typical(self):
])
for stmt, expected in tests:
with self.subTest(stmt):
name, vartype = parse_var(stmt)
name, vartype = _parse_var(stmt)

self.assertEqual((name, vartype), expected)

Expand Down
24 changes: 3 additions & 21 deletions Tools/c-analyzer/c_analyzer_common/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,26 +152,7 @@ def normalize_vartype(vartype):
return str(vartype)


def extract_storage(decl, *, isfunc=False):
"""Return (storage, vartype) based on the given declaration.

The default storage is "implicit" or "local".
"""
if decl == UNKNOWN:
return decl, decl
if decl.startswith('static '):
return 'static', decl
#return 'static', decl.partition(' ')[2].strip()
elif decl.startswith('extern '):
return 'extern', decl
#return 'extern', decl.partition(' ')[2].strip()
elif re.match('.*\b(static|extern)\b', decl):
raise NotImplementedError
elif isfunc:
return 'local', decl
else:
return 'implicit', decl

# XXX Variable.vartype -> decl (Declaration).

class Variable(_NTBase,
namedtuple('Variable', 'id storage vartype')):
Expand All @@ -189,7 +170,8 @@ class Variable(_NTBase,
@classonly
def from_parts(cls, filename, funcname, name, decl, storage=None):
if storage is None:
storage, decl = extract_storage(decl, isfunc=funcname)
from c_parser.declarations import extract_storage
storage = extract_storage(decl, infunc=funcname)
id = ID(filename, funcname, name)
self = cls(id, storage, decl)
return self
Expand Down
29 changes: 26 additions & 3 deletions Tools/c-analyzer/c_parser/declarations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import shlex
import subprocess

from c_analyzer_common.info import UNKNOWN

from . import source


Expand Down Expand Up @@ -194,7 +196,7 @@ def parse_func(stmt, body):
return name, signature


def parse_var(stmt):
def _parse_var(stmt):
"""Return (name, vartype) for the given variable declaration."""
stmt = stmt.rstrip(';')
m = LOCAL_STMT_START_RE.match(stmt)
Expand All @@ -220,6 +222,27 @@ def parse_var(stmt):
return name, vartype


def extract_storage(decl, *, infunc=None):
"""Return (storage, vartype) based on the given declaration.

The default storage is "implicit" (or "local" if infunc is True).
"""
if decl == UNKNOWN:
return decl
if decl.startswith('static '):
return 'static'
#return 'static', decl.partition(' ')[2].strip()
elif decl.startswith('extern '):
return 'extern'
#return 'extern', decl.partition(' ')[2].strip()
elif re.match('.*\b(static|extern)\b', decl):
raise NotImplementedError
elif infunc:
return 'local'
else:
return 'implicit'


def parse_compound(stmt, blocks):
"""Return (headers, bodies) for the given compound statement."""
# XXX Identify declarations inside compound statements
Expand All @@ -233,7 +256,7 @@ def iter_variables(filename, *,
_iter_global=iter_global_declarations,
_iter_local=iter_local_statements,
_parse_func=parse_func,
_parse_var=parse_var,
_parse_var=_parse_var,
_parse_compound=parse_compound,
):
"""Yield (funcname, name, vartype) for every variable in the given file."""
Expand All @@ -259,7 +282,7 @@ def iter_variables(filename, *,

def _iter_locals(lines, *,
_iter_statements=iter_local_statements,
_parse_var=parse_var,
_parse_var=_parse_var,
_parse_compound=parse_compound,
):
compound = [lines]
Expand Down
0