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

Function _iter_lines

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

Source from the content-addressed store, hash-verified

102
103
104def _iter_lines(text, reqfile, samefiles, cwd, raw=False):
105 lines = iter(text.splitlines())
106
107 # The first line is special.
108 # The next two lines are consistent.
109 firstlines = [
110 f'# 0 "{reqfile}"',
111 '# 0 "<built-in>"',
112 '# 0 "<command-line>"',
113 ]
114 if text.startswith('# 1 '):
115 # Some preprocessors emit a lineno of 1 for line-less entries.
116 firstlines = [l.replace('# 0 ', '# 1 ') for l in firstlines]
117 for expected in firstlines:
118 line = next(lines)
119 if line != expected:
120 raise NotImplementedError((line, expected))
121
122 # Do all the CLI-provided includes.
123 filter_reqfile = (lambda f: _filter_reqfile(f, reqfile, samefiles))
124 make_info = (lambda lno: _common.FileInfo(reqfile, lno))
125 last = None
126 for line in lines:
127 assert last != reqfile, (last,)
128 lno, included, flags = _parse_marker_line(line, reqfile)
129 if not included:
130 raise NotImplementedError((line,))
131 if included == reqfile:
132 # This will be the last one.
133 assert not flags, (line, flags)
134 else:
135 assert 1 in flags, (line, flags)
136 yield from _iter_top_include_lines(
137 lines,
138 _normpath(included, cwd),
139 cwd,
140 filter_reqfile,
141 make_info,
142 raw,
143 EXIT_MARKERS
144 )
145 last = included
146 # The last one is always the requested file.
147 assert included == reqfile, (line,)
148
149
150def _iter_top_include_lines(lines, topfile, cwd,

Callers 1

preprocessFunction · 0.70

Calls 7

_filter_reqfileFunction · 0.85
_parse_marker_lineFunction · 0.85
_iter_top_include_linesFunction · 0.85
_normpathFunction · 0.85
splitlinesMethod · 0.45
startswithMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…