Skip to content

Commit 7f62d59

Browse files
Extend error messages if too much code to c-analyzer
1 parent a7af5bd commit 7f62d59

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

Tools/c-analyzer/c_parser/parser/__init__.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,27 @@ def _iter_source(lines, *, maxtext=11_000, maxlines=200, showtext=False):
208208
return
209209
# At this point either the file ended prematurely
210210
# or there's "too much" text.
211-
filename, lno, text = srcinfo.filename, srcinfo._start, srcinfo.text
211+
filename, lno_from, lno_to = srcinfo.filename, srcinfo.start, srcinfo.end
212+
text = srcinfo.text
212213
if len(text) > 500:
213214
text = text[:500] + '...'
214-
raise Exception(f'unmatched text ({filename} starting at line {lno}):\n{text}')
215+
216+
if srcinfo.too_much_text(maxtext):
217+
msg = [
218+
'too much text, try to increase MAX_SIZES[MAXTEXT] in cpython/_parser.py',
219+
f'{filename} starting at line {lno_from} to {lno_to}',
220+
f'has code with length {len(text)} greater than {maxtext}:',
221+
text
222+
]
223+
raise Exception('\n'.join(msg))
224+
225+
if srcinfo.too_much_lines(maxlines):
226+
msg = [
227+
'too much lines, try to increase MAX_SIZES[MAXLINES] in cpython/_parser.py',
228+
f'{filename} starting at line {lno_from} to {lno_to}',
229+
f'has code with number of lines {lno_to - lno_from} greater than {maxlines}:',
230+
text
231+
]
232+
raise Exception('\n'.join(msg))
233+
234+
raise Exception(f'unmatched text ({filename} starting at line {lno_from}):\n{text}')

Tools/c-analyzer/c_parser/parser/_info.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,16 @@ def resolve(self, kind, data, name, parent=None):
123123
def done(self):
124124
self._set_ready()
125125

126+
def too_much_text(self, maxtext):
127+
return maxtext and len(self.text) > maxtext
128+
129+
def too_much_lines(self, maxlines):
130+
return maxlines and self.end - self.start > maxlines
131+
126132
def too_much(self, maxtext, maxlines):
127-
if maxtext and len(self.text) > maxtext:
133+
if self.too_much_text(maxtext):
128134
pass
129-
elif maxlines and self.end - self.start > maxlines:
135+
elif self.too_much_lines(maxlines):
130136
pass
131137
else:
132138
return False

0 commit comments

Comments
 (0)