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


Python PyGccWrapperTypeObject.tp_as_number方法代码示例

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


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

示例1: generate_tree_code_classes

# 需要导入模块: from wrapperbuilder import PyGccWrapperTypeObject [as 别名]
# 或者: from wrapperbuilder.PyGccWrapperTypeObject import tp_as_number [as 别名]
def generate_tree_code_classes():
    # Generate all of the concrete gcc.Tree subclasses based on the:
    #    enum tree_code
    # as subclasses of the above layer:
    global modinit_preinit
    global modinit_postinit

    for tree_type in tree_types:
        base_type = type_for_code_class[tree_type.TYPE]

        cc = tree_type.camel_cased_string()

        getsettable = PyGetSetDefTable(
            "gcc_%s_getset_table" % cc, [], identifier_prefix="gcc_%s" % cc, typename="PyGccTree"
        )

        tp_as_number = None
        tp_repr = None
        tp_str = None

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

        def get_getter_identifier(name):
            return "PyGcc%s_get_%s" % (cc, name)

        def add_simple_getter(name, c_expression, doc):
            getsettable.add_gsdef(
                name, cu.add_simple_getter(get_getter_identifier(name), "PyGccTree", c_expression), None, doc
            )

        def add_complex_getter(name, doc):
            getsettable.add_gsdef(name, get_getter_identifier(name), None, doc)

        if cc == "AddrExpr":
            add_simple_getter(
                "operand",
                "PyGccTree_New(gcc_addr_expr_get_operand(PyGccTree_as_gcc_addr_expr(self)))",
                "The operand of this expression, as a gcc.Tree",
            )

        if cc == "StringCst":
            add_simple_getter(
                "constant",
                "PyGccString_FromString(gcc_string_constant_get_char_ptr(PyGccTree_as_gcc_string_constant(self)))",
                "The actual value of this constant, as a str",
            )
            tp_repr = "(reprfunc)PyGccStringConstant_repr"

        if cc == "IntegerCst":
            getsettable.add_gsdef(
                "constant",
                "PyGccIntegerConstant_get_constant",
                None,
                "The actual value of this constant, as an int/long",
            )
            number_methods = PyNumberMethods("PyGccIntegerConstant_number_methods")
            tp_as_number = number_methods.identifier
            number_methods.nb_int = "PyGccIntegerConstant_get_constant"
            cu.add_defn(number_methods.c_defn())
            tp_repr = "(reprfunc)PyGccIntegerConstant_repr"

        if cc == "RealCst":
            getsettable.add_gsdef(
                "constant", "PyGccRealCst_get_constant", None, "The actual value of this constant, as a float"
            )
            tp_repr = "(reprfunc)PyGccRealCst_repr"

        # TYPE_QUALS for various foo_TYPE classes:
        if tree_type.SYM in (
            "VOID_TYPE",
            "INTEGER_TYPE",
            "REAL_TYPE",
            "FIXED_POINT_TYPE",
            "COMPLEX_TYPE",
            "VECTOR_TYPE",
            "ENUMERAL_TYPE",
            "BOOLEAN_TYPE",
        ):
            for qual in ("const", "volatile", "restrict"):
                add_simple_getter(
                    qual,
                    "PyBool_FromLong(TYPE_QUALS(self->t.inner) & TYPE_QUAL_%s)" % qual.upper(),
                    "Boolean: does this type have the '%s' modifier?" % qual,
                )
                add_simple_getter(
                    "%s_equivalent" % qual,
                    "PyGccTree_New(gcc_private_make_tree(build_qualified_type(self->t.inner, TYPE_QUAL_%s)))"
                    % qual.upper(),
                    "The gcc.Type for the %s version of this type" % qual,
                )
        if tree_type.SYM == "RECORD_TYPE":
            add_simple_getter(
                "const",
                "PyBool_FromLong(TYPE_READONLY(self->t.inner))",
                "Boolean: does this type have the 'const' modifier?",
            )

        if tree_type.SYM == "INTEGER_TYPE":
            add_simple_getter(
                "unsigned",
#.........这里部分代码省略.........
开发者ID:bganne,项目名称:gcc-python-plugin,代码行数:103,代码来源:generate-tree-c.py

示例2: generate_tree_code_classes

# 需要导入模块: from wrapperbuilder import PyGccWrapperTypeObject [as 别名]
# 或者: from wrapperbuilder.PyGccWrapperTypeObject import tp_as_number [as 别名]
def generate_tree_code_classes():
    # Generate all of the concrete gcc.Tree subclasses based on the:
    #    enum tree_code
    # as subclasses of the above layer:
    global modinit_preinit
    global modinit_postinit
    
    for tree_type in tree_types:
        base_type = type_for_code_class[tree_type.TYPE]

        cc = tree_type.camel_cased_string()

        getsettable =  PyGetSetDefTable('gcc_%s_getset_table' % cc, [],
                                        identifier_prefix='gcc_%s' % cc,
                                        typename='PyGccTree')

        tp_as_number = None
        tp_repr = None
        tp_str = None

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

        def get_getter_identifier(name):
            return 'gcc_%s_get_%s' % (cc, name)

        def add_simple_getter(name, c_expression, doc):
            getsettable.add_gsdef(name,
                                  cu.add_simple_getter(get_getter_identifier(name),
                                                       'PyGccTree',
                                                       c_expression),
                                  None,
                                  doc)

        def add_complex_getter(name, doc):
            getsettable.add_gsdef(name,
                                  get_getter_identifier(name),
                                  None,
                                  doc)

        if cc == 'AddrExpr':
            add_simple_getter('operand',
                              'gcc_python_make_wrapper_tree(TREE_OPERAND (self->t, 0))',
                              'The operand of this expression, as a gcc.Tree')

        if cc == 'StringCst':
            add_simple_getter('constant',
                              'gcc_python_string_from_string(TREE_STRING_POINTER(self->t))',
                              'The actual value of this constant, as a str')
            tp_repr = '(reprfunc)gcc_StringConstant_repr'

        if cc == 'IntegerCst':
            getsettable.add_gsdef('constant',
                                  'gcc_IntegerConstant_get_constant',
                                  None,
                                  'The actual value of this constant, as an int/long')
            number_methods = PyNumberMethods('gcc_IntegerConstant_number_methods')
            tp_as_number = number_methods.identifier
            number_methods.nb_int = 'gcc_IntegerConstant_get_constant'
            cu.add_defn(number_methods.c_defn())
            tp_repr = '(reprfunc)gcc_IntegerConstant_repr'

        if cc == 'RealCst':
            getsettable.add_gsdef('constant',
                                  'gcc_RealCst_get_constant',
                                  None,
                                  'The actual value of this constant, as a float')
            tp_repr = '(reprfunc)gcc_RealCst_repr'

        # TYPE_QUALS for various foo_TYPE classes:
        if tree_type.SYM in ('VOID_TYPE', 'INTEGER_TYPE', 'REAL_TYPE', 
                             'FIXED_POINT_TYPE', 'COMPLEX_TYPE', 'VECTOR_TYPE',
                             'ENUMERAL_TYPE', 'BOOLEAN_TYPE'):
            for qual in ('const', 'volatile', 'restrict'):
                add_simple_getter(qual,
                                  'PyBool_FromLong(TYPE_QUALS(self->t) & TYPE_QUAL_%s)' % qual.upper(),
                                  "Boolean: does this type have the '%s' modifier?" % qual)
                add_simple_getter('%s_equivalent' % qual,
                                  'gcc_python_make_wrapper_tree(build_qualified_type(self->t, TYPE_QUAL_%s))' % qual.upper(),
                                  'The gcc.Type for the %s version of this type' % qual)

        if tree_type.SYM == 'INTEGER_TYPE':
            add_simple_getter('unsigned',
                              'PyBool_FromLong(TYPE_UNSIGNED(self->t))',
                              "Boolean: True for 'unsigned', False for 'signed'")
            add_simple_getter('signed_equivalent',
                              'gcc_python_make_wrapper_tree(c_common_signed_type(self->t))',
                              'The gcc.IntegerType for the signed version of this type')
            add_simple_getter('unsigned_equivalent',
                              'gcc_python_make_wrapper_tree(c_common_unsigned_type(self->t))',
                              'The gcc.IntegerType for the unsigned version of this type')
            add_simple_getter('max_value',
                              'gcc_python_make_wrapper_tree(TYPE_MAX_VALUE(self->t))',
                              'The maximum possible value for this type, as a gcc.IntegerCst')
            add_simple_getter('min_value',
                              'gcc_python_make_wrapper_tree(TYPE_MIN_VALUE(self->t))',
                              'The minimum possible value for this type, as a gcc.IntegerCst')

        if tree_type.SYM in ('INTEGER_TYPE', 'REAL_TYPE', 'FIXED_POINT_TYPE'):
            add_simple_getter('precision',
                              'gcc_python_int_from_long(TYPE_PRECISION(self->t))',
#.........这里部分代码省略.........
开发者ID:h4ck3rm1k3,项目名称:gcc-python-plugin,代码行数:103,代码来源:generate-tree-c.py


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