当前位置: 首页>>代码示例>>Python>>正文


Python PyGccWrapperTypeObject.tp_repr方法代码示例

本文整理汇总了Python中wrapperbuilder.PyGccWrapperTypeObject.tp_repr方法的典型用法代码示例。如果您正苦于以下问题:Python PyGccWrapperTypeObject.tp_repr方法的具体用法?Python PyGccWrapperTypeObject.tp_repr怎么用?Python PyGccWrapperTypeObject.tp_repr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wrapperbuilder.PyGccWrapperTypeObject的用法示例。


在下文中一共展示了PyGccWrapperTypeObject.tp_repr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate_intermediate_tree_classes

# 需要导入模块: from wrapperbuilder import PyGccWrapperTypeObject [as 别名]
# 或者: from wrapperbuilder.PyGccWrapperTypeObject import tp_repr [as 别名]
def generate_intermediate_tree_classes():
    # Generate a "middle layer" of gcc.Tree subclasses, corresponding to most of the
    # values of
    #    enum_tree_code_class
    # from GCC's tree.h
    global modinit_preinit
    global modinit_postinit

    for code_type in type_for_code_class.values():
        # We've already built the base class:
        if code_type == "PyGccTree_TypeObj":
            continue

        # Strip off the "PyGcc" prefix and "_TypeObj" suffix:
        localname = code_type[5:-8]

        getsettable = PyGetSetDefTable("gcc_%s_getset_table" % localname, [])

        methods = PyMethodTable("gcc_%s_methods" % localname, [])

        pytype = PyGccWrapperTypeObject(
            identifier=code_type,
            localname=localname,
            tp_name="gcc.%s" % localname,
            struct_name="PyGccTree",
            tp_new="PyType_GenericNew",
            tp_base="&PyGccTree_TypeObj",
            tp_getset=getsettable.identifier,
            tp_methods=methods.identifier,
        )

        def add_simple_getter(name, c_expression, doc):
            getsettable.add_gsdef(
                name, cu.add_simple_getter("PyGcc%s_get_%s" % (localname, name), "PyGccTree", c_expression), None, doc
            )

        if localname == "Declaration":
            cu.add_defn(
                """
PyObject *
PyGccDeclaration_get_name(struct PyGccTree *self, void *closure)
{
    if (DECL_NAME(self->t.inner)) {
        return PyGccString_FromString(IDENTIFIER_POINTER (DECL_NAME (self->t.inner)));
    }
    Py_RETURN_NONE;
}

static PyObject *
PyGccDeclaration_get_location(struct PyGccTree *self, void *closure)
{
    return PyGccLocation_New(gcc_decl_get_location(PyGccTree_as_gcc_decl(self)));
}
"""
            )

            getsettable.add_gsdef("name", "PyGccDeclaration_get_name", None, "The name of this declaration (string)")
            getsettable.add_gsdef(
                "location", "PyGccDeclaration_get_location", None, "The gcc.Location for this declaration"
            )
            add_simple_getter(
                "is_artificial",
                "PyBool_FromLong(gcc_decl_is_artificial(PyGccTree_as_gcc_decl(self)))",
                "Is this a compiler-generated entity?",
            )
            add_simple_getter(
                "is_builtin",
                "PyBool_FromLong(gcc_decl_is_builtin(PyGccTree_as_gcc_decl(self)))",
                "Is this declaration built in by the compiler?",
            )
            pytype.tp_repr = "(reprfunc)PyGccDeclaration_repr"

        if localname == "Type":
            add_simple_getter(
                "name",
                "PyGccTree_New(gcc_type_get_name(PyGccTree_as_gcc_type(self)))",
                "The name of the type as a gcc.Tree, or None",
            )
            add_simple_getter(
                "pointer",
                "PyGccPointerType_New(gcc_type_get_pointer(PyGccTree_as_gcc_type(self)))",
                "The gcc.PointerType representing '(this_type *)'",
            )
            getsettable.add_gsdef(
                "attributes", "PyGccType_get_attributes", None, "The user-defined attributes on this type"
            )
            getsettable.add_gsdef("sizeof", "PyGccType_get_sizeof", None, "sizeof() this type, as a gcc.IntegerCst")

            def add_type(c_expr_for_node, typename):
                # Expose the given global type node within the gcc.Tree API
                #
                # The table is populated by tree.c:build_common_builtin_nodes
                # but unfortunately this seems to be called after our plugin is
                # initialized.
                #
                # Hence we add them as properties, so that they can be looked up on
                # demand, rather than trying to look them up once when the module
                # is set up
                cu.add_defn(
                    """
#.........这里部分代码省略.........
开发者ID:bganne,项目名称:gcc-python-plugin,代码行数:103,代码来源:generate-tree-c.py

示例2: generate_intermediate_tree_classes

# 需要导入模块: from wrapperbuilder import PyGccWrapperTypeObject [as 别名]
# 或者: from wrapperbuilder.PyGccWrapperTypeObject import tp_repr [as 别名]
def generate_intermediate_tree_classes():
    # Generate a "middle layer" of gcc.Tree subclasses, corresponding to most of the
    # values of
    #    enum_tree_code_class
    # from GCC's tree.h
    global modinit_preinit
    global modinit_postinit

    
    for code_type in type_for_code_class.values():
        # We've already built the base class:
        if code_type == 'gcc_TreeType':
            continue

        # Strip off the "gcc_" prefix and "Type" suffix:
        localname = code_type[4:-4]

        getsettable = PyGetSetDefTable('gcc_%s_getset_table' % localname, [])

        methods = PyMethodTable('gcc_%s_methods' % localname, [])

        pytype = PyGccWrapperTypeObject(identifier = code_type,
                              localname = localname,
                              tp_name = 'gcc.%s' % localname,
                              struct_name = 'PyGccTree',
                              tp_new = 'PyType_GenericNew',
                              tp_base = '&gcc_TreeType',
                              tp_getset = getsettable.identifier,
                              tp_methods = methods.identifier)

        def add_simple_getter(name, c_expression, doc):
            getsettable.add_gsdef(name,
                                  cu.add_simple_getter('gcc_%s_get_%s' % (localname, name),
                                                       'PyGccTree',
                                                       c_expression),
                                  None,
                                  doc)

        if localname == 'Declaration':
            cu.add_defn("""
PyObject *
gcc_Declaration_get_name(struct PyGccTree *self, void *closure)
{
    if (DECL_NAME(self->t)) {
        return gcc_python_string_from_string(IDENTIFIER_POINTER (DECL_NAME (self->t)));
    }
    Py_RETURN_NONE;
}

static PyObject *
gcc_Declaration_get_location(struct PyGccTree *self, void *closure)
{
    return gcc_python_make_wrapper_location(DECL_SOURCE_LOCATION(self->t));
}
""")

            getsettable.add_gsdef('name',
                                  'gcc_Declaration_get_name',
                                  None,
                                  'The name of this declaration (string)')
            getsettable.add_gsdef('location',
                                  'gcc_Declaration_get_location',
                                  None,
                                  'The gcc.Location for this declaration')
            add_simple_getter('is_artificial',
                              'PyBool_FromLong(DECL_ARTIFICIAL(self->t))',
                              "Is this a compiler-generated entity?")
            add_simple_getter('is_builtin',
                              'PyBool_FromLong(DECL_IS_BUILTIN(self->t))',
                              "Is this declaration built in by the compiler?")
            pytype.tp_repr = '(reprfunc)gcc_Declaration_repr'

        if localname == 'Type':
            add_simple_getter('name',
                              'gcc_python_make_wrapper_tree(TYPE_NAME(self->t))',
                              "The name of the type as a gcc.Tree, or None")
            add_simple_getter('pointer',
                              'gcc_python_make_wrapper_tree(build_pointer_type(self->t))',
                              "The gcc.PointerType representing '(this_type *)'")
            getsettable.add_gsdef('attributes',
                                  'gcc_Type_get_attributes',
                                  None,
                                  'The user-defined attributes on this type')
            getsettable.add_gsdef('sizeof',
                                  'gcc_Type_get_sizeof',
                                  None,
                                  'sizeof() this type, as a gcc.IntegerCst')

            def add_type(c_expr_for_node, typename):
                # Expose the given global type node within the gcc.Tree API
                #
                # The table is populated by tree.c:build_common_builtin_nodes
                # but unfortunately this seems to be called after our plugin is
                # initialized.
                #
                # Hence we add them as properties, so that they can be looked up on
                # demand, rather than trying to look them up once when the module
                # is set up
                cu.add_defn("""
PyObject*
#.........这里部分代码省略.........
开发者ID:h4ck3rm1k3,项目名称:gcc-python-plugin,代码行数:103,代码来源:generate-tree-c.py


注:本文中的wrapperbuilder.PyGccWrapperTypeObject.tp_repr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。