本文整理匯總了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",
#.........這裏部分代碼省略.........
示例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))',
#.........這裏部分代碼省略.........