Skip to content

Commit 501aa62

Browse files
committed
Update the compiler to use the new APIs
1 parent 36343c9 commit 501aa62

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Python/compile.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ struct compiler_unit {
197197
int u_firstlineno; /* the first lineno of the block */
198198
int u_lineno; /* the lineno for the current stmt */
199199
int u_col_offset; /* the offset of the current stmt */
200+
int u_end_lineno; /* the end line of the current stmt */
201+
int u_end_col_offset; /* the end offset of the current stmt */
200202
};
201203

202204
/* This struct captures the global state of a compilation.
@@ -641,6 +643,8 @@ compiler_enter_scope(struct compiler *c, identifier name,
641643
u->u_firstlineno = lineno;
642644
u->u_lineno = 0;
643645
u->u_col_offset = 0;
646+
u->u_end_lineno = 0;
647+
u->u_end_col_offset = 0;
644648
u->u_consts = PyDict_New();
645649
if (!u->u_consts) {
646650
compiler_unit_free(u);
@@ -911,7 +915,9 @@ compiler_next_instr(basicblock *b)
911915

912916
#define SET_LOC(c, x) \
913917
(c)->u->u_lineno = (x)->lineno; \
914-
(c)->u->u_col_offset = (x)->col_offset;
918+
(c)->u->u_col_offset = (x)->col_offset; \
919+
(c)->u->u_end_lineno = (x)->end_lineno; \
920+
(c)->u->u_end_col_offset = (x)->end_col_offset;
915921

916922
/* Return the stack effect of opcode with argument oparg.
917923
@@ -5474,8 +5480,9 @@ compiler_error(struct compiler *c, const char *format, ...)
54745480
Py_INCREF(Py_None);
54755481
loc = Py_None;
54765482
}
5477-
PyObject *args = Py_BuildValue("O(OiiO)", msg, c->c_filename,
5478-
c->u->u_lineno, c->u->u_col_offset + 1, loc);
5483+
PyObject *args = Py_BuildValue("O(OiiOi)", msg, c->c_filename,
5484+
c->u->u_lineno, c->u->u_col_offset + 1, loc,
5485+
c->u->u_end_lineno, c->u->u_end_col_offset + 1);
54795486
Py_DECREF(msg);
54805487
if (args == NULL) {
54815488
goto exit;

0 commit comments

Comments
 (0)