diff options
| author | Eric Snow <ericsnowcurrently@gmail.com> | 2019-09-11 19:49:45 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-09-11 19:49:45 +0100 |
| commit | ee536b2020b1f0baad1286dbd4345e13870324af (patch) | |
| tree | 2486233603db05a76aaef863bd6639455e3dfef7 /Tools/c-analyzer/c_parser/source.py | |
| parent | 9936371af298d465095ae70bc9c2943b4b16eac4 (diff) | |
| download | cpython-git-ee536b2020b1f0baad1286dbd4345e13870324af.tar.gz | |
bpo-36876: Add a tool that identifies unsupported global C variables. (#15877)
Diffstat (limited to 'Tools/c-analyzer/c_parser/source.py')
| -rw-r--r-- | Tools/c-analyzer/c_parser/source.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Tools/c-analyzer/c_parser/source.py b/Tools/c-analyzer/c_parser/source.py new file mode 100644 index 0000000000..f8998c8a33 --- /dev/null +++ b/Tools/c-analyzer/c_parser/source.py @@ -0,0 +1,34 @@ +from . import preprocessor + + +def iter_clean_lines(lines): + incomment = False + for line in lines: + # Deal with comments. + if incomment: + _, sep, line = line.partition('*/') + if sep: + incomment = False + continue + line, _, _ = line.partition('//') + line, sep, remainder = line.partition('/*') + if sep: + _, sep, after = remainder.partition('*/') + if not sep: + incomment = True + continue + line += ' ' + after + + # Ignore blank lines and leading/trailing whitespace. + line = line.strip() + if not line: + continue + + yield line + + +def iter_lines(filename, *, + preprocess=preprocessor.run, + ): + content = preprocess(filename) + return iter(content.splitlines()) |
