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

Function _iter_lines

Tools/c-analyzer/c_parser/preprocessor/clang.py:53–104  ·  view source on GitHub ↗
(text, reqfile, samefiles, cwd, raw=False)

Source from the content-addressed store, hash-verified

51
52
53def _iter_lines(text, reqfile, samefiles, cwd, raw=False):
54 lines = iter(text.splitlines())
55
56 # The first line is special.
57 # The subsequent lines are consistent.
58 firstlines = [
59 f'# 1 "{reqfile}"',
60 '# 1 "<built-in>" 1',
61 '# 1 "<built-in>" 3',
62 '# 370 "<built-in>" 3',
63 '# 1 "<command line>" 1',
64 '# 1 "<built-in>" 2',
65 ]
66 for expected in firstlines:
67 line = next(lines)
68 if line != expected:
69 raise NotImplementedError((line, expected))
70
71 # Do all the CLI-provided includes.
72 filter_reqfile = (lambda f: _gcc._filter_reqfile(f, reqfile, samefiles))
73 make_info = (lambda lno: _common.FileInfo(reqfile, lno))
74 last = None
75 for line in lines:
76 assert last != reqfile, (last,)
77 # NOTE:condition is clang specific
78 if not line:
79 continue
80 lno, included, flags = _gcc._parse_marker_line(line, reqfile)
81 if not included:
82 raise NotImplementedError((line,))
83 if included == reqfile:
84 # This will be the last one.
85 assert 2 in flags, (line, flags)
86 else:
87 # NOTE:first condition is specific to clang
88 if _normpath(included, cwd) == reqfile:
89 assert 1 in flags or 2 in flags, (line, flags, included, reqfile)
90 else:
91 assert 1 in flags, (line, flags, included, reqfile)
92 yield from _gcc._iter_top_include_lines(
93 lines,
94 _normpath(included, cwd),
95 cwd,
96 filter_reqfile,
97 make_info,
98 raw,
99 EXIT_MARKERS
100 )
101 last = included
102 # The last one is always the requested file.
103 # NOTE:_normpath is clang specific
104 assert _normpath(included, cwd) == reqfile, (line,)

Callers 1

preprocessFunction · 0.70

Calls 2

_normpathFunction · 0.85
splitlinesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…