Skip to content

Commit e6c8a85

Browse files
committed
add experimental print
1 parent 488ba78 commit e6c8a85

File tree

1 file changed

+39
-12
lines changed
  • Tools/c-analyzer/c_parser/preprocessor

1 file changed

+39
-12
lines changed

Tools/c-analyzer/c_parser/preprocessor/clang.py

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import os.path
2-
import re
2+
import re, sys
33

44
from . import common as _common
55
from . import gcc as _gcc
66

7+
_normpath = _gcc._normpath
78

89
TOOL = 'clang'
910

@@ -22,7 +23,7 @@ def preprocess(filename,
2223
):
2324
if not cwd or not os.path.isabs(cwd):
2425
cwd = os.path.abspath(cwd or '.')
25-
filename = _gcc._normpath(filename, cwd)
26+
filename = _normpath(filename, cwd)
2627

2728
postargs = _gcc.POST_ARGS
2829
basename = os.path.basename(filename)
@@ -46,14 +47,40 @@ def preprocess(filename,
4647
return _iter_lines(text, filename, samefiles, cwd)
4748

4849

50+
# Reasons:
51+
# py_curses related have a stack return in unusual order for /include/curses.h
52+
CLANG_IGNORES = (
53+
'/Include/py_curses.h',
54+
'/Modules/_cursesmodule.c',
55+
'/Modules/_curses_panel.c'
56+
)
57+
58+
EXPERIMENTAL_PRINTED = False
59+
60+
CLANG_EXPERIMENTAL = """
61+
62+
WARNING
63+
=======
64+
clang preprocessor is in experimental state.
65+
a) There might be false positives
66+
b) Following files are skipped
67+
{}
68+
69+
""".format('\n'.join([' ' + fn for fn in CLANG_IGNORES]))
70+
71+
4972
EXIT_MARKERS = {'# 2 "<built-in>" 2', '# 3 "<built-in>" 2', '# 4 "<built-in>" 2'}
5073

5174

5275
def _iter_lines(text, reqfile, samefiles, cwd, raw=False):
53-
# NOTE:HACK: has a stack return in unusual order for /include/curses.h
54-
if reqfile.endswith(('/Include/py_curses.h',
55-
'/Modules/_cursesmodule.c',
56-
'/Modules/_curses_panel.c')):
76+
global EXPERIMENTAL_PRINTED
77+
if not EXPERIMENTAL_PRINTED:
78+
print(CLANG_EXPERIMENTAL, flush=True)
79+
EXPERIMENTAL_PRINTED = True
80+
81+
# NOTE:clang specific
82+
if reqfile.endswith(CLANG_IGNORES):
83+
print(f'\nSkipping: {reqfile}', flush=True)
5784
return
5885

5986
lines = iter(text.splitlines())
@@ -79,7 +106,7 @@ def _iter_lines(text, reqfile, samefiles, cwd, raw=False):
79106
last = None
80107
for line in lines:
81108
assert last != reqfile, (last,)
82-
# NOTE:clang specific
109+
# NOTE:condition is clang specific
83110
if not line:
84111
continue
85112
lno, included, flags = _gcc._parse_marker_line(line, reqfile)
@@ -89,14 +116,14 @@ def _iter_lines(text, reqfile, samefiles, cwd, raw=False):
89116
# This will be the last one.
90117
assert 2 in flags, (line, flags)
91118
else:
92-
# NOTE:clang specific
93-
if _gcc._normpath(included, cwd) == reqfile:
119+
# NOTE:first condition is specific to clang
120+
if _normpath(included, cwd) == reqfile:
94121
assert 1 in flags or 2 in flags, (line, flags, included, reqfile)
95122
else:
96123
assert 1 in flags, (line, flags, included, reqfile)
97124
yield from _gcc._iter_top_include_lines(
98125
lines,
99-
_gcc._normpath(included, cwd),
126+
_normpath(included, cwd),
100127
cwd,
101128
filter_reqfile,
102129
make_info,
@@ -105,5 +132,5 @@ def _iter_lines(text, reqfile, samefiles, cwd, raw=False):
105132
)
106133
last = included
107134
# The last one is always the requested file.
108-
# NOTE:clang specific
109-
assert _gcc._normpath(included, cwd) == reqfile, (line,)
135+
# NOTE:_normpath is clang specific
136+
assert _normpath(included, cwd) == reqfile, (line,)

0 commit comments

Comments
 (0)