Skip to content

Commit 0a69415

Browse files
committed
gcc.Location: add caret, start, finish attributes
1 parent e3cdf2f commit 0a69415

File tree

4 files changed

+77
-4
lines changed

4 files changed

+77
-4
lines changed

docs/locations.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,27 @@ Locations
6060
if decl.location.in_system_header:
6161
return
6262

63+
From GCC 6 onwards, these values can represent both a caret and a range,
64+
e.g.::
65+
66+
a = (foo && bar)
67+
~~~~~^~~~~~~
68+
69+
.. py:attribute:: caret
70+
71+
(:py:class:`gcc.Location`) The caret location within this location.
72+
In the above example, the caret is on the first '&' character.
73+
74+
.. py:attribute:: start
75+
76+
(:py:class:`gcc.Location`) The start location of this range.
77+
In the above example, the start is on the opening parenthesis.
78+
79+
.. py:attribute:: start
80+
81+
(:py:class:`gcc.Location`) The finish location of this range.
82+
In the above example, the finish is on the closing parenthesis.
83+
6384
.. py:class:: gcc.RichLocation
6485
6586
Wrapper around GCC's `rich_location`, representing one or more locations

gcc-c-api/gcc-location.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
Copyright 2012 David Malcolm <dmalcolm@redhat.com>
3-
Copyright 2012 Red Hat, Inc.
2+
Copyright 2012, 2017 David Malcolm <dmalcolm@redhat.com>
3+
Copyright 2012, 2017 Red Hat, Inc.
44
55
This is free software: you can redistribute it and/or modify it
66
under the terms of the GNU General Public License as published by
@@ -62,6 +62,24 @@ GCC_IMPLEMENT_PUBLIC_API (bool) gcc_location_get_in_system_header (gcc_location
6262
return in_system_header_at (loc.inner);
6363
}
6464

65+
GCC_IMPLEMENT_PUBLIC_API (gcc_location)
66+
gcc_location_get_caret (gcc_location loc)
67+
{
68+
return gcc_private_make_location (get_pure_location (loc.inner));
69+
}
70+
71+
GCC_IMPLEMENT_PUBLIC_API (gcc_location)
72+
gcc_location_get_start (gcc_location loc)
73+
{
74+
return gcc_private_make_location (get_start (loc.inner));
75+
}
76+
77+
GCC_IMPLEMENT_PUBLIC_API (gcc_location)
78+
gcc_location_get_finish (gcc_location loc)
79+
{
80+
return gcc_private_make_location (get_finish (loc.inner));
81+
}
82+
6583
GCC_IMPLEMENT_PUBLIC_API (void) gcc_set_input_location (gcc_location loc)
6684
{
6785
input_location = loc.inner;

gcc-c-api/location.xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
3-
Copyright 2012 David Malcolm <dmalcolm@redhat.com>
4-
Copyright 2012 Red Hat, Inc.
3+
Copyright 2012, 2017 David Malcolm <dmalcolm@redhat.com>
4+
Copyright 2012, 2017 Red Hat, Inc.
55
66
This is free software: you can redistribute it and/or modify it
77
under the terms of the GNU General Public License as published by
@@ -36,6 +36,13 @@
3636

3737
<attribute name="in_system_header" kind="bool">
3838
</attribute>
39+
40+
<attribute name="caret" kind="location">
41+
</attribute>
42+
<attribute name="start" kind="location">
43+
</attribute>
44+
<attribute name="finish" kind="location">
45+
</attribute>
3946
</type>
4047

4148
<attribute name="input_location" kind="location" access="rw">

generate-location-c.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,39 @@ def generate_location():
6060
{
6161
return PyGccInt_FromLong(gcc_location_get_column(self->loc));
6262
}
63+
""")
64+
65+
cu.add_defn("""
66+
static PyObject *
67+
PyGccLocation_get_caret(struct PyGccLocation *self, void *closure)
68+
{
69+
return PyGccLocation_New(gcc_location_get_caret(self->loc));
70+
}
71+
""")
72+
73+
cu.add_defn("""
74+
static PyObject *
75+
PyGccLocation_get_start(struct PyGccLocation *self, void *closure)
76+
{
77+
return PyGccLocation_New(gcc_location_get_start(self->loc));
78+
}
79+
""")
80+
81+
cu.add_defn("""
82+
static PyObject *
83+
PyGccLocation_get_finish(struct PyGccLocation *self, void *closure)
84+
{
85+
return PyGccLocation_New(gcc_location_get_finish(self->loc));
86+
}
6387
""")
6488

6589
getsettable = PyGetSetDefTable('PyGccLocation_getset_table',
6690
[PyGetSetDef('file', 'PyGccLocation_get_file', None, 'Name of the source file'),
6791
PyGetSetDef('line', 'PyGccLocation_get_line', None, 'Line number within source file'),
6892
PyGetSetDef('column', 'PyGccLocation_get_column', None, 'Column number within source file'),
93+
PyGetSetDef('caret', 'PyGccLocation_get_caret', None, 'Location of caret'),
94+
PyGetSetDef('start', 'PyGccLocation_get_start', None, 'Starting location of range'),
95+
PyGetSetDef('finish', 'PyGccLocation_get_finish', None, 'End location of range'),
6996
],
7097
identifier_prefix='PyGccLocation',
7198
typename='PyGccLocation')

0 commit comments

Comments
 (0)