summaryrefslogtreecommitdiffstats
path: root/Include/cpython/code.h
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2021-07-02 14:10:11 (GMT)
committerGitHub <noreply@github.com>2021-07-02 14:10:11 (GMT)
commit98eee94421dcb42c15f2d7fc4cd21357722fbe2a (patch)
tree45a158d1e97f0b29d24ded80122559b50cc858f5 /Include/cpython/code.h
parent943e77d42d3f84b581f32c05f1fc8c05366b8ed3 (diff)
downloadcpython-98eee94421dcb42c15f2d7fc4cd21357722fbe2a.zip
cpython-98eee94421dcb42c15f2d7fc4cd21357722fbe2a.tar.gz
cpython-98eee94421dcb42c15f2d7fc4cd21357722fbe2a.tar.bz2
bpo-43950: Add code.co_positions (PEP 657) (GH-26955)
This PR is part of PEP 657 and augments the compiler to emit ending line numbers as well as starting and ending columns from the AST into compiled code objects. This allows bytecodes to be correlated to the exact source code ranges that generated them. This information is made available through the following public APIs: * The `co_positions` method on code objects. * The C API function `PyCode_Addr2Location`. Co-authored-by: Batuhan Taskaya <isidentical@gmail.com> Co-authored-by: Ammar Askar <ammar@ammaraskar.com>
Diffstat (limited to 'Include/cpython/code.h')
-rw-r--r--Include/cpython/code.h25
1 files changed, 21 insertions, 4 deletions
diff --git a/Include/cpython/code.h b/Include/cpython/code.h
index ed9ac2e..f402be6 100644
--- a/Include/cpython/code.h
+++ b/Include/cpython/code.h
@@ -75,8 +75,13 @@ struct PyCodeObject {
PyObject *co_localspluskinds; /* Bytes mapping to local kinds (one byte per variable) */
PyObject *co_filename; /* unicode (where it was loaded from) */
PyObject *co_name; /* unicode (name, for reference) */
- PyObject *co_linetable; /* string (encoding addr<->lineno mapping) See
+ PyObject *co_linetable; /* bytes (encoding addr<->lineno mapping) See
Objects/lnotab_notes.txt for details. */
+ PyObject *co_endlinetable; /* bytes object that holds end lineno for
+ instructions separated across different
+ lines */
+ PyObject *co_columntable; /* bytes object that holds start/end column
+ offset each instruction */
/* These fields are set with computed values on new code objects. */
@@ -149,12 +154,14 @@ PyAPI_DATA(PyTypeObject) PyCode_Type;
PyAPI_FUNC(PyCodeObject *) PyCode_New(
int, int, int, int, int, PyObject *, PyObject *,
PyObject *, PyObject *, PyObject *, PyObject *,
- PyObject *, PyObject *, int, PyObject *, PyObject *);
+ PyObject *, PyObject *, int, PyObject *, PyObject *,
+ PyObject *, PyObject *);
PyAPI_FUNC(PyCodeObject *) PyCode_NewWithPosOnlyArgs(
int, int, int, int, int, int, PyObject *, PyObject *,
PyObject *, PyObject *, PyObject *, PyObject *,
- PyObject *, PyObject *, int, PyObject *, PyObject *);
+ PyObject *, PyObject *, int, PyObject *, PyObject *,
+ PyObject *, PyObject *);
/* same as struct above */
/* Creates a new empty code object with the specified source location. */
@@ -166,6 +173,15 @@ PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno);
use PyFrame_GetLineNumber() instead. */
PyAPI_FUNC(int) PyCode_Addr2Line(PyCodeObject *, int);
+PyAPI_FUNC(int) PyCode_Addr2Location(PyCodeObject *, int, int *, int *, int *, int *);
+
+/* Return the ending source code line number from a bytecode index. */
+PyAPI_FUNC(int) _PyCode_Addr2EndLine(PyCodeObject *, int);
+/* Return the starting source code column offset from a bytecode index. */
+PyAPI_FUNC(int) _PyCode_Addr2Offset(PyCodeObject *, int);
+/* Return the ending source code column offset from a bytecode index. */
+PyAPI_FUNC(int) _PyCode_Addr2EndOffset(PyCodeObject *, int);
+
/* for internal use only */
struct _opaque {
int computed_line;
@@ -203,8 +219,9 @@ PyAPI_FUNC(int) _PyCode_GetExtra(PyObject *code, Py_ssize_t index,
PyAPI_FUNC(int) _PyCode_SetExtra(PyObject *code, Py_ssize_t index,
void *extra);
-/** API for initializing the line number table. */
+/** API for initializing the line number tables. */
int _PyCode_InitAddressRange(PyCodeObject* co, PyCodeAddressRange *bounds);
+int _PyCode_InitEndAddressRange(PyCodeObject* co, PyCodeAddressRange* bounds);
/** Out of process API for initializing the line number table. */
void PyLineTable_InitAddressRange(const char *linetable, Py_ssize_t length, int firstlineno, PyCodeAddressRange *range);