MCPcopy Index your code
hub / github.com/python/cpython / _iter_top_include_lines

Function _iter_top_include_lines

Tools/c-analyzer/c_parser/preprocessor/gcc.py:150–216  ·  view source on GitHub ↗
(lines, topfile, cwd,
                            filter_reqfile, make_info,
                            raw, exit_markers)

Source from the content-addressed store, hash-verified

148
149
150def _iter_top_include_lines(lines, topfile, cwd,
151 filter_reqfile, make_info,
152 raw, exit_markers):
153 partial = 0 # depth
154 files = [topfile]
155 # We start at 1 in case there are source lines (including blank ones)
156 # before the first marker line. Also, we already verified in
157 # _parse_marker_line() that the preprocessor reported lno as 1.
158 lno = 1
159 for line in lines:
160 if line in exit_markers:
161 # We're done with this top-level include.
162 return
163
164 _lno, included, flags = _parse_marker_line(line)
165 if included:
166 # HACK:
167 # Mixes curses.h and ncurses.h marker lines
168 # gcc silently passes this, while clang fails
169 # See: /Include/py_curses.h #if-elif directives
170 # And compare with preprocessor output
171 if os.path.basename(included) == 'curses.h':
172 included = os.path.join(os.path.dirname(included), 'ncurses.h')
173
174 lno = _lno
175 included = _normpath(included, cwd)
176 # We hit a marker line.
177 if 1 in flags:
178 # We're entering a file.
179 # XXX Cycles are unexpected?
180 #assert included not in files, (line, files)
181 files.append(included)
182 elif 2 in flags:
183 # We're returning to a file.
184 assert files and included in files, (line, files)
185 assert included != files[-1], (line, files)
186 while files[-1] != included:
187 files.pop()
188 # XXX How can a file return to line 1?
189 #assert lno > 1, (line, lno)
190 else:
191 if included == files[-1]:
192 # It's the next line from the file.
193 assert lno > 1, (line, lno)
194 else:
195 # We ran into a user-added #LINE directive,
196 # which we promptly ignore.
197 pass
198 elif not files:
199 raise NotImplementedError((line,))
200 elif filter_reqfile(files[-1]):
201 assert lno is not None, (line, files[-1])
202 if (m := PREPROC_DIRECTIVE_RE.match(line)):
203 name, = m.groups()
204 if name != 'pragma':
205 raise Exception(line)
206 else:
207 line = re.sub(r'__inline__', 'inline', line)

Callers 1

_iter_linesFunction · 0.85

Calls 11

_parse_marker_lineFunction · 0.85
_normpathFunction · 0.85
_strip_directivesFunction · 0.85
basenameMethod · 0.45
joinMethod · 0.45
dirnameMethod · 0.45
appendMethod · 0.45
popMethod · 0.45
matchMethod · 0.45
groupsMethod · 0.45
subMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…