def generate_rich_location(): # # Generate the gcc.RichLocation class: # # class rich_location was added to libcpp in gcc 6. GCC_VERSION = get_gcc_version() if GCC_VERSION < 6000: return global modinit_preinit global modinit_postinit methods = PyMethodTable('PyGccRichLocation_methods', []) methods.add_method('add_fixit_replace', '(PyCFunction)PyGccRichLocation_add_fixit_replace', 'METH_VARARGS | METH_KEYWORDS', "FIXME") cu.add_defn(methods.c_defn()) pytype = PyGccWrapperTypeObject(identifier = 'PyGccRichLocation_TypeObj', localname = 'RichLocation', tp_name = 'gcc.RichLocation', struct_name = 'PyGccRichLocation', tp_new = 'PyType_GenericNew', tp_init = '(initproc)PyGccRichLocation_init', #tp_getset = getsettable.identifier, #tp_hash = '(hashfunc)PyGccRichLocation_hash', #tp_repr = '(reprfunc)PyGccRichLocation_repr', #tp_str = '(reprfunc)PyGccRichLocation_str', tp_methods = methods.identifier, #tp_richcompare = 'PyGccRichLocation_richcompare', tp_dealloc = 'PyGccWrapper_Dealloc') cu.add_defn(pytype.c_defn()) modinit_preinit += pytype.c_invoke_type_ready() modinit_postinit += pytype.c_invoke_add_to_module()
def generate_rich_location(): # # Generate the gcc.RichLocation class: # # class rich_location was added to libcpp in gcc 6. GCC_VERSION = get_gcc_version() if GCC_VERSION < 6000: return global modinit_preinit global modinit_postinit methods = PyMethodTable('PyGccRichLocation_methods', []) methods.add_method('add_fixit_replace', '(PyCFunction)PyGccRichLocation_add_fixit_replace', 'METH_VARARGS | METH_KEYWORDS', "FIXME") cu.add_defn(methods.c_defn()) pytype = PyGccWrapperTypeObject( identifier='PyGccRichLocation_TypeObj', localname='RichLocation', tp_name='gcc.RichLocation', struct_name='PyGccRichLocation', tp_new='PyType_GenericNew', tp_init='(initproc)PyGccRichLocation_init', #tp_getset = getsettable.identifier, #tp_hash = '(hashfunc)PyGccRichLocation_hash', #tp_repr = '(reprfunc)PyGccRichLocation_repr', #tp_str = '(reprfunc)PyGccRichLocation_str', tp_methods=methods.identifier, #tp_richcompare = 'PyGccRichLocation_richcompare', tp_dealloc='PyGccWrapper_Dealloc') cu.add_defn(pytype.c_defn()) modinit_preinit += pytype.c_invoke_type_ready() modinit_postinit += pytype.c_invoke_add_to_module()
cu.add_include("gcc-python.h") cu.add_include("gcc-python-wrappers.h") cu.add_include("gcc-plugin.h") cu.add_include("tree.h") cu.add_include("function.h") cu.add_include("basic-block.h") cu.add_include("cp/cp-tree.h") cu.add_include("c-family/c-common.h") cu.add_include("gcc-c-api/gcc-tree.h") cu.add_include("gcc-c-api/gcc-constant.h") cu.add_include("gcc-c-api/gcc-declaration.h") cu.add_include("gcc-c-api/gcc-type.h") cu.add_include("cp/name-lookup.h") cu.add_include("autogenerated-casts.h") GCCPLUGINS_API_VERSION = get_gcc_version() if GCCPLUGINS_API_VERSION >= 4009: # GCC 4.9 moved debug_tree here: cu.add_include("print-tree.h") modinit_preinit = "" modinit_postinit = "" def generate_tree(): # # Generate the gcc.Tree class: # global modinit_preinit global modinit_postinit
# This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see # <http://www.gnu.org/licenses/>. from maketreetypes import iter_rtl_expr_types #, iter_rtl_struct_types from cpybuilder import * from testcpychecker import get_gcc_version from wrapperbuilder import PyGccWrapperTypeObject GCC_VERSION = get_gcc_version() cu = CompilationUnit() cu.add_include('gcc-python.h') cu.add_include('gcc-python-wrappers.h') cu.add_include('gcc-plugin.h') cu.add_include("rtl.h") modinit_preinit = '' modinit_postinit = '' #rtl_struct_types = list(iter_rtl_struct_types()) rtl_expr_types = list(iter_rtl_expr_types()) #print rtl_types # Should be a three-level hierarchy:
from collections import OrderedDict result = OrderedDict() with open(config_h) as f: for line in f.readlines(): m = re.match('#define (.+)', line) if m: result[m.group(1)] = True m = re.match('#undef (.+)', line) if m: result[m.group(1)] = False return result features = parse_autogenerated_config_h() CC = os.environ.get('CC', 'gcc') GCCPLUGINS_API_VERSION = get_gcc_version() class SkipTest(Exception): def __init__(self, reason): self.reason = reason def run_test(testdir): # Compile each 'input.c', using 'script.py' # Assume success and empty stdout; compare against expected stderr, or empty if file not present inputfiles = get_source_files(testdir) outfile = os.path.join(testdir, 'output.o') script_py = os.path.join(testdir, 'script.py') out = TestStream(os.path.join(testdir, 'stdout.txt')) err = TestStream(os.path.join(testdir, 'stderr.txt')) cp = configparser.SafeConfigParser()
def generate_location(): # # Generate the gcc.Location class: # global modinit_preinit global modinit_postinit cu.add_defn(""" static PyObject * PyGccLocation_get_file(struct PyGccLocation *self, void *closure) { const char *filename = gcc_location_get_filename(self->loc); if (!filename) { Py_RETURN_NONE; } return PyGccString_FromString(filename); } """) cu.add_defn(""" static PyObject * PyGccLocation_get_line(struct PyGccLocation *self, void *closure) { return PyGccInt_FromLong(gcc_location_get_line(self->loc)); } """) cu.add_defn(""" static PyObject * PyGccLocation_get_column(struct PyGccLocation *self, void *closure) { return PyGccInt_FromLong(gcc_location_get_column(self->loc)); } """) if get_gcc_version() >= 7000: cu.add_defn(""" static PyObject * PyGccLocation_get_caret(struct PyGccLocation *self, void *closure) { return PyGccLocation_New(gcc_location_get_caret(self->loc)); } """) cu.add_defn(""" static PyObject * PyGccLocation_get_start(struct PyGccLocation *self, void *closure) { return PyGccLocation_New(gcc_location_get_start(self->loc)); } """) cu.add_defn(""" static PyObject * PyGccLocation_get_finish(struct PyGccLocation *self, void *closure) { return PyGccLocation_New(gcc_location_get_finish(self->loc)); } """) getsettable = PyGetSetDefTable('PyGccLocation_getset_table', [PyGetSetDef('file', 'PyGccLocation_get_file', None, 'Name of the source file'), PyGetSetDef('line', 'PyGccLocation_get_line', None, 'Line number within source file'), PyGetSetDef('column', 'PyGccLocation_get_column', None, 'Column number within source file'), ], identifier_prefix='PyGccLocation', typename='PyGccLocation') if get_gcc_version() >= 7000: getsettable.gsdefs += [PyGetSetDef('caret', 'PyGccLocation_get_caret', None, 'Location of caret'), PyGetSetDef('start', 'PyGccLocation_get_start', None, 'Starting location of range'), PyGetSetDef('finish', 'PyGccLocation_get_finish', None, 'End location of range')] getsettable.add_simple_getter(cu, 'in_system_header', 'PyBool_FromLong(gcc_location_get_in_system_header(self->loc))', 'Boolean: is this location within a system header?') cu.add_defn(getsettable.c_defn()) methods = PyMethodTable('PyGccLocation_methods', []) if get_gcc_version() >= 5000: methods.add_method('offset_column', '(PyCFunction)PyGccLocation_offset_column', 'METH_VARARGS', "") cu.add_defn(methods.c_defn()) pytype = PyGccWrapperTypeObject(identifier = 'PyGccLocation_TypeObj', localname = 'Location', tp_name = 'gcc.Location', struct_name = 'PyGccLocation', tp_new = 'PyType_GenericNew', tp_init = '(initproc)PyGccLocation_init' if get_gcc_version() >= 7000 else None, tp_getset = getsettable.identifier, tp_hash = '(hashfunc)PyGccLocation_hash', tp_repr = '(reprfunc)PyGccLocation_repr', tp_str = '(reprfunc)PyGccLocation_str', tp_methods = methods.identifier, tp_richcompare = 'PyGccLocation_richcompare', tp_dealloc = 'PyGccWrapper_Dealloc') cu.add_defn(pytype.c_defn()) modinit_preinit += pytype.c_invoke_type_ready() modinit_postinit += pytype.c_invoke_add_to_module()
def generate_location(): # # Generate the gcc.Location class: # global modinit_preinit global modinit_postinit cu.add_defn(""" static PyObject * PyGccLocation_get_file(struct PyGccLocation *self, void *closure) { const char *filename = gcc_location_get_filename(self->loc); if (!filename) { Py_RETURN_NONE; } return PyGccString_FromString(filename); } """) cu.add_defn(""" static PyObject * PyGccLocation_get_line(struct PyGccLocation *self, void *closure) { return PyGccInt_FromLong(gcc_location_get_line(self->loc)); } """) cu.add_defn(""" static PyObject * PyGccLocation_get_column(struct PyGccLocation *self, void *closure) { return PyGccInt_FromLong(gcc_location_get_column(self->loc)); } """) if get_gcc_version() >= 7000: cu.add_defn(""" static PyObject * PyGccLocation_get_caret(struct PyGccLocation *self, void *closure) { return PyGccLocation_New(gcc_location_get_caret(self->loc)); } """) cu.add_defn(""" static PyObject * PyGccLocation_get_start(struct PyGccLocation *self, void *closure) { return PyGccLocation_New(gcc_location_get_start(self->loc)); } """) cu.add_defn(""" static PyObject * PyGccLocation_get_finish(struct PyGccLocation *self, void *closure) { return PyGccLocation_New(gcc_location_get_finish(self->loc)); } """) getsettable = PyGetSetDefTable('PyGccLocation_getset_table', [ PyGetSetDef('file', 'PyGccLocation_get_file', None, 'Name of the source file'), PyGetSetDef('line', 'PyGccLocation_get_line', None, 'Line number within source file'), PyGetSetDef('column', 'PyGccLocation_get_column', None, 'Column number within source file'), ], identifier_prefix='PyGccLocation', typename='PyGccLocation') if get_gcc_version() >= 7000: getsettable.gsdefs += [ PyGetSetDef('caret', 'PyGccLocation_get_caret', None, 'Location of caret'), PyGetSetDef('start', 'PyGccLocation_get_start', None, 'Starting location of range'), PyGetSetDef('finish', 'PyGccLocation_get_finish', None, 'End location of range') ] getsettable.add_simple_getter( cu, 'in_system_header', 'PyBool_FromLong(gcc_location_get_in_system_header(self->loc))', 'Boolean: is this location within a system header?') cu.add_defn(getsettable.c_defn()) methods = PyMethodTable('PyGccLocation_methods', []) if get_gcc_version() >= 5000: methods.add_method('offset_column', '(PyCFunction)PyGccLocation_offset_column', 'METH_VARARGS', "") cu.add_defn(methods.c_defn()) pytype = PyGccWrapperTypeObject(identifier='PyGccLocation_TypeObj', localname='Location', tp_name='gcc.Location', struct_name='PyGccLocation', tp_new='PyType_GenericNew', tp_init='(initproc)PyGccLocation_init' if get_gcc_version() >= 7000 else None, tp_getset=getsettable.identifier, tp_hash='(hashfunc)PyGccLocation_hash', tp_repr='(reprfunc)PyGccLocation_repr', tp_str='(reprfunc)PyGccLocation_str', tp_methods=methods.identifier, tp_richcompare='PyGccLocation_richcompare', tp_dealloc='PyGccWrapper_Dealloc') cu.add_defn(pytype.c_defn()) modinit_preinit += pytype.c_invoke_type_ready() modinit_postinit += pytype.c_invoke_add_to_module()