Skip to content

Commit 4c36443

Browse files
committed
Add gcc.Location.__init__
1 parent 43900d3 commit 4c36443

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

docs/locations.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ Locations
7171
a = (foo && bar)
7272
~~~~~^~~~~~~
7373

74+
.. py:method:: __init__(self, caret, start, finish)
75+
76+
Construct a location, using the caret location of caret as the
77+
caret, and the start/finish of start and finish respectively::
78+
79+
compound_loc = gcc.Location(caret, start, finish)
80+
7481
.. py:attribute:: caret
7582
7683
(:py:class:`gcc.Location`) The caret location within this location.

gcc-python-location.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,31 @@
3333
typedef unsigned int source_location;
3434
*/
3535

36+
int
37+
PyGccLocation_init(PyGccLocation *self, PyObject *args, PyObject *kwargs)
38+
{
39+
const char *keywords[] = {"caret", "start", "finish",
40+
NULL};
41+
PyGccLocation *caret_obj;
42+
PyGccLocation *start_obj;
43+
PyGccLocation *finish_obj;
44+
45+
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
46+
"O!O!O!", (char**)keywords,
47+
&PyGccLocation_TypeObj, &caret_obj,
48+
&PyGccLocation_TypeObj, &start_obj,
49+
&PyGccLocation_TypeObj, &finish_obj)) {
50+
return -1;
51+
}
52+
53+
self->loc
54+
= gcc_private_make_location (make_location (caret_obj->loc.inner,
55+
start_obj->loc.inner,
56+
finish_obj->loc.inner));
57+
58+
return 0;
59+
}
60+
3661
PyObject *
3762
PyGccLocation_repr(struct PyGccLocation * self)
3863
{

gcc-python-wrappers.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ extern PyObject *
132132
PyGccPass_New(struct opt_pass *pass);
133133

134134
/* gcc-python-location.c: */
135+
int
136+
PyGccLocation_init(PyGccLocation *self, PyObject *args, PyObject *kwargs);
137+
135138
PyObject *
136139
PyGccLocation_repr(struct PyGccLocation * self);
137140

generate-location-c.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def generate_location():
114114
tp_name = 'gcc.Location',
115115
struct_name = 'PyGccLocation',
116116
tp_new = 'PyType_GenericNew',
117+
tp_init = '(initproc)PyGccLocation_init',
117118
tp_getset = getsettable.identifier,
118119
tp_hash = '(hashfunc)PyGccLocation_hash',
119120
tp_repr = '(reprfunc)PyGccLocation_repr',

0 commit comments

Comments
 (0)