1616# <http://www.gnu.org/licenses/>.
1717
1818from cpybuilder import *
19+ from testcpychecker import get_gcc_version
1920from wrapperbuilder import PyGccWrapperTypeObject
2021
2122cu = CompilationUnit ()
@@ -61,24 +62,22 @@ def generate_location():
6162 return PyGccInt_FromLong(gcc_location_get_column(self->loc));
6263}
6364""" )
64-
65- cu .add_defn ("""
65+ if get_gcc_version () >= 7000 :
66+ cu .add_defn ("""
6667static PyObject *
6768PyGccLocation_get_caret(struct PyGccLocation *self, void *closure)
6869{
6970 return PyGccLocation_New(gcc_location_get_caret(self->loc));
7071}
7172""" )
72-
73- cu .add_defn ("""
73+ cu .add_defn ("""
7474static PyObject *
7575PyGccLocation_get_start(struct PyGccLocation *self, void *closure)
7676{
7777 return PyGccLocation_New(gcc_location_get_start(self->loc));
7878}
7979""" )
80-
81- cu .add_defn ("""
80+ cu .add_defn ("""
8281static PyObject *
8382PyGccLocation_get_finish(struct PyGccLocation *self, void *closure)
8483{
@@ -90,31 +89,33 @@ def generate_location():
9089 [PyGetSetDef ('file' , 'PyGccLocation_get_file' , None , 'Name of the source file' ),
9190 PyGetSetDef ('line' , 'PyGccLocation_get_line' , None , 'Line number within source file' ),
9291 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' ),
9692 ],
9793 identifier_prefix = 'PyGccLocation' ,
9894 typename = 'PyGccLocation' )
95+ if get_gcc_version () >= 7000 :
96+ getsettable .gsdefs += [PyGetSetDef ('caret' , 'PyGccLocation_get_caret' , None , 'Location of caret' ),
97+ PyGetSetDef ('start' , 'PyGccLocation_get_start' , None , 'Starting location of range' ),
98+ PyGetSetDef ('finish' , 'PyGccLocation_get_finish' , None , 'End location of range' )]
9999 getsettable .add_simple_getter (cu ,
100100 'in_system_header' ,
101101 'PyBool_FromLong(gcc_location_get_in_system_header(self->loc))' ,
102102 'Boolean: is this location within a system header?' )
103103 cu .add_defn (getsettable .c_defn ())
104104
105105 methods = PyMethodTable ('PyGccLocation_methods' , [])
106- methods .add_method ('offset_column' ,
107- '(PyCFunction)PyGccLocation_offset_column' ,
108- 'METH_VARARGS' ,
109- "" )
106+ if get_gcc_version () >= 5000 :
107+ methods .add_method ('offset_column' ,
108+ '(PyCFunction)PyGccLocation_offset_column' ,
109+ 'METH_VARARGS' ,
110+ "" )
110111 cu .add_defn (methods .c_defn ())
111112
112113 pytype = PyGccWrapperTypeObject (identifier = 'PyGccLocation_TypeObj' ,
113114 localname = 'Location' ,
114115 tp_name = 'gcc.Location' ,
115116 struct_name = 'PyGccLocation' ,
116117 tp_new = 'PyType_GenericNew' ,
117- tp_init = '(initproc)PyGccLocation_init' ,
118+ tp_init = '(initproc)PyGccLocation_init' if get_gcc_version () >= 7000 else None ,
118119 tp_getset = getsettable .identifier ,
119120 tp_hash = '(hashfunc)PyGccLocation_hash' ,
120121 tp_repr = '(reprfunc)PyGccLocation_repr' ,
@@ -130,6 +131,12 @@ def generate_rich_location():
130131 #
131132 # Generate the gcc.RichLocation class:
132133 #
134+
135+ # class rich_location was added to libcpp in gcc 6.
136+ GCC_VERSION = get_gcc_version ()
137+ if GCC_VERSION < 6000 :
138+ return
139+
133140 global modinit_preinit
134141 global modinit_postinit
135142
0 commit comments